SWIG for Python - returning 64 bit value

Discussion in 'Python' started by akineko@gmail.com, Apr 8, 2005.

  1. Guest

    Hello everyone,

    I'm very new to SWIG and I'm trying to use SWIG to interface my Python
    program to routines written in C. Only catch is it has to pass 40 bit
    data both ways.

    I found several postings in the Internet newsgroup related to such.
    My swig interface file is:

    %module ipc_msg
    %{

    %}

    %typemap(in) unsigned long long cmd40b {
    $1 = (unsigned long long) PyLong_AsUnsignedLongLong($input);
    }

    %typemap(out) unsigned long long {
    $result = PyLong_FromUnsignedLongLong((unsigned long long) $1);
    }

    int open_ipc(void);
    void close_ipc(void);
    int update(int, unsigned long long cmd40b);
    unsigned long long capture(int);

    //

    Now I confirmed a Python Long value is correctly sent to a C routine.
    But I found the returned Python Long value from a C routine was
    truncated to a 32 bit value (upper 32 bit).
    After looking at the generated wrapper file, I found the reason.

    > result = (unsigned long long)capture(arg1);


    There is no prototype of the function capture in the generated wrapper
    code. Thus, the function was assumed to return an int (32 bit).

    I added a prototype of the function manually.

    > unsigned long long capture(int arg1);


    Then Python received a correct 64 bit value from a C routine.

    My question is:
    (1) Am I missing something in my interface file?
    The function prototype, unsigned long long capture(int); is already
    there.
    What else I need?
    (2) Is this a bug in SWIG?
    (3) Is there any work around rather than using a code insertion block ?

    I tried to find an answer to this by reading SWIG manual and searching
    the Internet, but so far not successful.

    //

    My platform is Solaris 9 (SUN Sparc) and I'm using Pthon 2.3 and Swig
    1.3.24.

    Any comments will be greatly appreciated.

    Best regards,
    Aki Niimura
     
    , Apr 8, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kj.kjn

    returning a structure using SWIG

    kj.kjn, Jul 2, 2003, in forum: Python
    Replies:
    0
    Views:
    325
    kj.kjn
    Jul 2, 2003
  2. Replies:
    3
    Views:
    1,924
    Timothy Bendfelt
    Jan 19, 2007
  3. Replies:
    12
    Views:
    642
    Richard Heathfield
    Apr 8, 2007
  4. Replies:
    9
    Views:
    1,146
    Juha Nieminen
    Aug 22, 2007
  5. Jeff.M
    Replies:
    6
    Views:
    233
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page