chiark / gitweb /
d7ecbe2c8ffbf3e6232b10542a06b7fd985e5018
[mLib-python] / grim.h
1 /* -*-c-*-
2  *
3  * $Id$
4  *
5  * Grim hacks to support the Pyrex code
6  *
7  * (c) 2005 Straylight/Edgeware
8  */
9
10 /*----- Licensing notice --------------------------------------------------* 
11  *
12  * This file is part of the Python interface to mLib.
13  *
14  * mLib/Python is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  * 
19  * mLib/Python is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with mLib/Python; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27  */
28
29 #ifndef GRIM_H
30 #define GRIM_H
31
32 #ifdef __cplusplus
33   extern "C" {
34 #endif
35
36 /*----- Header files ------------------------------------------------------*/
37
38 #include <Python.h>
39
40 /*----- Functions provided ------------------------------------------------*/
41
42 #define PSIZEOF(x) sizeof(*x)
43
44 /*----- Utilities ---------------------------------------------------------*/
45
46 #define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
47 #define RETURN_ME RETURN_OBJ(me)
48 #define RETURN_NONE RETURN_OBJ(Py_None)
49 #define RETURN_NOTIMPL RETURN_OBJ(Py_NotImplemented)
50
51 #define METH(func, doc)                                                 \
52   { #func, METHNAME(func), METH_VARARGS, doc },
53 #define KWMETH(func, doc)                                               \
54   { #func, (PyCFunction)METHNAME(func),                                 \
55     METH_VARARGS | METH_KEYWORDS, doc },
56
57 #define GET(func, doc)                                                  \
58   { #func, GETSETNAME(get, func), 0, doc },
59 #define GETSET(func, doc)                                               \
60   { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc },
61
62 #ifndef PySequence_Fast_ITEMS
63 #  define PySequence_Fast_ITEMS(o)                                      \
64   (PyList_Check(o) ? &PyList_GET_ITEM(o, 0) : &PyTuple_GET_ITEM(o, 0))
65 #endif
66
67 #define FREEOBJ(obj)                                                    \
68   (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
69
70 /*----- That's all, folks -------------------------------------------------*/
71
72 #ifdef __cplusplus
73   }
74 #endif
75
76 #endif