X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=internals%2F_PDCLIB_config.h;h=41fe02cb3f62711e2ee40b482ef3adc66f3137f7;hb=e802f3cc4c1e7f5b53adf9f3f5f9066195a145b6;hp=74eb290286d8178ca66e6cbb5b0db8fc1af7e286;hpb=d7b8babd5baa57655500362845a6bf78a79a8e16;p=pdclib.old diff --git a/internals/_PDCLIB_config.h b/internals/_PDCLIB_config.h index 74eb290..41fe02c 100644 --- a/internals/_PDCLIB_config.h +++ b/internals/_PDCLIB_config.h @@ -16,6 +16,18 @@ /* The character (sequence) your platform uses as newline. */ #define _PDCLIB_endl "\n" +/* exit() can signal success to the host environment by the value of zero or */ +/* the constant EXIT_SUCCESS. Failure is signaled by EXIT_FAILURE. Note that */ +/* any other return value is "implementation-defined", i.e. your environment */ +/* is not required to handle it gracefully. Set your definitions here. */ +#define _PDCLIB_SUCCESS 0 +#define _PDCLIB_FAILURE -1 + +/* qsort() in requires a function that swaps two memory areas. */ +/* Below is a naive implementation that can be improved significantly for */ +/* specific platforms, e.g. by swapping int instead of char. */ +#define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size ); + /* -------------------------------------------------------------------------- */ /* Integers */ /* -------------------------------------------------------------------------- */ @@ -39,6 +51,30 @@ #define _PDCLIB_LONG_BYTES 4 #define _PDCLIB_LLONG_BYTES 8 +/* defines the div() function family that allows taking quotient */ +/* and remainder of an integer division in one operation. Many platforms */ +/* support this in hardware / opcode, and the standard permits ordering of */ +/* the return structure in any way to fit the hardware. That is why those */ +/* structs can be configured here. */ + +struct _PDCLIB_div_t +{ + int quot; + int rem; +}; + +struct _PDCLIB_ldiv_t +{ + long int quot; + long int rem; +}; + +struct _PDCLIB_lldiv_t +{ + long long int quot; + long long int rem; +}; + /* -------------------------------------------------------------------------- */ /* defines a set of integer types that are of a minimum width, and */ /* "usually fastest" on the system. (If, for example, accessing a single char */ @@ -85,7 +121,7 @@ */ #define _PDCLIB_SIG_ATOMIC INT -/* Result type of the 'sizeof' operator */ +/* Result type of the 'sizeof' operator (must be unsigned) */ #define _PDCLIB_size unsigned int #define _PDCLIB_SIZE UINT @@ -98,6 +134,7 @@ #define _PDCLIB_intptr int #define _PDCLIB_INTPTR INT +/* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */ #define _PDCLIB_intmax long long int #define _PDCLIB_INTMAX LLINT /* You are also required to state the literal suffix for the intmax type */ @@ -162,3 +199,33 @@ typedef char * _PDCLIB_va_list; #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) + +/* -------------------------------------------------------------------------- */ +/* OS "glue" */ +/* This is where PDCLib interfaces with the operating system. The examples */ +/* below are POSIX calls; provide your OS' equivalents. */ +/* -------------------------------------------------------------------------- */ + +/* A system call that terminates the calling process */ +void _exit( int status ) __attribute__(( noreturn )); +#define _PDCLIB_Exit( x ) _exit( x ) + +/* Memory management */ + +/* Set this to the page size of your OS. If your OS does not support paging, set + to an appropriate value. (Too small, and malloc() will call the kernel too + often. Too large, and you will waste memory. +*/ +#define _PDCLIB_PAGESIZE 4096 + +/* Set this to the minimum memory node size. Any malloc() for a smaller siz + will be satisfied by a malloc() of this size instead. +*/ +#define _PDCLIB_MINALLOC 8 + +/* Request another x pages (of size _PDCLIB_PAGESIZE) of memory from the kernel, + or release them back to the kernel if n is negative. + Return a (void *) pointing to the former end-of-heap if successful, NULL + otherwise. +*/ +void * _PDCLIB_allocpages( int n );