473,387 Members | 1,705 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,387 software developers and data experts.

'long int too large to convert to int' in 'garbage collection' ignored

Hi,

I believe I have discovered a bug in Python 2.3. Could anyone suggest a get around?

When I tested my existing Python code with the newly released Python 2.3, I get the following warning:

FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up

It is because I used some constants such as 0x80ff3366, so I change it to 0x80ff3366L, hoping to get rid of the warning.

But then I get the following fatal error:

Exception exceptions.OverflowError: 'long int too large to convert to int' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection

abnormal program termination

I have tried testing the same code in Python 1.5.2 to Python 2.2. In all these versions, there is no error, no matter I use 0x80ff3366 or 0x80ff3366L. But in Python 2.3, I get warning or fatal error in these cases.

The details are as follows:

The code is running on Windows 2000. Python 2.3.

The Python code calls a C library and pass 0x80ff3366 or 0x80ff3366L to the C library. In the C library, it calls

//convert the given argument to Long in case it is not already Long
PyObject *longObj = PyNumber_Long(argObj);

//get the value of the Python Long variable
long ret = PyLong_AsLong(longObj);

I have done some testing and confirm that the error does not happen if the second line "PyLong_AsLong" is commented out. Also, the erorr does not happen immediately when executing the above statement. It occurs slightly afterwards (during garbage collection?).

Could someone suggest a word around without touching the C library, and without making the Python code too ugly?

Regards
Peter Kwan


Jul 18 '05 #1
2 4953
"Peter Kwan" <pk***@advsofteng.com> wrote in message news:<ma*********************************@python.o rg>...
Hi,

I believe I have discovered a bug in Python 2.3.
This is consistent with most developer's belief systems, which include
code similar to:

blame_list = ["God", "Bill Gates", "Intel", "software supplier", "team
mate", "self"]

and need application of the .reverse() method.
Could anyone suggest a
get around?

When I tested my existing Python code with the newly released Python
2.3, I get the following warning:

FutureWarning: hex/oct constants > sys.maxint will return positive
values in Python 2.4 and up

It is because I used some constants such as 0x80ff3366, so I change it
to 0x80ff3366L, hoping to get rid of the warning.

But then I get the following fatal error:

Exception exceptions.OverflowError: 'long int too large to convert to
int' in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection

abnormal program termination

I have tried testing the same code in Python 1.5.2 to Python 2.2. In all
these versions, there is no error, no matter I use 0x80ff3366 or
0x80ff3366L. But in Python 2.3, I get warning or fatal error in these
cases.

The details are as follows:

The code is running on Windows 2000. Python 2.3.

The Python code calls a C library and pass 0x80ff3366 or 0x80ff3366L to
the C library. In the C library, it calls

//convert the given argument to Long in case it is not already Long
PyObject *longObj = PyNumber Long(argObj);
Danger; you are not testing for an error here. Some clueless caller
could supply an argument that can't be converted to Python Long. You
should do something like this:

PyObject *longObj;

longObj = PyNumber Long(argObj);
if (longObj == NULL) something_nasty_happened(....);

//get the value of the Python Long variable
long ret = PyLong AsLong(longObj);

I have done some testing and confirm that the error does not happen if
the second line "PyLong AsLong" is commented out. Also, the erorr does
not happen immediately when executing the above statement. It occurs
slightly afterwards (during garbage collection?).
You need to distinguish between the happening of the error and the
reporting of it. The error *happens* when you try to convert a long
int value to int type and it won't fit. You are not testing for the
error and clearing it, so it is *reported* later.

Any behavioural difference between versions is probably due to (a)
extra checking in the garbage collection phase in Python 2.3 (b) you
do a one-shot test and immediately exit Python or somehow trigger a
garbage collection before executing some other code -- if you do more
Python execution I would expect the delayed exception to be triggered
whatever the version of Python.

Here's what the doco says:
"""For C programmers, however, error checking always has to be
explicit. All functions in the Python/C API can raise exceptions,
unless an explicit claim is made otherwise in a function's
documentation. In general, when a function encounters an error, it
sets an exception, discards any object references that it owns, and
returns an error indicator -- usually NULL or -1. A few functions
return a Boolean true/false result, with false indicating an error.
Very few functions return no explicit error indicator or have an
ambiguous return value, and require explicit testing for errors with
PyErr_Occurred()"""

The last sentence applies to PyLong_AsLong().

It is of course very remotely possible that the behaviour of
PyLong_AsLong() changed in 2.3 but your posting is very remote from
evidence of that.
Could someone suggest a word around without touching the C library, and
without making the Python code too ugly?


Your C library needs (IMHO) touching so that, with any Python version,
it (a) permits either int or long int arguments (b) detects and
reports bad argument types (c) detects argument values that are not in
your permissible range (d) checks all API function calls for errors.

By the way, what is your permissible range for this argument? Is it a
32-bit vector, or is it whatever what (used to) fit in a Python int?
What should happen on a 64-bit machine?

As a design principle, you are the expert who is providing the library
to non-experts, so the Python code that has to be written to call a
function in your library should be no more ugly than having to have
"L" at the end of constants, if necessary. The work-around should be
done in your C code.

Have you considered using Pyrex? Even if you don't use it to develop
whole modules, looking at the C code that's generated can be very
useful if you need help on how to do reference counting or error
handling (including how to clean up before you return from your
function, both in normal circumstances and when an error has been
detected).

Hope this helps,
John
Jul 18 '05 #2
In article <c7**************************@posting.google.com >,
John Machin <sj******@lexicon.net> wrote:
"Peter Kwan" <pk***@advsofteng.com> wrote in message news:<ma*********************************@python.o rg>...

I believe I have discovered a bug in Python 2.3.


This is consistent with most developer's belief systems, which include
code similar to:

blame_list = ["God", "Bill Gates", "Intel", "software supplier", "team
mate", "self"]

and need application of the .reverse() method.


Possibly. OTOH, I have in the past discovered a real bug in MS SQL
Server.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz
Jul 18 '05 #3

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

Similar topics

4
by: Joe Peterson | last post by:
I could not find another example of this via internet searches, so here it is... I am wondering if this is a python bug or otherwise. The first example of this happened in a larger program of...
13
by: Jeff Melvaine | last post by:
I note that I can write expressions like "1 << 100" and the result is stored as a long integer, which means it is stored as an integer of arbitrary length. I may need to use a large number of...
11
by: Grant Edwards | last post by:
I give up, how do I make this not fail under 2.4? fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00)) I get an OverflowError: long int too large to convert to int ...
11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
1
by: lwickland | last post by:
Summary: System.Net.ScatterGatherBuffers.MemoryChuck allocates inordinately large bytes when sending large post data. The following application consumes inordinate quantities of memory. My code...
18
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful...
9
by: Simple Simon | last post by:
Java longs are 8 bytes. I have a Java long that is coming in from the network, and that represents milliseconds since Epoch (Jan 1 1970 00:00:00). I'm having trouble understanding how to get it...
1
by: khgoh | last post by:
Hi, Need help for the error "OverflowError: long int too large to convert to int" while reading a zip file content. Python version: Python 2.4.1 (#1, Sep 13 2005, 00:39:20) on linux2 Code...
12
by: Ahmad Jalil Qarshi | last post by:
Hi, I have an integer value which is very long like 9987967441778573855. Now I want to convert it into equivalent Hex value. The result must be 8A9C63784361021F I have used...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.