Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

python/rpmrc-py.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include "Python.h"
00008 #ifdef __LCLINT__
00009 #undef  PyObject_HEAD
00010 #define PyObject_HEAD   int _PyObjectHead;
00011 #endif
00012 
00013 #include "structmember.h"
00014 
00015 #include "rpmdebug-py.c"
00016 
00017 #include <rpmcli.h>
00018 
00019 #include "rpmrc-py.h"
00020 
00021 #include "debug.h"
00022 
00023 /*@unchecked@*/
00024 static int _rc_debug = 0;
00025 
00035 
00038 PyObject * rpmrc_AddMacro(/*@unused@*/ PyObject * self, PyObject * args)
00039 {
00040     char * name, * val;
00041 
00042     if (!PyArg_ParseTuple(args, "ss:AddMacro", &name, &val))
00043         return NULL;
00044 
00045     addMacro(NULL, name, NULL, val, -1);
00046 
00047     Py_INCREF(Py_None);
00048     return Py_None;
00049 }
00050 
00053 PyObject * rpmrc_DelMacro(/*@unused@*/ PyObject * self, PyObject * args)
00054 {
00055     char * name;
00056 
00057     if (!PyArg_ParseTuple(args, "s:DelMacro", &name))
00058         return NULL;
00059 
00060     delMacro(NULL, name);
00061 
00062     Py_INCREF(Py_None);
00063     return Py_None;
00064 }
00065 
00066 #if Py_TPFLAGS_HAVE_ITER        /* XXX backport to python-1.5.2 */
00067 
00069 static void rpmrc_dealloc(PyObject * s)
00070         /*@*/
00071 {
00072 if (_rc_debug)
00073 fprintf(stderr, "*** rpmrc_dealloc(%p[%s])\n", s, lbl(s));
00074     PyDict_Type.tp_dealloc(s);
00075 }
00076 
00079 static int rpmrc_print(PyObject * s, FILE *fp, int flags)
00080         /*@*/
00081 {
00082 /*@-formattype@*/
00083 if (_rc_debug)
00084 fprintf(stderr, "*** rpmrc_print(%p[%s],%p,%x)\n", s, lbl(s), fp, flags);
00085 /*@=formattype@*/
00086     return PyDict_Type.tp_print(s, fp, flags);
00087 }
00088 
00091 static int rpmrc_compare(PyObject * a, PyObject * b)
00092         /*@*/
00093 {
00094 if (_rc_debug)
00095 fprintf(stderr, "*** rpmrc_compare(%p[%s],%p[%s])\n", a, lbl(a), b, lbl(b));
00096     return PyDict_Type.tp_compare(a, b);
00097 }
00098 
00101 static PyObject * rpmrc_repr(PyObject * s)
00102         /*@*/
00103 {
00104 if (_rc_debug)
00105 fprintf(stderr, "*** rpmrc_repr(%p[%s])\n", s, lbl(s));
00106     return PyDict_Type.tp_repr(s);
00107 }
00108 
00111 static long rpmrc_hash(PyObject * s)
00112         /*@*/
00113 {
00114     /* XXX dict objects are unhashable */
00115 if (_rc_debug)
00116 fprintf(stderr, "*** rpmrc_hash(%p[%s])\n", s, lbl(s));
00117     return PyDict_Type.tp_hash(s);
00118 }
00119 
00122 static int
00123 rpmrc_length(PyObject * s)
00124         /*@*/
00125 {
00126 if (_rc_debug)
00127 fprintf(stderr, "*** rpmrc_length(%p[%s])\n", s, lbl(s));
00128     return PyDict_Type.tp_as_mapping->mp_length(s);
00129 }
00130 
00133 static PyObject *
00134 rpmrc_subscript(PyObject * s, PyObject * key)
00135         /*@*/
00136 {
00137 if (_rc_debug)
00138 fprintf(stderr, "*** rpmrc_subscript(%p[%s], %p[%s])\n", s, lbl(s), key, lbl(key));
00139     return PyDict_Type.tp_as_mapping->mp_subscript(s, key);
00140 }
00141 
00144 static int
00145 rpmrc_ass_subscript(PyObject * s, PyObject * key, PyObject * value)
00146         /*@*/
00147 {
00148 if (_rc_debug)
00149 fprintf(stderr, "*** rpmrc_ass_subscript(%p[%s], %p[%s], %p[%s])\n", s, lbl(s), key, lbl(key), value, lbl(value));
00150     return PyDict_Type.tp_as_mapping->mp_ass_subscript(s, key, value);
00151 }
00152 
00153 /*@unchecked@*/ /*@observer@*/
00154 static PyMappingMethods rpmrc_as_mapping = {
00155     rpmrc_length,               /* mp_length */
00156     rpmrc_subscript,            /* mp_subscript */
00157     rpmrc_ass_subscript,                /* mp_ass_subscript */
00158 };
00159 
00162 static PyObject * rpmrc_getattro (PyObject *s, PyObject *name)
00163         /*@*/
00164 {
00165 if (_rc_debug)
00166 fprintf(stderr, "*** rpmrc_getattro(%p[%s], \"%s\")\n", s, lbl(s), PyString_AS_STRING(name));
00167     return PyObject_GenericGetAttr(s, name);
00168 }
00169 
00172 static int rpmrc_setattro (PyObject *s, PyObject *name, PyObject * value)
00173         /*@*/
00174 {
00175 if (_rc_debug)
00176 fprintf(stderr, "*** rpmrc_setattro(%p[%s], \"%s \", \"%s\")\n", s, lbl(s), PyString_AS_STRING(name), PyString_AS_STRING(value));
00177     return PyDict_Type.tp_setattro(s, name, value);
00178 }
00179 
00182 /*@unchecked@*/ /*@observer@*/
00183 static char rpmrc_doc[] =
00184 "";
00185 
00188 static int rpmrc_traverse(PyObject * s, visitproc visit, void *arg)
00189         /*@*/
00190 {
00191 if (_rc_debug)
00192 fprintf(stderr, "*** rpmrc_traverse(%p[%s],%p,%p)\n", s, lbl(s), visit, arg);
00193     return PyDict_Type.tp_traverse(s, visit, arg);
00194 }
00195 
00198 static int rpmrc_clear(PyObject * s)
00199         /*@*/
00200 {
00201 if (_rc_debug)
00202 fprintf(stderr, "*** rpmrc_clear(%p[%s])\n", s, lbl(s));
00203     return PyDict_Type.tp_clear(s);
00204 }
00205 
00208 static PyObject * rpmrc_richcompare(PyObject * v, PyObject * w, int op)
00209         /*@*/
00210 {
00211 if (_rc_debug)
00212 fprintf(stderr, "*** rpmrc_richcompare(%p[%s],%p[%s],%x)\n", v, lbl(v), w, lbl(w), op);
00213     return PyDict_Type.tp_richcompare(v, w, op);
00214 }
00215 
00218 static PyObject * rpmrc_iter(PyObject * s)
00219         /*@*/
00220 {
00221 if (_rc_debug)
00222 fprintf(stderr, "*** rpmrc_iter(%p[%s])\n", s, lbl(s));
00223     if (s->ob_type == &PyDictIter_Type)
00224         return PyDictIter_Type.tp_iter(s);
00225     return PyDict_Type.tp_iter(s);
00226 }
00227 
00230 static PyObject * rpmrc_iternext(PyObject * s)
00231         /*@*/
00232 {
00233 if (_rc_debug)
00234 fprintf(stderr, "*** rpmrc_iternext(%p[%s])\n", s, lbl(s));
00235     if (s->ob_type == &PyDictIter_Type)
00236         return PyDictIter_Type.tp_iternext(s);
00237     return NULL;
00238 }
00239 
00242 static PyObject * rpmrc_next(PyObject * s, PyObject *args)
00243         /*@*/
00244 {
00245 if (_rc_debug)
00246 fprintf(stderr, "*** rpmrc_next(%p[%s],%p)\n", s, lbl(s), args);
00247     if (s->ob_type == &PyDictIter_Type)
00248         return PyDictIter_Type.tp_methods[0].ml_meth(s, args);
00249     return NULL;
00250 }
00251 
00254 static int rpmrc_init(PyObject * s, PyObject *args, PyObject *kwds)
00255         /*@*/
00256 {
00257 if (_rc_debug)
00258 fprintf(stderr, "*** rpmrc_init(%p[%s],%p,%p)\n", s, lbl(s), args, kwds);
00259     if (PyDict_Type.tp_init(s, args, kwds) < 0)
00260         return -1;
00261     return 0;
00262 }
00263 
00266 static void rpmrc_free(PyObject * s)
00267         /*@*/
00268 {
00269 if (_rc_debug)
00270 fprintf(stderr, "*** rpmrc_free(%p[%s])\n", s, lbl(s));
00271    _PyObject_GC_Del(s);
00272 }
00273 
00276 static PyObject * rpmrc_alloc(PyTypeObject * subtype, int nitems)
00277         /*@*/
00278 {
00279     PyObject * ns = PyType_GenericAlloc(subtype, nitems);
00280 
00281 if (_rc_debug)
00282 fprintf(stderr, "*** rpmrc_alloc(%p[%s},%d) ret %p[%s]\n", subtype, lbl(subtype), nitems, ns, lbl(ns));
00283     return (PyObject *) ns;
00284 }
00285 
00288 static PyObject * rpmrc_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
00289         /*@*/
00290 {
00291     PyObject * ns;
00292 
00293     /* Derive an initialized dictionary of the appropriate size. */
00294     ns = PyDict_Type.tp_new(&rpmrc_Type, args, kwds);
00295 
00296     /* Perform additional initialization. */
00297     if (rpmrc_init(ns, args, kwds) < 0) {
00298         rpmrc_free(ns);
00299         return NULL;
00300     }
00301 
00302 if (_rc_debug)
00303 fprintf(stderr, "*** rpmrc_new(%p[%s],%p,%p) ret %p[%s]\n", subtype, lbl(subtype), args, kwds, ns, lbl(ns));
00304     return ns;
00305 }
00306 #endif
00307 
00310 /*@-fullinitblock@*/
00311 /*@unchecked@*/ /*@observer@*/
00312 static struct PyMethodDef rpmrc_methods[] = {
00313     { "addMacro",       (PyCFunction) rpmrc_AddMacro, METH_VARARGS,
00314         NULL },
00315     { "delMacro",       (PyCFunction) rpmrc_DelMacro, METH_VARARGS,
00316         NULL },
00317 #if Py_TPFLAGS_HAVE_ITER        /* XXX backport to python-1.5.2 */
00318     { "next",           (PyCFunction) rpmrc_next,     METH_VARARGS,
00319         "next() -- get the next value, or raise StopIteration"},
00320 #endif
00321     {NULL,              NULL}           /* sentinel */
00322 };
00323 /*@=fullinitblock@*/
00324 
00327 /*@-fullinitblock@*/
00328 #if Py_TPFLAGS_HAVE_ITER
00329 PyTypeObject rpmrc_Type = {
00330         PyObject_HEAD_INIT(&PyType_Type)
00331         0,                              /* ob_size */
00332         "rpm.rc",                       /* tp_name */
00333         sizeof(rpmrcObject),            /* tp_size */
00334         0,                              /* tp_itemsize */
00335         (destructor) rpmrc_dealloc,     /* tp_dealloc */
00336         rpmrc_print,                    /* tp_print */
00337         0,                              /* tp_getattr */
00338         0,                              /* tp_setattr */
00339         rpmrc_compare,                  /* tp_compare */
00340         rpmrc_repr,                     /* tp_repr */
00341         0,                              /* tp_as_number */
00342         0,                              /* tp_as_sequence */
00343         &rpmrc_as_mapping,              /* tp_as_mapping */
00344         rpmrc_hash,                     /* tp_hash */
00345         0,                              /* tp_call */
00346         0,                              /* tp_str */
00347         (getattrofunc) rpmrc_getattro,  /* tp_getattro */
00348         (setattrofunc) rpmrc_setattro,  /* tp_setattro */
00349         0,                              /* tp_as_buffer */
00350         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /* tp_flags */
00351         rpmrc_doc,                      /* tp_doc */
00352         rpmrc_traverse,                 /* tp_traverse */
00353         rpmrc_clear,                    /* tp_clear */
00354         rpmrc_richcompare,              /* tp_richcompare */
00355         0,                              /* tp_weaklistoffset */
00356         rpmrc_iter,                     /* tp_iter */
00357         rpmrc_iternext,                 /* tp_iternext */
00358         rpmrc_methods,                  /* tp_methods */
00359         0,                              /* tp_members */
00360         0,                              /* tp_getset */
00361         &PyDict_Type,                   /* tp_base */
00362         0,                              /* tp_dict */
00363         0,                              /* tp_descr_get */
00364         0,                              /* tp_descr_set */
00365         0,                              /* tp_dictoffset */
00366         rpmrc_init,                     /* tp_init */
00367         rpmrc_alloc,                    /* tp_alloc */
00368         rpmrc_new,                      /* tp_new */
00369         rpmrc_free,                     /* tp_free */
00370         0,                              /* tp_is_gc */
00371 };
00372 #else
00373 PyTypeObject rpmrc_Type = {
00374         PyObject_HEAD_INIT(&PyType_Type)
00375         0,                              /* ob_size */
00376         "rpm.rc",                       /* tp_name */
00377         sizeof(rpmrcObject),            /* tp_size */
00378         0,                              /* tp_itemsize */
00379         0,                              /* tp_dealloc */
00380         0,                              /* tp_print */
00381         0,                              /* tp_getattr */
00382         0,                              /* tp_setattr */
00383         0,                              /* tp_compare */
00384         0,                              /* tp_repr */
00385         0,                              /* tp_as_number */
00386         0,                              /* tp_as_sequence */
00387         0,                              /* tp_as_mapping */
00388         0,                              /* tp_hash */
00389         0,                              /* tp_call */
00390         0,                              /* tp_str */
00391         0,                              /* tp_getattro */
00392         0,                              /* tp_setattro */
00393         0,                              /* tp_as_buffer */
00394         0,                              /* tp_flags */
00395         0                               /* tp_doc */
00396 };
00397 #endif
00398 /*@=fullinitblock@*/
00399 
00400 #if Py_TPFLAGS_HAVE_ITER
00401 PyObject * rpmrc_Create(/*@unused@*/ PyObject * self, PyObject *args, PyObject *kwds)
00402 {
00403     return rpmrc_new(&rpmrc_Type, args, kwds);
00404 }
00405 #endif
00406 

Generated on Sun Oct 26 13:02:02 2003 for rpm by doxygen1.2.18