473,246 Members | 1,304 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,246 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 2989
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
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.