File: p_neo_util.h

package info (click to toggle)
clearsilver 0.10.5-1.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,276 kB
  • sloc: ansic: 24,586; python: 4,233; sh: 2,502; cs: 1,429; ruby: 819; java: 735; makefile: 602; perl: 118; lisp: 34; sql: 21
file content (91 lines) | stat: -rw-r--r-- 2,554 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Copyright 2001-2004 Brandon Long
 * All Rights Reserved.
 *
 * ClearSilver Templating System
 *
 * This code is made available under the terms of the ClearSilver License.
 * http://www.clearsilver.net/license.hdf
 *
 */

#ifndef __P_NEO_UTIL_H_
#define __P_NEO_UTIL_H_ 1

#include "util/neo_misc.h"
#include "util/neo_hdf.h"

#ifndef DL_EXPORT
#define DL_EXPORT(x)	x
#endif

__BEGIN_DECLS

/* external HDF object interface. */

#define P_HDF_TO_OBJECT_NUM 0
#define P_HDF_TO_OBJECT_RETURN PyObject *
#define P_HDF_TO_OBJECT_PROTO (HDF *data, int dealloc)

#define P_OBJECT_TO_HDF_NUM 1
#define P_OBJECT_TO_HDF_RETURN HDF *
#define P_OBJECT_TO_HDF_PROTO (PyObject *ho)

#define P_NEO_ERROR_NUM 2
#define P_NEO_ERROR_RETURN PyObject *
#define P_NEO_ERROR_PROTO (NEOERR *err)

/* external CS object interface */
#define P_CS_TO_OBJECT_NUM 3
#define P_CS_TO_OBJECT_RETURN PyObject *
#define P_CS_TO_OBJECT_PROTO (CSPARSE *data)

#define P_NEO_CGI_POINTERS 4

#ifdef NEO_CGI_MODULE
P_HDF_TO_OBJECT_RETURN p_hdf_to_object P_HDF_TO_OBJECT_PROTO;
P_OBJECT_TO_HDF_RETURN p_object_to_hdf P_OBJECT_TO_HDF_PROTO;
P_NEO_ERROR_RETURN p_neo_error P_NEO_ERROR_PROTO;
P_CS_TO_OBJECT_RETURN p_cs_to_object P_CS_TO_OBJECT_PROTO;

/* other functions */

void initneo_util(void);
void initneo_cs(void);

#else
static void **NEO_PYTHON_API;

#define p_hdf_to_object \
  (*(P_HDF_TO_OBJECT_RETURN (*)P_HDF_TO_OBJECT_PROTO) NEO_PYTHON_API[P_HDF_TO_OBJECT_NUM])

#define p_object_to_hdf \
  (*(P_OBJECT_TO_HDF_RETURN (*)P_OBJECT_TO_HDF_PROTO) NEO_PYTHON_API[P_OBJECT_TO_HDF_NUM])

#define p_neo_error \
  (*(P_NEO_ERROR_RETURN (*)P_NEO_ERROR_PROTO) NEO_PYTHON_API[P_NEO_ERROR_NUM])

#define p_cs_to_object \
  (*(P_CS_TO_OBJECT_RETURN (*)P_CS_TO_OBJECT_PROTO) NEO_PYTHON_API[P_CS_TO_OBJECT_NUM])

#define import_neo_cgi() \
{ \
  PyObject *module = PyImport_ImportModule("neo_cgi"); \
  if (module != NULL) { \
    PyObject *module_dict = PyModule_GetDict(module); \
    PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
    PyObject *c_api_num_o = PyDict_GetItemString(module_dict, "_C_API_NUM"); \
    if (PyInt_AsLong(c_api_num_o) < P_NEO_CGI_POINTERS) { \
      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); \
    } \
    if (PyCObject_Check(c_api_object)) { \
      NEO_PYTHON_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
    } \
  } \
}

#endif

__END_DECLS

#endif /* __P_NEO_UTIL_H_ */