chiark / gitweb /
General reorganization.
[mLib-python] / grim.h
CommitLineData
20bce5e9 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
579d0169 40/*----- Utilities ---------------------------------------------------------*/
20bce5e9 41
42#define PSIZEOF(x) sizeof(*x)
43
20bce5e9 44#define RETURN_OBJ(obj) do { Py_INCREF(obj); return (obj); } while (0)
45#define RETURN_ME RETURN_OBJ(me)
46#define RETURN_NONE RETURN_OBJ(Py_None)
47#define RETURN_NOTIMPL RETURN_OBJ(Py_NotImplemented)
48
49#define METH(func, doc) \
50 { #func, METHNAME(func), METH_VARARGS, doc },
51#define KWMETH(func, doc) \
52 { #func, (PyCFunction)METHNAME(func), \
53 METH_VARARGS | METH_KEYWORDS, doc },
54
55#define GET(func, doc) \
56 { #func, GETSETNAME(get, func), 0, doc },
57#define GETSET(func, doc) \
58 { #func, GETSETNAME(get, func), GETSETNAME(set, func), doc },
59
60#ifndef PySequence_Fast_ITEMS
61# define PySequence_Fast_ITEMS(o) \
62 (PyList_Check(o) ? &PyList_GET_ITEM(o, 0) : &PyTuple_GET_ITEM(o, 0))
63#endif
64
65#define FREEOBJ(obj) \
66 (((PyObject *)(obj))->ob_type->tp_free((PyObject *)(obj)))
67
68/*----- That's all, folks -------------------------------------------------*/
69
70#ifdef __cplusplus
71 }
72#endif
73
74#endif