6.2.4.5. Marc-Andre's Generic header for mx extensions

Comienzo C section to interscript/core/mxh.h[1 /1 ]
     1: #line 2641 "mxTools.pak"
     2: #ifndef MXH_H
     3: #define MXH_H
     4: 
     5: /*
     6:   mxh.h -- Generic header file for mx extenstions
     7: 
     8:   This file should be included by every mx extension header file
     9:   and the C file.
    10: 
    11:   (c) Marc-Andre Lemburg; All Rights Reserved; mailto: mal@lemburg.com
    12:   See the documentation for further copyright information or contact
    13:   the author.
    14: 
    15: */
    16: 
    17: /* We use our own definitions since Python's don't allow specifying
    18:    both imported and exported symbols at the same time; these
    19:    defines haven't been thoroughly tested yet, patches are most
    20:    welcome :-)
    21: */
    22: 
    23: /* Macro to "mark" a symbol for DLL export */
    24: 
    25: #if defined(_MSC_VER) && _MSC_VER > 850 /* MS VC++ 2.0 and up */
    26: #   define MX_EXPORT(type) type __declspec(dllexport)
    27: #elif defined(__WATCOMC__)
    28: #   define MX_EXPORT(type) type __export
    29: #else
    30: #   define MX_EXPORT(type) type
    31: #endif
    32: 
    33: /* Macro to "mark" a symbol for DLL import */
    34: 
    35: #if defined(__BORLANDC__)
    36: #   define MX_IMPORT(type) extern type __import
    37: #elif defined(_MSC_VER) && _MSC_VER > 850 /* MS VC++ 2.0 and up */
    38: #   define MX_IMPORT(type) extern "C" type __declspec(dllimport)
    39: #else
    40: #   define MX_IMPORT(type) extern type
    41: #endif
    42: 
    43: /* EOF */
    44: #endif
    45: 
