root/releases/pkgcore/0.2.3/src/common.h @ marienz%2540gentoo.org-20061129231634-2tu7a1cuxsflpzc4

Revision marienz%2540gentoo.org-20061129231634-2tu7a1cuxsflpzc4, 5.0 KB (checked in by Marien Zwart <marienz@…>, 2 years ago)

Remove redundant semicolons.

Line 
1/*
2 * Copyright: 2006 Brian Harring <ferringb@gmail.com>
3 * License: GPL2
4 *
5 * common macros.
6 */
7
8#ifndef PKGCORE_COMMON_HEADER
9#define PKGCORE_COMMON_HEADER 1
10
11#include <Python.h>
12#include "py24-compatibility.h"
13
14#define PKGCORE_IMMUTABLE_ATTR_BOOL(type, name, attr, test)             \
15static int                                                              \
16type##_set_##attr (type *self, PyObject *v, void *closure)              \
17{                                                                       \
18    PyErr_SetString(PyExc_AttributeError, name" is immutable");         \
19    return -1;                                                          \
20}                                                                       \
21                                                                        \
22static PyObject *                                                       \
23type##_get_##attr (type *self, void *closure)                           \
24{                                                                       \
25    PyObject *s = (test) ? Py_True : Py_False;                          \
26    Py_INCREF(s);                                                       \
27    return s;                                                           \
28}
29
30#define PKGCORE_GETSET(type, doc, attr)         \
31    {doc, (getter)type##_get_##attr ,           \
32        (setter)type##_set_##attr , NULL}
33
34
35#define PKGCORE_FUNC_DESC(meth_name, class_name, func, methargs)        \
36_PKGCORE_FUNC_DESC(meth_name, class_name, func, methargs, 0)
37#define _PKGCORE_FUNC_DESC(meth_name, class_name, func, methargs, desc) \
38                                                                        \
39static PyTypeObject func##_type = {                                     \
40    PyObject_HEAD_INIT(NULL)                                            \
41    0,                                  /* ob_size        */            \
42    class_name,                         /* tp_name        */            \
43    sizeof(PyObject),                   /* tp_basicsize   */            \
44    0,                                  /* tp_itemsize    */            \
45    0,                                  /* tp_dealloc     */            \
46    0,                                  /* tp_print       */            \
47    0,                                  /* tp_getattr     */            \
48    0,                                  /* tp_setattr     */            \
49    0,                                  /* tp_compare     */            \
50    0,                                  /* tp_repr        */            \
51    0,                                  /* tp_as_number   */            \
52    0,                                  /* tp_as_sequence */            \
53    0,                                  /* tp_as_mapping  */            \
54    0,                                  /* tp_hash      */              \
55    (ternaryfunc)func,                  /* tp_call      */              \
56    0,                                  /* tp_str       */              \
57    0,                                  /* tp_getattro  */              \
58    0,                                  /* tp_setattro  */              \
59    0,                                  /* tp_as_buffer */              \
60    Py_TPFLAGS_DEFAULT,                 /* tp_flags     */              \
61    "cpython version of "#meth_name,   /* tp_doc       */               \
62    0,                                  /* tp_traverse  */              \
63    0,                                  /* tp_clear     */              \
64    0,                                  /* tp_richcompare    */         \
65    0,                                  /* tp_weaklistoffset */         \
66    0,                                  /* tp_iter      */              \
67    0,                                  /* tp_iternext  */              \
68    0,                                  /* tp_methods   */              \
69    0,                                  /* tp_members   */              \
70    0,                                  /* tp_getset    */              \
71    0,                                  /* tp_base      */              \
72    0,                                  /* tp_dict      */              \
73    desc,                               /* tp_descr_get */              \
74    0,                                  /* tp_descr_set */              \
75};
76
77#define PKGCORE_FUNC_BINDING(meth_name, class_name, func, methargs)    \
78static PyObject *                                                       \
79func##_get_descr(PyObject *self, PyObject *obj, PyObject *type)         \
80{                                                                       \
81    static PyMethodDef mdef = {meth_name, (PyCFunction)func, methargs,  \
82        NULL};                                                          \
83    return PyCFunction_New(&mdef, obj);                                 \
84}                                                                       \
85                                                                        \
86_PKGCORE_FUNC_DESC(meth_name, class_name, func, methargs,               \
87    func##_get_descr)
88
89#endif
Note: See TracBrowser for help on using the browser.