473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

In C extension .pyd, sizeof INT64 = 4?

My C extension works wrong, and debug it, found that sizeof (INT64) =
4, not 8.
I compile on Windows XP platform.
Please tell me how to fix it to support INT64?
Thanks.

Jun 12 '07 #1
12 3001
On 6 12 , 6 03 , Allen <Allen.Che...@gmail.comwrote:
My C extension works wrong, and debug it, found that sizeof (INT64) =
4, not 8.
I compile on Windows XP platform.
Please tell me how to fix it to support INT64?
Thanks.
I find it is strange. In an exe win32 console project, sizeof(INT64) =
8.

My code is just like this:

/* my.h header file */

#ifdef __cplusplus
extern "C" {
#endif

static PyObject* method(PyObject* self, PyObject *args);

#idef __cplusplus
}
#endif

/* my.cpp source file */
PyObject* method(PyObject* self, PyObject *args)
{
INT64 nValue; /* LINE_HERE */
INT32 nRet;
nRet = DoSomeCOperations(nValue);
return PyBuildValue("i", nRet);
}

If I changed INT64 nValue to be static INT64 nValue at LINE_HERE, it
is ok.
Why?
Jun 12 '07 #2
En Tue, 12 Jun 2007 08:39:43 -0300, Allen <Al**********@gmail.com>
escribió:
PyObject* method(PyObject* self, PyObject *args)
{
INT64 nValue; /* LINE_HERE */
INT32 nRet;
nRet = DoSomeCOperations(nValue);
return PyBuildValue("i", nRet);
}

If I changed INT64 nValue to be static INT64 nValue at LINE_HERE, it
is ok.
Why?
I don't know, but I don't see either where Python is involved... you don't
use any argument and the returned Python object is not an INT64...

--
Gabriel Genellina

Jun 12 '07 #3
On 6 12 , 8 08 , "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Tue, 12 Jun 2007 08:39:43 -0300, Allen <Allen.Che...@gmail.com>
escribió:
PyObject* method(PyObject* self, PyObject *args)
{
INT64 nValue; /* LINE_HERE */
INT32 nRet;
nRet = DoSomeCOperations(nValue);
return PyBuildValue("i", nRet);
}
If I changed INT64 nValue to be static INT64 nValue at LINE_HERE, it
is ok.
Why?

I don't know, but I don't see either where Python is involved... you don't
use any argument and the returned Python object is not an INT64...

--
Gabriel Genellina
The problem is obviously compiler involved.
But I don't know why the sizeof INT64 is changed to be 4.

Jun 12 '07 #4
En Tue, 12 Jun 2007 10:01:47 -0300, Allen <Al**********@gmail.com>
escribió:
The problem is obviously compiler involved.
But I don't know why the sizeof INT64 is changed to be 4.
This prints 8, compiled with Visual C++ 2005 Express, Python 2.5.1, inside
a Python extension with all the normal definitions and #include's

void test(void)
{
INT64 i=1;
printf("%d\n", sizeof(i));
}

--
Gabriel Genellina

Jun 12 '07 #5
Allen schrieb:
My C extension works wrong, and debug it, found that sizeof (INT64) =
4, not 8.
I compile on Windows XP platform.
Please tell me how to fix it to support INT64?
What *is* INT64? It's not a builtin type of standard C, it isn't
defined by Microsoft C, and it isn't predefined by Python.

So it must be something that you have defined, and apparently
incorrectly. How did you define it?

Regards,
Martin
Jun 12 '07 #6
On 6 13 , 4 06 , "Martin v. Lo"wis" <mar...@v.loewis.dewrote:
Allen schrieb:
My C extension works wrong, and debug it, found that sizeof (INT64) =
4, not 8.
I compile on Windows XP platform.
Please tell me how to fix it to support INT64?

What *is* INT64? It's not a builtin type of standard C, it isn't
defined by Microsoft C, and it isn't predefined by Python.

So it must be something that you have defined, and apparently
incorrectly. How did you define it?

Regards,
Martin
Thanks for your reply.

I defined in this way:

#ifndef WIN32
typedef long long INT64;
#else
typedef __int64 INT64;
#endif

I feel it strange that when I use INT64 as local variable, it will run
error.
When I change the local variable to be static or global, it will be
ok.

Jun 13 '07 #7
On 6 13 , 9 00 , Allen <pruyu.c...@gmail.comwrote:
On 6 13 , 4 06 , "Martin v. Lo"wis" <mar...@v.loewis.dewrote:
Allen schrieb:
My C extension works wrong, and debug it, found that sizeof (INT64) =
4, not 8.
I compile on Windows XP platform.
Please tell me how to fix it to support INT64?
What *is* INT64? It's not a builtin type of standard C, it isn't
defined by Microsoft C, and it isn't predefined by Python.
So it must be something that you have defined, and apparently
incorrectly. How did you define it?
Regards,
Martin

Thanks for your reply.

I defined in this way:

#ifndef WIN32
typedef long long INT64;
#else
typedef __int64 INT64;
#endif

I feel it strange that when I use INT64 as local variable, it will run
error.
When I change the local variable to be static or global, it will be
ok.
I feel very very sorry.
It is my fault.
I used INT64 and initialize its value from PyArg_ParseTuple.
The code is PyArg_ParseTuple(args, "l", &nValue).
It should be PyArg_ParseTuple(args, "L", &nValue).

