[PyKDE] atoll conversion problem in PyKDE-3.3.2

Jim Bublitz jbublitz at nwinternet.com
Fri Aug 23 06:04:01 BST 2002


On 23-Aug-02 Steve Simmons wrote:
> I'm getting compile errors from at attempt to build PyKDE-3.3.2:
> It appears that atoll() is a function present in stdlib in NetBSD
> but not FreeBSD.  Is there a missing switch or spec I need here?

The line causing the error in filesize_t.sip is:

        long long val = atoll (s);

As you point out, atoll() is defined in stdlib.h in Linux. I don't
have access to FreeBSD, so I can't suggest an alternative. If I
remember correctly, the problem is that there isn't any guarantee
that the long long conversion code in Python is compiled in (it's
conditionally compiled), so in filesize_t.sip the PyLong is
converted to a string and then to a long long using atoll(). If you
can't find a replacement for atoll() (and the proper include file)
to edit into filesize_t.sip, you can try replacing the
%ConvertToTypeCode block with:

%ConvertToTypeCode
        // Convert a Python long integer to a C++ long long

        if (sipIsErr == NULL)
             return PyLong_Check (sipPy);

        long long val = PyLong_AsLongLong (sipPy);

        *sipCppPtr = (kiofilesize_t *) &val;

        return 1;
%End

There is also a PyLong_AsUnsignedLongLong (), although I doubt it
will make a difference. Whether this works, depends on whether your
Python was compiled with HAVE_LONG_LONG #defined (see longobject.h
in the Python Include subdirectory). It also depends on whether
FreeBSD defines a long long type. Of course it also depends on the
above code being correct - I believe it is, but haven't tried it.

A final (unatractive) alternative if you have neither atoll()
or PyLong_AsLongLong would be to replace the above code with:

        long long val = 0;
        *sipCppPtr = (kiofilesize_t *) &val;

but then 0 will always be passed to C++ when you pass filesize_t.
Normally the value returned to Python (which is generated in
%ConvertFromTypeCode in the same file) is what you'd be interested
in for most cases. A Python 'long' is only limited by available
memory.

There is no platform-based conditional code (or defines or
switches) in PyKDE at the moment.


Jim





More information about the PyQt mailing list