-
Notifications
You must be signed in to change notification settings - Fork 13
/
perlmodule.h
84 lines (68 loc) · 2.79 KB
/
perlmodule.h
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
/* vim: set expandtab shiftwidth=4 softtabstop=4 cinoptions='\:2=2': */
#ifndef Py_PERLMODULE_H
#define Py_PERLMODULE_H
#ifdef __cplusplus
extern "C" {
#endif
/* _perl_pkg: a class which wraps Perl packages */
typedef struct {
PyObject_HEAD
PyObject *base; /* the name of the "parent" package */
PyObject *pkg; /* the name of the package */
PyObject *full; /* the fully-qualified name (base::pkg) */
} PerlPkg_object;
/* _perl_obj: a class which wraps Perl objects */
typedef struct {
PyObject_HEAD
PyObject *pkg; /* the name of the package */
SV *obj; /* the blessed Perl object */
} PerlObj_object;
/* _perl_sub: a class which wraps Perl subs and methods */
typedef struct {
PyObject_HEAD
PyObject *pkg; /* the (fully-qualified) name of the package */
PyObject *sub; /* the (unqualified) name of the sub */
PyObject *full; /* the (fully-qualified) name of the sub */
SV *ref; /* reference to the Perl subroutine (if found) */
SV *obj; /* reference to a Perl object (if a method) */
int conf; /* flag: is this sub/method confirmed to exist? */
I32 flgs; /* flags to pass to perl_call_sv() */
PyObject* (*cfun)(PyObject *self, PyObject *args); /* a regular Python function */
} PerlSub_object;
extern PyTypeObject PerlPkg_type, PerlObj_type, PerlSub_type;
#ifndef PyVarObject_HEAD_INIT /* Python 2.5 does not define this*/
#define PyVarObject_HEAD_INIT(type, size) \
PyObject_HEAD_INIT(type) size,
#endif
#ifndef Py_TYPE /* Python 2.5 does not define this*/
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif
#define PerlPkgObject_Check(v) (Py_TYPE(v) == &PerlPkg_type)
#define PerlObjObject_Check(v) (Py_TYPE(v) == &PerlObj_type)
#define PerlSubObject_Check(v) (Py_TYPE(v) == &PerlSub_type)
#if PY_MAJOR_VERSION >= 3
#define PKG_EQ(obj,pkg) (strcmp(PyBytes_AsString((obj)->full), (pkg))==0)
#else
#define PKG_EQ(obj,pkg) (strcmp(PyString_AsString((obj)->full), (pkg))==0)
#endif
/* Macro for returning Py_NotImplemented from a function */
#ifndef Py_RETURN_NOTIMPLEMENTED /* Python 3.1 does not define this*/
#define Py_RETURN_NOTIMPLEMENTED \
return Py_INCREF(Py_NotImplemented), Py_NotImplemented
#endif
/***************************************
* METHOD DECLARATIONS *
***************************************/
/* methods of _perl_pkg */
extern PyObject * newPerlPkg_object(PyObject *, PyObject *);
/* methods of _perl_obj */
extern PyObject * newPerlObj_object(SV *, PyObject *);
/* methods of _perl_sub */
extern PyObject * newPerlSub_object(PyObject *, PyObject *, SV *);
extern PyObject * newPerlMethod_object(PyObject*, PyObject*, SV*);
extern PyObject * newPerlCfun_object(PyObject* (*)(PyObject *, PyObject *));
extern void initperl(void);
#ifdef __cplusplus
}
#endif
#endif