473,761 Members | 3,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'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.Over flowError: '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(a rgObj);

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

I have done some testing and confirm that the error does not happen if the second line "PyLong_AsL ong" 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 4974
"Peter Kwan" <pk***@advsofte ng.com> wrote in message news:<ma******* *************** ***********@pyt hon.org>...
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.Over flowError: '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******@lexic on.net> wrote:
"Peter Kwan" <pk***@advsofte ng.com> wrote in message news:<ma******* *************** ***********@pyt hon.org>...

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**@pythoncra ft.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
1625
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 mine, and the traceback reports the problem at the start of a "for" loop (making no sense), but I cannot easily include the full code and instructions here. So I wrote a small test program containing the offending code, and in this case the...
13
2536
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 these, and am interested to know whether the storage efficiency of long integers is in danger of breaking my code if I use too many. Would I do better to write a class that defines bitwise operations on arrays of integers, each integer being assumed...
11
6301
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 ioctl() is expecting a 32-bit integer value, and 0xc0047a80 has the high-order bit set. I'm assuming Python thinks it's a signed value. How do I tell Python that 0xc0047a80 is an unsigned 32-bit value?
11
5312
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 4-month old C#/MC++ .NET project project. I'd like to thank in advance anyone who takes the time to read and/or respond to this message. At a couple points, it may seem like a rant against C# / .NET, but we are pretty firmly stuck with this approach...
1
4012
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 does not explicitly allocate memory in a loop nor does it explicitly allocate large blocks of memory. Yet, the application’s memory footprint will grow as large as 370 MB. Rarely will it run to completion; usually, it throws an out of memory...
18
2210
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 documents that you could point me to help me control the GC, then that would be great also. The .Net GC does not cleanup memory of our service process unless it is forced to by another process that hogs memory. · GC Algorithm - This is an issue...
9
3685
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 into a struct timeval object. I get the ByteBuffer as an array of const unsigned char, 'buffer'. Here's an example: 00 00 01 0A 29 1D 07 E4 This value maps somehow to Thu Mar 23 16:57:49 2006 and some
1
4334
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 >>> import os, datetime, sys, optparse, string, operator, gzip >>> health_day_summary_file = gzip.GzipFile( "health_CORR_summary.csv.gz", "rb")
12
13515
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 sprintf(pHex,"%0X",9987967441778573855). But it only returns 8
0
9538
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9353
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10123
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9788
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5241
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2765
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.