End C section to interscript/core/mxh.h[1]
Comienzo C section to interscript/core/mxstdlib.h[1 /1 ]
     1: #line 2686 "mxTools.pak"
     2: #ifndef MXSTDLIB_H
     3: #define MXSTDLIB_H
     4: 
     5: /* Standard stuff I use often -- not Python specific
     6: 
     7:    (c) Marc-Andre Lemburg; All Rights Reserved; mailto: mal@lemburg.com
     8:    See the documentation for further copyright information or contact
     9:    the author.
    10: 
    11:  */
    12: 
    13: #include <stdlib.h>
    14: #include <stdio.h>
    15: #include <stdarg.h>
    16: #include <string.h>
    17: #include <time.h>
    18: #include <math.h>
    19: #ifdef HAVE_LIMITS_H
    20: #include <limits.h>
    21: #else
    22: #define INT_MAX 2147483647
    23: #endif
    24: 
    25: /* --- My own macros for memory allocation... --------------------------- */
    26: 
    27: #ifdef MAL_MEM_DEBUG
    28: # define newstruct(x) \
    29:          (mxDebugPrintf("* malloc for struct "#x" (%s:%i)\n",__FILE__,__LINE__),\
    30:           (x *)malloc(sizeof(x)))
    31: # define cnewstruct(x) \
    32:          (mxDebugPrintf("* calloc for struct "#x" (%s:%i)\n",c,__FILE__,__LINE__),\
    33:           (x *)calloc(sizeof(x),1))
    34: # define new(x,c) \
    35:          (mxDebugPrintf("* malloc for "#c"=%i '"#x"'s (%s:%i)\n",c,__FILE__,__LINE__),\
    36:           (x *)malloc(sizeof(x)*(c)))
    37: # define cnew(x,c) \
    38:          (mxDebugPrintf("* calloc for "#c"=%i '"#x"'s (%s:%i)\n",c,__FILE__,__LINE__),\
    39:           (x *)calloc((c),sizeof(x)))
    40: # define resize(var,x,c) \
    41:          (mxDebugPrintf("* realloc "#x" at %X to size "#c"=%i (%s:%i)\n",x,c,__FILE__,__LINE__),\
    42:           (x *)realloc((void*)(var),sizeof(x)*(c)))
    43: # define free(x) \
    44:          (mxDebugPrintf("* freeing "#x" at %X (%s:%i)\n",x,__FILE__,__LINE__),\
    45:           free((void*)(x)))
    46: #else
    47: # define newstruct(x)           (x *)malloc(sizeof(x))
    48: # define cnewstruct(x)          (x *)calloc(sizeof(x),1)
    49: # define new(x,c)               (x *)malloc(sizeof(x)*(c))
    50: # define cnew(x,c)              (x *)calloc((c),sizeof(x))
    51: # define resize(var,x,c)        (x *)realloc((void*)(var),sizeof(x)*(c))
    52: # define free(x)                free((void*)(x))
    53: #endif
    54: 
    55: /* --- Debugging output ------------------------------------------------- */
    56: 
    57: /* Indicator for the availability of these interfaces: */
    58: 
    59: #define HAVE_MAL_DEBUG
    60: 
    61: /* File name to be used for debug logging (each object file using this
    62:    facility may set its own logging file): */
    63: 
    64: #ifndef MAL_DEBUG_OUTPUTFILE
    65: # define MAL_DEBUG_OUTPUTFILE "stderr"
    66: #endif
    67: 
    68: /* Log id to be used */
    69: 
    70: #ifndef MAL_DEBUG_LOGID
    71: # define MAL_DEBUG_LOGID "New Log Session"
    72: #endif
    73: 
    74: static
    75: void mxDebugPrintf(const char *format, ...)
    76: {
    77:     va_list args;
    78:     static FILE *mxDebugPrintf_file;
    79: 
    80:     if (!mxDebugPrintf_file) {
    81:         time_t now;
    82: 
    83:         now = time(NULL);
    84:         if (strcmp(MAL_DEBUG_OUTPUTFILE,"stdout") == 0)
    85:             mxDebugPrintf_file = stdout;
    86:         else if (strcmp(MAL_DEBUG_OUTPUTFILE,"stderr") == 0)
    87:             mxDebugPrintf_file = stderr;
    88:         else
    89:             mxDebugPrintf_file = fopen(MAL_DEBUG_OUTPUTFILE,"ab");
    90:         if (!mxDebugPrintf_file) {
    91:             /* Hack to shut up "cc -Wall" warning that this function
    92:                was not used... */
    93:             static void *mxDebugPrintf_used;
    94:             mxDebugPrintf_used = (void *)mxDebugPrintf;
    95:             /* Default to stderr in case the log file cannot be opened */
    96:             mxDebugPrintf_file = stderr;
    97:             fprintf(mxDebugPrintf_file,
    98:                     "\n*** Failed to open log file '"MAL_DEBUG_LOGID"'; "
    99:                     "using stderr\n");
   100:         }
   101:         fprintf(mxDebugPrintf_file,
   102:                 "\n--- "MAL_DEBUG_LOGID" --- %s\n",
   103:                 ctime(&now));
   104:     }
   105: 
   106:     va_start(args,format);
   107:     vfprintf(mxDebugPrintf_file,format,args);
   108:     fflush(mxDebugPrintf_file);
   109:     va_end(args);
   110:     return;
   111: }
   112: 
   113: #ifdef MAL_DEBUG
   114: # if defined(PyFloat_AS_DOUBLE) /* check whether we're compiling a Python ext. */
   115: #  define DPRINTF if (Py_DebugFlag) mxDebugPrintf
   116: #  define IF_DEBUGGING if (Py_DebugFlag)
   117: # else
   118: #  define DPRINTF mxDebugPrintf
   119: #  define IF_DEBUGGING
   120: # endif
   121: #else
   122: # define DPRINTF if (0) mxDebugPrintf
   123: # define IF_DEBUGGING if (0)
   124: #endif
   125: 
   126: /* --- Misc ------------------------------------------------------------- */
   127: 
   128: /* The usual bunch... */
   129: #ifndef max
   130: #define max(a,b) ((a>b)?(a):(b))
   131: #endif
   132: #ifndef min
   133: #define min(a,b) ((a<b)?(a):(b))
   134: #endif
   135: 
   136: /* EOF */
   137: #endif
   138: 
End C section to interscript/core/mxstdlib.h[1]