2 * collectd - src/cpython.h
3 * Copyright (C) 2009 Sven Trenkel
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Sven Trenkel <collectd at semidefinite.de>
27 /* These two macros are basicly Py_BEGIN_ALLOW_THREADS and Py_BEGIN_ALLOW_THREADS
28 * from the other direction. If a Python thread calls a C function
29 * Py_BEGIN_ALLOW_THREADS is used to allow other python threads to run because
30 * we don't intend to call any Python functions.
32 * These two macros are used whenever a C thread intends to call some Python
33 * function, usually because some registered callback was triggered.
34 * Just like Py_BEGIN_ALLOW_THREADS it opens a block so these macros have to be
35 * used in pairs. They aquire the GIL, create a new Python thread state and swap
36 * the current thread state with the new one. This means this thread is now allowed
37 * to execute Python code. */
39 #define CPY_LOCK_THREADS {\
40 PyGILState_STATE gil_state;\
41 gil_state = PyGILState_Ensure();
43 #define CPY_RETURN_FROM_THREADS \
44 PyGILState_Release(gil_state);\
47 #define CPY_RELEASE_THREADS \
48 PyGILState_Release(gil_state);\
51 /* Python 2.4 has this macro, older versions do not. */
53 #define Py_VISIT(o) do {\
56 _vret = visit((o), arg);\
63 /* Python 2.4 has this macro, older versions do not. */
65 #define Py_CLEAR(o) do {\
72 /* Python 2.4 has this macro, older versions do not. */
73 #ifndef Py_RETURN_NONE
74 # define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
78 PyObject_HEAD /* No semicolon! */
79 PyObject *parent; /* Config */
80 PyObject *key; /* String */
81 PyObject *values; /* Sequence */
82 PyObject *children; /* Sequence */
85 PyTypeObject ConfigType;
88 PyObject_HEAD /* No semicolon! */
90 char host[DATA_MAX_NAME_LEN];
91 char plugin[DATA_MAX_NAME_LEN];
92 char plugin_instance[DATA_MAX_NAME_LEN];
93 char type[DATA_MAX_NAME_LEN];
94 char type_instance[DATA_MAX_NAME_LEN];
97 PyTypeObject PluginDataType;
101 PyObject *values; /* Sequence */
105 PyTypeObject ValuesType;
110 char message[NOTIF_MAX_MSG_LEN];
113 PyTypeObject NotificationType;