SWIG for Python - returning 64 bit value

A

akineko

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top