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

rpmrc-py.c

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

Generated on Sun Jul 24 03:53:39 2005 for rpm by  doxygen 1.3.9.1