Use PyObject_{New,Del} consistently throughout.
CVS patchset: 5931
CVS date: 2002/12/10 19:46:03
SUBDIRS = rpmdb test
+EXTRA_DIST = rpmdebug-py.c
+
INCLUDES = -I. \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/rpmdb \
s->md5list = _free(s->md5list);
s->fileList = _free(s->fileList);
s->linkList = _free(s->linkList);
- PyMem_DEL(s);
+ PyObject_Del(s);
}
/** \ingroup python
hdrObject * hdr_Wrap(Header h)
{
- hdrObject * hdr = PyObject_NEW(hdrObject, &hdr_Type);
+ hdrObject * hdr = PyObject_New(hdrObject, &hdr_Type);
hdr->h = headerLink(h);
hdr->fileList = hdr->linkList = hdr->md5list = NULL;
hdr->uids = hdr->gids = hdr->mtimes = hdr->fileSizes = NULL;
#define PY_POPT_VERSION "0.2"
-static const char *rcs_id = "$Id: poptmodule.c,v 1.7 2002/06/05 20:28:03 jbj Exp $";
+static const char *rcs_id = "$Id: poptmodule.c,v 1.8 2002/12/10 19:46:03 jbj Exp $";
static char *module_doc = "Python bindings for the popt library\n\
\n\
self->options = NULL;
}
poptFreeContext(self->ctx);
- PyMem_DEL(self);
+ PyObject_Del(self);
}
static PyTypeObject poptContextType = {
/* Presumably they've set the exception at a previous level */
return NULL;
/* Parse argv */
- c = PyObject_NEW(poptContextObject, &poptContextType);
+ c = PyObject_New(poptContextObject, &poptContextType);
c->options = opts;
c->optionsNo = count;
c->opt = -1;
{
if (s) {
s->al = rpmalFree(s->al);
- PyMem_DEL(s);
+ PyObject_Del(s);
}
}
rpmalObject *
rpmal_Wrap(rpmal al)
{
- rpmalObject *s = PyObject_NEW(rpmalObject, &rpmal_Type);
+ rpmalObject *s = PyObject_New(rpmalObject, &rpmal_Type);
if (s == NULL)
return NULL;
s->al = al;
#include "rpmbc-py.h"
-#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
-/*@unchecked@*/
-extern PyTypeObject PyCode_Type;
-/*@unchecked@*/
-extern PyTypeObject PyDictIter_Type;
-/*@unchecked@*/
-extern PyTypeObject PyFrame_Type;
-
-#include <rpmcli.h> /* XXX debug only */
-
-#include "header-py.h" /* XXX debug only */
-#include "rpmal-py.h" /* XXX debug only */
-#include "rpmds-py.h" /* XXX debug only */
-#include "rpmfd-py.h" /* XXX debug only */
-#include "rpmfi-py.h" /* XXX debug only */
-#include "rpmmi-py.h" /* XXX debug only */
-#include "rpmrc-py.h" /* XXX debug only */
-#include "rpmte-py.h" /* XXX debug only */
-#include "rpmts-py.h" /* XXX debug only */
-#endif
+#include "rpmdebug-py.c"
#include "debug.h"
#define is_rpmbc(o) ((o)->ob_type == &rpmbc_Type)
-/**
- */
-static const char * lbl(void * s)
- /*@*/
-{
- PyObject * o = s;
-
- if (o == NULL) return "null";
-
- if (o->ob_type == &PyType_Type) return o->ob_type->tp_name;
-
- if (o->ob_type == &PyBuffer_Type) return "Buffer";
- if (o->ob_type == &PyCFunction_Type) return "CFunction";
- if (o->ob_type == &PyCObject_Type) return "CObject";
- if (o->ob_type == &PyCell_Type) return "Cell";
- if (o->ob_type == &PyClass_Type) return "Class";
- if (o->ob_type == &PyCode_Type) return "Code";
- if (o->ob_type == &PyComplex_Type) return "Complex";
- if (o->ob_type == &PyDict_Type) return "Dict";
- if (o->ob_type == &PyDictIter_Type) return "DictIter";
- if (o->ob_type == &PyFile_Type) return "File";
- if (o->ob_type == &PyFloat_Type) return "Float";
- if (o->ob_type == &PyFrame_Type) return "Frame";
- if (o->ob_type == &PyFunction_Type) return "Function";
- if (o->ob_type == &PyInstance_Type) return "Instance";
- if (o->ob_type == &PyInt_Type) return "Int";
- if (o->ob_type == &PyList_Type) return "List";
- if (o->ob_type == &PyLong_Type) return "Long";
- if (o->ob_type == &PyMethod_Type) return "Method";
- if (o->ob_type == &PyModule_Type) return "Module";
- if (o->ob_type == &PyRange_Type) return "Range";
- if (o->ob_type == &PySeqIter_Type) return "SeqIter";
- if (o->ob_type == &PySlice_Type) return "Slice";
- if (o->ob_type == &PyString_Type) return "String";
- if (o->ob_type == &PyTuple_Type) return "Tuple";
- if (o->ob_type == &PyType_Type) return "Type";
- if (o->ob_type == &PyUnicode_Type) return "Unicode";
-
- if (o->ob_type == &hdr_Type) return "hdr";
- if (o->ob_type == &rpmal_Type) return "rpmal";
- if (o->ob_type == &rpmbc_Type) return "rpmbc";
- if (o->ob_type == &rpmds_Type) return "rpmds";
- if (o->ob_type == &rpmfd_Type) return "rpmfd";
- if (o->ob_type == &rpmfi_Type) return "rpmfi";
- if (o->ob_type == &rpmmi_Type) return "rpmmi";
- if (o->ob_type == &rpmrc_Type) return "rpmrc";
- if (o->ob_type == &rpmte_Type) return "rpmte";
- if (o->ob_type == &rpmts_Type) return "rpmts";
-
- return "Unknown";
-}
-
/* ---------- */
static void
fprintf(stderr, "*** rpmbc_dealloc(%p)\n", s);
mp32nfree(&s->n);
- PyObject_DEL(s);
+ PyObject_Del(s);
}
static int
if (_bc_debug)
fprintf(stderr, "*** rpmbc_free(%p[%s])\n", s, lbl(s));
mp32nfree(&s->n);
- _PyObject_GC_Del((PyObject *)s);
+ PyObject_Del(s);
}
/** \ingroup python
{
PyObject * ns = (PyObject *) PyObject_New(rpmbcObject, &rpmbc_Type);
- mp32nzero(&((rpmbcObject *)ns)->n);
+ if (ns != NULL)
+ mp32nzero(&((rpmbcObject *)ns)->n);
if (_bc_debug)
fprintf(stderr, "*** rpmbc_new(%p[%s],%p[%s],%p[%s]) ret %p[%s]\n", subtype, lbl(subtype), args, lbl(args), kwds, lbl(kwds), ns, lbl(ns));
{
if (s->db)
rpmdbClose(s->db);
- PyMem_DEL(s);
+ PyObject_Del(s);
}
/**
if (!PyArg_ParseTuple(args, "|is", &forWrite, &root)) return NULL;
- o = PyObject_NEW(rpmdbObject, &rpmdb_Type);
+ o = PyObject_New(rpmdbObject, &rpmdb_Type);
o->db = NULL;
if (rpmdbOpen(root, &o->db, forWrite ? O_RDWR | O_CREAT: O_RDONLY, 0644)) {
--- /dev/null
+
+/*@unchecked@*/
+extern PyTypeObject PyCode_Type;
+/*@unchecked@*/
+extern PyTypeObject PyDictIter_Type;
+/*@unchecked@*/
+extern PyTypeObject PyFrame_Type;
+
+#include "rpmbc-py.h" /* XXX debug only */
+#include <rpmcli.h> /* XXX debug only */
+
+#include "header-py.h" /* XXX debug only */
+#include "rpmal-py.h" /* XXX debug only */
+#include "rpmds-py.h" /* XXX debug only */
+#include "rpmfd-py.h" /* XXX debug only */
+#include "rpmfi-py.h" /* XXX debug only */
+#include "rpmmi-py.h" /* XXX debug only */
+#include "rpmrc-py.h" /* XXX debug only */
+#include "rpmte-py.h" /* XXX debug only */
+#include "rpmts-py.h" /* XXX debug only */
+
+/**
+ */
+static const char * lbl(void * s)
+ /*@*/
+{
+ PyObject * o = s;
+
+ if (o == NULL) return "null";
+
+ if (o->ob_type == &PyType_Type) return o->ob_type->tp_name;
+
+ if (o->ob_type == &PyBuffer_Type) return "Buffer";
+ if (o->ob_type == &PyCFunction_Type) return "CFunction";
+ if (o->ob_type == &PyCObject_Type) return "CObject";
+ if (o->ob_type == &PyCell_Type) return "Cell";
+ if (o->ob_type == &PyClass_Type) return "Class";
+ if (o->ob_type == &PyCode_Type) return "Code";
+ if (o->ob_type == &PyComplex_Type) return "Complex";
+ if (o->ob_type == &PyDict_Type) return "Dict";
+ if (o->ob_type == &PyDictIter_Type) return "DictIter";
+ if (o->ob_type == &PyFile_Type) return "File";
+ if (o->ob_type == &PyFloat_Type) return "Float";
+ if (o->ob_type == &PyFrame_Type) return "Frame";
+ if (o->ob_type == &PyFunction_Type) return "Function";
+ if (o->ob_type == &PyInstance_Type) return "Instance";
+ if (o->ob_type == &PyInt_Type) return "Int";
+ if (o->ob_type == &PyList_Type) return "List";
+ if (o->ob_type == &PyLong_Type) return "Long";
+ if (o->ob_type == &PyMethod_Type) return "Method";
+ if (o->ob_type == &PyModule_Type) return "Module";
+ if (o->ob_type == &PyRange_Type) return "Range";
+ if (o->ob_type == &PySeqIter_Type) return "SeqIter";
+ if (o->ob_type == &PySlice_Type) return "Slice";
+ if (o->ob_type == &PyString_Type) return "String";
+ if (o->ob_type == &PyTuple_Type) return "Tuple";
+ if (o->ob_type == &PyType_Type) return "Type";
+ if (o->ob_type == &PyUnicode_Type) return "Unicode";
+
+ if (o->ob_type == &hdr_Type) return "hdr";
+ if (o->ob_type == &rpmal_Type) return "rpmal";
+ if (o->ob_type == &rpmbc_Type) return "rpmbc";
+ if (o->ob_type == &rpmds_Type) return "rpmds";
+ if (o->ob_type == &rpmfd_Type) return "rpmfd";
+ if (o->ob_type == &rpmfi_Type) return "rpmfi";
+ if (o->ob_type == &rpmmi_Type) return "rpmmi";
+ if (o->ob_type == &rpmrc_Type) return "rpmrc";
+ if (o->ob_type == &rpmte_Type) return "rpmte";
+ if (o->ob_type == &rpmts_Type) return "rpmts";
+
+ return "Unknown";
+}
{
if (s) {
s->ds = rpmdsFree(s->ds);
- PyMem_DEL(s);
+ PyObject_Del(s);
}
}
rpmdsObject *
rpmds_Wrap(rpmds ds)
{
- rpmdsObject * s = PyObject_NEW(rpmdsObject, &rpmds_Type);
+ rpmdsObject * s = PyObject_New(rpmdsObject, &rpmds_Type);
if (s == NULL)
return NULL;
rpmfdObject * rpmfd_Wrap(FD_t fd)
{
- rpmfdObject *s = PyObject_NEW(rpmfdObject, &rpmfd_Type);
+ rpmfdObject *s = PyObject_New(rpmfdObject, &rpmfd_Type);
if (s == NULL)
return NULL;
s->fd = fd;
{
if (s) {
s->fi = rpmfiFree(s->fi);
- PyMem_DEL(s);
+ PyObject_Del(s);
}
}
rpmfiObject *
rpmfi_Wrap(rpmfi fi)
{
- rpmfiObject *s = PyObject_NEW(rpmfiObject, &rpmfi_Type);
+ rpmfiObject *s = PyObject_New(rpmfiObject, &rpmfi_Type);
if (s == NULL)
return NULL;
{
if (s) {
if (s->mi) s->mi = rpmdbFreeIterator(s->mi);
- PyMem_DEL(s);
+ PyObject_Del(s);
}
}
rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi)
{
- rpmmiObject * mio = (rpmmiObject *) PyObject_NEW(rpmmiObject, &rpmmi_Type);
+ rpmmiObject * mio = (rpmmiObject *) PyObject_New(rpmmiObject, &rpmmi_Type);
if (mio == NULL) {
PyErr_SetString(pyrpmError, "out of memory creating rpmmiObject");
#include "structmember.h"
-/*@unchecked@*/
-extern PyTypeObject PyDictIter_Type;
+#include "rpmdebug-py.c"
#include <rpmcli.h>
#include "rpmrc-py.h"
-#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
-#include "header-py.h" /* XXX debug only */
-#include "rpmal-py.h" /* XXX debug only */
-#include "rpmds-py.h" /* XXX debug only */
-#include "rpmfd-py.h" /* XXX debug only */
-#include "rpmfi-py.h" /* XXX debug only */
-#include "rpmmi-py.h" /* XXX debug only */
-#include "rpmte-py.h" /* XXX debug only */
-#include "rpmts-py.h" /* XXX debug only */
-#endif
-
#include "debug.h"
-#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
/*@unchecked@*/
static int _rc_debug = 0;
-#endif
/** \ingroup python
* \class Rpmrc
}
#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
-/**
- */
-static const char * lbl(void * s)
- /*@*/
-{
- PyObject * o = s;
-
- if (o == NULL) return "null";
-
- if (o->ob_type == &PyType_Type) return o->ob_type->tp_name;
-
- if (o->ob_type == &PyClass_Type) return "Class";
- if (o->ob_type == &PyComplex_Type) return "Complex";
- if (o->ob_type == &PyDict_Type) return "Dict";
- if (o->ob_type == &PyDictIter_Type) return "DictIter";
- if (o->ob_type == &PyFile_Type) return "File";
- if (o->ob_type == &PyFloat_Type) return "Float";
- if (o->ob_type == &PyFunction_Type) return "Function";
- if (o->ob_type == &PyInt_Type) return "Int";
- if (o->ob_type == &PyList_Type) return "List";
- if (o->ob_type == &PyLong_Type) return "Long";
- if (o->ob_type == &PyMethod_Type) return "Method";
- if (o->ob_type == &PyModule_Type) return "Module";
- if (o->ob_type == &PyString_Type) return "String";
- if (o->ob_type == &PyTuple_Type) return "Tuple";
- if (o->ob_type == &PyType_Type) return "Type";
- if (o->ob_type == &PyUnicode_Type) return "Unicode";
-
- if (o->ob_type == &hdr_Type) return "hdr";
- if (o->ob_type == &rpmal_Type) return "rpmal";
- if (o->ob_type == &rpmds_Type) return "rpmds";
- if (o->ob_type == &rpmfd_Type) return "rpmfd";
- if (o->ob_type == &rpmfi_Type) return "rpmfi";
- if (o->ob_type == &rpmmi_Type) return "rpmmi";
- if (o->ob_type == &rpmrc_Type) return "rpmrc";
- if (o->ob_type == &rpmte_Type) return "rpmte";
- if (o->ob_type == &rpmts_Type) return "rpmts";
-
- return "Unknown";
-}
/**
*/
rpmteObject * rpmte_Wrap(rpmte te)
{
- rpmteObject *s = PyObject_NEW(rpmteObject, &rpmte_Type);
+ rpmteObject *s = PyObject_New(rpmteObject, &rpmte_Type);
if (s == NULL)
return NULL;
s->te = te;
#include "debug.h"
+/*@unchecked@*/
static int _rpmts_debug = 0;
/*@access alKey @*/
/* this will free the keyList, and decrement the ref count of all
the items on the list as well :-) */
Py_DECREF(trans->keyList);
- PyMem_DEL(o);
+ PyObject_Del(o);
}
/** \ingroup python
return 0;
}
+/** \ingroup python
+ */
+static int rpmts_init(rpmtsObject * s, PyObject *args, PyObject *kwds)
+ /*@*/
+{
+ char * rootDir = "/";
+ int vsflags = rpmExpandNumeric("%{?_vsflags_up2date}");
+
+if (_rpmts_debug < 0)
+fprintf(stderr, "*** rpmts_init(%p,%p,%p)\n", s, args, kwds);
+
+ if (!PyArg_ParseTuple(args, "|si:rpmts_init", &rootDir, &vsflags))
+ return -1;
+
+ s->ts = rpmtsCreate();
+ (void) rpmtsSetRootDir(s->ts, rootDir);
+ (void) rpmtsSetVSFlags(s->ts, vsflags);
+ s->keyList = PyList_New(0);
+ s->scriptFd = NULL;
+ s->tsi = NULL;
+ s->tsiFilter = 0;
+
+ return 0;
+}
+
+/** \ingroup python
+ */
+static void rpmts_free(rpmtsObject * s)
+ /*@*/
+{
+if (_rpmts_debug)
+fprintf(stderr, "%p -- ts %p db %p\n", s, s->ts, s->ts->rdb);
+ rpmtsFree(s->ts);
+
+ if (s->scriptFd)
+ Fclose(s->scriptFd);
+
+ /* this will free the keyList, and decrement the ref count of all
+ the items on the list as well :-) */
+ Py_DECREF(s->keyList);
+
+ _PyObject_GC_Del((PyObject *)s);
+}
+
+/** \ingroup python
+ */
+static PyObject * rpmts_alloc(PyTypeObject * subtype, int nitems)
+ /*@*/
+{
+ PyObject * s = PyType_GenericAlloc(subtype, nitems);
+
+if (_rpmts_debug < 0)
+fprintf(stderr, "*** rpmts_alloc(%p,%d) ret %p\n", subtype, nitems, s);
+ return s;
+}
+
+/** \ingroup python
+ */
+static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
+ /*@*/
+{
+ rpmtsObject * s = (void *) PyObject_New(rpmtsObject, subtype);
+
+ /* Perform additional initialization. */
+ if (rpmts_init(s, args, kwds) < 0) {
+ rpmts_free(s);
+ return NULL;
+ }
+
+if (_rpmts_debug)
+fprintf(stderr, "%p ++ ts %p db %p\n", s, s->ts, s->ts->rdb);
+
+ return (PyObject *)s;
+}
+
/**
*/
/*@unchecked@*/ /*@observer@*/
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- 0, /* tp_new */
- 0, /* tp_free */
+ (initproc) rpmts_init, /* tp_init */
+ (allocfunc) rpmts_alloc, /* tp_alloc */
+ (newfunc) rpmts_new, /* tp_new */
+ (destructor) rpmts_free, /* tp_free */
0, /* tp_is_gc */
#endif
};