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 /*@unchecked@*/
00016 extern PyTypeObject PyDictIter_Type;
00017 
00018 #include <rpmcli.h>
00019 
00020 #include "rpmrc-py.h"
00021 
00022 #if Py_TPFLAGS_HAVE_ITER        /* XXX backport to python-1.5.2 */
00023 #include "header-py.h"  /* XXX debug only */
00024 #include "rpmal-py.h"   /* XXX debug only */
00025 #include "rpmds-py.h"   /* XXX debug only */
00026 #include "rpmfd-py.h"   /* XXX debug only */
00027 #include "rpmfi-py.h"   /* XXX debug only */
00028 #include "rpmmi-py.h"   /* XXX debug only */
00029 #include "rpmte-py.h"   /* XXX debug only */
00030 #include "rpmts-py.h"   /* XXX debug only */
00031 #endif
00032 
00033 #include "debug.h"
00034 
00035 #if Py_TPFLAGS_HAVE_ITER        /* XXX backport to python-1.5.2 */
00036 /*@unchecked@*/
00037 static int _rc_debug = 0;
00038 #endif
00039 
00049 
00052 PyObject * rpmrc_AddMacro(/*@unused@*/ PyObject * self, PyObject * args)
00053 {
00054     char * name, * val;
00055 
00056     if (!PyArg_ParseTuple(args, "ss:AddMacro", &name, &val))
00057         return NULL;
00058 
00059     addMacro(NULL, name, NULL, val, -1);
00060 
00061     Py_INCREF(Py_None);
00062     return Py_None;
00063 }
00064 
00067 PyObject * rpmrc_DelMacro(/*@unused@*/ PyObject * self, PyObject * args)
00068 {
00069     char * name;
00070 
00071     if (!PyArg_ParseTuple(args, "s:DelMacro", &name))
00072         return NULL;
00073 
00074     delMacro(NULL, name);
00075 
00076     Py_INCREF(Py_None);
00077     return Py_None;
00078 }
00079 
00080 #if Py_TPFLAGS_HAVE_ITER        /* XXX backport to python-1.5.2 */
00081 
00084 static const char * lbl(void * s)
00085         /*@*/
00086 {
00087     PyObject * o = s;
00088 
00089     if (o == NULL)      return "null";
00090 
00091     if (o->ob_type == &PyType_Type)     return o->ob_type->tp_name;
00092 
00093     if (o->ob_type == &PyClass_Type)    return "Class";
00094     if (o->ob_type == &PyComplex_Type)  return "Complex";
00095     if (o->ob_type == &PyDict_Type)     return "Dict";
00096     if (o->ob_type == &PyDictIter_Type) return "DictIter";
00097     if (o->ob_type == &PyFile_Type)     return "File";
00098     if (o->ob_type == &PyFloat_Type)    return "Float";
00099     if (o->ob_type == &PyFunction_Type) return "Function";
00100     if (o->ob_type == &PyInt_Type)      return "Int";
00101     if (o->ob_type == &PyList_Type)     return "List";
00102     if (o->ob_type == &PyLong_Type)     return "Long";
00103     if (o->ob_type == &PyMethod_Type)   return "Method";
00104     if (o->ob_type == &PyModule_Type)   return "Module";
00105     if (o->ob_type == &PyString_Type)   return "String";
00106     if (o->ob_type == &PyTuple_Type)    return "Tuple";
00107     if (o->ob_type == &PyType_Type)     return "Type";
00108     if (o->ob_type == &PyUnicode_Type)  return "Unicode";
00109 
00110     if (o->ob_type == &hdr_Type)        return "hdr";
00111     if (o->ob_type == &rpmal_Type)      return "rpmal";
00112     if (o->ob_type == &rpmds_Type)      return "rpmds";
00113     if (o->ob_type == &rpmfd_Type)      return "rpmfd";
00114     if (o->ob_type == &rpmfi_Type)      return "rpmfi";
00115     if (o->ob_type == &rpmmi_Type)      return "rpmmi";
00116     if (o->ob_type == &rpmrc_Type)      return "rpmrc";
00117     if (o->ob_type == &rpmte_Type)      return "rpmte";
00118     if (o->ob_type == &rpmts_Type)      return "rpmts";
00119 
00120     return "Unknown";
00121 }
00122 
00125 static PyObject *
00126 rpmrc_getstate(rpmrcObject *s, PyObject *args)
00127         /*@*/
00128 {
00129     if (!PyArg_ParseTuple(args, ":getstate"))
00130         return NULL;
00131     return PyInt_FromLong(s->state);
00132 }
00133 
00136 static PyObject *
00137 rpmrc_setstate(rpmrcObject *s, PyObject *args)
00138         /*@globals _Py_NoneStruct @*/
00139         /*@modifies s, _Py_NoneStruct @*/
00140 {
00141     int state;
00142 
00143     if (!PyArg_ParseTuple(args, "i:setstate", &state))
00144         return NULL;
00145     s->state = state;
00146     Py_INCREF(Py_None);
00147     return Py_None;
00148 }
00149 
00152 static void rpmrc_dealloc(PyObject * s)
00153         /*@*/
00154 {
00155 if (_rc_debug)
00156 fprintf(stderr, "*** rpmrc_dealloc(%p[%s])\n", s, lbl(s));
00157     PyDict_Type.tp_dealloc(s);
00158 }
00159 
00162 static int rpmrc_print(PyObject * s, FILE *fp, int flags)
00163         /*@*/
00164 {
00165 /*@-formattype@*/
00166 if (_rc_debug)
00167 fprintf(stderr, "*** rpmrc_print(%p[%s],%p,%x)\n", s, lbl(s), fp, flags);
00168 /*@=formattype@*/
00169     return PyDict_Type.tp_print(s, fp, flags);
00170 }
00171 
00174 static int rpmrc_compare(PyObject * a, PyObject * b)
00175         /*@*/
00176 {
00177 if (_rc_debug)
00178 fprintf(stderr, "*** rpmrc_compare(%p[%s],%p[%s])\n", a, lbl(a), b, lbl(b));
00179     return PyDict_Type.tp_compare(a, b);
00180 }
00181 
00184 static PyObject * rpmrc_repr(PyObject * s)
00185         /*@*/
00186 {
00187 if (_rc_debug)
00188 fprintf(stderr, "*** rpmrc_repr(%p[%s])\n", s, lbl(s));
00189     return PyDict_Type.tp_repr(s);
00190 }
00191 
00194 static long rpmrc_hash(PyObject * s)
00195         /*@*/
00196 {
00197     /* XXX dict objects are unhashable */
00198 if (_rc_debug)
00199 fprintf(stderr, "*** rpmrc_hash(%p[%s])\n", s, lbl(s));
00200     return PyDict_Type.tp_hash(s);
00201 }
00202 
00205 static int
00206 rpmrc_length(PyObject * s)
00207         /*@*/
00208 {
00209 if (_rc_debug)
00210 fprintf(stderr, "*** rpmrc_length(%p[%s])\n", s, lbl(s));
00211     return PyDict_Type.tp_as_mapping->mp_length(s);
00212 }
00213 
00216 static PyObject *
00217 rpmrc_subscript(PyObject * s, PyObject * key)
00218         /*@*/
00219 {
00220 if (_rc_debug)
00221 fprintf(stderr, "*** rpmrc_subscript(%p[%s], %p[%s])\n", s, lbl(s), key, lbl(key));
00222     return PyDict_Type.tp_as_mapping->mp_subscript(s, key);
00223 }
00224 
00227 static int
00228 rpmrc_ass_subscript(PyObject * s, PyObject * key, PyObject * value)
00229         /*@*/
00230 {
00231 if (_rc_debug)
00232 fprintf(stderr, "*** rpmrc_ass_subscript(%p[%s], %p[%s], %p[%s])\n", s, lbl(s), key, lbl(key), value, lbl(value));
00233     return PyDict_Type.tp_as_mapping->mp_ass_subscript(s, key, value);
00234 }
00235 
00236 /*@unchecked@*/ /*@observer@*/
00237 static PyMappingMethods rpmrc_as_mapping = {
00238     rpmrc_length,               /* mp_length */
00239     rpmrc_subscript,            /* mp_subscript */
00240     rpmrc_ass_subscript,                /* mp_ass_subscript */
00241 };
00242 
00245 static PyObject * rpmrc_getattro (PyObject *s, PyObject *name)
00246         /*@*/
00247 {
00248 if (_rc_debug)
00249 fprintf(stderr, "*** rpmrc_getattro(%p[%s], \"%s\")\n", s, lbl(s), PyString_AS_STRING(name));
00250     return PyObject_GenericGetAttr(s, name);
00251 }
00252 
00255 static int rpmrc_setattro (PyObject *s, PyObject *name, PyObject * value)
00256         /*@*/
00257 {
00258 if (_rc_debug)
00259 fprintf(stderr, "*** rpmrc_setattro(%p[%s], \"%s \", \"%s\")\n", s, lbl(s), PyString_AS_STRING(name), PyString_AS_STRING(value));
00260     return PyDict_Type.tp_setattro(s, name, value);
00261 }
00262 
00265 /*@unchecked@*/ /*@observer@*/
00266 static char rpmrc_doc[] =
00267 "";
00268 
00271 static int rpmrc_traverse(PyObject * s, visitproc visit, void *arg)
00272         /*@*/
00273 {
00274 if (_rc_debug)
00275 fprintf(stderr, "*** rpmrc_traverse(%p[%s],%p,%p)\n", s, lbl(s), visit, arg);
00276     return PyDict_Type.tp_traverse(s, visit, arg);
00277 }
00278 
00281 static int rpmrc_clear(PyObject * s)
00282         /*@*/
00283 {
00284 if (_rc_debug)
00285 fprintf(stderr, "*** rpmrc_clear(%p[%s])\n", s, lbl(s));
00286     return PyDict_Type.tp_clear(s);
00287 }
00288 
00291 static PyObject * rpmrc_richcompare(PyObject * v, PyObject * w, int op)
00292         /*@*/
00293 {
00294 if (_rc_debug)
00295 fprintf(stderr, "*** rpmrc_richcompare(%p[%s],%p[%s],%x)\n", v, lbl(v), w, lbl(w), op);
00296     return PyDict_Type.tp_richcompare(v, w, op);
00297 }
00298 
00301 static PyObject * rpmrc_iter(PyObject * s)
00302         /*@*/
00303 {
00304 if (_rc_debug)
00305 fprintf(stderr, "*** rpmrc_iter(%p[%s])\n", s, lbl(s));
00306     if (s->ob_type == &PyDictIter_Type)
00307         return PyDictIter_Type.tp_iter(s);
00308     return PyDict_Type.tp_iter(s);
00309 }
00310 
00313 static PyObject * rpmrc_iternext(PyObject * s)
00314         /*@*/
00315 {
00316 if (_rc_debug)
00317 fprintf(stderr, "*** rpmrc_iternext(%p[%s])\n", s, lbl(s));
00318     if (s->ob_type == &PyDictIter_Type)
00319         return PyDictIter_Type.tp_iternext(s);
00320     return NULL;
00321 }
00322 
00325 static PyObject * rpmrc_next(PyObject * s, PyObject *args)
00326         /*@*/
00327 {
00328 if (_rc_debug)
00329 fprintf(stderr, "*** rpmrc_next(%p[%s],%p)\n", s, lbl(s), args);
00330     if (s->ob_type == &PyDictIter_Type)
00331         return PyDictIter_Type.tp_methods[0].ml_meth(s, args);
00332     return NULL;
00333 }
00334 
00335 /*@-fullinitblock@*/
00336 /*@unchecked@*/ /*@observer@*/
00337 static PyMemberDef rpmrc_members[] = {
00338     {"state", T_INT, offsetof(rpmrcObject, state), READONLY,
00339          "an int variable for demonstration purposes"},
00340     {0}
00341 };
00342 /*@=fullinitblock@*/
00343 
00346 static int rpmrc_init(PyObject * s, PyObject *args, PyObject *kwds)
00347         /*@*/
00348 {
00349 if (_rc_debug)
00350 fprintf(stderr, "*** rpmrc_init(%p[%s],%p,%p)\n", s, lbl(s), args, kwds);
00351     if (PyDict_Type.tp_init(s, args, kwds) < 0)
00352         return -1;
00353     ((rpmrcObject *)s)->state = 0;
00354     return 0;
00355 }
00356 
00359 static void rpmrc_free(PyObject * s)
00360         /*@*/
00361 {
00362 if (_rc_debug)
00363 fprintf(stderr, "*** rpmrc_free(%p[%s])\n", s, lbl(s));
00364    _PyObject_GC_Del(s);
00365 }
00366 
00369 static PyObject * rpmrc_alloc(PyTypeObject * subtype, int nitems)
00370         /*@*/
00371 {
00372     PyObject * ns = PyType_GenericAlloc(subtype, nitems);
00373 
00374 if (_rc_debug)
00375 fprintf(stderr, "*** rpmrc_alloc(%p[%s},%d) ret %p[%s]\n", subtype, lbl(subtype), nitems, ns, lbl(ns));
00376     return (PyObject *) ns;
00377 }
00378 
00381 static PyObject * rpmrc_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
00382         /*@*/
00383 {
00384     PyObject * ns;
00385 
00386     /* Derive an initialized dictionary of the appropriate size. */
00387     ns = PyDict_Type.tp_new(&rpmrc_Type, args, kwds);
00388 
00389     /* Perform additional initialization. */
00390     if (rpmrc_init(ns, args, kwds) < 0) {
00391         rpmrc_free(ns);
00392         return NULL;
00393     }
00394 
00395 if (_rc_debug)
00396 fprintf(stderr, "*** rpmrc_new(%p[%s],%p,%p) ret %p[%s]\n", subtype, lbl(subtype), args, kwds, ns, lbl(ns));
00397     return ns;
00398 }
00399 #endif
00400 
00403 /*@-fullinitblock@*/
00404 /*@unchecked@*/ /*@observer@*/
00405 static struct PyMethodDef rpmrc_methods[] = {
00406     { "addMacro",       (PyCFunction) rpmrc_AddMacro, METH_VARARGS,
00407         NULL },
00408     { "delMacro",       (PyCFunction) rpmrc_DelMacro, METH_VARARGS,
00409         NULL },
00410 #if Py_TPFLAGS_HAVE_ITER        /* XXX backport to python-1.5.2 */
00411     { "getstate",       (PyCFunction) rpmrc_getstate, METH_VARARGS,
00412         "getstate() -> state"},
00413     { "setstate",       (PyCFunction) rpmrc_setstate, METH_VARARGS,
00414         "setstate(state)"},
00415     { "next",           (PyCFunction) rpmrc_next,     METH_VARARGS,
00416         "next() -- get the next value, or raise StopIteration"},
00417 #endif
00418     {NULL,              NULL}           /* sentinel */
00419 };
00420 /*@=fullinitblock@*/
00421 
00424 /*@-fullinitblock@*/
00425 #if Py_TPFLAGS_HAVE_ITER
00426 PyTypeObject rpmrc_Type = {
00427         PyObject_HEAD_INIT(&PyType_Type)
00428         0,                              /* ob_size */
00429         "rpm.rc",                       /* tp_name */
00430         sizeof(rpmrcObject),            /* tp_size */
00431         0,                              /* tp_itemsize */
00432         (destructor) rpmrc_dealloc,     /* tp_dealloc */
00433         rpmrc_print,                    /* tp_print */
00434         0,                              /* tp_getattr */
00435         0,                              /* tp_setattr */
00436         rpmrc_compare,                  /* tp_compare */
00437         rpmrc_repr,                     /* tp_repr */
00438         0,                              /* tp_as_number */
00439         0,                              /* tp_as_sequence */
00440         &rpmrc_as_mapping,              /* tp_as_mapping */
00441         rpmrc_hash,                     /* tp_hash */
00442         0,                              /* tp_call */
00443         0,                              /* tp_str */
00444         (getattrofunc) rpmrc_getattro,  /* tp_getattro */
00445         (setattrofunc) rpmrc_setattro,  /* tp_setattro */
00446         0,                              /* tp_as_buffer */
00447         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /* tp_flags */
00448         rpmrc_doc,                      /* tp_doc */
00449         rpmrc_traverse,                 /* tp_traverse */
00450         rpmrc_clear,                    /* tp_clear */
00451         rpmrc_richcompare,              /* tp_richcompare */
00452         0,                              /* tp_weaklistoffset */
00453         rpmrc_iter,                     /* tp_iter */
00454         rpmrc_iternext,                 /* tp_iternext */
00455         rpmrc_methods,                  /* tp_methods */
00456         rpmrc_members,                  /* tp_members */
00457         0,                              /* tp_getset */
00458         &PyDict_Type,                   /* tp_base */
00459         0,                              /* tp_dict */
00460         0,                              /* tp_descr_get */
00461         0,                              /* tp_descr_set */
00462         0,                              /* tp_dictoffset */
00463         rpmrc_init,                     /* tp_init */
00464         rpmrc_alloc,                    /* tp_alloc */
00465         rpmrc_new,                      /* tp_new */
00466         rpmrc_free,                     /* tp_free */
00467         0,                              /* tp_is_gc */
00468 };
00469 #else
00470 PyTypeObject rpmrc_Type = {
00471         PyObject_HEAD_INIT(&PyType_Type)
00472         0,                              /* ob_size */
00473         "rpm.rc",                       /* tp_name */
00474         sizeof(rpmrcObject),            /* tp_size */
00475         0,                              /* tp_itemsize */
00476         0,                              /* tp_dealloc */
00477         0,                              /* tp_print */
00478         0,                              /* tp_getattr */
00479         0,                              /* tp_setattr */
00480         0,                              /* tp_compare */
00481         0,                              /* tp_repr */
00482         0,                              /* tp_as_number */
00483         0,                              /* tp_as_sequence */
00484         0,                              /* tp_as_mapping */
00485         0,                              /* tp_hash */
00486         0,                              /* tp_call */
00487         0,                              /* tp_str */
00488         0,                              /* tp_getattro */
00489         0,                              /* tp_setattro */
00490         0,                              /* tp_as_buffer */
00491         0,                              /* tp_flags */
00492         0                               /* tp_doc */
00493 };
00494 #endif
00495 /*@=fullinitblock@*/
00496 
00497 #if Py_TPFLAGS_HAVE_ITER
00498 PyObject * rpmrc_Create(/*@unused@*/ PyObject * self, PyObject *args, PyObject *kwds)
00499 {
00500     return rpmrc_new(&rpmrc_Type, args, kwds);
00501 }
00502 #endif
00503 

Generated on Tue Sep 17 15:59:55 2002 for rpm by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002