39#define PyInt_Check PyLong_Check
40#define PyInt_FromLong PyLong_FromLong
41#define PyInt_AsLong PyLong_AsLong
42#define PyInt_Type PyLong_Type
46#define PyString_Check PyUnicode_Check
47#define PyString_AsString PyUnicode_AsUTF8
48#define PyString_FromString PyUnicode_FromString
49#define PyString_FromFormat PyUnicode_FromFormat
52#if PY_MAJOR_VERSION >= 3
53#define PY_RAVE_ATTRO_NAME_TO_STRING PyUnicode_AsUTF8
56#define PY_RAVE_ATTRO_NAME_TO_STRING PyString_AsString
60#define PY_COMPARE_ATTRO_NAME_WITH_STRING(ptr, name) PyPpcAPI_CompareWithASCIIString(ptr, name)
62#define PY_COMPARE_STRING_WITH_ATTRO_NAME(name, ptr) PyPpcAPI_CompareWithASCIIString(ptr, name)
64#if PY_MAJOR_VERSION >= 3
65#define MOD_INIT_ERROR NULL
66#define MOD_INIT_SUCCESS(val) val
67#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
68#define MOD_INIT_DEF(ob, name, doc, methods) \
69 static struct PyModuleDef moduledef = { \
70 PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
71 ob = PyModule_Create(&moduledef);
73#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
74static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
75{ ob->ob_type = type; }
76#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
79#define MOD_INIT_CREATE_CAPI(ptr, name) PyCapsule_New(ptr, name, NULL)
80#define MOD_INIT_IS_CAPI(ptr) PyCapsule_CheckExact(ptr)
81#define MOD_INIT_GET_CAPI(ptr, name) PyCapsule_GetPointer(ptr, name)
82#define MOD_INIT_SETUP_TYPE(itype, otype) Py_SET_TYPE(&itype, otype)
83#define MOD_INIT_VERIFY_TYPE_READY(type) if (PyType_Ready(type) < 0) return MOD_INIT_ERROR
87#define MOD_INIT_SUCCESS(val)
88#define MOD_INIT(name) void init##name(void)
89#define MOD_INIT_DEF(ob, name, doc, methods) \
90 ob = Py_InitModule3(name, methods, doc);
91#define MOD_INIT_CREATE_CAPI(ptr, name) PyCObject_FromVoidPtr(ptr, name)
92#define MOD_INIT_IS_CAPI(ptr) PyCObject_Check(ptr)
93#define MOD_INIT_GET_CAPI(ptr, name) PyCObject_AsVoidPtr(ptr)
94#define MOD_INIT_SETUP_TYPE(itype, otype) itype.ob_type = otype
95#define MOD_INIT_VERIFY_TYPE_READY(type)
101#define MOD_DIR_FORWARD_DECLARE(name) static PyObject* _##name##__dir__(name *self)
103#define MOD_DIR_REFERENCE(name) _##name##__dir__
105#define MOD_DIR_APPEND(list, str) \
107 PyObject *o = PyUnicode_FromString(str); \
109 PyList_Append(list, o); \
113#define MOD_DIR_FUNCTION(name, method_listing) static PyObject * _##name##__dir__(name *self) { \
115 PyObject* rc = PyList_New(0); \
119 while (method_listing[i].ml_name != NULL) { \
120 MOD_DIR_APPEND(rc, method_listing[i++].ml_name); \
132static int PyPpcAPI_CompareWithASCIIString(PyObject* ptr,
const char* name) {
134 if (!PyString_Check(ptr)){
135#ifdef Py_USING_UNICODE
136 if (PyUnicode_Check(ptr)) {
137 PyObject* tmp = PyUnicode_AsEncodedString(ptr, NULL, NULL);
139 result = strcmp(PyString_AsString(tmp), name);
145 result = strcmp(PyString_AsString(ptr), name);