[C++-sig] Problem with FILE*

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[C++-sig] Problem with FILE*

Ron Clarke
I know there are some earlier postings similar to this topic, but I've tried
what is shown there with no success. Perhaps I've missed an important point
somewhere along the line. So, if you'll please indulge a question that has
probably been answered somewhere before...

We have a C++ function (not a class member) that takes a pointer to a
proprietary image format, a FILE*, and some optional arguments:
void planeMajor(bkimage *img, FILE *fp, xint32_t pln0 = 0, xint32_t row0 =
0, xint32_t col0 = 0, xint32_t pln1 = -1, xint32_t row1 = -1, xint32_t ,
col1 = -1);

This code is wrapped via Boost like this:
struct FILE_to_pyfile
{
    static PyObject* convert(FILE* x)
    {
        return PyFile_FromFile(x, "", "", NULL);
    }
};

struct pyfile_to_FILE
{
    static FILE& execute(PyObject& o)
    {
        return *PyFile_AsFile(&o);
    }
};


BOOST_PYTHON_FUNCTION_OVERLOADS(pclModule_planeMajor, planeMajor, 2, 8)

BOOST_PYTHON_MODULE(pclModule)
{
to_python_converter<FILE*, FILE_to_pyfile>();
...
def("planeMajor", planeMajor, pclModule_planeMajor() );
...
}

And here is the Python code that calls the C++ function, where "im" is the
Boost-wrapped proprietary image (no problems with the image and all its
methods), and "f" is a file opened using the Python library:
     f = open(dict['fname'], 'wb')
     f.write(dict['head'])
     print 'opened file %s for pcl output' % dict['fname']

     pclModule.planeMajor(im, f)    <<===== this is the line that causes the
error


When this is run, I get the following error:

opened file CRD2.pcl for pcl output  <<======the "print" statement from
above
Traceback (most recent call last):
  File "tryCRD2.py", line 60, in ?
    PCLfns.CRD2PCL(im,dict=dict)
  File "D:\cvsbk\lib\bk\modules\PCLfns.py", line 29, in CRD2PCL
    makePCL(im, dict)
  File "D:\cvsbk\lib\bk\modules\PCLfns.py", line 231, in makePCL
    pclModule.planeMajor(im, f)
Boost.Python.ArgumentError: Python argument types in
    bk.modules.pclModule.planeMajor(bkimage, file)
did not match C++ signature:
    planeMajor(class bkimage *, struct _iobuf *)
    planeMajor(class bkimage *, struct _iobuf *, long)
    planeMajor(class bkimage *, struct _iobuf *, long, long)
    planeMajor(class bkimage *, struct _iobuf *, long, long, long)
    planeMajor(class bkimage *, struct _iobuf *, long, long, long, long)
    planeMajor(class bkimage *, struct _iobuf *, long, long, long, long,
long)
    planeMajor(class bkimage *, struct _iobuf *, long, long, long, long,
long, long)


I'm running Python 2.3, Boost.Python 1.31, on Windows XP. Everything is
compiled under Visual Studio .NET 2003. I've re-built the environment to
make sure the same C++ runtime is being used by Boost and our code.

Any ideas on what is causing this error?
Thanks in advance.

--
Ron Clarke
[hidden email]



_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] Problem with FILE*

David Abrahams
"Ron Clarke" <[hidden email]> writes:

> I'm running Python 2.3, Boost.Python 1.31, on Windows XP. Everything is
> compiled under Visual Studio .NET 2003.

Including Python?

> I've re-built the environment to
> make sure the same C++ runtime is being used by Boost and our code.

If you pass FILE* across the Python/C++ boundary, it had better mean
exactly the same thing on both sides.

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig