added SQLTable pickle test
[pygr.git] / pygr / default.h
blobf42a6e55717e3d58960be3e51979c524911d53df
2 #ifndef DEFAULT_HEADER_INCLUDED
3 #define DEFAULT_HEADER_INCLUDED 1
5 /* ON LINUX, GIVE US SUPPORT FOR LARGE FILES BY DEFAULT */
6 #define _FILE_OFFSET_BITS 64
7 #define PYGR_OFF_T off_t
9 /* try to get 64 bit fseek on Windows if available, otherwise fall
10 back to regular fseek version. On other platforms use POSIX fseeko */
11 #ifdef __MSVCRT__
12 #define PYGR_FSEEK(IFILE,OFFSET,WHENCE) fseeko64(IFILE,OFFSET,WHENCE)
13 #elif defined(_WIN32)
14 #define PYGR_FSEEK(IFILE,OFFSET,WHENCE) fseek(IFILE,OFFSET,WHENCE)
15 #else
16 #define PYGR_FSEEK(IFILE,OFFSET,WHENCE) fseeko(IFILE,OFFSET,WHENCE)
17 #endif
19 #ifdef BUILD_C_LIBRARY
20 #include <sys/types.h>
21 #else
22 #include "Python.h"
23 #endif
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stddef.h>
27 #include <math.h>
28 #include <string.h>
29 #include <ctype.h>
31 #if defined(__STDC__) || defined(__ANSI_CPP__) /*###################*/
32 #define STRINGIFY(NAME) # NAME
33 #else
34 #define STRINGIFY(NAME) "NAME"
35 #endif
37 #define FREE(P) if (P) {free(P);(P)=NULL;}
40 #ifndef BUILD_C_LIBRARY
41 /* USE THESE DEFINITIONS FOR BUILDING A PYTHON EXTENSION MODULE *****************************/
44 /* IF YOU USE CALLOC, YOUR FUNCTION MUST DEFINE A HANDLER WITH LABEL
45 handle_malloc_failure:
46 THIS HANDLER SHOULD RELEASE ANY TEMPORARILY ALLOCATED MEMORY AND
47 return AN ERROR CODE SIGNALING ITS CALLER THAT IT WAS UNABLE TO
48 ALLOCATE THE DESIRED RESOURCE... */
49 #define MALLOC_FAILURE_ACTION goto handle_malloc_failure
51 /* USE OF THIS MACRO WILL HANDLE MALLOC FAILURES BY
52 RAISING THE APPROPRIATE PYTHON EXCEPTIONS
53 INSTEAD OF CRASHING PYTHON OR FORCING THE PROCESS TO ABORT... */
54 #define CALLOC(memptr,N,ATYPE) \
55 if ((N)<=0) {\
56 char errstr[1024]; \
57 sprintf(errstr,"%s, line %d: *** invalid memory request: %s[%d].\n",\
58 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
59 PyErr_SetString(PyExc_ValueError,errstr); \
60 MALLOC_FAILURE_ACTION;\
62 else if (NULL == ((memptr)=(ATYPE *)calloc((size_t)(N),sizeof(ATYPE)))) { \
63 char errstr[1024]; \
64 sprintf(errstr,"%s, line %d: memory request failed: %s[%d].\n",\
65 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
66 PyErr_SetString(PyExc_MemoryError,errstr); \
67 MALLOC_FAILURE_ACTION;\
70 /* IF realloc FAILS, memptr REMAINS VALID, BUT MALLOC_FAILURE_ACTION IS INVOKED. */
71 #define REALLOC(memptr,N,ATYPE) \
72 if ((N)<=0) {\
73 char errstr[1024]; \
74 sprintf(errstr,"%s, line %d: *** invalid memory request: %s[%d].\n",\
75 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
76 PyErr_SetString(PyExc_ValueError,errstr); \
77 MALLOC_FAILURE_ACTION;\
79 else {\
80 void *tmp_realloc_ptrZZ; \
81 if (NULL == (tmp_realloc_ptrZZ=realloc((memptr),(size_t)(N)*sizeof(ATYPE)))) { \
82 char errstr[1024]; \
83 sprintf(errstr,"%s, line %d: memory request failed: %s[%d].\n",\
84 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
85 PyErr_SetString(PyExc_MemoryError,errstr); \
86 MALLOC_FAILURE_ACTION;\
87 } \
88 else \
89 (memptr)=(ATYPE *)tmp_realloc_ptrZZ; \
93 #else
94 /* USE THESE DEFINITIONS FOR BUILDING A C LIBRARY *****************************/
95 #define MALLOC_FAILURE_ACTION abort()
96 #define CALLOC(memptr,N,ATYPE) \
97 if ((N)<=0) {\
98 fprintf(stderr,"%s, line %d: *** invalid memory request: %s[%d].\n",\
99 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
100 MALLOC_FAILURE_ACTION;\
102 else if (NULL == ((memptr)=(ATYPE *)calloc((size_t)(N),sizeof(ATYPE)))) { \
103 fprintf(stderr,"%s, line %d: memory request failed: %s[%d].\n",\
104 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
105 MALLOC_FAILURE_ACTION;\
108 /* IF realloc FAILS, memptr REMAINS VALID, BUT MALLOC_FAILURE_ACTION IS INVOKED. */
109 #define REALLOC(memptr,N,ATYPE) \
110 if ((N)<=0) {\
111 fprintf(stderr,"%s, line %d: *** invalid memory request: %s[%d].\n",\
112 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
113 MALLOC_FAILURE_ACTION;\
115 else {\
116 void *tmp_realloc_ptrZZ; \
117 if (NULL == (tmp_realloc_ptrZZ=realloc((memptr),(size_t)(N)*sizeof(ATYPE)))) { \
118 fprintf(stderr,"%s, line %d: memory request failed: %s[%d].\n",\
119 __FILE__,__LINE__,STRINGIFY(memptr),(N)); \
120 MALLOC_FAILURE_ACTION;\
122 else \
123 (memptr)=(ATYPE *)tmp_realloc_ptrZZ; \
125 #endif
129 #endif