1#include "Python.h" 2 3#ifdef UNUSED 4#elif defined(__GNUC__) 5# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) 6#elif defined(__LCLINT__) 7# define UNUSED(x) /*@unused@*/ x 8#else 9# define UNUSED(x) x 10#endif 11 12#define py_decref(x) { if (x) Py_DECREF(x); } 13 14static int py_append_string(PyObject *list, const char* value) 15{ 16 int rt; 17 PyObject *obj = PyString_FromString(value); 18 if (!obj) return -1; 19 rt = PyList_Append(list, obj); 20 Py_DECREF(obj); 21 return rt; 22} 23 24static int py_append_obj(PyObject *list, PyObject *obj) 25{ 26 int rt; 27 if (!obj) return -1; 28 rt = PyList_Append(list, obj); 29 return rt; 30} 31 32static int py_insert_obj(PyObject *dict, const char *name, PyObject *obj) 33{ 34 int rt; 35 if (!obj) return -1; 36 rt = PyDict_SetItemString(dict, name, obj); 37 return rt; 38} 39 40static int py_insert_string(PyObject *dict, const char *name, const char* value) 41{ 42 int rt; 43 PyObject *obj = PyString_FromString(value); 44 if (!obj) return -1; 45 rt = PyDict_SetItemString(dict, name, obj); 46 Py_DECREF(obj); 47 return rt; 48} 49 50 51