Thanks all of you.

Regars,
Allen Chen

Jun 13 '07 #8
I used INT64 and initialize its value from PyArg_ParseTuple.
The code is PyArg_ParseTuple(args, "l", &nValue).
It should be PyArg_ParseTuple(args, "L", &nValue).
That's still incorrect. For the L format flag, use PY_LONG_LONG,
not your own INT64 type. More generally: always use the type
documented in

http://docs.python.org/api/arg-parsing.html

Regards,
Martin
Jun 13 '07 #9
On 6 13 , 11 55 , "Martin v. Löwis" <mar...@v.loewis.dewrote:
I used INT64 and initialize its value from PyArg_ParseTuple.
The code is PyArg_ParseTuple(args, "l", &nValue).
It should be PyArg_ParseTuple(args, "L", &nValue).

That's still incorrect. For the L format flag, use PY_LONG_LONG,
not your own INT64 type. More generally: always use the type
documented in

http://docs.python.org/api/arg-parsing.html

Regards,
Martin
PY_LONG_LONG is decleared as __int64 on windows. There is no
difference.

Regards,
Allen Chen

Jun 13 '07 #10

On 12 jun 2007, at 12.03, Allen wrote:
My C extension works wrong, and debug it, found that sizeof (INT64) =
4, not 8.
I compile on Windows XP platform.
Please tell me how to fix it to support INT64?
Thanks.

--
http://mail.python.org/mailman/listinfo/python-list
On compilers that can gnerate both 32 and 64 bit executables, the
size of some
data types vary according to compiler options.
You are probably using a typedef long INT64;
In order for INT64 to always be 64 bits/8bytes you should declare:
typedef long long INT64;
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
to************@comhem.se

Jun 13 '07 #11
On 12 jun, 17:06, "Martin v. Lo"wis" <mar...@v.loewis.dewrote:
>
What *is*INT64? It's not a builtin type of standard C, it isn't
defined by Microsoft C, and it isn't predefined by Python.

So it must be something that you have defined, and apparently
incorrectly. How did you define it?
It is defined in basetsd.h, included by winnt.h; the OP should not
redefine it, and that also explains why I could compile my test
program without any problem.

--
Gabriel Genellina

Jun 13 '07 #12
Allen wrote:
On 6 13 , 11 55 , "Martin v. Löwis" <mar...@v.loewis.dewrote:
I used INT64 and initialize its value from PyArg_ParseTuple.
The code is PyArg_ParseTuple(args, "l", &nValue).
It should be PyArg_ParseTuple(args, "L", &nValue).

That's still incorrect. For the L format flag, use PY_LONG_LONG,
not your own INT64 type. More generally: always use the type
documented in

http://docs.python.org/api/arg-parsing.html

Regards,
Martin

PY_LONG_LONG is decleared as __int64 on windows. There is no
difference.
IMHO. Make your code platform independant and use your compiler capacities.

If for an 'L' argument PyArg_ParseTuple requires a PY_LONG_LONG, then give
it a PY_LONG_LONG and assign the parsed value into an INT64 after parsing.

You dont know if PY_LONG_LONG or INT64 wil not be defined differently in the
future, so use them where they are specified, do the assignment, and leave
the compiler warn you if anything become invalid in the futur.

My 2 cents.

A+

Laurent.

Jun 14 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben Chivers | last post by:
Hi, I am having problems trying to connect to php://input through a stream in a php extension. The extension successfully connects to php://input but when I pass data to it, the code I have...
3
by: Peter Sparago | last post by:
(Sorry in advance for the long post.) Hi, I'm having a great deal of difficulty buiding a Python COM extension. I am using the MSHTML ActiveX control in my application but I need to interact...
6
by: Java and Swing | last post by:
Hi, I have been posting about writing a C extension for Python...so far, so good. At least for the "simple" functions that I need to wrap. Ok, my c function looks like... MY_NUM...
14
by: Josh Ferguson | last post by:
I don't believe a syntax driven equivalent exists for this, but I just thought it would be neat if you could use foreach to do something like this: foreach (Object x in collection1, collection2)...
4
by: Simon Devlin | last post by:
Hi folks, I've been bashing my head against this all afternoon and am now totally baffled. Given this (a simple routine to turn a ip address string into an decimal) <snip> Dim Parts(3) as...
5
by: harishashim | last post by:
I have gone through necessary step and have been able to use a .Net libraries (created using C#) in VB6. It run good untill I try to use certain function in the library that is using Int64 type as...
14
by: cj | last post by:
VB2003. I need a large positive integer. Which is larger int64 or double? I see int64 also apparently is known as long and will hold -9,223,372,036,854,775,808 through...
3
by: Tim Sprout | last post by:
To convert hex to Int64 I can use: string hex = "413208A97245F5AE"; Int64 intFromHex = System.Convert.ToInt64(hex, 16); //intFromHex = 4697826885160531374 How do I reverse this, and convert...
6
by: msb_6 | last post by:
Currently I have a PHP extension thats all written and compiles under windows, but the PC I'm going to end up putting it on is running Ubuntu 8.04 (g++ 4.2.3). I've delved into PHP documentation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.