1 /* vim: set expandtab shiftwidth=4 softtabstop=4 cinoptions='\:2=2': */
2 #ifndef __INL_PY_UTILS__
3 #define __INL_PY_UTILS__
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 /* Python 2 => 3 rename */
9 #if PY_MAJOR_VERSION >= 3
10 #define PyInt_FromLong PyLong_FromLong
11 #define PyInt_AsLong PyLong_AsLong
12 #define PyInt_Check PyLong_Check
13 
14 #define PyClass_Check PyType_Check
15 
16 #define staticforward static
17 #define statichere static
18 #endif
19 
20 #ifndef Py_REFCNT /* Python 2.5 does not define this */
21 	#define Py_REFCNT(ob)           (((PyObject*)(ob))->ob_refcnt)
22 #endif
23 
24 /* Before Perl 5.6, this didn't exist */
25 #ifndef SvPV_nolen
26 #define SvPV_nolen(sv) SvPV(sv,PL_na)
27 #endif
28 
29 #ifndef pTHX_
30 # define pTHX_
31 # define aTHX_
32 # define pTHX
33 # define aTHX
34 #endif
35 
36 #ifdef I_PY_DEBUG
37 #define Printf(x) printf x
38 #else
39 #define Printf(x)
40 #endif
41 
42 /* This structure is used to distinguish Python objects from regular
43  * Perl objects. It could also be used to store additional information
44  * about the objects, if necessary. It is a private area -- untouchable
45  * from perl-space.
46  */
47 typedef struct {
48     I32 key; /* to make sure it came from Inline */
49 } _inline_magic;
50 
51 #define INLINE_MAGIC_KEY 0x0DD515FD
52 #define TUPLE_MAGIC_KEY 0x7475706C
53 #define Inline_Magic_Key(mg_ptr) (((_inline_magic*)mg_ptr)->key)
54 #define Inline_Magic_Check(mg_ptr) (Inline_Magic_Key(mg_ptr)==INLINE_MAGIC_KEY)
55 
56 extern PyObject * get_perl_pkg_subs(PyObject *);
57 extern int        perl_pkg_exists(char *, char *);
58 extern PyObject * perl_sub_exists(PyObject *, PyObject *);
59 extern int        py_is_tuple(SV *arr);
60 
61 extern MGVTBL inline_mg_vtbl;
62 /* This is called when Perl deallocates a PerlObj object */
63 extern int free_inline_py_obj(pTHX_ SV* obj, MAGIC *mg);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 #endif
69