Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > SWIG for Python - returning 64 bit value

Reply
Thread Tools

SWIG for Python - returning 64 bit value

 
 
akineko@gmail.com
Guest
Posts: n/a
 
      04-08-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
A 64-bit binary returning a value to a 32-bit binary? spammenotplui31@yahoo.ca C Programming 12 04-08-2007 07:02 AM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM
returning a structure using SWIG kj.kjn Python 0 07-02-2003 08:53 AM



Advertisments