Mapping 64 bit int from C to Python-2.2

  • Thread starter Explore_Imagination
  • Start date
E

Explore_Imagination

Hi

I want to map 64 bit integers from C to python. I must use Python 2.2
BUT There is no support for 64 bits integers in Python2.2 (Supported
in 2.5).

Now the problem is that I have these four variables:

unit32_t a,b,c;
uint64_t w,x,y,z;

I use this funtion to map values:

Py_BuildValue( "(lllllll)", a,b,c,w,x,y,z );

As I access 32 bit values in Python it works fine BUT 64 bit intergers
in Pythong give garbage values . I think there may be a case of
overflow when 64 bit values in C are mapped to python.

Any Suggestions?
 
M

MRAB

Explore_Imagination said:
Hi

I want to map 64 bit integers from C to python. I must use Python 2.2
BUT There is no support for 64 bits integers in Python2.2 (Supported
in 2.5).

Now the problem is that I have these four variables:

unit32_t a,b,c;
uint64_t w,x,y,z;

I use this funtion to map values:

Py_BuildValue( "(lllllll)", a,b,c,w,x,y,z );

As I access 32 bit values in Python it works fine BUT 64 bit intergers
in Pythong give garbage values . I think there may be a case of
overflow when 64 bit values in C are mapped to python.

Any Suggestions?
Split the 64-bit values into 2 x 32-bit values?
 
P

pruebauno

Hi

I want to map 64 bit integers from C to python. I must use Python 2.2
BUT There is no support for 64 bits integers in Python2.2 (Supported
in 2.5).

Now the problem is that I have these four variables:

unit32_t a,b,c;
uint64_t w,x,y,z;

I use this funtion to map values:

Py_BuildValue( "(lllllll)", a,b,c,w,x,y,z );

As I access 32 bit values in Python it works fine BUT 64 bit intergers
in Pythong give garbage values . I think there may be a case of
overflow when 64 bit values in C are mapped to python.

Any Suggestions?

You should be able to create PyLong objects from your 64 bit integers.
PyLong objects have unlimited integer precision. Alas I don't know
enough about the internal C code of Python to know what function to
use to do the conversion from an int64 to a PyLong object.
 
G

Gabriel Genellina

En Mon, 09 Mar 2009 13:51:59 -0200, Explore_Imagination
I want to map 64 bit integers from C to python. I must use Python 2.2
BUT There is no support for 64 bits integers in Python2.2 (Supported
in 2.5).

Now the problem is that I have these four variables:

unit32_t a,b,c;
uint64_t w,x,y,z;

I use this funtion to map values:

Py_BuildValue( "(lllllll)", a,b,c,w,x,y,z );

As I access 32 bit values in Python it works fine BUT 64 bit intergers
in Pythong give garbage values . I think there may be a case of
overflow when 64 bit values in C are mapped to python.

You'll have to use a Python long integer. Try PyLong_FromLongLong (I don't
know if it exists in 2.2)
 
M

Mark Hammond

Hi

I want to map 64 bit integers from C to python. I must use Python 2.2
BUT There is no support for 64 bits integers in Python2.2 (Supported
in 2.5).

Now the problem is that I have these four variables:

unit32_t a,b,c;
uint64_t w,x,y,z;

I use this funtion to map values:

Py_BuildValue( "(lllllll)", a,b,c,w,x,y,z );

As I access 32 bit values in Python it works fine BUT 64 bit intergers
in Pythong give garbage values . I think there may be a case of
overflow when 64 bit values in C are mapped to python.

Any Suggestions?

pywin32 had this requirement, and although support was recently removed,
if you look at:

http://pywin32.cvs.sourceforge.net/...PyLARGE_INTEGER.cpp?revision=1.11&view=markup

you should find routines that work without 'longlong' support in Python
itself.

Cheers,

Mark
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top