35#ifndef PYHLHDFCOMPAT_H
36#define PYHLHDFCOMPAT_H
53#if PY_MAJOR_VERSION >= 3
54#define PyString_FromStringAndSize(str, len) PyUnicode_FromStringAndSize(str, len)
55#define PyInt_Check PyLong_Check
56#define PyInt_FromLong PyLong_FromLong
57#define PyInt_AsLong PyLong_AsLong
58#define PyInt_Type PyLong_Type
59#define PyString_Check PyUnicode_Check
60#define PyString_AsString PyUnicode_AsUTF8
61#define PyString_FromString PyUnicode_FromString
62#define PyString_FromFormat PyUnicode_FromFormat
65#if PY_MAJOR_VERSION >= 3
66#define PY_ATTRO_NAME_TO_STRING PyUnicode_AsUTF8
68#define PY_ATTRO_NAME_TO_STRING PyString_AsString
71#define PY_COMPARE_ATTRO_NAME_WITH_STRING(ptr, name) PyHlhdfAPI_CompareWithASCIIString(ptr, name)
73#define PY_COMPARE_STRING_WITH_ATTRO_NAME(name, ptr) PyHlhdfAPI_CompareWithASCIIString(ptr, name)
75#if PY_MAJOR_VERSION >= 3
76#define MOD_INIT_ERROR NULL
77#define MOD_INIT_SUCCESS(val) val
78#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
80#define MOD_INIT_DEF(ob, name, doc, methods) \
81 static struct PyModuleDef moduledef = { \
82 PyModuleDef_HEAD_INIT, name, doc, -1, methods, NULL, NULL, NULL, NULL }; \
83 ob = PyModule_Create(&moduledef);
85#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
86static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
87{ ob->ob_type = type; }
88#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
91#define MOD_INIT_SETUP_TYPE(itype, otype) Py_SET_TYPE(&itype, otype)
92#define MOD_INIT_VERIFY_TYPE_READY(type) if (PyType_Ready(type) < 0) return MOD_INIT_ERROR
96#define MOD_INIT_SUCCESS(val)
97#define MOD_INIT(name) void init##name(void)
98#define MOD_INIT_DEF(ob, name, doc, methods) \
99 ob = Py_InitModule3(name, methods, doc);
100#define MOD_INIT_SETUP_TYPE(itype, otype) itype.ob_type = otype
101#define MOD_INIT_VERIFY_TYPE_READY(type)
108#define MOD_DIR_FORWARD_DECLARE(name) static PyObject* _##name##__dir__(name *self)
110#define MOD_DIR_REFERENCE(name) _##name##__dir__
112#define MOD_DIR_APPEND(list, str) \
114 PyObject *o = PyUnicode_FromString(str); \
116 PyList_Append(list, o); \
120#define MOD_DIR_FUNCTION(name, method_listing) static PyObject * _##name##__dir__(name *self) { \
122 PyObject* rc = PyList_New(0); \
126 while (method_listing[i].ml_name != NULL) { \
127 MOD_DIR_APPEND(rc, method_listing[i++].ml_name); \
PyObject * PyHlhdf_StringOrUnicode_FromASCII(const char *buffer, Py_ssize_t size)
Tries to get same behaviour for the result returned when getting a string from the data node.
Definition pyhlcompat.c:48
int PyHlhdfAPI_CompareWithASCIIString(PyObject *ptr, const char *name)
Tests if a python object string (or unicode) is equal to name.
Definition pyhlcompat.c:29