29 #include <longintrepr.h>
46 #define CPY_LOCK_THREADS \
48 PyGILState_STATE gil_state; \
49 gil_state = PyGILState_Ensure();
51 #define CPY_RETURN_FROM_THREADS \
52 PyGILState_Release(gil_state); \
55 #define CPY_RELEASE_THREADS \
56 PyGILState_Release(gil_state); \
66 #define CPY_SUBSTITUTE(func, a, ...) \
69 PyObject *__tmp = (a); \
70 (a) = func(__VA_ARGS__); \
78 #if PY_MAJOR_VERSION >= 3
84 #define PyInt_FromLong PyLong_FromLong
85 #define CPY_INIT_TYPE PyVarObject_HEAD_INIT(NULL, 0)
86 #define IS_BYTES_OR_UNICODE(o) (PyUnicode_Check(o) || PyBytes_Check(o))
87 #define CPY_STRCAT_AND_DEL(a, b) \
89 CPY_STRCAT((a), (b)); \
92 static inline void CPY_STRCAT(PyObject **a, PyObject *b) {
98 ret = PyUnicode_Concat(*a, b);
105 #define CPY_INIT_TYPE PyObject_HEAD_INIT(NULL) 0,
106 #define IS_BYTES_OR_UNICODE(o) (PyUnicode_Check(o) || PyString_Check(o))
107 #define CPY_STRCAT_AND_DEL PyString_ConcatAndDel
108 #define CPY_STRCAT PyString_Concat
112 static inline const char *cpy_unicode_or_bytes_to_string(PyObject **o) {
113 if (PyUnicode_Check(*o)) {
115 tmp = PyUnicode_AsEncodedString(*o, NULL, NULL);
122 return PyBytes_AsString(*o);
124 return PyString_AsString(*o);
128 static inline PyObject *cpy_string_to_unicode_or_bytes(
const char *buf) {
132 ret = PyUnicode_Decode(buf, strlen(buf), NULL, NULL);
136 return PyBytes_FromString(buf);
138 return PyString_FromString(buf);
142 void cpy_log_exception(
const char *context);
155 extern PyTypeObject ConfigType;
162 char host[DATA_MAX_NAME_LEN];
163 char plugin[DATA_MAX_NAME_LEN];
164 char plugin_instance[DATA_MAX_NAME_LEN];
165 char type[DATA_MAX_NAME_LEN];
166 char type_instance[DATA_MAX_NAME_LEN];
168 extern PyTypeObject PluginDataType;
169 #define PluginData_New() \
170 PyObject_CallFunctionObjArgs((PyObject *)&PluginDataType, (void *)0)
178 extern PyTypeObject ValuesType;
179 #define Values_New() \
180 PyObject_CallFunctionObjArgs((PyObject *)&ValuesType, (void *)0)
186 char message[NOTIF_MAX_MSG_LEN];
188 extern PyTypeObject NotificationType;
189 #define Notification_New() \
190 PyObject_CallFunctionObjArgs((PyObject *)&NotificationType, (void *)0)
192 typedef PyLongObject Signed;
193 extern PyTypeObject SignedType;
195 typedef PyLongObject Unsigned;
196 extern PyTypeObject UnsignedType;