From 7970f9696d438b3e2fb6d9272f9f77f60f7c4651 Mon Sep 17 00:00:00 2001 From: "elias.bachaalany" Date: Thu, 29 Oct 2009 11:31:53 +0000 Subject: [PATCH] added from_cobject method to both loader_input_t and qfile_t python classes --- swig/diskio.i | 11 +++++++++++ swig/fpro.i | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/swig/diskio.i b/swig/diskio.i index 4646838..8362b87 100644 --- a/swig/diskio.i +++ b/swig/diskio.i @@ -145,6 +145,17 @@ public: return l; } + //-------------------------------------------------------------------------- + // This method can be used to pass a linput_t* from C code + static loader_input_t *from_cobject(PyObject *pycobject) + { + if (!PyCObject_Check(pycobject)) + return NULL; + loader_input_t *l = new loader_input_t(); + l->set_linput((linput_t *)PyCObject_AsVoidPtr(pycobject)); + return l; + } + //-------------------------------------------------------------------------- static loader_input_t *from_fp(FILE *fp) { diff --git a/swig/fpro.i b/swig/fpro.i index 916acef..a3c7011 100644 --- a/swig/fpro.i +++ b/swig/fpro.i @@ -75,6 +75,13 @@ public: return qf; } + //-------------------------------------------------------------------------- + // This method can be used to pass a FILE* from C code + static qfile_t *from_cobject(PyObject *pycobject) + { + return PyCObject_Check(pycobject) ? from_fp((FILE *)PyCObject_AsVoidPtr(pycobject)) : NULL; + } + //-------------------------------------------------------------------------- static qfile_t *tmpfile() { @@ -162,7 +169,7 @@ public: } //-------------------------------------------------------------------------- - int write(PyObject *py_buf, bool big_endian) + int writebytes(PyObject *py_buf, bool big_endian) { int sz = PyString_GET_SIZE(py_buf); void *buf = (void *)PyString_AS_STRING(py_buf);