wxInputStream and the tell() file method

Hi,

When wxpython-2.4.2.4 is compiled with largefiles support, wxInputStream
wrapping file-alike methods will fail to wrap the tell() file method if
it doesn't return a long object, such as in the case of the cStringIO's.

Attached is an example of this bug.

The wrapper code from wxPython/src/helpers.cpp is very strange:

off_t wxPyCBInputStream::OnSysTell() const {
    wxPyBeginBlockThreads();
    PyObject* arglist = Py_BuildValue("()");
    PyObject* result = PyEval_CallObject(m_tell, arglist);
    Py_DECREF(arglist);
    off_t o = 0;
    if (result != NULL) {
#ifdef _LARGE_FILES
        if (PyLong_Check(result))
            o = PyLong_AsLongLong(result);
        else
#else

Isn't this "#else" directive in excess here? Otherwise 'result'
reference count is not decreased when 'PyLong_Check(result)' verifies,
and result isn't used otherwise...

        o = PyInt_AsLong(result);
#endif
        Py_DECREF(result);
    };
    wxPyEndBlockThreads();
    return o;
}

Sorry for not testing this out but I'm using wxPython from Debian and it
would be too much trouble to compile it from scratch.

Regards,

José Fonseca

test.py (1.46 KB)

José Fonseca wrote:

Hi,

When wxpython-2.4.2.4 is compiled with largefiles support, wxInputStream
wrapping file-alike methods will fail to wrap the tell() file method if
it doesn't return a long object, such as in the case of the cStringIO's.

Attached is an example of this bug.

The wrapper code from wxPython/src/helpers.cpp is very strange:

off_t wxPyCBInputStream::OnSysTell() const {
   wxPyBeginBlockThreads();
   PyObject* arglist = Py_BuildValue("()");
   PyObject* result = PyEval_CallObject(m_tell, arglist);
   Py_DECREF(arglist);
   off_t o = 0;
   if (result != NULL) {
#ifdef _LARGE_FILES
       if (PyLong_Check(result))
           o = PyLong_AsLongLong(result);
       else
#else

Isn't this "#else" directive in excess here?

Yes. You are correct. It should be changed to #endif.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!