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 "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 *
00033 rpmrc_AddMacro(/*@unused@*/ PyObject * self, PyObject * args, PyObject * kwds)
00034 {
00035     char * name, * val;
00036     char * kwlist[] = {"name", "value", NULL};
00037 
00038     if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss:AddMacro", kwlist,
00039             &name, &val))
00040         return NULL;
00041 
00042     addMacro(NULL, name, NULL, val, -1);
00043 
00044     Py_INCREF(Py_None);
00045     return Py_None;
00046 }
00047 
00050 PyObject *
00051 rpmrc_DelMacro(/*@unused@*/ PyObject * self, PyObject * args, PyObject * kwds)
00052 {
00053     char * name;
00054     char * kwlist[] = {"name", NULL};
00055 
00056     if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:DelMacro", kwlist, &name))
00057         return NULL;
00058 
00059     delMacro(NULL, name);
00060 
00061     Py_INCREF(Py_None);
00062     return Py_None;
00063 }
00064 
00067 #if Py_TPFLAGS_HAVE_ITER        /* XXX backport to python-1.5.2 */
00068 
00070 static void rpmrc_dealloc(PyObject * s)
00071         /*@*/
00072 {
00073 if (_rc_debug)
00074 fprintf(stderr, "*** rpmrc_dealloc(%p[%s])\n", s, lbl(s));
00075     PyDict_Type.tp_dealloc(s);
00076 }
00077 
00080 static int rpmrc_print(PyObject * s, FILE *fp, int flags)
00081         /*@*/
00082 {
00083 /*@-formattype@*/
00084 if (_rc_debug)
00085 fprintf(stderr, "*** rpmrc_print(%p[%s],%p,%x)\n", s, lbl(s), fp, flags);
00086 /*@=formattype@*/
00087     return PyDict_Type.tp_print(s, fp, flags);
00088 }
00089 
00092 static int rpmrc_compare(PyObject * a, PyObject * b)
00093         /*@*/
00094 {
00095 if (_rc_debug)
00096 fprintf(stderr, "*** rpmrc_compare(%p[%s],%p[%s])\n", a, lbl(a), b, lbl(b));
00097     return PyDict_Type.tp_compare(a, b);
00098 }
00099 
00102 static PyObject * rpmrc_repr(PyObject * s)
00103         /*@*/
00104 {
00105 if (_rc_debug)
00106 fprintf(stderr, "*** rpmrc_repr(%p[%s])\n", s, lbl(s));
00107     return PyDict_Type.tp_repr(s);
00108 }
00109 
00112 static long rpmrc_hash(PyObject * s)
00113         /*@*/
00114 {
00115     /* XXX dict objects are unhashable */
00116 if (_rc_debug)
00117 fprintf(stderr, "*** rpmrc_hash(%p[%s])\n", s, lbl(s));
00118     return PyDict_Type.tp_hash(s);
00119 }
00120 
00123 static int
00124 rpmrc_length(PyObject * s)
00125         /*@*/
00126 {
00127 if (_rc_debug)
00128 fprintf(stderr, "*** rpmrc_length(%p[%s])\n", s, lbl(s));
00129     return PyDict_Type.tp_as_mapping->mp_length(s);
00130 }
00131 
00134 static PyObject *
00135 rpmrc_subscript(PyObject * s, PyObject * key)
00136         /*@*/
00137 {
00138 if (_rc_debug)
00139 fprintf(stderr, "*** rpmrc_subscript(%p[%s], %p[%s])\n", s, lbl(s), key, lbl(key));
00140     return PyDict_Type.tp_as_mapping->mp_subscript(s, key);
00141 }
00142 
00145 static int
00146 rpmrc_ass_subscript(PyObject * s, PyObject * key, PyObject * value)
00147         /*@*/
00148 {
00149 if (_rc_debug)
00150 fprintf(stderr, "*** rpmrc_ass_subscript(%p[%s], %p[%s], %p[%s])\n", s, lbl(s), key, lbl(key), value, lbl(value));
00151     return PyDict_Type.tp_as_mapping->mp_ass_subscript(s, key, value);
00152 }
00153 
00154 /*@unchecked@*/ /*@observer@*/
00155 static PyMappingMethods rpmrc_as_mapping = {
00156     rpmrc_length,               /* mp_length */
00157     rpmrc_subscript,            /* mp_subscript */
00158     rpmrc_ass_subscript,                /* mp_ass_subscript */
00159 };
00160 
00163 static PyObject * rpmrc_getattro (PyObject *s, PyObject *name)
00164         /*@*/
00165 {
00166 if (_rc_debug)
00167 fprintf(stderr, "*** rpmrc_getattro(%p[%s], \"%s\")\n", s, lbl(s), PyString_AS_STRING(name));
00168     return PyObject_GenericGetAttr(s, name);
00169 }
00170 
00173 static int rpmrc_setattro (PyObject *s, PyObject *name, PyObject * value)
00174         /*@*/
00175 {
00176 if (_rc_debug)
00177 fprintf(stderr, "*** rpmrc_setattro(%p[%s], \"%s \", \"%s\")\n", s, lbl(s), PyString_AS_STRING(name), PyString_AS_STRING(value));
00178     return PyDict_Type.tp_setattro(s, name, value);
00179 }
00180 
00183 /*@unchecked@*/ /*@observer@*/
00184 static char rpmrc_doc[] =
00185 "";
00186 
00189 static int rpmrc_traverse(PyObject * s, visitproc visit, void *arg)
00190         /*@*/
00191 {
00192 if (_rc_debug)
00193 fprintf(stderr, "*** rpmrc_traverse(%p[%s],%p,%p)\n", s, lbl(s), visit, arg);
00194     return PyDict_Type.tp_traverse(s, visit, arg);
00195 }
00196 
00199 static int rpmrc_clear(PyObject * s)
00200         /*@*/
00201 {
00202 if (_rc_debug)
00203 fprintf(stderr, "*** rpmrc_clear(%p[%s])\n", s, lbl(s));
00204     return PyDict_Type.tp_clear(s);
00205 }
00206 
00209 static PyObject * rpmrc_richcompare(PyObject * v, PyObject * w, int op)
00210         /*@*/
00211 {
00212 if (_rc_debug)
00213 fprintf(stderr, "*** rpmrc_richcompare(%p[%s],%p[%s],%x)\n", v, lbl(v), w, lbl(w), op);
00214     return PyDict_Type.tp_richcompare(v, w, op);
00215 }
00216 
00217 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 4
00218 
00220 static PyObject * rpmrc_iter(PyObject * s)
00221         /*@*/
00222 {
00223 if (_rc_debug)
00224 fprintf(stderr, "*** rpmrc_iter(%p[%s])\n", s, lbl(s));
00225     if (s->ob_type == &PyDictIter_Type)
00226         return PyDictIter_Type.tp_iter(s);
00227     return PyDict_Type.tp_iter(s);
00228 }
00229 
00232 /*@null@*/
00233 static PyObject * rpmrc_iternext(PyObject * s)
00234         /*@*/
00235 {
00236 if (_rc_debug)
00237 fprintf(stderr, "*** rpmrc_iternext(%p[%s])\n", s, lbl(s));
00238     if (s->ob_type == &PyDictIter_Type)
00239         return PyDictIter_Type.tp_iternext(s);
00240     return NULL;
00241 }
00242 
00245 /*@null@*/
00246 /* XXX: does this _actually_ take any arguments?  I don't think it does... */
00247 static PyObject * rpmrc_next(PyObject * s, PyObject *args)
00248         /*@*/
00249 {
00250 if (_rc_debug)
00251 fprintf(stderr, "*** rpmrc_next(%p[%s],%p)\n", s, lbl(s), args);
00252     if (s->ob_type == &PyDictIter_Type)
00253         return PyDictIter_Type.tp_methods[0].ml_meth(s, args);
00254     return NULL;
00255 }
00256 #else
00257 #define rpmrc_iter      0
00258 #define rpmrc_iternext  0
00259 #endif
00260 
00263 static int rpmrc_init(PyObject * s, PyObject *args, PyObject *kwds)
00264         /*@*/
00265 {
00266 if (_rc_debug)
00267 fprintf(stderr, "*** rpmrc_init(%p[%s],%p,%p)\n", s, lbl(s), args, kwds);
00268     if (PyDict_Type.tp_init(s, args, kwds) < 0)
00269         return -1;
00270     return 0;
00271 }
00272 
00275 static void rpmrc_free(PyObject * s)
00276         /*@*/
00277 {
00278 if (_rc_debug)
00279 fprintf(stderr, "*** rpmrc_free(%p[%s])\n", s, lbl(s));
00280    _PyObject_GC_Del(s);
00281 }
00282 
00285 static PyObject * rpmrc_alloc(PyTypeObject * subtype, int nitems)
00286         /*@*/
00287 {
00288     PyObject * ns = PyType_GenericAlloc(subtype, nitems);
00289 
00290 if (_rc_debug)
00291 fprintf(stderr, "*** rpmrc_alloc(%p[%s},%d) ret %p[%s]\n", subtype, lbl(subtype), nitems, ns, lbl(ns));
00292     return (PyObject *) ns;
00293 }
00294 
00297 /*@null@*/
00298 static PyObject * rpmrc_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
00299         /*@*/
00300 {
00301     PyObject * ns;
00302 
00303     /* Derive an initialized dictionary of the appropriate size. */
00304     ns = PyDict_Type.tp_new(&rpmrc_Type, args, kwds);
00305 
00306     /* Perform additional initialization. */
00307     if (rpmrc_init(ns, args, kwds) < 0) {
00308         rpmrc_free(ns);
00309         return NULL;
00310     }
00311 
00312 if (_rc_debug)
00313 fprintf(stderr, "*** rpmrc_new(%p[%s],%p,%p) ret %p[%s]\n", subtype, lbl(subtype), args, kwds, ns, lbl(ns));
00314     return ns;
00315 }
00316 #endif
00317 
00320 /*@-fullinitblock@*/
00321 /*@unchecked@*/ /*@observer@*/
00322 static struct PyMethodDef rpmrc_methods[] = {
00323     { "addMacro",       (PyCFunction) rpmrc_AddMacro, METH_VARARGS|METH_KEYWORDS,
00324         NULL },
00325     { "delMacro",       (PyCFunction) rpmrc_DelMacro, METH_VARARGS|METH_KEYWORDS,
00326         NULL },
00327 #if Py_TPFLAGS_HAVE_ITER && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 4
00328     { "next",           (PyCFunction) rpmrc_next,     METH_VARARGS,
00329         "next() -- get the next value, or raise StopIteration"},
00330 #endif
00331     {NULL,              NULL}           /* sentinel */
00332 };
00333 /*@=fullinitblock@*/
00334 
00337 /*@-fullinitblock@*/
00338 #if Py_TPFLAGS_HAVE_ITER
00339 PyTypeObject rpmrc_Type = {
00340         PyObject_HEAD_INIT(&PyType_Type)
00341         0,                              /* ob_size */
00342         "rpm.rc",                       /* tp_name */
00343         sizeof(rpmrcObject),            /* tp_size */
00344         0,                              /* tp_itemsize */
00345         (destructor) rpmrc_dealloc,     /* tp_dealloc */
00346         rpmrc_print,                    /* tp_print */
00347         0,                              /* tp_getattr */
00348         0,                              /* tp_setattr */
00349         rpmrc_compare,                  /* tp_compare */
00350         rpmrc_repr,                     /* tp_repr */
00351         0,                              /* tp_as_number */
00352         0,                              /* tp_as_sequence */
00353         &rpmrc_as_mapping,              /* tp_as_mapping */
00354         rpmrc_hash,                     /* tp_hash */
00355         0,                              /* tp_call */
00356         0,                              /* tp_str */
00357         (getattrofunc) rpmrc_getattro,  /* tp_getattro */
00358         (setattrofunc) rpmrc_setattro,  /* tp_setattro */
00359         0,                              /* tp_as_buffer */
00360         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /* tp_flags */
00361         rpmrc_doc,                      /* tp_doc */
00362         rpmrc_traverse,                 /* tp_traverse */
00363         rpmrc_clear,                    /* tp_clear */
00364         rpmrc_richcompare,              /* tp_richcompare */
00365         0,                              /* tp_weaklistoffset */
00366         rpmrc_iter,                     /* tp_iter */
00367         rpmrc_iternext,                 /* tp_iternext */
00368         rpmrc_methods,                  /* tp_methods */
00369         0,                              /* tp_members */
00370         0,                              /* tp_getset */
00371         &PyDict_Type,                   /* tp_base */
00372         0,                              /* tp_dict */
00373         0,                              /* tp_descr_get */
00374         0,                              /* tp_descr_set */
00375         0,                              /* tp_dictoffset */
00376         rpmrc_init,                     /* tp_init */
00377         rpmrc_alloc,                    /* tp_alloc */
00378         rpmrc_new,                      /* tp_new */
00379         rpmrc_free,                     /* tp_free */
00380         0,                              /* tp_is_gc */
00381 };
00382 #else
00383 PyTypeObject rpmrc_Type = {
00384         PyObject_HEAD_INIT(&PyType_Type)
00385         0,                              /* ob_size */
00386         "rpm.rc",                       /* tp_name */
00387         sizeof(rpmrcObject),            /* tp_size */
00388         0,                              /* tp_itemsize */
00389         0,                              /* tp_dealloc */
00390         0,                              /* tp_print */
00391         0,                              /* tp_getattr */
00392         0,                              /* tp_setattr */
00393         0,                              /* tp_compare */
00394         0,                              /* tp_repr */
00395         0,                              /* tp_as_number */
00396         0,                              /* tp_as_sequence */
00397         0,                              /* tp_as_mapping */
00398         0,                              /* tp_hash */
00399         0,                              /* tp_call */
00400         0,                              /* tp_str */
00401         0,                              /* tp_getattro */
00402         0,                              /* tp_setattro */
00403         0,                              /* tp_as_buffer */
00404         0,                              /* tp_flags */
00405         0                               /* tp_doc */
00406 };
00407 #endif
00408 /*@=fullinitblock@*/
00409 
00410 #if Py_TPFLAGS_HAVE_ITER
00411 PyObject * rpmrc_Create(/*@unused@*/ PyObject * self, PyObject *args, PyObject *kwds)
00412 {
00413     return rpmrc_new(&rpmrc_Type, args, kwds);
00414 }
00415 #endif

Generated on Sat Oct 1 16:48:15 2011 for rpm by  doxygen 1.4.4