1 /* 2 * Copyright 2001-2004 Brandon Long 3 * All Rights Reserved. 4 * 5 * ClearSilver Templating System 6 * 7 * This code is made available under the terms of the ClearSilver License. 8 * http://www.clearsilver.net/license.hdf 9 * 10 */ 11 12 #ifndef __P_NEO_UTIL_H_ 13 #define __P_NEO_UTIL_H_ 1 14 15 #include "util/neo_misc.h" 16 #include "util/neo_hdf.h" 17 18 #ifndef DL_EXPORT 19 #define DL_EXPORT(x) x 20 #endif 21 22 __BEGIN_DECLS 23 24 /* external HDF object interface. */ 25 26 #define P_HDF_TO_OBJECT_NUM 0 27 #define P_HDF_TO_OBJECT_RETURN PyObject * 28 #define P_HDF_TO_OBJECT_PROTO (HDF *data, int dealloc) 29 30 #define P_OBJECT_TO_HDF_NUM 1 31 #define P_OBJECT_TO_HDF_RETURN HDF * 32 #define P_OBJECT_TO_HDF_PROTO (PyObject *ho) 33 34 #define P_NEO_ERROR_NUM 2 35 #define P_NEO_ERROR_RETURN PyObject * 36 #define P_NEO_ERROR_PROTO (NEOERR *err) 37 38 /* external CS object interface */ 39 #define P_CS_TO_OBJECT_NUM 3 40 #define P_CS_TO_OBJECT_RETURN PyObject * 41 #define P_CS_TO_OBJECT_PROTO (CSPARSE *data) 42 43 #define P_NEO_CGI_POINTERS 4 44 45 #ifdef NEO_CGI_MODULE 46 P_HDF_TO_OBJECT_RETURN p_hdf_to_object P_HDF_TO_OBJECT_PROTO; 47 P_OBJECT_TO_HDF_RETURN p_object_to_hdf P_OBJECT_TO_HDF_PROTO; 48 P_NEO_ERROR_RETURN p_neo_error P_NEO_ERROR_PROTO; 49 P_CS_TO_OBJECT_RETURN p_cs_to_object P_CS_TO_OBJECT_PROTO; 50 51 /* other functions */ 52 53 void initneo_util(void); 54 void initneo_cs(void); 55 56 #else 57 static void **NEO_PYTHON_API; 58 59 #define p_hdf_to_object \ 60 (*(P_HDF_TO_OBJECT_RETURN (*)P_HDF_TO_OBJECT_PROTO) NEO_PYTHON_API[P_HDF_TO_OBJECT_NUM]) 61 62 #define p_object_to_hdf \ 63 (*(P_OBJECT_TO_HDF_RETURN (*)P_OBJECT_TO_HDF_PROTO) NEO_PYTHON_API[P_OBJECT_TO_HDF_NUM]) 64 65 #define p_neo_error \ 66 (*(P_NEO_ERROR_RETURN (*)P_NEO_ERROR_PROTO) NEO_PYTHON_API[P_NEO_ERROR_NUM]) 67 68 #define p_cs_to_object \ 69 (*(P_CS_TO_OBJECT_RETURN (*)P_CS_TO_OBJECT_PROTO) NEO_PYTHON_API[P_CS_TO_OBJECT_NUM]) 70 71 #define import_neo_cgi() \ 72 { \ 73 PyObject *module = PyImport_ImportModule("neo_cgi"); \ 74 if (module != NULL) { \ 75 PyObject *module_dict = PyModule_GetDict(module); \ 76 PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \ 77 PyObject *c_api_num_o = PyDict_GetItemString(module_dict, "_C_API_NUM"); \ 78 if (PyInt_AsLong(c_api_num_o) < P_NEO_CGI_POINTERS) { \ 79 PyErr_Format(PyExc_ImportError, "neo_cgi module doesn't match header compiled against, use of this module may cause a core dump: %ld < %ld", PyInt_AsLong(c_api_num_o), (long) P_NEO_CGI_POINTERS); \ 80 } \ 81 if (PyCObject_Check(c_api_object)) { \ 82 NEO_PYTHON_API = (void **)PyCObject_AsVoidPtr(c_api_object); \ 83 } \ 84 } \ 85 } 86 87 #endif 88 89 __END_DECLS 90 91 #endif /* __P_NEO_UTIL_H_ */ 92