summaryrefslogtreecommitdiffstats
path: root/rpmmodule
diff options
context:
space:
mode:
authorMatt Wilson <msw@redhat.com>2000-01-02 20:48:19 +0000
committerMatt Wilson <msw@redhat.com>2000-01-02 20:48:19 +0000
commit7de9b8ca0ff2a145a3a40f00b182e1f4408b7377 (patch)
tree3f89b8a9caa874bc71175a3cc4b1f795085ac3a9 /rpmmodule
parentfd09794abe87df16d38b118aeb3938a0a8bc6efc (diff)
downloadanaconda-7de9b8ca0ff2a145a3a40f00b182e1f4408b7377.tar.gz
anaconda-7de9b8ca0ff2a145a3a40f00b182e1f4408b7377.tar.xz
anaconda-7de9b8ca0ff2a145a3a40f00b182e1f4408b7377.zip
some work
Diffstat (limited to 'rpmmodule')
-rw-r--r--rpmmodule/rpmmodule.c66
1 files changed, 61 insertions, 5 deletions
diff --git a/rpmmodule/rpmmodule.c b/rpmmodule/rpmmodule.c
index 4265b8a6e..26145ab2c 100644
--- a/rpmmodule/rpmmodule.c
+++ b/rpmmodule/rpmmodule.c
@@ -64,6 +64,7 @@ static void rpmtransDealloc(PyObject * o);
static PyObject * rpmtransGetAttr(rpmtransObject * o, char * name);
static int rpmtransSetAttr(rpmtransObject * o, char * name,
PyObject * val);
+static PyObject * doFopen(PyObject * self, PyObject * args);
/* Types */
@@ -82,6 +83,9 @@ static PyMethodDef rpmModuleMethods[] = {
{ "errorString", (PyCFunction) errorString, METH_VARARGS, NULL },
{ "versionCompare", (PyCFunction) versionCompare, METH_VARARGS, NULL },
{ "labelCompare", (PyCFunction) labelCompare, METH_VARARGS, NULL },
+ /* Don't use me yet.
+ { "Fopen", (PyCFunction) doFopen, METH_VARARGS, NULL },
+ */
{ NULL }
} ;
@@ -223,7 +227,7 @@ void initrpm(void) {
for (i = 0; i < rpmTagTableSize; i++) {
tag = PyInt_FromLong(rpmTagTable[i].val);
- PyDict_SetItemString(d, rpmTagTable[i].name, tag);
+ PyDict_SetItemString(d, (char *) rpmTagTable[i].name, tag);
PyDict_SetItem(dict, tag, PyString_FromString(rpmTagTable[i].name + 7));
}
@@ -605,6 +609,22 @@ static PyObject * errorSetCallback (PyObject * self, PyObject * args) {
if (!PyArg_ParseTuple(args, "O|O", &errorCB, &errorData)) return NULL;
+ /* if we're getting a void*, set the error callback to this. */
+ /* also, we can possibly decref any python callbacks we had */
+ /* and set them to NULL. */
+ if (PyCObject_Check (errorCB)) {
+ rpmErrorSetCallback (PyCObject_AsVoidPtr(errorCB));
+
+ Py_XDECREF (errorCB);
+ Py_XDECREF (errorData);
+
+ errorCB = NULL;
+ errorData = NULL;
+
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
if (!PyCallable_Check (errorCB)) {
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
@@ -613,10 +633,7 @@ static PyObject * errorSetCallback (PyObject * self, PyObject * args) {
Py_INCREF (errorCB);
Py_XINCREF (errorData);
- rpmErrorSetCallback (errorcb);
-
- Py_INCREF(Py_None);
- return Py_None;
+ return PyCObject_FromVoidPtr(rpmErrorSetCallback (errorcb), NULL);
}
static PyObject * errorString (PyObject * self, PyObject * args) {
@@ -1457,3 +1474,42 @@ static PyObject * doAddMacro(PyObject * self, PyObject * args) {
Py_INCREF(Py_None);
return Py_None;
}
+
+static int closeCallback(FILE * f) {
+ /* XXX FD_t leak */
+ /* XXX lookup the FD_t from the fp and close with Fclose */
+ return fclose(f);
+ return 0;
+}
+
+static PyObject * doFopen(PyObject * self, PyObject * args) {
+ char * path, * mode;
+ FD_t fd;
+ FILE *f;
+
+ if (!PyArg_ParseTuple(args, "ss", &path, &mode))
+ return NULL;
+
+ fd = Fopen(path, mode);
+ fd = fdLink(fd, "doFopen");
+
+ if (!fd) {
+ PyErr_SetFromErrno(pyrpmError);
+ return NULL;
+ }
+
+ if (Ferror(fd)) {
+ const char *err = Fstrerror(fd);
+ if (err) {
+ PyErr_SetString(pyrpmError, err);
+ return NULL;
+ }
+ }
+ f = fdGetFp(fd);
+ if (!f) {
+ PyErr_SetString(pyrpmError, "FD_t has no FILE*");
+ return NULL;
+ }
+
+ return PyFile_FromFile (f, path, mode, closeCallback);
+}