added from_cobject method to both loader_input_t and qfile_t python classes

This commit is contained in:
elias.bachaalany 2009-10-29 11:31:53 +00:00
parent b9465ab7f6
commit 7970f9696d
2 changed files with 19 additions and 1 deletions

View File

@ -145,6 +145,17 @@ public:
return l; 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) static loader_input_t *from_fp(FILE *fp)
{ {

View File

@ -75,6 +75,13 @@ public:
return qf; 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() 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); int sz = PyString_GET_SIZE(py_buf);
void *buf = (void *)PyString_AS_STRING(py_buf); void *buf = (void *)PyString_AS_STRING(py_buf);