1991-02-19 08:39:46 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* Integer object implementation */
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
#include "Python.h"
|
1999-10-12 16:54:53 -03:00
|
|
|
#include <ctype.h>
|
1990-10-14 09:07:46 -03:00
|
|
|
|
1993-12-24 06:22:45 -04:00
|
|
|
long
|
2000-07-09 12:16:51 -03:00
|
|
|
PyInt_GetMax(void)
|
1993-12-24 06:22:45 -04:00
|
|
|
{
|
|
|
|
return LONG_MAX; /* To initialize sys.maxint */
|
|
|
|
}
|
|
|
|
|
1990-12-20 11:06:42 -04:00
|
|
|
/* Integers are quite normal objects, to make object handling uniform.
|
|
|
|
(Using odd pointers to represent integers would save much space
|
|
|
|
but require extra checks for this special case throughout the code.)
|
2002-04-28 13:57:34 -03:00
|
|
|
Since a typical Python program spends much of its time allocating
|
1990-12-20 11:06:42 -04:00
|
|
|
and deallocating integers, these operations should be very fast.
|
|
|
|
Therefore we use a dedicated allocation scheme with a much lower
|
|
|
|
overhead (in space and time) than straight malloc(): a simple
|
|
|
|
dedicated free list, filled when necessary with memory from malloc().
|
2002-04-28 13:57:34 -03:00
|
|
|
|
|
|
|
block_list is a singly-linked list of all PyIntBlocks ever allocated,
|
|
|
|
linked via their next members. PyIntBlocks are never returned to the
|
|
|
|
system before shutdown (PyInt_Fini).
|
|
|
|
|
|
|
|
free_list is a singly-linked list of available PyIntObjects, linked
|
|
|
|
via abuse of their ob_type members.
|
1990-12-20 11:06:42 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define BLOCK_SIZE 1000 /* 1K less typical malloc overhead */
|
1999-03-12 15:43:17 -04:00
|
|
|
#define BHEAD_SIZE 8 /* Enough for a 64-bit pointer */
|
|
|
|
#define N_INTOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyIntObject))
|
1999-03-10 18:55:24 -04:00
|
|
|
|
1999-03-12 15:43:17 -04:00
|
|
|
struct _intblock {
|
|
|
|
struct _intblock *next;
|
|
|
|
PyIntObject objects[N_INTOBJECTS];
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _intblock PyIntBlock;
|
|
|
|
|
|
|
|
static PyIntBlock *block_list = NULL;
|
|
|
|
static PyIntObject *free_list = NULL;
|
1990-12-20 11:06:42 -04:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyIntObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
fill_free_list(void)
|
1990-12-20 11:06:42 -04:00
|
|
|
{
|
1997-05-02 00:12:38 -03:00
|
|
|
PyIntObject *p, *q;
|
2002-04-28 13:57:34 -03:00
|
|
|
/* Python's object allocator isn't appropriate for large blocks. */
|
2000-05-03 20:44:39 -03:00
|
|
|
p = (PyIntObject *) PyMem_MALLOC(sizeof(PyIntBlock));
|
1990-12-20 11:06:42 -04:00
|
|
|
if (p == NULL)
|
2000-05-03 20:44:39 -03:00
|
|
|
return (PyIntObject *) PyErr_NoMemory();
|
1999-03-12 15:43:17 -04:00
|
|
|
((PyIntBlock *)p)->next = block_list;
|
|
|
|
block_list = (PyIntBlock *)p;
|
2002-04-28 13:57:34 -03:00
|
|
|
/* Link the int objects together, from rear to front, then return
|
|
|
|
the address of the last int object in the block. */
|
1999-03-12 15:43:17 -04:00
|
|
|
p = &((PyIntBlock *)p)->objects[0];
|
1990-12-20 11:06:42 -04:00
|
|
|
q = p + N_INTOBJECTS;
|
|
|
|
while (--q > p)
|
1999-03-10 18:55:24 -04:00
|
|
|
q->ob_type = (struct _typeobject *)(q-1);
|
|
|
|
q->ob_type = NULL;
|
1990-12-20 11:06:42 -04:00
|
|
|
return p + N_INTOBJECTS - 1;
|
|
|
|
}
|
|
|
|
|
1993-10-15 13:18:48 -03:00
|
|
|
#ifndef NSMALLPOSINTS
|
2006-02-22 07:30:06 -04:00
|
|
|
#define NSMALLPOSINTS 257
|
1993-10-15 13:18:48 -03:00
|
|
|
#endif
|
|
|
|
#ifndef NSMALLNEGINTS
|
2002-12-30 18:29:22 -04:00
|
|
|
#define NSMALLNEGINTS 5
|
1993-10-15 13:18:48 -03:00
|
|
|
#endif
|
|
|
|
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
|
|
|
|
/* References to small integers are saved in this array so that they
|
|
|
|
can be shared.
|
|
|
|
The integers that are saved are those in the range
|
|
|
|
-NSMALLNEGINTS (inclusive) to NSMALLPOSINTS (not inclusive).
|
|
|
|
*/
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyIntObject *small_ints[NSMALLNEGINTS + NSMALLPOSINTS];
|
1993-10-15 13:18:48 -03:00
|
|
|
#endif
|
|
|
|
#ifdef COUNT_ALLOCS
|
|
|
|
int quick_int_allocs, quick_neg_int_allocs;
|
|
|
|
#endif
|
1990-12-20 11:06:42 -04:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
PyInt_FromLong(long ival)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
1997-05-02 00:12:38 -03:00
|
|
|
register PyIntObject *v;
|
1993-10-15 13:18:48 -03:00
|
|
|
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
|
2002-12-30 18:29:22 -04:00
|
|
|
if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
|
|
|
|
v = small_ints[ival + NSMALLNEGINTS];
|
1997-05-02 00:12:38 -03:00
|
|
|
Py_INCREF(v);
|
1993-10-15 13:18:48 -03:00
|
|
|
#ifdef COUNT_ALLOCS
|
|
|
|
if (ival >= 0)
|
|
|
|
quick_int_allocs++;
|
|
|
|
else
|
|
|
|
quick_neg_int_allocs++;
|
|
|
|
#endif
|
1997-05-02 00:12:38 -03:00
|
|
|
return (PyObject *) v;
|
1993-10-15 13:18:48 -03:00
|
|
|
}
|
|
|
|
#endif
|
1990-12-20 11:06:42 -04:00
|
|
|
if (free_list == NULL) {
|
|
|
|
if ((free_list = fill_free_list()) == NULL)
|
|
|
|
return NULL;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
2002-08-19 16:26:42 -03:00
|
|
|
/* Inline PyObject_New */
|
1990-12-20 11:06:42 -04:00
|
|
|
v = free_list;
|
1999-03-10 18:55:24 -04:00
|
|
|
free_list = (PyIntObject *)v->ob_type;
|
2000-05-03 20:44:39 -03:00
|
|
|
PyObject_INIT(v, &PyInt_Type);
|
1990-12-20 11:06:42 -04:00
|
|
|
v->ob_ival = ival;
|
1997-05-02 00:12:38 -03:00
|
|
|
return (PyObject *) v;
|
1990-12-20 11:06:42 -04:00
|
|
|
}
|
|
|
|
|
2006-02-15 13:27:45 -04:00
|
|
|
PyObject *
|
|
|
|
PyInt_FromSize_t(size_t ival)
|
|
|
|
{
|
|
|
|
if (ival <= LONG_MAX)
|
|
|
|
return PyInt_FromLong((long)ival);
|
|
|
|
return _PyLong_FromSize_t(ival);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
PyInt_FromSsize_t(Py_ssize_t ival)
|
|
|
|
{
|
|
|
|
if (ival >= LONG_MIN && ival <= LONG_MAX)
|
|
|
|
return PyInt_FromLong((long)ival);
|
|
|
|
return _PyLong_FromSsize_t(ival);
|
|
|
|
}
|
|
|
|
|
1990-12-20 11:06:42 -04:00
|
|
|
static void
|
2000-07-09 12:16:51 -03:00
|
|
|
int_dealloc(PyIntObject *v)
|
1990-12-20 11:06:42 -04:00
|
|
|
{
|
2001-09-11 13:13:52 -03:00
|
|
|
if (PyInt_CheckExact(v)) {
|
2001-08-29 12:47:46 -03:00
|
|
|
v->ob_type = (struct _typeobject *)free_list;
|
|
|
|
free_list = v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
v->ob_type->tp_free((PyObject *)v);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2002-04-25 21:53:34 -03:00
|
|
|
static void
|
|
|
|
int_free(PyIntObject *v)
|
|
|
|
{
|
|
|
|
v->ob_type = (struct _typeobject *)free_list;
|
|
|
|
free_list = v;
|
|
|
|
}
|
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
long
|
2000-07-09 12:16:51 -03:00
|
|
|
PyInt_AsLong(register PyObject *op)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
1997-05-02 00:12:38 -03:00
|
|
|
PyNumberMethods *nb;
|
|
|
|
PyIntObject *io;
|
1994-08-29 09:48:32 -03:00
|
|
|
long val;
|
2001-12-04 19:05:10 -04:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
if (op && PyInt_Check(op))
|
|
|
|
return PyInt_AS_LONG((PyIntObject*) op);
|
2001-12-04 19:05:10 -04:00
|
|
|
|
1994-08-29 09:48:32 -03:00
|
|
|
if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
|
|
|
|
nb->nb_int == NULL) {
|
2000-05-09 11:27:48 -03:00
|
|
|
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
1990-10-14 09:07:46 -03:00
|
|
|
return -1;
|
|
|
|
}
|
2001-12-04 19:05:10 -04:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
io = (PyIntObject*) (*nb->nb_int) (op);
|
1994-08-29 09:48:32 -03:00
|
|
|
if (io == NULL)
|
|
|
|
return -1;
|
1997-05-02 00:12:38 -03:00
|
|
|
if (!PyInt_Check(io)) {
|
2002-11-19 16:49:15 -04:00
|
|
|
if (PyLong_Check(io)) {
|
|
|
|
/* got a long? => retry int conversion */
|
|
|
|
val = PyLong_AsLong((PyObject *)io);
|
2003-02-20 16:32:11 -04:00
|
|
|
Py_DECREF(io);
|
|
|
|
if ((val == -1) && PyErr_Occurred())
|
2002-11-19 16:49:15 -04:00
|
|
|
return -1;
|
2003-02-20 16:32:11 -04:00
|
|
|
return val;
|
2002-11-19 16:49:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-04-17 15:55:45 -03:00
|
|
|
Py_DECREF(io);
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"nb_int should return int object");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val = PyInt_AS_LONG(io);
|
|
|
|
Py_DECREF(io);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2006-02-15 13:27:45 -04:00
|
|
|
Py_ssize_t
|
|
|
|
PyInt_AsSsize_t(register PyObject *op)
|
|
|
|
{
|
2006-02-15 19:08:56 -04:00
|
|
|
#if SIZEOF_SIZE_T != SIZEOF_LONG
|
2006-02-15 13:27:45 -04:00
|
|
|
PyNumberMethods *nb;
|
|
|
|
PyIntObject *io;
|
|
|
|
Py_ssize_t val;
|
2006-02-15 19:08:56 -04:00
|
|
|
#endif
|
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
which unfortunately means the errors from the bytes type change somewhat:
bytes([300]) still raises a ValueError, but bytes([10**100]) now raises a
TypeError (either that, or bytes(1.0) also raises a ValueError --
PyNumber_AsSsize_t() can only raise one type of exception.)
Merged revisions 51188-51433 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r51189 | kurt.kaiser | 2006-08-10 19:11:09 +0200 (Thu, 10 Aug 2006) | 4 lines
Retrieval of previous shell command was not always preserving indentation
since 1.2a1) Patch 1528468 Tal Einat.
........
r51190 | guido.van.rossum | 2006-08-10 19:41:07 +0200 (Thu, 10 Aug 2006) | 3 lines
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
SF bug #1112549.
........
r51191 | guido.van.rossum | 2006-08-10 19:42:50 +0200 (Thu, 10 Aug 2006) | 2 lines
News item for SF bug 1112549.
........
r51192 | guido.van.rossum | 2006-08-10 20:09:25 +0200 (Thu, 10 Aug 2006) | 2 lines
Fix title -- it's rc1, not beta3.
........
r51194 | martin.v.loewis | 2006-08-10 21:04:00 +0200 (Thu, 10 Aug 2006) | 3 lines
Update dangling references to the 3.2 database to
mention that this is UCD 4.1 now.
........
r51195 | tim.peters | 2006-08-11 00:45:34 +0200 (Fri, 11 Aug 2006) | 6 lines
Followup to bug #1069160.
PyThreadState_SetAsyncExc(): internal correctness changes wrt
refcount safety and deadlock avoidance. Also added a basic test
case (relying on ctypes) and repaired the docs.
........
r51196 | tim.peters | 2006-08-11 00:48:45 +0200 (Fri, 11 Aug 2006) | 2 lines
Whitespace normalization.
........
r51197 | tim.peters | 2006-08-11 01:22:13 +0200 (Fri, 11 Aug 2006) | 5 lines
Whitespace normalization broke test_cgi, because a line
of quoted test data relied on preserving a single trailing
blank. Changed the string from raw to regular, and forced
in the trailing blank via an explicit \x20 escape.
........
r51198 | tim.peters | 2006-08-11 02:49:01 +0200 (Fri, 11 Aug 2006) | 10 lines
test_PyThreadState_SetAsyncExc(): This is failing on some
64-bit boxes. I have no idea what the ctypes docs mean
by "integers", and blind-guessing here that it intended to
mean the signed C "int" type, in which case perhaps I can
repair this by feeding the thread id argument to type
ctypes.c_long().
Also made the worker thread daemonic, so it doesn't hang
Python shutdown if the test continues to fail.
........
r51199 | tim.peters | 2006-08-11 05:49:10 +0200 (Fri, 11 Aug 2006) | 6 lines
force_test_exit(): This has been completely ineffective
at stopping test_signal from hanging forever on the Tru64
buildbot. That could be because there's no such thing as
signal.SIGALARM. Changed to the idiotic (but standard)
signal.SIGALRM instead, and added some more debug output.
........
r51202 | neal.norwitz | 2006-08-11 08:09:41 +0200 (Fri, 11 Aug 2006) | 6 lines
Fix the failures on cygwin (2006-08-10 fixed the actual locking issue).
The first hunk changes the colon to an ! like other Windows variants.
We need to always wait on the child so the lock gets released and
no other tests fail. This is the try/finally in the second hunk.
........
r51205 | georg.brandl | 2006-08-11 09:15:38 +0200 (Fri, 11 Aug 2006) | 3 lines
Add Chris McDonough (latest cgi.py patch)
........
r51206 | georg.brandl | 2006-08-11 09:26:10 +0200 (Fri, 11 Aug 2006) | 3 lines
logging's atexit hook now runs even if the rest of the module has
already been cleaned up.
........
r51212 | thomas.wouters | 2006-08-11 17:02:39 +0200 (Fri, 11 Aug 2006) | 4 lines
Add ignore of *.pyc and *.pyo to Lib/xml/etree/.
........
r51215 | thomas.heller | 2006-08-11 21:55:35 +0200 (Fri, 11 Aug 2006) | 7 lines
When a ctypes C callback function is called, zero out the result
storage before converting the result to C data. See the comment in
the code for details.
Provide a better context for errors when the conversion of a callback
function's result cannot be converted.
........
r51218 | neal.norwitz | 2006-08-12 03:43:40 +0200 (Sat, 12 Aug 2006) | 6 lines
Klocwork made another run and found a bunch more problems.
This is the first batch of fixes that should be easy to verify based on context.
This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
........
r51219 | neal.norwitz | 2006-08-12 03:45:47 +0200 (Sat, 12 Aug 2006) | 9 lines
Even though _Py_Mangle() isn't truly public anyone can call it and
there was no verification that privateobj was a PyString. If it wasn't
a string, this could have allowed a NULL pointer to creep in below and crash.
I wonder if this should be PyString_CheckExact? Must identifiers be strings
or can they be subclasses?
Klocwork #275
........
r51220 | neal.norwitz | 2006-08-12 03:46:42 +0200 (Sat, 12 Aug 2006) | 5 lines
It's highly unlikely, though possible for PyEval_Get*() to return NULLs.
So be safe and do an XINCREF.
Klocwork # 221-222.
........
r51221 | neal.norwitz | 2006-08-12 03:47:59 +0200 (Sat, 12 Aug 2006) | 7 lines
This code is actually not used unless WITHOUT_COMPLEX is defined.
However, there was no error checking that PyFloat_FromDouble returned
a valid pointer. I believe this change is correct as it seemed
to follow other code in the area.
Klocwork # 292.
........
r51222 | neal.norwitz | 2006-08-12 03:49:12 +0200 (Sat, 12 Aug 2006) | 5 lines
Handle NULL nodes while parsing. I'm not entirely sure this is correct.
There might be something else that needs to be done to setup the error.
Klocwork #295.
........
r51223 | neal.norwitz | 2006-08-12 03:50:38 +0200 (Sat, 12 Aug 2006) | 6 lines
If _stat_float_times is false, we will try to INCREF ival which could be NULL.
Return early in that case. The caller checks for PyErr_Occurred so this
should be ok.
Klocwork #297
........
r51224 | neal.norwitz | 2006-08-12 03:51:12 +0200 (Sat, 12 Aug 2006) | 3 lines
Move the assert which checks for a NULL pointer first.
Klocwork #274.
........
r51225 | neal.norwitz | 2006-08-12 03:53:28 +0200 (Sat, 12 Aug 2006) | 5 lines
Try to handle a malloc failure. I'm not entirely sure this is correct.
There might be something else we need to do to handle the exception.
Klocwork # 212-213
........
r51226 | neal.norwitz | 2006-08-12 03:57:47 +0200 (Sat, 12 Aug 2006) | 6 lines
I'm not sure why this code allocates this string for the error message.
I think it would be better to always use snprintf and have the format
limit the size of the name appropriately (like %.200s).
Klocwork #340
........
r51227 | neal.norwitz | 2006-08-12 04:06:34 +0200 (Sat, 12 Aug 2006) | 3 lines
Check returned pointer is valid.
Klocwork #233
........
r51228 | neal.norwitz | 2006-08-12 04:12:30 +0200 (Sat, 12 Aug 2006) | 1 line
Whoops, how did that get in there. :-) Revert all the parts of 51227 that were not supposed to go it. Only Modules/_ctypes/cfields.c was supposed to be changed
........
r51229 | neal.norwitz | 2006-08-12 04:33:36 +0200 (Sat, 12 Aug 2006) | 4 lines
Don't deref v if it's NULL.
Klocwork #214
........
r51230 | neal.norwitz | 2006-08-12 05:16:54 +0200 (Sat, 12 Aug 2006) | 5 lines
Check return of PyMem_MALLOC (garbage) is non-NULL.
Check seq in both portions of if/else.
Klocwork #289-290.
........
r51231 | neal.norwitz | 2006-08-12 05:17:41 +0200 (Sat, 12 Aug 2006) | 4 lines
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Klocwork #298-299.
........
r51232 | neal.norwitz | 2006-08-12 05:18:50 +0200 (Sat, 12 Aug 2006) | 5 lines
Verify verdat which is returned from malloc is not NULL.
Ensure we don't pass NULL to free.
Klocwork #306 (at least the first part, checking malloc)
........
r51233 | tim.peters | 2006-08-12 06:42:47 +0200 (Sat, 12 Aug 2006) | 35 lines
test_signal: Signal handling on the Tru64 buildbot
appears to be utterly insane. Plug some theoretical
insecurities in the test script:
- Verify that the SIGALRM handler was actually installed.
- Don't call alarm() before the handler is installed.
- Move everything that can fail inside the try/finally,
so the test cleans up after itself more often.
- Try sending all the expected signals in
force_test_exit(), not just SIGALRM. Since that was
fixed to actually send SIGALRM (instead of invisibly
dying with an AttributeError), we've seen that sending
SIGALRM alone does not stop this from hanging.
- Move the "kill the child" business into the finally
clause, so the child doesn't survive test failure
to send SIGALRM to other tests later (there are also
baffling SIGALRM-related failures in test_socket).
- Cancel the alarm in the finally clause -- if the
test dies early, we again don't want SIGALRM showing
up to confuse a later test.
Alas, this still relies on timing luck wrt the spawned
script that sends the test signals, but it's hard to see
how waiting for seconds can so often be so unlucky.
test_threadedsignals: curiously, this test never fails
on Tru64, but doesn't normally signal SIGALRM. Anyway,
fixed an obvious (but probably inconsequential) logic
error.
........
r51234 | tim.peters | 2006-08-12 07:17:41 +0200 (Sat, 12 Aug 2006) | 8 lines
Ah, fudge. One of the prints here actually "shouldn't be"
protected by "if verbose:", which caused the test to fail on
all non-Windows boxes.
Note that I deliberately didn't convert this to unittest yet,
because I expect it would be even harder to debug this on Tru64
after conversion.
........
r51235 | georg.brandl | 2006-08-12 10:32:02 +0200 (Sat, 12 Aug 2006) | 3 lines
Repair logging test spew caused by rev. 51206.
........
r51236 | neal.norwitz | 2006-08-12 19:03:09 +0200 (Sat, 12 Aug 2006) | 8 lines
Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments. This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward. I don't want this to hold up release if possible.
........
r51238 | neal.norwitz | 2006-08-12 20:44:06 +0200 (Sat, 12 Aug 2006) | 10 lines
Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots
were failing due to inappropriate clipping of numbers larger than 2**31
with new-style classes. (typeobject.c) In reviewing the code for classic
classes, there were 2 problems. Any negative value return could be returned.
Always return -1 if there was an error. Also make the checks similar
with the new-style classes. I believe this is correct for 32 and 64 bit
boxes, including Windows64.
Add a test of classic classes too.
........
r51240 | neal.norwitz | 2006-08-13 02:20:49 +0200 (Sun, 13 Aug 2006) | 1 line
SF bug #1539336, distutils example code missing
........
r51245 | neal.norwitz | 2006-08-13 20:10:10 +0200 (Sun, 13 Aug 2006) | 6 lines
Move/copy assert for tstate != NULL before first use.
Verify that PyEval_Get{Globals,Locals} returned valid pointers.
Klocwork 231-232
........
r51246 | neal.norwitz | 2006-08-13 20:10:28 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle a whole lot of failures from PyString_FromInternedString().
Should fix most of Klocwork 234-272.
........
r51247 | neal.norwitz | 2006-08-13 20:10:47 +0200 (Sun, 13 Aug 2006) | 8 lines
cpathname could be NULL if it was longer than MAXPATHLEN. Don't try
to write the .pyc to NULL.
Check results of PyList_GetItem() and PyModule_GetDict() are not NULL.
Klocwork 282, 283, 285
........
r51248 | neal.norwitz | 2006-08-13 20:11:08 +0200 (Sun, 13 Aug 2006) | 6 lines
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.
Klocwork 308
........
r51250 | neal.norwitz | 2006-08-13 20:11:27 +0200 (Sun, 13 Aug 2006) | 5 lines
Check return result of PyModule_GetDict().
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51251 | neal.norwitz | 2006-08-13 20:11:43 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle malloc and fopen failures more gracefully.
Klocwork 180-181
........
r51252 | neal.norwitz | 2006-08-13 20:12:03 +0200 (Sun, 13 Aug 2006) | 7 lines
It's very unlikely, though possible that source is not a string. Verify
that PyString_AsString() returns a valid pointer. (The problem can
arise when zlib.decompress doesn't return a string.)
Klocwork 346
........
r51253 | neal.norwitz | 2006-08-13 20:12:26 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle failures from lookup.
Klocwork 341-342
........
r51254 | neal.norwitz | 2006-08-13 20:12:45 +0200 (Sun, 13 Aug 2006) | 6 lines
Handle failure from PyModule_GetDict() (Klocwork 208).
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51255 | neal.norwitz | 2006-08-13 20:13:02 +0200 (Sun, 13 Aug 2006) | 4 lines
Really address the issue of where to place the assert for leftblock.
(Followup of Klocwork 274)
........
r51256 | neal.norwitz | 2006-08-13 20:13:36 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle malloc failure.
Klocwork 281
........
r51258 | neal.norwitz | 2006-08-13 20:40:39 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle alloca failures.
Klocwork 225-228
........
r51259 | neal.norwitz | 2006-08-13 20:41:15 +0200 (Sun, 13 Aug 2006) | 1 line
Get rid of compiler warning
........
r51261 | neal.norwitz | 2006-08-14 02:51:15 +0200 (Mon, 14 Aug 2006) | 1 line
Ignore pgen.exe and kill_python.exe for cygwin
........
r51262 | neal.norwitz | 2006-08-14 02:59:03 +0200 (Mon, 14 Aug 2006) | 4 lines
Can't return NULL from a void function. If there is a memory error,
about the best we can do is call PyErr_WriteUnraisable and go on.
We won't be able to do the call below either, so verify delstr is valid.
........
r51263 | neal.norwitz | 2006-08-14 03:49:54 +0200 (Mon, 14 Aug 2006) | 1 line
Update purify doc some.
........
r51264 | thomas.heller | 2006-08-14 09:13:05 +0200 (Mon, 14 Aug 2006) | 2 lines
Remove unused, buggy test function.
Fixes klockwork issue #207.
........
r51265 | thomas.heller | 2006-08-14 09:14:09 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value from new_CArgObject().
Fixes klockwork issues #183, #184, #185.
........
r51266 | thomas.heller | 2006-08-14 09:50:14 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value of GenericCData_new().
Fixes klockwork issues #188, #189.
........
r51274 | thomas.heller | 2006-08-14 12:02:24 +0200 (Mon, 14 Aug 2006) | 2 lines
Revert the change that tries to zero out a closure's result storage
area because the size if unknown in source/callproc.c.
........
r51276 | marc-andre.lemburg | 2006-08-14 12:55:19 +0200 (Mon, 14 Aug 2006) | 11 lines
Slightly revised version of patch #1538956:
Replace UnicodeDecodeErrors raised during == and !=
compares of Unicode and other objects with a new
UnicodeWarning.
All other comparisons continue to raise exceptions.
Exceptions other than UnicodeDecodeErrors are also left
untouched.
........
r51277 | thomas.heller | 2006-08-14 13:17:48 +0200 (Mon, 14 Aug 2006) | 13 lines
Apply the patch #1532975 plus ideas from the patch #1533481.
ctypes instances no longer have the internal and undocumented
'_as_parameter_' attribute which was used to adapt them to foreign
function calls; this mechanism is replaced by a function pointer in
the type's stgdict.
In the 'from_param' class methods, try the _as_parameter_ attribute if
other conversions are not possible.
This makes the documented _as_parameter_ mechanism work as intended.
Change the ctypes version number to 1.0.1.
........
r51278 | marc-andre.lemburg | 2006-08-14 13:44:34 +0200 (Mon, 14 Aug 2006) | 3 lines
Readd NEWS items that were accidentally removed by r51276.
........
r51279 | georg.brandl | 2006-08-14 14:36:06 +0200 (Mon, 14 Aug 2006) | 3 lines
Improve markup in PyUnicode_RichCompare.
........
r51280 | marc-andre.lemburg | 2006-08-14 14:57:27 +0200 (Mon, 14 Aug 2006) | 3 lines
Correct an accidentally removed previous patch.
........
r51281 | thomas.heller | 2006-08-14 18:17:41 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536908: Add support for AMD64 / OpenBSD.
Remove the -no-stack-protector compiler flag for OpenBSD
as it has been reported to be unneeded.
........
r51282 | thomas.heller | 2006-08-14 18:20:04 +0200 (Mon, 14 Aug 2006) | 1 line
News item for rev 51281.
........
r51283 | georg.brandl | 2006-08-14 22:25:39 +0200 (Mon, 14 Aug 2006) | 3 lines
Fix refleak introduced in rev. 51248.
........
r51284 | georg.brandl | 2006-08-14 23:34:08 +0200 (Mon, 14 Aug 2006) | 5 lines
Make tabnanny recognize IndentationErrors raised by tokenize.
Add a test to test_inspect to make sure indented source
is recognized correctly. (fixes #1224621)
........
r51285 | georg.brandl | 2006-08-14 23:42:55 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
........
r51287 | georg.brandl | 2006-08-14 23:45:32 +0200 (Mon, 14 Aug 2006) | 3 lines
Add an additional test: BZ2File write methods should raise IOError
when file is read-only.
........
r51289 | georg.brandl | 2006-08-14 23:55:28 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536071: trace.py should now find the full module name of a
file correctly even on Windows.
........
r51290 | georg.brandl | 2006-08-15 00:01:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Cookie.py shouldn't "bogusly" use string._idmap.
........
r51291 | georg.brandl | 2006-08-15 00:10:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Patch #1511317: don't crash on invalid hostname info
........
r51292 | tim.peters | 2006-08-15 02:25:04 +0200 (Tue, 15 Aug 2006) | 2 lines
Whitespace normalization.
........
r51293 | neal.norwitz | 2006-08-15 06:14:57 +0200 (Tue, 15 Aug 2006) | 3 lines
Georg fixed one of my bugs, so I'll repay him with 2 NEWS entries.
Now we're even. :-)
........
r51295 | neal.norwitz | 2006-08-15 06:58:28 +0200 (Tue, 15 Aug 2006) | 8 lines
Fix the test for SocketServer so it should pass on cygwin and not fail
sporadically on other platforms. This is really a band-aid that doesn't
fix the underlying issue in SocketServer. It's not clear if it's worth
it to fix SocketServer, however, I opened a bug to track it:
http://python.org/sf/1540386
........
r51296 | neal.norwitz | 2006-08-15 06:59:30 +0200 (Tue, 15 Aug 2006) | 3 lines
Update the docstring to use a version a little newer than 1999. This was
taken from a Debian patch. Should we update the version for each release?
........
r51298 | neal.norwitz | 2006-08-15 08:29:03 +0200 (Tue, 15 Aug 2006) | 2 lines
Subclasses of int/long are allowed to define an __index__.
........
r51300 | thomas.heller | 2006-08-15 15:07:21 +0200 (Tue, 15 Aug 2006) | 1 line
Check for NULL return value from new_CArgObject calls.
........
r51303 | kurt.kaiser | 2006-08-16 05:15:26 +0200 (Wed, 16 Aug 2006) | 2 lines
The 'with' statement is now a Code Context block opener
........
r51304 | anthony.baxter | 2006-08-16 05:42:26 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1
........
r51305 | anthony.baxter | 2006-08-16 05:58:37 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1 - no, really this time
........
r51306 | kurt.kaiser | 2006-08-16 07:01:42 +0200 (Wed, 16 Aug 2006) | 9 lines
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
before raising SystemExit, allowing IDLE to honor quit() and exit().
M Lib/site.py
M Lib/idlelib/PyShell.py
M Lib/idlelib/CREDITS.txt
M Lib/idlelib/NEWS.txt
M Misc/NEWS
........
r51307 | ka-ping.yee | 2006-08-16 09:02:50 +0200 (Wed, 16 Aug 2006) | 6 lines
Update code and tests to support the 'bytes_le' attribute (for
little-endian byte order on Windows), and to work around clocks
with low resolution yielding duplicate UUIDs.
Anthony Baxter has approved this change.
........
r51308 | kurt.kaiser | 2006-08-16 09:04:17 +0200 (Wed, 16 Aug 2006) | 2 lines
Get quit() and exit() to work cleanly when not using subprocess.
........
r51309 | marc-andre.lemburg | 2006-08-16 10:13:26 +0200 (Wed, 16 Aug 2006) | 2 lines
Revert to having static version numbers again.
........
r51310 | martin.v.loewis | 2006-08-16 14:55:10 +0200 (Wed, 16 Aug 2006) | 2 lines
Build _hashlib on Windows. Build OpenSSL with masm assembler code.
Fixes #1535502.
........
r51311 | thomas.heller | 2006-08-16 15:03:11 +0200 (Wed, 16 Aug 2006) | 6 lines
Add commented assert statements to check that the result of
PyObject_stgdict() and PyType_stgdict() calls are non-NULL before
dereferencing the result. Hopefully this fixes what klocwork is
complaining about.
Fix a few other nits as well.
........
r51312 | anthony.baxter | 2006-08-16 15:08:25 +0200 (Wed, 16 Aug 2006) | 1 line
news entry for 51307
........
r51313 | andrew.kuchling | 2006-08-16 15:22:20 +0200 (Wed, 16 Aug 2006) | 1 line
Add UnicodeWarning
........
r51314 | andrew.kuchling | 2006-08-16 15:41:52 +0200 (Wed, 16 Aug 2006) | 1 line
Bump document version to 1.0; remove pystone paragraph
........
r51315 | andrew.kuchling | 2006-08-16 15:51:32 +0200 (Wed, 16 Aug 2006) | 1 line
Link to docs; remove an XXX comment
........
r51316 | martin.v.loewis | 2006-08-16 15:58:51 +0200 (Wed, 16 Aug 2006) | 1 line
Make cl build step compile-only (/c). Remove libs from source list.
........
r51317 | thomas.heller | 2006-08-16 16:07:44 +0200 (Wed, 16 Aug 2006) | 5 lines
The __repr__ method of a NULL py_object does no longer raise an
exception. Remove a stray '?' character from the exception text
when the value is retrieved of such an object.
Includes tests.
........
r51318 | andrew.kuchling | 2006-08-16 16:18:23 +0200 (Wed, 16 Aug 2006) | 1 line
Update bug/patch counts
........
r51319 | andrew.kuchling | 2006-08-16 16:21:14 +0200 (Wed, 16 Aug 2006) | 1 line
Wording/typo fixes
........
r51320 | thomas.heller | 2006-08-16 17:10:12 +0200 (Wed, 16 Aug 2006) | 9 lines
Remove the special casing of Py_None when converting the return value
of the Python part of a callback function to C. If it cannot be
converted, call PyErr_WriteUnraisable with the exception we got.
Before, arbitrary data has been passed to the calling C code in this
case.
(I'm not really sure the NEWS entry is understandable, but I cannot
find better words)
........
r51321 | marc-andre.lemburg | 2006-08-16 18:11:01 +0200 (Wed, 16 Aug 2006) | 2 lines
Add NEWS item mentioning the reverted distutils version number patch.
........
r51322 | fredrik.lundh | 2006-08-16 18:47:07 +0200 (Wed, 16 Aug 2006) | 5 lines
SF#1534630
ignore data that arrives before the opening start tag
........
r51324 | andrew.kuchling | 2006-08-16 19:11:18 +0200 (Wed, 16 Aug 2006) | 1 line
Grammar fix
........
r51328 | thomas.heller | 2006-08-16 20:02:11 +0200 (Wed, 16 Aug 2006) | 12 lines
Tutorial:
Clarify somewhat how parameters are passed to functions
(especially explain what integer means).
Correct the table - Python integers and longs can both be used.
Further clarification to the table comparing ctypes types, Python
types, and C types.
Reference:
Replace integer by C ``int`` where it makes sense.
........
r51329 | kurt.kaiser | 2006-08-16 23:45:59 +0200 (Wed, 16 Aug 2006) | 8 lines
File menu hotkeys: there were three 'p' assignments. Reassign the
'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the
Shell menu hotkey from 's' to 'l'.
M Bindings.py
M PyShell.py
M NEWS.txt
........
r51330 | neil.schemenauer | 2006-08-17 01:38:05 +0200 (Thu, 17 Aug 2006) | 3 lines
Fix a bug in the ``compiler`` package that caused invalid code to be
generated for generator expressions.
........
r51342 | martin.v.loewis | 2006-08-17 21:19:32 +0200 (Thu, 17 Aug 2006) | 3 lines
Merge 51340 and 51341 from 2.5 branch:
Leave tk build directory to restore original path.
Invoke debug mk1mf.pl after running Configure.
........
r51354 | martin.v.loewis | 2006-08-18 05:47:18 +0200 (Fri, 18 Aug 2006) | 3 lines
Bug #1541863: uuid.uuid1 failed to generate unique identifiers
on systems with low clock resolution.
........
r51355 | neal.norwitz | 2006-08-18 05:57:54 +0200 (Fri, 18 Aug 2006) | 1 line
Add template for 2.6 on HEAD
........
r51356 | neal.norwitz | 2006-08-18 06:01:38 +0200 (Fri, 18 Aug 2006) | 1 line
More post-release wibble
........
r51357 | neal.norwitz | 2006-08-18 06:58:33 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again
........
r51358 | neal.norwitz | 2006-08-18 07:10:00 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again. Take 2
........
r51359 | neal.norwitz | 2006-08-18 07:39:20 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Unix bots install working again.
........
r51360 | neal.norwitz | 2006-08-18 07:41:46 +0200 (Fri, 18 Aug 2006) | 1 line
Set version to 2.6a0, seems more consistent.
........
r51362 | neal.norwitz | 2006-08-18 08:14:52 +0200 (Fri, 18 Aug 2006) | 1 line
More version wibble
........
r51364 | georg.brandl | 2006-08-18 09:27:59 +0200 (Fri, 18 Aug 2006) | 4 lines
Bug #1541682: Fix example in the "Refcount details" API docs.
Additionally, remove a faulty example showing PySequence_SetItem applied
to a newly created list object and add notes that this isn't a good idea.
........
r51366 | anthony.baxter | 2006-08-18 09:29:02 +0200 (Fri, 18 Aug 2006) | 3 lines
Updating IDLE's version number to match Python's (as per python-dev
discussion).
........
r51367 | anthony.baxter | 2006-08-18 09:30:07 +0200 (Fri, 18 Aug 2006) | 1 line
RPM specfile updates
........
r51368 | georg.brandl | 2006-08-18 09:35:47 +0200 (Fri, 18 Aug 2006) | 2 lines
Typo in tp_clear docs.
........
r51378 | andrew.kuchling | 2006-08-18 15:57:13 +0200 (Fri, 18 Aug 2006) | 1 line
Minor edits
........
r51379 | thomas.heller | 2006-08-18 16:38:46 +0200 (Fri, 18 Aug 2006) | 6 lines
Add asserts to check for 'impossible' NULL values, with comments.
In one place where I'n not 1000% sure about the non-NULL, raise
a RuntimeError for safety.
This should fix the klocwork issues that Neal sent me. If so,
it should be applied to the release25-maint branch also.
........
r51400 | neal.norwitz | 2006-08-19 06:22:33 +0200 (Sat, 19 Aug 2006) | 5 lines
Move initialization of interned strings to before allocating the
object so we don't leak op. (Fixes an earlier patch to this code)
Klockwork #350
........
r51401 | neal.norwitz | 2006-08-19 06:23:04 +0200 (Sat, 19 Aug 2006) | 4 lines
Move assert to after NULL check, otherwise we deref NULL in the assert.
Klocwork #307
........
r51402 | neal.norwitz | 2006-08-19 06:25:29 +0200 (Sat, 19 Aug 2006) | 2 lines
SF #1542693: Remove semi-colon at end of PyImport_ImportModuleEx macro
........
r51403 | neal.norwitz | 2006-08-19 06:28:55 +0200 (Sat, 19 Aug 2006) | 6 lines
Move initialization to after the asserts for non-NULL values.
Klocwork 286-287.
(I'm not backporting this, but if someone wants to, feel free.)
........
r51404 | neal.norwitz | 2006-08-19 06:52:03 +0200 (Sat, 19 Aug 2006) | 6 lines
Handle PyString_FromInternedString() failing (unlikely, but possible).
Klocwork #325
(I'm not backporting this, but if someone wants to, feel free.)
........
r51416 | georg.brandl | 2006-08-20 15:15:39 +0200 (Sun, 20 Aug 2006) | 2 lines
Patch #1542948: fix urllib2 header casing issue. With new test.
........
r51428 | jeremy.hylton | 2006-08-21 18:19:37 +0200 (Mon, 21 Aug 2006) | 3 lines
Move peephole optimizer to separate file.
........
r51429 | jeremy.hylton | 2006-08-21 18:20:29 +0200 (Mon, 21 Aug 2006) | 2 lines
Move peephole optimizer to separate file. (Forgot .h in previous checkin.)
........
r51432 | neal.norwitz | 2006-08-21 19:59:46 +0200 (Mon, 21 Aug 2006) | 5 lines
Fix bug #1543303, tarfile adds padding that breaks gunzip.
Patch # 1543897.
Will backport to 2.5
........
r51433 | neal.norwitz | 2006-08-21 20:01:30 +0200 (Mon, 21 Aug 2006) | 2 lines
Add assert to make Klocwork happy (#276)
........
2006-08-21 16:07:27 -03:00
|
|
|
|
|
|
|
if (op == NULL) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PyInt_Check(op))
|
|
|
|
return PyInt_AS_LONG((PyIntObject*) op);
|
|
|
|
if (PyLong_Check(op))
|
2006-02-15 13:27:45 -04:00
|
|
|
return _PyLong_AsSsize_t(op);
|
2006-02-15 19:08:56 -04:00
|
|
|
#if SIZEOF_SIZE_T == SIZEOF_LONG
|
2006-02-15 13:27:45 -04:00
|
|
|
return PyInt_AsLong(op);
|
|
|
|
#else
|
|
|
|
|
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
which unfortunately means the errors from the bytes type change somewhat:
bytes([300]) still raises a ValueError, but bytes([10**100]) now raises a
TypeError (either that, or bytes(1.0) also raises a ValueError --
PyNumber_AsSsize_t() can only raise one type of exception.)
Merged revisions 51188-51433 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r51189 | kurt.kaiser | 2006-08-10 19:11:09 +0200 (Thu, 10 Aug 2006) | 4 lines
Retrieval of previous shell command was not always preserving indentation
since 1.2a1) Patch 1528468 Tal Einat.
........
r51190 | guido.van.rossum | 2006-08-10 19:41:07 +0200 (Thu, 10 Aug 2006) | 3 lines
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
SF bug #1112549.
........
r51191 | guido.van.rossum | 2006-08-10 19:42:50 +0200 (Thu, 10 Aug 2006) | 2 lines
News item for SF bug 1112549.
........
r51192 | guido.van.rossum | 2006-08-10 20:09:25 +0200 (Thu, 10 Aug 2006) | 2 lines
Fix title -- it's rc1, not beta3.
........
r51194 | martin.v.loewis | 2006-08-10 21:04:00 +0200 (Thu, 10 Aug 2006) | 3 lines
Update dangling references to the 3.2 database to
mention that this is UCD 4.1 now.
........
r51195 | tim.peters | 2006-08-11 00:45:34 +0200 (Fri, 11 Aug 2006) | 6 lines
Followup to bug #1069160.
PyThreadState_SetAsyncExc(): internal correctness changes wrt
refcount safety and deadlock avoidance. Also added a basic test
case (relying on ctypes) and repaired the docs.
........
r51196 | tim.peters | 2006-08-11 00:48:45 +0200 (Fri, 11 Aug 2006) | 2 lines
Whitespace normalization.
........
r51197 | tim.peters | 2006-08-11 01:22:13 +0200 (Fri, 11 Aug 2006) | 5 lines
Whitespace normalization broke test_cgi, because a line
of quoted test data relied on preserving a single trailing
blank. Changed the string from raw to regular, and forced
in the trailing blank via an explicit \x20 escape.
........
r51198 | tim.peters | 2006-08-11 02:49:01 +0200 (Fri, 11 Aug 2006) | 10 lines
test_PyThreadState_SetAsyncExc(): This is failing on some
64-bit boxes. I have no idea what the ctypes docs mean
by "integers", and blind-guessing here that it intended to
mean the signed C "int" type, in which case perhaps I can
repair this by feeding the thread id argument to type
ctypes.c_long().
Also made the worker thread daemonic, so it doesn't hang
Python shutdown if the test continues to fail.
........
r51199 | tim.peters | 2006-08-11 05:49:10 +0200 (Fri, 11 Aug 2006) | 6 lines
force_test_exit(): This has been completely ineffective
at stopping test_signal from hanging forever on the Tru64
buildbot. That could be because there's no such thing as
signal.SIGALARM. Changed to the idiotic (but standard)
signal.SIGALRM instead, and added some more debug output.
........
r51202 | neal.norwitz | 2006-08-11 08:09:41 +0200 (Fri, 11 Aug 2006) | 6 lines
Fix the failures on cygwin (2006-08-10 fixed the actual locking issue).
The first hunk changes the colon to an ! like other Windows variants.
We need to always wait on the child so the lock gets released and
no other tests fail. This is the try/finally in the second hunk.
........
r51205 | georg.brandl | 2006-08-11 09:15:38 +0200 (Fri, 11 Aug 2006) | 3 lines
Add Chris McDonough (latest cgi.py patch)
........
r51206 | georg.brandl | 2006-08-11 09:26:10 +0200 (Fri, 11 Aug 2006) | 3 lines
logging's atexit hook now runs even if the rest of the module has
already been cleaned up.
........
r51212 | thomas.wouters | 2006-08-11 17:02:39 +0200 (Fri, 11 Aug 2006) | 4 lines
Add ignore of *.pyc and *.pyo to Lib/xml/etree/.
........
r51215 | thomas.heller | 2006-08-11 21:55:35 +0200 (Fri, 11 Aug 2006) | 7 lines
When a ctypes C callback function is called, zero out the result
storage before converting the result to C data. See the comment in
the code for details.
Provide a better context for errors when the conversion of a callback
function's result cannot be converted.
........
r51218 | neal.norwitz | 2006-08-12 03:43:40 +0200 (Sat, 12 Aug 2006) | 6 lines
Klocwork made another run and found a bunch more problems.
This is the first batch of fixes that should be easy to verify based on context.
This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
........
r51219 | neal.norwitz | 2006-08-12 03:45:47 +0200 (Sat, 12 Aug 2006) | 9 lines
Even though _Py_Mangle() isn't truly public anyone can call it and
there was no verification that privateobj was a PyString. If it wasn't
a string, this could have allowed a NULL pointer to creep in below and crash.
I wonder if this should be PyString_CheckExact? Must identifiers be strings
or can they be subclasses?
Klocwork #275
........
r51220 | neal.norwitz | 2006-08-12 03:46:42 +0200 (Sat, 12 Aug 2006) | 5 lines
It's highly unlikely, though possible for PyEval_Get*() to return NULLs.
So be safe and do an XINCREF.
Klocwork # 221-222.
........
r51221 | neal.norwitz | 2006-08-12 03:47:59 +0200 (Sat, 12 Aug 2006) | 7 lines
This code is actually not used unless WITHOUT_COMPLEX is defined.
However, there was no error checking that PyFloat_FromDouble returned
a valid pointer. I believe this change is correct as it seemed
to follow other code in the area.
Klocwork # 292.
........
r51222 | neal.norwitz | 2006-08-12 03:49:12 +0200 (Sat, 12 Aug 2006) | 5 lines
Handle NULL nodes while parsing. I'm not entirely sure this is correct.
There might be something else that needs to be done to setup the error.
Klocwork #295.
........
r51223 | neal.norwitz | 2006-08-12 03:50:38 +0200 (Sat, 12 Aug 2006) | 6 lines
If _stat_float_times is false, we will try to INCREF ival which could be NULL.
Return early in that case. The caller checks for PyErr_Occurred so this
should be ok.
Klocwork #297
........
r51224 | neal.norwitz | 2006-08-12 03:51:12 +0200 (Sat, 12 Aug 2006) | 3 lines
Move the assert which checks for a NULL pointer first.
Klocwork #274.
........
r51225 | neal.norwitz | 2006-08-12 03:53:28 +0200 (Sat, 12 Aug 2006) | 5 lines
Try to handle a malloc failure. I'm not entirely sure this is correct.
There might be something else we need to do to handle the exception.
Klocwork # 212-213
........
r51226 | neal.norwitz | 2006-08-12 03:57:47 +0200 (Sat, 12 Aug 2006) | 6 lines
I'm not sure why this code allocates this string for the error message.
I think it would be better to always use snprintf and have the format
limit the size of the name appropriately (like %.200s).
Klocwork #340
........
r51227 | neal.norwitz | 2006-08-12 04:06:34 +0200 (Sat, 12 Aug 2006) | 3 lines
Check returned pointer is valid.
Klocwork #233
........
r51228 | neal.norwitz | 2006-08-12 04:12:30 +0200 (Sat, 12 Aug 2006) | 1 line
Whoops, how did that get in there. :-) Revert all the parts of 51227 that were not supposed to go it. Only Modules/_ctypes/cfields.c was supposed to be changed
........
r51229 | neal.norwitz | 2006-08-12 04:33:36 +0200 (Sat, 12 Aug 2006) | 4 lines
Don't deref v if it's NULL.
Klocwork #214
........
r51230 | neal.norwitz | 2006-08-12 05:16:54 +0200 (Sat, 12 Aug 2006) | 5 lines
Check return of PyMem_MALLOC (garbage) is non-NULL.
Check seq in both portions of if/else.
Klocwork #289-290.
........
r51231 | neal.norwitz | 2006-08-12 05:17:41 +0200 (Sat, 12 Aug 2006) | 4 lines
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Klocwork #298-299.
........
r51232 | neal.norwitz | 2006-08-12 05:18:50 +0200 (Sat, 12 Aug 2006) | 5 lines
Verify verdat which is returned from malloc is not NULL.
Ensure we don't pass NULL to free.
Klocwork #306 (at least the first part, checking malloc)
........
r51233 | tim.peters | 2006-08-12 06:42:47 +0200 (Sat, 12 Aug 2006) | 35 lines
test_signal: Signal handling on the Tru64 buildbot
appears to be utterly insane. Plug some theoretical
insecurities in the test script:
- Verify that the SIGALRM handler was actually installed.
- Don't call alarm() before the handler is installed.
- Move everything that can fail inside the try/finally,
so the test cleans up after itself more often.
- Try sending all the expected signals in
force_test_exit(), not just SIGALRM. Since that was
fixed to actually send SIGALRM (instead of invisibly
dying with an AttributeError), we've seen that sending
SIGALRM alone does not stop this from hanging.
- Move the "kill the child" business into the finally
clause, so the child doesn't survive test failure
to send SIGALRM to other tests later (there are also
baffling SIGALRM-related failures in test_socket).
- Cancel the alarm in the finally clause -- if the
test dies early, we again don't want SIGALRM showing
up to confuse a later test.
Alas, this still relies on timing luck wrt the spawned
script that sends the test signals, but it's hard to see
how waiting for seconds can so often be so unlucky.
test_threadedsignals: curiously, this test never fails
on Tru64, but doesn't normally signal SIGALRM. Anyway,
fixed an obvious (but probably inconsequential) logic
error.
........
r51234 | tim.peters | 2006-08-12 07:17:41 +0200 (Sat, 12 Aug 2006) | 8 lines
Ah, fudge. One of the prints here actually "shouldn't be"
protected by "if verbose:", which caused the test to fail on
all non-Windows boxes.
Note that I deliberately didn't convert this to unittest yet,
because I expect it would be even harder to debug this on Tru64
after conversion.
........
r51235 | georg.brandl | 2006-08-12 10:32:02 +0200 (Sat, 12 Aug 2006) | 3 lines
Repair logging test spew caused by rev. 51206.
........
r51236 | neal.norwitz | 2006-08-12 19:03:09 +0200 (Sat, 12 Aug 2006) | 8 lines
Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments. This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward. I don't want this to hold up release if possible.
........
r51238 | neal.norwitz | 2006-08-12 20:44:06 +0200 (Sat, 12 Aug 2006) | 10 lines
Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots
were failing due to inappropriate clipping of numbers larger than 2**31
with new-style classes. (typeobject.c) In reviewing the code for classic
classes, there were 2 problems. Any negative value return could be returned.
Always return -1 if there was an error. Also make the checks similar
with the new-style classes. I believe this is correct for 32 and 64 bit
boxes, including Windows64.
Add a test of classic classes too.
........
r51240 | neal.norwitz | 2006-08-13 02:20:49 +0200 (Sun, 13 Aug 2006) | 1 line
SF bug #1539336, distutils example code missing
........
r51245 | neal.norwitz | 2006-08-13 20:10:10 +0200 (Sun, 13 Aug 2006) | 6 lines
Move/copy assert for tstate != NULL before first use.
Verify that PyEval_Get{Globals,Locals} returned valid pointers.
Klocwork 231-232
........
r51246 | neal.norwitz | 2006-08-13 20:10:28 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle a whole lot of failures from PyString_FromInternedString().
Should fix most of Klocwork 234-272.
........
r51247 | neal.norwitz | 2006-08-13 20:10:47 +0200 (Sun, 13 Aug 2006) | 8 lines
cpathname could be NULL if it was longer than MAXPATHLEN. Don't try
to write the .pyc to NULL.
Check results of PyList_GetItem() and PyModule_GetDict() are not NULL.
Klocwork 282, 283, 285
........
r51248 | neal.norwitz | 2006-08-13 20:11:08 +0200 (Sun, 13 Aug 2006) | 6 lines
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.
Klocwork 308
........
r51250 | neal.norwitz | 2006-08-13 20:11:27 +0200 (Sun, 13 Aug 2006) | 5 lines
Check return result of PyModule_GetDict().
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51251 | neal.norwitz | 2006-08-13 20:11:43 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle malloc and fopen failures more gracefully.
Klocwork 180-181
........
r51252 | neal.norwitz | 2006-08-13 20:12:03 +0200 (Sun, 13 Aug 2006) | 7 lines
It's very unlikely, though possible that source is not a string. Verify
that PyString_AsString() returns a valid pointer. (The problem can
arise when zlib.decompress doesn't return a string.)
Klocwork 346
........
r51253 | neal.norwitz | 2006-08-13 20:12:26 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle failures from lookup.
Klocwork 341-342
........
r51254 | neal.norwitz | 2006-08-13 20:12:45 +0200 (Sun, 13 Aug 2006) | 6 lines
Handle failure from PyModule_GetDict() (Klocwork 208).
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51255 | neal.norwitz | 2006-08-13 20:13:02 +0200 (Sun, 13 Aug 2006) | 4 lines
Really address the issue of where to place the assert for leftblock.
(Followup of Klocwork 274)
........
r51256 | neal.norwitz | 2006-08-13 20:13:36 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle malloc failure.
Klocwork 281
........
r51258 | neal.norwitz | 2006-08-13 20:40:39 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle alloca failures.
Klocwork 225-228
........
r51259 | neal.norwitz | 2006-08-13 20:41:15 +0200 (Sun, 13 Aug 2006) | 1 line
Get rid of compiler warning
........
r51261 | neal.norwitz | 2006-08-14 02:51:15 +0200 (Mon, 14 Aug 2006) | 1 line
Ignore pgen.exe and kill_python.exe for cygwin
........
r51262 | neal.norwitz | 2006-08-14 02:59:03 +0200 (Mon, 14 Aug 2006) | 4 lines
Can't return NULL from a void function. If there is a memory error,
about the best we can do is call PyErr_WriteUnraisable and go on.
We won't be able to do the call below either, so verify delstr is valid.
........
r51263 | neal.norwitz | 2006-08-14 03:49:54 +0200 (Mon, 14 Aug 2006) | 1 line
Update purify doc some.
........
r51264 | thomas.heller | 2006-08-14 09:13:05 +0200 (Mon, 14 Aug 2006) | 2 lines
Remove unused, buggy test function.
Fixes klockwork issue #207.
........
r51265 | thomas.heller | 2006-08-14 09:14:09 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value from new_CArgObject().
Fixes klockwork issues #183, #184, #185.
........
r51266 | thomas.heller | 2006-08-14 09:50:14 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value of GenericCData_new().
Fixes klockwork issues #188, #189.
........
r51274 | thomas.heller | 2006-08-14 12:02:24 +0200 (Mon, 14 Aug 2006) | 2 lines
Revert the change that tries to zero out a closure's result storage
area because the size if unknown in source/callproc.c.
........
r51276 | marc-andre.lemburg | 2006-08-14 12:55:19 +0200 (Mon, 14 Aug 2006) | 11 lines
Slightly revised version of patch #1538956:
Replace UnicodeDecodeErrors raised during == and !=
compares of Unicode and other objects with a new
UnicodeWarning.
All other comparisons continue to raise exceptions.
Exceptions other than UnicodeDecodeErrors are also left
untouched.
........
r51277 | thomas.heller | 2006-08-14 13:17:48 +0200 (Mon, 14 Aug 2006) | 13 lines
Apply the patch #1532975 plus ideas from the patch #1533481.
ctypes instances no longer have the internal and undocumented
'_as_parameter_' attribute which was used to adapt them to foreign
function calls; this mechanism is replaced by a function pointer in
the type's stgdict.
In the 'from_param' class methods, try the _as_parameter_ attribute if
other conversions are not possible.
This makes the documented _as_parameter_ mechanism work as intended.
Change the ctypes version number to 1.0.1.
........
r51278 | marc-andre.lemburg | 2006-08-14 13:44:34 +0200 (Mon, 14 Aug 2006) | 3 lines
Readd NEWS items that were accidentally removed by r51276.
........
r51279 | georg.brandl | 2006-08-14 14:36:06 +0200 (Mon, 14 Aug 2006) | 3 lines
Improve markup in PyUnicode_RichCompare.
........
r51280 | marc-andre.lemburg | 2006-08-14 14:57:27 +0200 (Mon, 14 Aug 2006) | 3 lines
Correct an accidentally removed previous patch.
........
r51281 | thomas.heller | 2006-08-14 18:17:41 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536908: Add support for AMD64 / OpenBSD.
Remove the -no-stack-protector compiler flag for OpenBSD
as it has been reported to be unneeded.
........
r51282 | thomas.heller | 2006-08-14 18:20:04 +0200 (Mon, 14 Aug 2006) | 1 line
News item for rev 51281.
........
r51283 | georg.brandl | 2006-08-14 22:25:39 +0200 (Mon, 14 Aug 2006) | 3 lines
Fix refleak introduced in rev. 51248.
........
r51284 | georg.brandl | 2006-08-14 23:34:08 +0200 (Mon, 14 Aug 2006) | 5 lines
Make tabnanny recognize IndentationErrors raised by tokenize.
Add a test to test_inspect to make sure indented source
is recognized correctly. (fixes #1224621)
........
r51285 | georg.brandl | 2006-08-14 23:42:55 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
........
r51287 | georg.brandl | 2006-08-14 23:45:32 +0200 (Mon, 14 Aug 2006) | 3 lines
Add an additional test: BZ2File write methods should raise IOError
when file is read-only.
........
r51289 | georg.brandl | 2006-08-14 23:55:28 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536071: trace.py should now find the full module name of a
file correctly even on Windows.
........
r51290 | georg.brandl | 2006-08-15 00:01:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Cookie.py shouldn't "bogusly" use string._idmap.
........
r51291 | georg.brandl | 2006-08-15 00:10:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Patch #1511317: don't crash on invalid hostname info
........
r51292 | tim.peters | 2006-08-15 02:25:04 +0200 (Tue, 15 Aug 2006) | 2 lines
Whitespace normalization.
........
r51293 | neal.norwitz | 2006-08-15 06:14:57 +0200 (Tue, 15 Aug 2006) | 3 lines
Georg fixed one of my bugs, so I'll repay him with 2 NEWS entries.
Now we're even. :-)
........
r51295 | neal.norwitz | 2006-08-15 06:58:28 +0200 (Tue, 15 Aug 2006) | 8 lines
Fix the test for SocketServer so it should pass on cygwin and not fail
sporadically on other platforms. This is really a band-aid that doesn't
fix the underlying issue in SocketServer. It's not clear if it's worth
it to fix SocketServer, however, I opened a bug to track it:
http://python.org/sf/1540386
........
r51296 | neal.norwitz | 2006-08-15 06:59:30 +0200 (Tue, 15 Aug 2006) | 3 lines
Update the docstring to use a version a little newer than 1999. This was
taken from a Debian patch. Should we update the version for each release?
........
r51298 | neal.norwitz | 2006-08-15 08:29:03 +0200 (Tue, 15 Aug 2006) | 2 lines
Subclasses of int/long are allowed to define an __index__.
........
r51300 | thomas.heller | 2006-08-15 15:07:21 +0200 (Tue, 15 Aug 2006) | 1 line
Check for NULL return value from new_CArgObject calls.
........
r51303 | kurt.kaiser | 2006-08-16 05:15:26 +0200 (Wed, 16 Aug 2006) | 2 lines
The 'with' statement is now a Code Context block opener
........
r51304 | anthony.baxter | 2006-08-16 05:42:26 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1
........
r51305 | anthony.baxter | 2006-08-16 05:58:37 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1 - no, really this time
........
r51306 | kurt.kaiser | 2006-08-16 07:01:42 +0200 (Wed, 16 Aug 2006) | 9 lines
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
before raising SystemExit, allowing IDLE to honor quit() and exit().
M Lib/site.py
M Lib/idlelib/PyShell.py
M Lib/idlelib/CREDITS.txt
M Lib/idlelib/NEWS.txt
M Misc/NEWS
........
r51307 | ka-ping.yee | 2006-08-16 09:02:50 +0200 (Wed, 16 Aug 2006) | 6 lines
Update code and tests to support the 'bytes_le' attribute (for
little-endian byte order on Windows), and to work around clocks
with low resolution yielding duplicate UUIDs.
Anthony Baxter has approved this change.
........
r51308 | kurt.kaiser | 2006-08-16 09:04:17 +0200 (Wed, 16 Aug 2006) | 2 lines
Get quit() and exit() to work cleanly when not using subprocess.
........
r51309 | marc-andre.lemburg | 2006-08-16 10:13:26 +0200 (Wed, 16 Aug 2006) | 2 lines
Revert to having static version numbers again.
........
r51310 | martin.v.loewis | 2006-08-16 14:55:10 +0200 (Wed, 16 Aug 2006) | 2 lines
Build _hashlib on Windows. Build OpenSSL with masm assembler code.
Fixes #1535502.
........
r51311 | thomas.heller | 2006-08-16 15:03:11 +0200 (Wed, 16 Aug 2006) | 6 lines
Add commented assert statements to check that the result of
PyObject_stgdict() and PyType_stgdict() calls are non-NULL before
dereferencing the result. Hopefully this fixes what klocwork is
complaining about.
Fix a few other nits as well.
........
r51312 | anthony.baxter | 2006-08-16 15:08:25 +0200 (Wed, 16 Aug 2006) | 1 line
news entry for 51307
........
r51313 | andrew.kuchling | 2006-08-16 15:22:20 +0200 (Wed, 16 Aug 2006) | 1 line
Add UnicodeWarning
........
r51314 | andrew.kuchling | 2006-08-16 15:41:52 +0200 (Wed, 16 Aug 2006) | 1 line
Bump document version to 1.0; remove pystone paragraph
........
r51315 | andrew.kuchling | 2006-08-16 15:51:32 +0200 (Wed, 16 Aug 2006) | 1 line
Link to docs; remove an XXX comment
........
r51316 | martin.v.loewis | 2006-08-16 15:58:51 +0200 (Wed, 16 Aug 2006) | 1 line
Make cl build step compile-only (/c). Remove libs from source list.
........
r51317 | thomas.heller | 2006-08-16 16:07:44 +0200 (Wed, 16 Aug 2006) | 5 lines
The __repr__ method of a NULL py_object does no longer raise an
exception. Remove a stray '?' character from the exception text
when the value is retrieved of such an object.
Includes tests.
........
r51318 | andrew.kuchling | 2006-08-16 16:18:23 +0200 (Wed, 16 Aug 2006) | 1 line
Update bug/patch counts
........
r51319 | andrew.kuchling | 2006-08-16 16:21:14 +0200 (Wed, 16 Aug 2006) | 1 line
Wording/typo fixes
........
r51320 | thomas.heller | 2006-08-16 17:10:12 +0200 (Wed, 16 Aug 2006) | 9 lines
Remove the special casing of Py_None when converting the return value
of the Python part of a callback function to C. If it cannot be
converted, call PyErr_WriteUnraisable with the exception we got.
Before, arbitrary data has been passed to the calling C code in this
case.
(I'm not really sure the NEWS entry is understandable, but I cannot
find better words)
........
r51321 | marc-andre.lemburg | 2006-08-16 18:11:01 +0200 (Wed, 16 Aug 2006) | 2 lines
Add NEWS item mentioning the reverted distutils version number patch.
........
r51322 | fredrik.lundh | 2006-08-16 18:47:07 +0200 (Wed, 16 Aug 2006) | 5 lines
SF#1534630
ignore data that arrives before the opening start tag
........
r51324 | andrew.kuchling | 2006-08-16 19:11:18 +0200 (Wed, 16 Aug 2006) | 1 line
Grammar fix
........
r51328 | thomas.heller | 2006-08-16 20:02:11 +0200 (Wed, 16 Aug 2006) | 12 lines
Tutorial:
Clarify somewhat how parameters are passed to functions
(especially explain what integer means).
Correct the table - Python integers and longs can both be used.
Further clarification to the table comparing ctypes types, Python
types, and C types.
Reference:
Replace integer by C ``int`` where it makes sense.
........
r51329 | kurt.kaiser | 2006-08-16 23:45:59 +0200 (Wed, 16 Aug 2006) | 8 lines
File menu hotkeys: there were three 'p' assignments. Reassign the
'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the
Shell menu hotkey from 's' to 'l'.
M Bindings.py
M PyShell.py
M NEWS.txt
........
r51330 | neil.schemenauer | 2006-08-17 01:38:05 +0200 (Thu, 17 Aug 2006) | 3 lines
Fix a bug in the ``compiler`` package that caused invalid code to be
generated for generator expressions.
........
r51342 | martin.v.loewis | 2006-08-17 21:19:32 +0200 (Thu, 17 Aug 2006) | 3 lines
Merge 51340 and 51341 from 2.5 branch:
Leave tk build directory to restore original path.
Invoke debug mk1mf.pl after running Configure.
........
r51354 | martin.v.loewis | 2006-08-18 05:47:18 +0200 (Fri, 18 Aug 2006) | 3 lines
Bug #1541863: uuid.uuid1 failed to generate unique identifiers
on systems with low clock resolution.
........
r51355 | neal.norwitz | 2006-08-18 05:57:54 +0200 (Fri, 18 Aug 2006) | 1 line
Add template for 2.6 on HEAD
........
r51356 | neal.norwitz | 2006-08-18 06:01:38 +0200 (Fri, 18 Aug 2006) | 1 line
More post-release wibble
........
r51357 | neal.norwitz | 2006-08-18 06:58:33 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again
........
r51358 | neal.norwitz | 2006-08-18 07:10:00 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again. Take 2
........
r51359 | neal.norwitz | 2006-08-18 07:39:20 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Unix bots install working again.
........
r51360 | neal.norwitz | 2006-08-18 07:41:46 +0200 (Fri, 18 Aug 2006) | 1 line
Set version to 2.6a0, seems more consistent.
........
r51362 | neal.norwitz | 2006-08-18 08:14:52 +0200 (Fri, 18 Aug 2006) | 1 line
More version wibble
........
r51364 | georg.brandl | 2006-08-18 09:27:59 +0200 (Fri, 18 Aug 2006) | 4 lines
Bug #1541682: Fix example in the "Refcount details" API docs.
Additionally, remove a faulty example showing PySequence_SetItem applied
to a newly created list object and add notes that this isn't a good idea.
........
r51366 | anthony.baxter | 2006-08-18 09:29:02 +0200 (Fri, 18 Aug 2006) | 3 lines
Updating IDLE's version number to match Python's (as per python-dev
discussion).
........
r51367 | anthony.baxter | 2006-08-18 09:30:07 +0200 (Fri, 18 Aug 2006) | 1 line
RPM specfile updates
........
r51368 | georg.brandl | 2006-08-18 09:35:47 +0200 (Fri, 18 Aug 2006) | 2 lines
Typo in tp_clear docs.
........
r51378 | andrew.kuchling | 2006-08-18 15:57:13 +0200 (Fri, 18 Aug 2006) | 1 line
Minor edits
........
r51379 | thomas.heller | 2006-08-18 16:38:46 +0200 (Fri, 18 Aug 2006) | 6 lines
Add asserts to check for 'impossible' NULL values, with comments.
In one place where I'n not 1000% sure about the non-NULL, raise
a RuntimeError for safety.
This should fix the klocwork issues that Neal sent me. If so,
it should be applied to the release25-maint branch also.
........
r51400 | neal.norwitz | 2006-08-19 06:22:33 +0200 (Sat, 19 Aug 2006) | 5 lines
Move initialization of interned strings to before allocating the
object so we don't leak op. (Fixes an earlier patch to this code)
Klockwork #350
........
r51401 | neal.norwitz | 2006-08-19 06:23:04 +0200 (Sat, 19 Aug 2006) | 4 lines
Move assert to after NULL check, otherwise we deref NULL in the assert.
Klocwork #307
........
r51402 | neal.norwitz | 2006-08-19 06:25:29 +0200 (Sat, 19 Aug 2006) | 2 lines
SF #1542693: Remove semi-colon at end of PyImport_ImportModuleEx macro
........
r51403 | neal.norwitz | 2006-08-19 06:28:55 +0200 (Sat, 19 Aug 2006) | 6 lines
Move initialization to after the asserts for non-NULL values.
Klocwork 286-287.
(I'm not backporting this, but if someone wants to, feel free.)
........
r51404 | neal.norwitz | 2006-08-19 06:52:03 +0200 (Sat, 19 Aug 2006) | 6 lines
Handle PyString_FromInternedString() failing (unlikely, but possible).
Klocwork #325
(I'm not backporting this, but if someone wants to, feel free.)
........
r51416 | georg.brandl | 2006-08-20 15:15:39 +0200 (Sun, 20 Aug 2006) | 2 lines
Patch #1542948: fix urllib2 header casing issue. With new test.
........
r51428 | jeremy.hylton | 2006-08-21 18:19:37 +0200 (Mon, 21 Aug 2006) | 3 lines
Move peephole optimizer to separate file.
........
r51429 | jeremy.hylton | 2006-08-21 18:20:29 +0200 (Mon, 21 Aug 2006) | 2 lines
Move peephole optimizer to separate file. (Forgot .h in previous checkin.)
........
r51432 | neal.norwitz | 2006-08-21 19:59:46 +0200 (Mon, 21 Aug 2006) | 5 lines
Fix bug #1543303, tarfile adds padding that breaks gunzip.
Patch # 1543897.
Will backport to 2.5
........
r51433 | neal.norwitz | 2006-08-21 20:01:30 +0200 (Mon, 21 Aug 2006) | 2 lines
Add assert to make Klocwork happy (#276)
........
2006-08-21 16:07:27 -03:00
|
|
|
if ((nb = op->ob_type->tp_as_number) == NULL ||
|
2006-02-15 13:27:45 -04:00
|
|
|
(nb->nb_int == NULL && nb->nb_long == 0)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nb->nb_long != 0) {
|
|
|
|
io = (PyIntObject*) (*nb->nb_long) (op);
|
|
|
|
} else {
|
|
|
|
io = (PyIntObject*) (*nb->nb_int) (op);
|
|
|
|
}
|
|
|
|
if (io == NULL)
|
|
|
|
return -1;
|
|
|
|
if (!PyInt_Check(io)) {
|
|
|
|
if (PyLong_Check(io)) {
|
|
|
|
/* got a long? => retry int conversion */
|
|
|
|
val = _PyLong_AsSsize_t((PyObject *)io);
|
|
|
|
Py_DECREF(io);
|
|
|
|
if ((val == -1) && PyErr_Occurred())
|
|
|
|
return -1;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Py_DECREF(io);
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"nb_int should return int object");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val = PyInt_AS_LONG(io);
|
|
|
|
Py_DECREF(io);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-04-17 15:55:45 -03:00
|
|
|
unsigned long
|
|
|
|
PyInt_AsUnsignedLongMask(register PyObject *op)
|
|
|
|
{
|
|
|
|
PyNumberMethods *nb;
|
|
|
|
PyIntObject *io;
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
if (op && PyInt_Check(op))
|
|
|
|
return PyInt_AS_LONG((PyIntObject*) op);
|
|
|
|
if (op && PyLong_Check(op))
|
|
|
|
return PyLong_AsUnsignedLongMask(op);
|
|
|
|
|
|
|
|
if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
|
|
|
|
nb->nb_int == NULL) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned long)-1;
|
2003-04-17 15:55:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
io = (PyIntObject*) (*nb->nb_int) (op);
|
|
|
|
if (io == NULL)
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned long)-1;
|
2003-04-17 15:55:45 -03:00
|
|
|
if (!PyInt_Check(io)) {
|
|
|
|
if (PyLong_Check(io)) {
|
|
|
|
val = PyLong_AsUnsignedLongMask((PyObject *)io);
|
|
|
|
Py_DECREF(io);
|
|
|
|
if (PyErr_Occurred())
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned long)-1;
|
2003-04-17 15:55:45 -03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Py_DECREF(io);
|
2002-11-19 16:49:15 -04:00
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"nb_int should return int object");
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned long)-1;
|
2002-11-19 16:49:15 -04:00
|
|
|
}
|
1994-08-29 09:48:32 -03:00
|
|
|
}
|
2001-12-04 19:05:10 -04:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
val = PyInt_AS_LONG(io);
|
|
|
|
Py_DECREF(io);
|
2001-12-04 19:05:10 -04:00
|
|
|
|
1994-08-29 09:48:32 -03:00
|
|
|
return val;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2003-04-17 15:55:45 -03:00
|
|
|
#ifdef HAVE_LONG_LONG
|
|
|
|
unsigned PY_LONG_LONG
|
|
|
|
PyInt_AsUnsignedLongLongMask(register PyObject *op)
|
|
|
|
{
|
|
|
|
PyNumberMethods *nb;
|
|
|
|
PyIntObject *io;
|
|
|
|
unsigned PY_LONG_LONG val;
|
|
|
|
|
|
|
|
if (op && PyInt_Check(op))
|
|
|
|
return PyInt_AS_LONG((PyIntObject*) op);
|
|
|
|
if (op && PyLong_Check(op))
|
|
|
|
return PyLong_AsUnsignedLongLongMask(op);
|
|
|
|
|
|
|
|
if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
|
|
|
|
nb->nb_int == NULL) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "an integer is required");
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned PY_LONG_LONG)-1;
|
2003-04-17 15:55:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
io = (PyIntObject*) (*nb->nb_int) (op);
|
|
|
|
if (io == NULL)
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned PY_LONG_LONG)-1;
|
2003-04-17 15:55:45 -03:00
|
|
|
if (!PyInt_Check(io)) {
|
|
|
|
if (PyLong_Check(io)) {
|
|
|
|
val = PyLong_AsUnsignedLongLongMask((PyObject *)io);
|
|
|
|
Py_DECREF(io);
|
|
|
|
if (PyErr_Occurred())
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned PY_LONG_LONG)-1;
|
2003-04-17 15:55:45 -03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Py_DECREF(io);
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"nb_int should return int object");
|
2006-04-21 07:40:58 -03:00
|
|
|
return (unsigned PY_LONG_LONG)-1;
|
2003-04-17 15:55:45 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val = PyInt_AS_LONG(io);
|
|
|
|
Py_DECREF(io);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-12 16:54:53 -03:00
|
|
|
PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
PyInt_FromString(char *s, char **pend, int base)
|
1999-10-12 16:54:53 -03:00
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
long x;
|
2006-04-21 07:40:58 -03:00
|
|
|
Py_ssize_t slen;
|
|
|
|
PyObject *sobj, *srepr;
|
1999-10-12 16:54:53 -03:00
|
|
|
|
|
|
|
if ((base != 0 && base < 2) || base > 36) {
|
2003-02-12 16:48:22 -04:00
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"int() base must be >= 2 and <= 36");
|
1999-10-12 16:54:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*s && isspace(Py_CHARMASK(*s)))
|
|
|
|
s++;
|
|
|
|
errno = 0;
|
2003-02-12 16:48:22 -04:00
|
|
|
if (base == 0 && s[0] == '0') {
|
1999-10-12 16:54:53 -03:00
|
|
|
x = (long) PyOS_strtoul(s, &end, base);
|
2003-02-12 16:48:22 -04:00
|
|
|
if (x < 0)
|
2003-11-29 19:52:13 -04:00
|
|
|
return PyLong_FromString(s, pend, base);
|
2003-02-12 16:48:22 -04:00
|
|
|
}
|
1999-10-12 16:54:53 -03:00
|
|
|
else
|
|
|
|
x = PyOS_strtol(s, &end, base);
|
2001-03-06 08:12:02 -04:00
|
|
|
if (end == s || !isalnum(Py_CHARMASK(end[-1])))
|
1999-10-12 16:54:53 -03:00
|
|
|
goto bad;
|
|
|
|
while (*end && isspace(Py_CHARMASK(*end)))
|
|
|
|
end++;
|
|
|
|
if (*end != '\0') {
|
|
|
|
bad:
|
2006-04-21 07:40:58 -03:00
|
|
|
slen = strlen(s) < 200 ? strlen(s) : 200;
|
|
|
|
sobj = PyString_FromStringAndSize(s, slen);
|
|
|
|
if (sobj == NULL)
|
|
|
|
return NULL;
|
|
|
|
srepr = PyObject_Repr(sobj);
|
|
|
|
Py_DECREF(sobj);
|
|
|
|
if (srepr == NULL)
|
|
|
|
return NULL;
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"invalid literal for int() with base %d: %s",
|
|
|
|
base, PyString_AS_STRING(srepr));
|
|
|
|
Py_DECREF(srepr);
|
1999-10-12 16:54:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-08-24 23:14:08 -03:00
|
|
|
else if (errno != 0)
|
2002-11-06 12:15:14 -04:00
|
|
|
return PyLong_FromString(s, pend, base);
|
1999-10-12 16:54:53 -03:00
|
|
|
if (pend)
|
|
|
|
*pend = end;
|
|
|
|
return PyInt_FromLong(x);
|
|
|
|
}
|
|
|
|
|
2001-08-17 15:39:25 -03:00
|
|
|
#ifdef Py_USING_UNICODE
|
2000-04-05 17:11:21 -03:00
|
|
|
PyObject *
|
2006-02-15 13:27:45 -04:00
|
|
|
PyInt_FromUnicode(Py_UNICODE *s, Py_ssize_t length, int base)
|
2000-04-05 17:11:21 -03:00
|
|
|
{
|
2002-11-06 12:15:14 -04:00
|
|
|
PyObject *result;
|
2006-04-21 07:40:58 -03:00
|
|
|
char *buffer = (char *)PyMem_MALLOC(length+1);
|
2001-12-04 19:05:10 -04:00
|
|
|
|
2002-11-06 12:15:14 -04:00
|
|
|
if (buffer == NULL)
|
2000-04-05 17:11:21 -03:00
|
|
|
return NULL;
|
2002-11-06 12:15:14 -04:00
|
|
|
|
|
|
|
if (PyUnicode_EncodeDecimal(s, length, buffer, NULL)) {
|
|
|
|
PyMem_FREE(buffer);
|
2000-04-05 17:11:21 -03:00
|
|
|
return NULL;
|
2002-11-06 12:15:14 -04:00
|
|
|
}
|
|
|
|
result = PyInt_FromString(buffer, NULL, base);
|
|
|
|
PyMem_FREE(buffer);
|
|
|
|
return result;
|
2000-04-05 17:11:21 -03:00
|
|
|
}
|
2001-08-17 15:39:25 -03:00
|
|
|
#endif
|
2000-04-05 17:11:21 -03:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* Methods */
|
|
|
|
|
2001-01-03 21:45:33 -04:00
|
|
|
/* Integers are seen as the "smallest" of all numeric types and thus
|
|
|
|
don't have any knowledge about conversion of other types to
|
|
|
|
integers. */
|
|
|
|
|
|
|
|
#define CONVERT_TO_LONG(obj, lng) \
|
|
|
|
if (PyInt_Check(obj)) { \
|
|
|
|
lng = PyInt_AS_LONG(obj); \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
Py_INCREF(Py_NotImplemented); \
|
|
|
|
return Py_NotImplemented; \
|
|
|
|
}
|
|
|
|
|
1992-03-27 13:31:02 -04:00
|
|
|
/* ARGSUSED */
|
1991-06-07 13:10:43 -03:00
|
|
|
static int
|
2000-07-09 12:16:51 -03:00
|
|
|
int_print(PyIntObject *v, FILE *fp, int flags)
|
|
|
|
/* flags -- not used but required by interface */
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
|
|
|
fprintf(fp, "%ld", v->ob_ival);
|
1991-06-07 13:10:43 -03:00
|
|
|
return 0;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_repr(PyIntObject *v)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2001-11-30 22:52:56 -04:00
|
|
|
char buf[64];
|
2001-11-28 16:55:34 -04:00
|
|
|
PyOS_snprintf(buf, sizeof(buf), "%ld", v->ob_ival);
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyString_FromString(buf);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-07-09 12:16:51 -03:00
|
|
|
int_compare(PyIntObject *v, PyIntObject *w)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
|
|
|
register long i = v->ob_ival;
|
|
|
|
register long j = w->ob_ival;
|
|
|
|
return (i < j) ? -1 : (i > j) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2006-08-23 21:41:19 -03:00
|
|
|
static PyObject *
|
|
|
|
int_richcompare(PyObject *self, PyObject *other, int op)
|
|
|
|
{
|
|
|
|
if (!PyInt_Check(self) || !PyInt_Check(other)) {
|
|
|
|
Py_INCREF(Py_NotImplemented);
|
|
|
|
return Py_NotImplemented;
|
|
|
|
}
|
|
|
|
return Py_CmpToRich(op, int_compare((PyIntObject *)self,
|
|
|
|
(PyIntObject *)other));
|
|
|
|
}
|
|
|
|
|
1993-03-29 06:43:31 -04:00
|
|
|
static long
|
2000-07-09 12:16:51 -03:00
|
|
|
int_hash(PyIntObject *v)
|
1993-03-29 06:43:31 -04:00
|
|
|
{
|
1997-01-06 18:53:20 -04:00
|
|
|
/* XXX If this is changed, you also need to change the way
|
|
|
|
Python's long, float and complex types are hashed. */
|
1993-03-29 06:43:31 -04:00
|
|
|
long x = v -> ob_ival;
|
|
|
|
if (x == -1)
|
|
|
|
x = -2;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_add(PyIntObject *v, PyIntObject *w)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
|
|
|
register long a, b, x;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
1990-10-14 09:07:46 -03:00
|
|
|
x = a + b;
|
2001-08-22 23:59:04 -03:00
|
|
|
if ((x^a) >= 0 || (x^b) >= 0)
|
|
|
|
return PyInt_FromLong(x);
|
|
|
|
return PyLong_Type.tp_as_number->nb_add((PyObject *)v, (PyObject *)w);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_sub(PyIntObject *v, PyIntObject *w)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
|
|
|
register long a, b, x;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
1990-10-14 09:07:46 -03:00
|
|
|
x = a - b;
|
2001-08-22 23:59:04 -03:00
|
|
|
if ((x^a) >= 0 || (x^~b) >= 0)
|
|
|
|
return PyInt_FromLong(x);
|
|
|
|
return PyLong_Type.tp_as_number->nb_subtract((PyObject *)v,
|
|
|
|
(PyObject *)w);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1994-08-29 09:48:32 -03:00
|
|
|
/*
|
2001-12-04 19:05:10 -04:00
|
|
|
Integer overflow checking for * is painful: Python tried a couple ways, but
|
|
|
|
they didn't work on all platforms, or failed in endcases (a product of
|
|
|
|
-sys.maxint-1 has been a particular pain).
|
|
|
|
|
|
|
|
Here's another way:
|
|
|
|
|
|
|
|
The native long product x*y is either exactly right or *way* off, being
|
|
|
|
just the last n bits of the true product, where n is the number of bits
|
|
|
|
in a long (the delivered product is the true product plus i*2**n for
|
|
|
|
some integer i).
|
|
|
|
|
|
|
|
The native double product (double)x * (double)y is subject to three
|
|
|
|
rounding errors: on a sizeof(long)==8 box, each cast to double can lose
|
|
|
|
info, and even on a sizeof(long)==4 box, the multiplication can lose info.
|
|
|
|
But, unlike the native long product, it's not in *range* trouble: even
|
|
|
|
if sizeof(long)==32 (256-bit longs), the product easily fits in the
|
|
|
|
dynamic range of a double. So the leading 50 (or so) bits of the double
|
|
|
|
product are correct.
|
|
|
|
|
|
|
|
We check these two ways against each other, and declare victory if they're
|
|
|
|
approximately the same. Else, because the native long product is the only
|
|
|
|
one that can lose catastrophic amounts of information, it's the native long
|
|
|
|
product that must have overflowed.
|
1994-08-29 09:48:32 -03:00
|
|
|
*/
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2001-01-03 21:45:33 -04:00
|
|
|
int_mul(PyObject *v, PyObject *w)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2001-12-04 19:05:10 -04:00
|
|
|
long a, b;
|
|
|
|
long longprod; /* a*b in native long arithmetic */
|
|
|
|
double doubled_longprod; /* (double)longprod */
|
|
|
|
double doubleprod; /* (double)a * (double)b */
|
1994-08-29 09:48:32 -03:00
|
|
|
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
2001-12-04 19:05:10 -04:00
|
|
|
longprod = a * b;
|
|
|
|
doubleprod = (double)a * (double)b;
|
|
|
|
doubled_longprod = (double)longprod;
|
|
|
|
|
|
|
|
/* Fast path for normal case: small multiplicands, and no info
|
|
|
|
is lost in either method. */
|
|
|
|
if (doubled_longprod == doubleprod)
|
|
|
|
return PyInt_FromLong(longprod);
|
|
|
|
|
|
|
|
/* Somebody somewhere lost info. Close enough, or way off? Note
|
|
|
|
that a != 0 and b != 0 (else doubled_longprod == doubleprod == 0).
|
|
|
|
The difference either is or isn't significant compared to the
|
|
|
|
true value (of which doubleprod is a good approximation).
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
const double diff = doubled_longprod - doubleprod;
|
|
|
|
const double absdiff = diff >= 0.0 ? diff : -diff;
|
|
|
|
const double absprod = doubleprod >= 0.0 ? doubleprod :
|
|
|
|
-doubleprod;
|
|
|
|
/* absdiff/absprod <= 1/32 iff
|
|
|
|
32 * absdiff <= absprod -- 5 good bits is "close enough" */
|
|
|
|
if (32.0 * absdiff <= absprod)
|
|
|
|
return PyInt_FromLong(longprod);
|
|
|
|
else
|
|
|
|
return PyLong_Type.tp_as_number->nb_multiply(v, w);
|
1994-08-29 09:48:32 -03:00
|
|
|
}
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2001-08-22 23:59:04 -03:00
|
|
|
/* Return type of i_divmod */
|
|
|
|
enum divmod_result {
|
|
|
|
DIVMOD_OK, /* Correct result */
|
|
|
|
DIVMOD_OVERFLOW, /* Overflow, try again using longs */
|
|
|
|
DIVMOD_ERROR /* Exception raised */
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum divmod_result
|
2001-06-18 16:21:11 -03:00
|
|
|
i_divmod(register long x, register long y,
|
2000-07-09 12:16:51 -03:00
|
|
|
long *p_xdivy, long *p_xmody)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
1992-01-19 12:28:51 -04:00
|
|
|
long xdivy, xmody;
|
2001-12-04 19:05:10 -04:00
|
|
|
|
2001-06-18 16:21:11 -03:00
|
|
|
if (y == 0) {
|
1997-05-02 00:12:38 -03:00
|
|
|
PyErr_SetString(PyExc_ZeroDivisionError,
|
2000-10-24 16:57:45 -03:00
|
|
|
"integer division or modulo by zero");
|
2001-08-22 23:59:04 -03:00
|
|
|
return DIVMOD_ERROR;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
2001-06-18 16:21:11 -03:00
|
|
|
/* (-sys.maxint-1)/-1 is the only overflow case. */
|
2004-08-24 23:14:08 -03:00
|
|
|
if (y == -1 && x < 0 && x == -x)
|
2001-08-22 23:59:04 -03:00
|
|
|
return DIVMOD_OVERFLOW;
|
2001-06-18 16:21:11 -03:00
|
|
|
xdivy = x / y;
|
|
|
|
xmody = x - xdivy * y;
|
|
|
|
/* If the signs of x and y differ, and the remainder is non-0,
|
|
|
|
* C89 doesn't define whether xdivy is now the floor or the
|
|
|
|
* ceiling of the infinitely precise quotient. We want the floor,
|
|
|
|
* and we have it iff the remainder's sign matches y's.
|
|
|
|
*/
|
|
|
|
if (xmody && ((y ^ xmody) < 0) /* i.e. and signs differ */) {
|
|
|
|
xmody += y;
|
|
|
|
--xdivy;
|
|
|
|
assert(xmody && ((y ^ xmody) >= 0));
|
1992-01-19 12:28:51 -04:00
|
|
|
}
|
|
|
|
*p_xdivy = xdivy;
|
|
|
|
*p_xmody = xmody;
|
2001-08-22 23:59:04 -03:00
|
|
|
return DIVMOD_OK;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2006-08-21 14:06:07 -03:00
|
|
|
int_floor_div(PyIntObject *x, PyIntObject *y)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2001-01-03 21:45:33 -04:00
|
|
|
long xi, yi;
|
1992-01-19 12:28:51 -04:00
|
|
|
long d, m;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(x, xi);
|
|
|
|
CONVERT_TO_LONG(y, yi);
|
2001-08-22 23:59:04 -03:00
|
|
|
switch (i_divmod(xi, yi, &d, &m)) {
|
|
|
|
case DIVMOD_OK:
|
|
|
|
return PyInt_FromLong(d);
|
|
|
|
case DIVMOD_OVERFLOW:
|
2006-03-24 04:14:36 -04:00
|
|
|
return PyLong_Type.tp_as_number->nb_floor_divide((PyObject *)x,
|
|
|
|
(PyObject *)y);
|
Add warning mode for classic division, almost exactly as specified in
PEP 238. Changes:
- add a new flag variable Py_DivisionWarningFlag, declared in
pydebug.h, defined in object.c, set in main.c, and used in
{int,long,float,complex}object.c. When this flag is set, the
classic division operator issues a DeprecationWarning message.
- add a new API PyRun_SimpleStringFlags() to match
PyRun_SimpleString(). The main() function calls this so that
commands run with -c can also benefit from -Dnew.
- While I was at it, I changed the usage message in main() somewhat:
alphabetized the options, split it in *four* parts to fit in under
512 bytes (not that I still believe this is necessary -- doc strings
elsewhere are much longer), and perhaps most visibly, don't display
the full list of options on each command line error. Instead, the
full list is only displayed when -h is used, and otherwise a brief
reminder of -h is displayed. When -h is used, write to stdout so
that you can do `python -h | more'.
Notes:
- I don't want to use the -W option to control whether the classic
division warning is issued or not, because the machinery to decide
whether to display the warning or not is very expensive (it involves
calling into the warnings.py module). You can use -Werror to turn
the warnings into exceptions though.
- The -Dnew option doesn't select future division for all of the
program -- only for the __main__ module. I don't know if I'll ever
change this -- it would require changes to the .pyc file magic
number to do it right, and a more global notion of compiler flags.
- You can usefully combine -Dwarn and -Dnew: this gives the __main__
module new division, and warns about classic division everywhere
else.
2001-08-31 14:40:15 -03:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-04 02:52:47 -03:00
|
|
|
static PyObject *
|
|
|
|
int_true_divide(PyObject *v, PyObject *w)
|
|
|
|
{
|
2001-09-04 03:17:36 -03:00
|
|
|
/* If they aren't both ints, give someone else a chance. In
|
|
|
|
particular, this lets int/long get handled by longs, which
|
|
|
|
underflows to 0 gracefully if the long is too big to convert
|
|
|
|
to float. */
|
|
|
|
if (PyInt_Check(v) && PyInt_Check(w))
|
|
|
|
return PyFloat_Type.tp_as_number->nb_true_divide(v, w);
|
|
|
|
Py_INCREF(Py_NotImplemented);
|
|
|
|
return Py_NotImplemented;
|
2001-09-04 02:52:47 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_mod(PyIntObject *x, PyIntObject *y)
|
1992-01-19 12:28:51 -04:00
|
|
|
{
|
2001-01-03 21:45:33 -04:00
|
|
|
long xi, yi;
|
1992-01-19 12:28:51 -04:00
|
|
|
long d, m;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(x, xi);
|
|
|
|
CONVERT_TO_LONG(y, yi);
|
2001-08-22 23:59:04 -03:00
|
|
|
switch (i_divmod(xi, yi, &d, &m)) {
|
|
|
|
case DIVMOD_OK:
|
|
|
|
return PyInt_FromLong(m);
|
|
|
|
case DIVMOD_OVERFLOW:
|
|
|
|
return PyLong_Type.tp_as_number->nb_remainder((PyObject *)x,
|
|
|
|
(PyObject *)y);
|
|
|
|
default:
|
1992-01-19 12:28:51 -04:00
|
|
|
return NULL;
|
2001-08-22 23:59:04 -03:00
|
|
|
}
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_divmod(PyIntObject *x, PyIntObject *y)
|
1991-05-05 17:08:27 -03:00
|
|
|
{
|
2001-01-03 21:45:33 -04:00
|
|
|
long xi, yi;
|
1992-01-19 12:28:51 -04:00
|
|
|
long d, m;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(x, xi);
|
|
|
|
CONVERT_TO_LONG(y, yi);
|
2001-08-22 23:59:04 -03:00
|
|
|
switch (i_divmod(xi, yi, &d, &m)) {
|
|
|
|
case DIVMOD_OK:
|
|
|
|
return Py_BuildValue("(ll)", d, m);
|
|
|
|
case DIVMOD_OVERFLOW:
|
|
|
|
return PyLong_Type.tp_as_number->nb_divmod((PyObject *)x,
|
|
|
|
(PyObject *)y);
|
|
|
|
default:
|
1991-05-05 17:08:27 -03:00
|
|
|
return NULL;
|
2001-08-22 23:59:04 -03:00
|
|
|
}
|
1991-05-05 17:08:27 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
1996-12-06 16:14:43 -04:00
|
|
|
register long iv, iw, iz=0, ix, temp, prev;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, iv);
|
|
|
|
CONVERT_TO_LONG(w, iw);
|
1994-08-29 09:48:32 -03:00
|
|
|
if (iw < 0) {
|
2001-09-03 05:35:41 -03:00
|
|
|
if ((PyObject *)z != Py_None) {
|
2001-09-05 03:24:58 -03:00
|
|
|
PyErr_SetString(PyExc_TypeError, "pow() 2nd argument "
|
|
|
|
"cannot be negative when 3rd argument specified");
|
2001-09-03 05:35:41 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-12 08:19:45 -03:00
|
|
|
/* Return a float. This works because we know that
|
|
|
|
this calls float_pow() which converts its
|
|
|
|
arguments to double. */
|
|
|
|
return PyFloat_Type.tp_as_number->nb_power(
|
|
|
|
(PyObject *)v, (PyObject *)w, (PyObject *)z);
|
1994-08-29 09:48:32 -03:00
|
|
|
}
|
1997-05-02 00:12:38 -03:00
|
|
|
if ((PyObject *)z != Py_None) {
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(z, iz);
|
1996-12-06 16:14:43 -04:00
|
|
|
if (iz == 0) {
|
1997-05-02 00:12:38 -03:00
|
|
|
PyErr_SetString(PyExc_ValueError,
|
2001-09-05 03:24:58 -03:00
|
|
|
"pow() 3rd argument cannot be 0");
|
1996-12-06 16:14:43 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
1994-08-29 09:48:32 -03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX: The original exponentiation code stopped looping
|
|
|
|
* when temp hit zero; this code will continue onwards
|
|
|
|
* unnecessarily, but at least it won't cause any errors.
|
|
|
|
* Hopefully the speed improvement from the fast exponentiation
|
|
|
|
* will compensate for the slight inefficiency.
|
|
|
|
* XXX: Better handling of overflows is desperately needed.
|
|
|
|
*/
|
|
|
|
temp = iv;
|
|
|
|
ix = 1;
|
|
|
|
while (iw > 0) {
|
|
|
|
prev = ix; /* Save value for overflow check */
|
2001-12-04 19:05:10 -04:00
|
|
|
if (iw & 1) {
|
1994-08-29 09:48:32 -03:00
|
|
|
ix = ix*temp;
|
|
|
|
if (temp == 0)
|
|
|
|
break; /* Avoid ix / 0 */
|
2001-08-22 23:59:04 -03:00
|
|
|
if (ix / temp != prev) {
|
|
|
|
return PyLong_Type.tp_as_number->nb_power(
|
|
|
|
(PyObject *)v,
|
|
|
|
(PyObject *)w,
|
2001-08-23 18:28:33 -03:00
|
|
|
(PyObject *)z);
|
2001-08-22 23:59:04 -03:00
|
|
|
}
|
1994-08-29 09:48:32 -03:00
|
|
|
}
|
|
|
|
iw >>= 1; /* Shift exponent down by 1 bit */
|
|
|
|
if (iw==0) break;
|
|
|
|
prev = temp;
|
|
|
|
temp *= temp; /* Square the value of temp */
|
2004-08-24 23:14:08 -03:00
|
|
|
if (prev != 0 && temp / prev != prev) {
|
2001-08-22 23:59:04 -03:00
|
|
|
return PyLong_Type.tp_as_number->nb_power(
|
|
|
|
(PyObject *)v, (PyObject *)w, (PyObject *)z);
|
|
|
|
}
|
1996-12-06 16:14:43 -04:00
|
|
|
if (iz) {
|
1994-08-29 09:48:32 -03:00
|
|
|
/* If we did a multiplication, perform a modulo */
|
|
|
|
ix = ix % iz;
|
|
|
|
temp = temp % iz;
|
|
|
|
}
|
|
|
|
}
|
1996-12-06 16:14:43 -04:00
|
|
|
if (iz) {
|
2001-01-03 21:45:33 -04:00
|
|
|
long div, mod;
|
2001-08-22 23:59:04 -03:00
|
|
|
switch (i_divmod(ix, iz, &div, &mod)) {
|
|
|
|
case DIVMOD_OK:
|
|
|
|
ix = mod;
|
|
|
|
break;
|
|
|
|
case DIVMOD_OVERFLOW:
|
|
|
|
return PyLong_Type.tp_as_number->nb_power(
|
|
|
|
(PyObject *)v, (PyObject *)w, (PyObject *)z);
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyInt_FromLong(ix);
|
2001-12-04 19:05:10 -04:00
|
|
|
}
|
1990-10-14 09:07:46 -03:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_neg(PyIntObject *v)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
|
|
|
register long a, x;
|
|
|
|
a = v->ob_ival;
|
|
|
|
x = -a;
|
2001-08-22 23:59:04 -03:00
|
|
|
if (a < 0 && x < 0) {
|
2004-08-24 23:14:08 -03:00
|
|
|
PyObject *o = PyLong_FromLong(a);
|
2003-01-19 11:40:09 -04:00
|
|
|
if (o != NULL) {
|
|
|
|
PyObject *result = PyNumber_Negative(o);
|
|
|
|
Py_DECREF(o);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return NULL;
|
2001-08-22 23:59:04 -03:00
|
|
|
}
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyInt_FromLong(x);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_pos(PyIntObject *v)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2001-09-11 18:44:14 -03:00
|
|
|
if (PyInt_CheckExact(v)) {
|
|
|
|
Py_INCREF(v);
|
|
|
|
return (PyObject *)v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PyInt_FromLong(v->ob_ival);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_abs(PyIntObject *v)
|
1991-05-05 17:08:27 -03:00
|
|
|
{
|
|
|
|
if (v->ob_ival >= 0)
|
|
|
|
return int_pos(v);
|
|
|
|
else
|
|
|
|
return int_neg(v);
|
|
|
|
}
|
|
|
|
|
1991-05-14 09:05:32 -03:00
|
|
|
static int
|
2000-07-09 12:16:51 -03:00
|
|
|
int_nonzero(PyIntObject *v)
|
1991-05-14 09:05:32 -03:00
|
|
|
{
|
|
|
|
return v->ob_ival != 0;
|
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_invert(PyIntObject *v)
|
1991-10-24 11:59:31 -03:00
|
|
|
{
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyInt_FromLong(~v->ob_ival);
|
1991-10-24 11:59:31 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_lshift(PyIntObject *v, PyIntObject *w)
|
1991-10-24 11:59:31 -03:00
|
|
|
{
|
2002-08-11 01:24:12 -03:00
|
|
|
long a, b, c;
|
2004-06-26 20:22:57 -03:00
|
|
|
PyObject *vv, *ww, *result;
|
|
|
|
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
1992-01-14 14:33:22 -04:00
|
|
|
if (b < 0) {
|
1997-05-02 00:12:38 -03:00
|
|
|
PyErr_SetString(PyExc_ValueError, "negative shift count");
|
1992-01-14 14:33:22 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-11 18:44:14 -03:00
|
|
|
if (a == 0 || b == 0)
|
|
|
|
return int_pos(v);
|
1993-10-26 12:21:51 -03:00
|
|
|
if (b >= LONG_BIT) {
|
2004-06-26 20:22:57 -03:00
|
|
|
vv = PyLong_FromLong(PyInt_AS_LONG(v));
|
|
|
|
if (vv == NULL)
|
|
|
|
return NULL;
|
|
|
|
ww = PyLong_FromLong(PyInt_AS_LONG(w));
|
|
|
|
if (ww == NULL) {
|
|
|
|
Py_DECREF(vv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
result = PyNumber_Lshift(vv, ww);
|
|
|
|
Py_DECREF(vv);
|
|
|
|
Py_DECREF(ww);
|
|
|
|
return result;
|
1992-01-14 14:33:22 -04:00
|
|
|
}
|
2002-08-11 14:54:42 -03:00
|
|
|
c = a << b;
|
|
|
|
if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
|
2004-06-26 20:22:57 -03:00
|
|
|
vv = PyLong_FromLong(PyInt_AS_LONG(v));
|
|
|
|
if (vv == NULL)
|
|
|
|
return NULL;
|
|
|
|
ww = PyLong_FromLong(PyInt_AS_LONG(w));
|
|
|
|
if (ww == NULL) {
|
|
|
|
Py_DECREF(vv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
result = PyNumber_Lshift(vv, ww);
|
|
|
|
Py_DECREF(vv);
|
|
|
|
Py_DECREF(ww);
|
|
|
|
return result;
|
2002-08-11 01:24:12 -03:00
|
|
|
}
|
|
|
|
return PyInt_FromLong(c);
|
1991-10-24 11:59:31 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_rshift(PyIntObject *v, PyIntObject *w)
|
1991-10-24 11:59:31 -03:00
|
|
|
{
|
|
|
|
register long a, b;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
1992-01-14 14:33:22 -04:00
|
|
|
if (b < 0) {
|
1997-05-02 00:12:38 -03:00
|
|
|
PyErr_SetString(PyExc_ValueError, "negative shift count");
|
1992-01-14 14:33:22 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-11 18:44:14 -03:00
|
|
|
if (a == 0 || b == 0)
|
|
|
|
return int_pos(v);
|
1993-10-26 12:21:51 -03:00
|
|
|
if (b >= LONG_BIT) {
|
1992-01-14 14:33:22 -04:00
|
|
|
if (a < 0)
|
|
|
|
a = -1;
|
|
|
|
else
|
|
|
|
a = 0;
|
|
|
|
}
|
|
|
|
else {
|
2000-07-08 01:17:21 -03:00
|
|
|
a = Py_ARITHMETIC_RIGHT_SHIFT(long, a, b);
|
1992-01-14 14:33:22 -04:00
|
|
|
}
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyInt_FromLong(a);
|
1991-10-24 11:59:31 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_and(PyIntObject *v, PyIntObject *w)
|
1991-10-24 11:59:31 -03:00
|
|
|
{
|
|
|
|
register long a, b;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyInt_FromLong(a & b);
|
1991-10-24 11:59:31 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_xor(PyIntObject *v, PyIntObject *w)
|
1991-10-24 11:59:31 -03:00
|
|
|
{
|
|
|
|
register long a, b;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyInt_FromLong(a ^ b);
|
1991-10-24 11:59:31 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_or(PyIntObject *v, PyIntObject *w)
|
1991-10-24 11:59:31 -03:00
|
|
|
{
|
|
|
|
register long a, b;
|
2001-01-03 21:45:33 -04:00
|
|
|
CONVERT_TO_LONG(v, a);
|
|
|
|
CONVERT_TO_LONG(w, b);
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyInt_FromLong(a | b);
|
1991-10-24 11:59:31 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_int(PyIntObject *v)
|
1992-09-12 08:09:23 -03:00
|
|
|
{
|
2005-04-26 00:45:26 -03:00
|
|
|
if (PyInt_CheckExact(v))
|
|
|
|
Py_INCREF(v);
|
|
|
|
else
|
|
|
|
v = (PyIntObject *)PyInt_FromLong(v->ob_ival);
|
1997-05-02 00:12:38 -03:00
|
|
|
return (PyObject *)v;
|
1992-09-12 08:09:23 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_long(PyIntObject *v)
|
1992-09-12 08:09:23 -03:00
|
|
|
{
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyLong_FromLong((v -> ob_ival));
|
1992-09-12 08:09:23 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_float(PyIntObject *v)
|
1992-09-12 08:09:23 -03:00
|
|
|
{
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyFloat_FromDouble((double)(v -> ob_ival));
|
1992-09-12 08:09:23 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_oct(PyIntObject *v)
|
1992-09-12 08:09:23 -03:00
|
|
|
{
|
1997-01-14 11:43:41 -04:00
|
|
|
char buf[100];
|
1993-03-29 06:43:31 -04:00
|
|
|
long x = v -> ob_ival;
|
2003-11-29 19:52:13 -04:00
|
|
|
if (x < 0)
|
|
|
|
PyOS_snprintf(buf, sizeof(buf), "-0%lo", -x);
|
|
|
|
else if (x == 0)
|
1992-09-12 08:09:23 -03:00
|
|
|
strcpy(buf, "0");
|
|
|
|
else
|
2001-11-28 16:55:34 -04:00
|
|
|
PyOS_snprintf(buf, sizeof(buf), "0%lo", x);
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyString_FromString(buf);
|
1992-09-12 08:09:23 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2000-07-09 12:16:51 -03:00
|
|
|
int_hex(PyIntObject *v)
|
1992-09-12 08:09:23 -03:00
|
|
|
{
|
1997-01-14 11:43:41 -04:00
|
|
|
char buf[100];
|
1993-03-29 06:43:31 -04:00
|
|
|
long x = v -> ob_ival;
|
2003-11-29 19:52:13 -04:00
|
|
|
if (x < 0)
|
|
|
|
PyOS_snprintf(buf, sizeof(buf), "-0x%lx", -x);
|
|
|
|
else
|
|
|
|
PyOS_snprintf(buf, sizeof(buf), "0x%lx", x);
|
1997-05-02 00:12:38 -03:00
|
|
|
return PyString_FromString(buf);
|
1992-09-12 08:09:23 -03:00
|
|
|
}
|
|
|
|
|
2002-07-17 13:30:39 -03:00
|
|
|
static PyObject *
|
2001-08-29 12:47:46 -03:00
|
|
|
int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
|
|
|
|
2001-08-02 01:15:00 -03:00
|
|
|
static PyObject *
|
|
|
|
int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|
|
|
{
|
|
|
|
PyObject *x = NULL;
|
|
|
|
int base = -909;
|
2006-02-27 12:46:16 -04:00
|
|
|
static char *kwlist[] = {"x", "base", 0};
|
2001-08-02 01:15:00 -03:00
|
|
|
|
2001-08-29 12:47:46 -03:00
|
|
|
if (type != &PyInt_Type)
|
|
|
|
return int_subtype_new(type, args, kwds); /* Wimp out */
|
2001-08-02 01:15:00 -03:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:int", kwlist,
|
|
|
|
&x, &base))
|
|
|
|
return NULL;
|
|
|
|
if (x == NULL)
|
|
|
|
return PyInt_FromLong(0L);
|
|
|
|
if (base == -909)
|
|
|
|
return PyNumber_Int(x);
|
|
|
|
if (PyString_Check(x))
|
|
|
|
return PyInt_FromString(PyString_AS_STRING(x), NULL, base);
|
2001-08-17 15:39:25 -03:00
|
|
|
#ifdef Py_USING_UNICODE
|
2001-08-02 01:15:00 -03:00
|
|
|
if (PyUnicode_Check(x))
|
|
|
|
return PyInt_FromUnicode(PyUnicode_AS_UNICODE(x),
|
|
|
|
PyUnicode_GET_SIZE(x),
|
|
|
|
base);
|
2001-08-17 15:39:25 -03:00
|
|
|
#endif
|
2001-08-02 01:15:00 -03:00
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"int() can't convert non-string with explicit base");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-29 12:47:46 -03:00
|
|
|
/* Wimpy, slow approach to tp_new calls for subtypes of int:
|
|
|
|
first create a regular int from whatever arguments we got,
|
|
|
|
then allocate a subtype instance and initialize its ob_ival
|
|
|
|
from the regular int. The regular int is then thrown away.
|
|
|
|
*/
|
|
|
|
static PyObject *
|
|
|
|
int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|
|
|
{
|
2006-04-21 07:40:58 -03:00
|
|
|
PyObject *tmp, *newobj;
|
2003-02-09 22:12:43 -04:00
|
|
|
long ival;
|
2001-08-29 12:47:46 -03:00
|
|
|
|
|
|
|
assert(PyType_IsSubtype(type, &PyInt_Type));
|
|
|
|
tmp = int_new(&PyInt_Type, args, kwds);
|
|
|
|
if (tmp == NULL)
|
|
|
|
return NULL;
|
2003-02-09 22:12:43 -04:00
|
|
|
if (!PyInt_Check(tmp)) {
|
|
|
|
ival = PyLong_AsLong(tmp);
|
2003-08-11 14:32:02 -03:00
|
|
|
if (ival == -1 && PyErr_Occurred()) {
|
|
|
|
Py_DECREF(tmp);
|
2003-02-09 22:12:43 -04:00
|
|
|
return NULL;
|
2003-08-11 14:32:02 -03:00
|
|
|
}
|
2003-02-09 22:12:43 -04:00
|
|
|
} else {
|
|
|
|
ival = ((PyIntObject *)tmp)->ob_ival;
|
|
|
|
}
|
|
|
|
|
2006-04-21 07:40:58 -03:00
|
|
|
newobj = type->tp_alloc(type, 0);
|
|
|
|
if (newobj == NULL) {
|
2003-06-28 17:04:25 -03:00
|
|
|
Py_DECREF(tmp);
|
2001-08-29 12:47:46 -03:00
|
|
|
return NULL;
|
2003-06-28 17:04:25 -03:00
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
((PyIntObject *)newobj)->ob_ival = ival;
|
2001-08-29 12:47:46 -03:00
|
|
|
Py_DECREF(tmp);
|
2006-04-21 07:40:58 -03:00
|
|
|
return newobj;
|
2001-08-29 12:47:46 -03:00
|
|
|
}
|
|
|
|
|
2003-01-29 13:58:45 -04:00
|
|
|
static PyObject *
|
|
|
|
int_getnewargs(PyIntObject *v)
|
|
|
|
{
|
|
|
|
return Py_BuildValue("(l)", v->ob_ival);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef int_methods[] = {
|
|
|
|
{"__getnewargs__", (PyCFunction)int_getnewargs, METH_NOARGS},
|
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(int_doc,
|
2001-08-02 01:15:00 -03:00
|
|
|
"int(x[, base]) -> integer\n\
|
|
|
|
\n\
|
|
|
|
Convert a string or number to an integer, if possible. A floating point\n\
|
|
|
|
argument will be truncated towards zero (this does not include a string\n\
|
|
|
|
representation of a floating point number!) When converting a string, use\n\
|
|
|
|
the optional base. It is an error to supply a base when converting a\n\
|
2002-11-19 16:49:15 -04:00
|
|
|
non-string. If the argument is outside the integer range a long object\n\
|
|
|
|
will be returned instead.");
|
2001-08-02 01:15:00 -03:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyNumberMethods int_as_number = {
|
2001-01-03 21:45:33 -04:00
|
|
|
(binaryfunc)int_add, /*nb_add*/
|
|
|
|
(binaryfunc)int_sub, /*nb_subtract*/
|
|
|
|
(binaryfunc)int_mul, /*nb_multiply*/
|
|
|
|
(binaryfunc)int_mod, /*nb_remainder*/
|
|
|
|
(binaryfunc)int_divmod, /*nb_divmod*/
|
|
|
|
(ternaryfunc)int_pow, /*nb_power*/
|
|
|
|
(unaryfunc)int_neg, /*nb_negative*/
|
|
|
|
(unaryfunc)int_pos, /*nb_positive*/
|
|
|
|
(unaryfunc)int_abs, /*nb_absolute*/
|
|
|
|
(inquiry)int_nonzero, /*nb_nonzero*/
|
|
|
|
(unaryfunc)int_invert, /*nb_invert*/
|
|
|
|
(binaryfunc)int_lshift, /*nb_lshift*/
|
|
|
|
(binaryfunc)int_rshift, /*nb_rshift*/
|
|
|
|
(binaryfunc)int_and, /*nb_and*/
|
|
|
|
(binaryfunc)int_xor, /*nb_xor*/
|
|
|
|
(binaryfunc)int_or, /*nb_or*/
|
2006-08-21 14:06:07 -03:00
|
|
|
0, /*nb_coerce*/
|
2001-01-03 21:45:33 -04:00
|
|
|
(unaryfunc)int_int, /*nb_int*/
|
|
|
|
(unaryfunc)int_long, /*nb_long*/
|
|
|
|
(unaryfunc)int_float, /*nb_float*/
|
|
|
|
(unaryfunc)int_oct, /*nb_oct*/
|
|
|
|
(unaryfunc)int_hex, /*nb_hex*/
|
|
|
|
0, /*nb_inplace_add*/
|
|
|
|
0, /*nb_inplace_subtract*/
|
|
|
|
0, /*nb_inplace_multiply*/
|
|
|
|
0, /*nb_inplace_remainder*/
|
|
|
|
0, /*nb_inplace_power*/
|
|
|
|
0, /*nb_inplace_lshift*/
|
|
|
|
0, /*nb_inplace_rshift*/
|
|
|
|
0, /*nb_inplace_and*/
|
|
|
|
0, /*nb_inplace_xor*/
|
|
|
|
0, /*nb_inplace_or*/
|
2006-08-21 14:06:07 -03:00
|
|
|
(binaryfunc)int_floor_div, /* nb_floor_divide */
|
2001-08-08 02:00:18 -03:00
|
|
|
int_true_divide, /* nb_true_divide */
|
|
|
|
0, /* nb_inplace_floor_divide */
|
|
|
|
0, /* nb_inplace_true_divide */
|
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
which unfortunately means the errors from the bytes type change somewhat:
bytes([300]) still raises a ValueError, but bytes([10**100]) now raises a
TypeError (either that, or bytes(1.0) also raises a ValueError --
PyNumber_AsSsize_t() can only raise one type of exception.)
Merged revisions 51188-51433 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r51189 | kurt.kaiser | 2006-08-10 19:11:09 +0200 (Thu, 10 Aug 2006) | 4 lines
Retrieval of previous shell command was not always preserving indentation
since 1.2a1) Patch 1528468 Tal Einat.
........
r51190 | guido.van.rossum | 2006-08-10 19:41:07 +0200 (Thu, 10 Aug 2006) | 3 lines
Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
SF bug #1112549.
........
r51191 | guido.van.rossum | 2006-08-10 19:42:50 +0200 (Thu, 10 Aug 2006) | 2 lines
News item for SF bug 1112549.
........
r51192 | guido.van.rossum | 2006-08-10 20:09:25 +0200 (Thu, 10 Aug 2006) | 2 lines
Fix title -- it's rc1, not beta3.
........
r51194 | martin.v.loewis | 2006-08-10 21:04:00 +0200 (Thu, 10 Aug 2006) | 3 lines
Update dangling references to the 3.2 database to
mention that this is UCD 4.1 now.
........
r51195 | tim.peters | 2006-08-11 00:45:34 +0200 (Fri, 11 Aug 2006) | 6 lines
Followup to bug #1069160.
PyThreadState_SetAsyncExc(): internal correctness changes wrt
refcount safety and deadlock avoidance. Also added a basic test
case (relying on ctypes) and repaired the docs.
........
r51196 | tim.peters | 2006-08-11 00:48:45 +0200 (Fri, 11 Aug 2006) | 2 lines
Whitespace normalization.
........
r51197 | tim.peters | 2006-08-11 01:22:13 +0200 (Fri, 11 Aug 2006) | 5 lines
Whitespace normalization broke test_cgi, because a line
of quoted test data relied on preserving a single trailing
blank. Changed the string from raw to regular, and forced
in the trailing blank via an explicit \x20 escape.
........
r51198 | tim.peters | 2006-08-11 02:49:01 +0200 (Fri, 11 Aug 2006) | 10 lines
test_PyThreadState_SetAsyncExc(): This is failing on some
64-bit boxes. I have no idea what the ctypes docs mean
by "integers", and blind-guessing here that it intended to
mean the signed C "int" type, in which case perhaps I can
repair this by feeding the thread id argument to type
ctypes.c_long().
Also made the worker thread daemonic, so it doesn't hang
Python shutdown if the test continues to fail.
........
r51199 | tim.peters | 2006-08-11 05:49:10 +0200 (Fri, 11 Aug 2006) | 6 lines
force_test_exit(): This has been completely ineffective
at stopping test_signal from hanging forever on the Tru64
buildbot. That could be because there's no such thing as
signal.SIGALARM. Changed to the idiotic (but standard)
signal.SIGALRM instead, and added some more debug output.
........
r51202 | neal.norwitz | 2006-08-11 08:09:41 +0200 (Fri, 11 Aug 2006) | 6 lines
Fix the failures on cygwin (2006-08-10 fixed the actual locking issue).
The first hunk changes the colon to an ! like other Windows variants.
We need to always wait on the child so the lock gets released and
no other tests fail. This is the try/finally in the second hunk.
........
r51205 | georg.brandl | 2006-08-11 09:15:38 +0200 (Fri, 11 Aug 2006) | 3 lines
Add Chris McDonough (latest cgi.py patch)
........
r51206 | georg.brandl | 2006-08-11 09:26:10 +0200 (Fri, 11 Aug 2006) | 3 lines
logging's atexit hook now runs even if the rest of the module has
already been cleaned up.
........
r51212 | thomas.wouters | 2006-08-11 17:02:39 +0200 (Fri, 11 Aug 2006) | 4 lines
Add ignore of *.pyc and *.pyo to Lib/xml/etree/.
........
r51215 | thomas.heller | 2006-08-11 21:55:35 +0200 (Fri, 11 Aug 2006) | 7 lines
When a ctypes C callback function is called, zero out the result
storage before converting the result to C data. See the comment in
the code for details.
Provide a better context for errors when the conversion of a callback
function's result cannot be converted.
........
r51218 | neal.norwitz | 2006-08-12 03:43:40 +0200 (Sat, 12 Aug 2006) | 6 lines
Klocwork made another run and found a bunch more problems.
This is the first batch of fixes that should be easy to verify based on context.
This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
........
r51219 | neal.norwitz | 2006-08-12 03:45:47 +0200 (Sat, 12 Aug 2006) | 9 lines
Even though _Py_Mangle() isn't truly public anyone can call it and
there was no verification that privateobj was a PyString. If it wasn't
a string, this could have allowed a NULL pointer to creep in below and crash.
I wonder if this should be PyString_CheckExact? Must identifiers be strings
or can they be subclasses?
Klocwork #275
........
r51220 | neal.norwitz | 2006-08-12 03:46:42 +0200 (Sat, 12 Aug 2006) | 5 lines
It's highly unlikely, though possible for PyEval_Get*() to return NULLs.
So be safe and do an XINCREF.
Klocwork # 221-222.
........
r51221 | neal.norwitz | 2006-08-12 03:47:59 +0200 (Sat, 12 Aug 2006) | 7 lines
This code is actually not used unless WITHOUT_COMPLEX is defined.
However, there was no error checking that PyFloat_FromDouble returned
a valid pointer. I believe this change is correct as it seemed
to follow other code in the area.
Klocwork # 292.
........
r51222 | neal.norwitz | 2006-08-12 03:49:12 +0200 (Sat, 12 Aug 2006) | 5 lines
Handle NULL nodes while parsing. I'm not entirely sure this is correct.
There might be something else that needs to be done to setup the error.
Klocwork #295.
........
r51223 | neal.norwitz | 2006-08-12 03:50:38 +0200 (Sat, 12 Aug 2006) | 6 lines
If _stat_float_times is false, we will try to INCREF ival which could be NULL.
Return early in that case. The caller checks for PyErr_Occurred so this
should be ok.
Klocwork #297
........
r51224 | neal.norwitz | 2006-08-12 03:51:12 +0200 (Sat, 12 Aug 2006) | 3 lines
Move the assert which checks for a NULL pointer first.
Klocwork #274.
........
r51225 | neal.norwitz | 2006-08-12 03:53:28 +0200 (Sat, 12 Aug 2006) | 5 lines
Try to handle a malloc failure. I'm not entirely sure this is correct.
There might be something else we need to do to handle the exception.
Klocwork # 212-213
........
r51226 | neal.norwitz | 2006-08-12 03:57:47 +0200 (Sat, 12 Aug 2006) | 6 lines
I'm not sure why this code allocates this string for the error message.
I think it would be better to always use snprintf and have the format
limit the size of the name appropriately (like %.200s).
Klocwork #340
........
r51227 | neal.norwitz | 2006-08-12 04:06:34 +0200 (Sat, 12 Aug 2006) | 3 lines
Check returned pointer is valid.
Klocwork #233
........
r51228 | neal.norwitz | 2006-08-12 04:12:30 +0200 (Sat, 12 Aug 2006) | 1 line
Whoops, how did that get in there. :-) Revert all the parts of 51227 that were not supposed to go it. Only Modules/_ctypes/cfields.c was supposed to be changed
........
r51229 | neal.norwitz | 2006-08-12 04:33:36 +0200 (Sat, 12 Aug 2006) | 4 lines
Don't deref v if it's NULL.
Klocwork #214
........
r51230 | neal.norwitz | 2006-08-12 05:16:54 +0200 (Sat, 12 Aug 2006) | 5 lines
Check return of PyMem_MALLOC (garbage) is non-NULL.
Check seq in both portions of if/else.
Klocwork #289-290.
........
r51231 | neal.norwitz | 2006-08-12 05:17:41 +0200 (Sat, 12 Aug 2006) | 4 lines
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Klocwork #298-299.
........
r51232 | neal.norwitz | 2006-08-12 05:18:50 +0200 (Sat, 12 Aug 2006) | 5 lines
Verify verdat which is returned from malloc is not NULL.
Ensure we don't pass NULL to free.
Klocwork #306 (at least the first part, checking malloc)
........
r51233 | tim.peters | 2006-08-12 06:42:47 +0200 (Sat, 12 Aug 2006) | 35 lines
test_signal: Signal handling on the Tru64 buildbot
appears to be utterly insane. Plug some theoretical
insecurities in the test script:
- Verify that the SIGALRM handler was actually installed.
- Don't call alarm() before the handler is installed.
- Move everything that can fail inside the try/finally,
so the test cleans up after itself more often.
- Try sending all the expected signals in
force_test_exit(), not just SIGALRM. Since that was
fixed to actually send SIGALRM (instead of invisibly
dying with an AttributeError), we've seen that sending
SIGALRM alone does not stop this from hanging.
- Move the "kill the child" business into the finally
clause, so the child doesn't survive test failure
to send SIGALRM to other tests later (there are also
baffling SIGALRM-related failures in test_socket).
- Cancel the alarm in the finally clause -- if the
test dies early, we again don't want SIGALRM showing
up to confuse a later test.
Alas, this still relies on timing luck wrt the spawned
script that sends the test signals, but it's hard to see
how waiting for seconds can so often be so unlucky.
test_threadedsignals: curiously, this test never fails
on Tru64, but doesn't normally signal SIGALRM. Anyway,
fixed an obvious (but probably inconsequential) logic
error.
........
r51234 | tim.peters | 2006-08-12 07:17:41 +0200 (Sat, 12 Aug 2006) | 8 lines
Ah, fudge. One of the prints here actually "shouldn't be"
protected by "if verbose:", which caused the test to fail on
all non-Windows boxes.
Note that I deliberately didn't convert this to unittest yet,
because I expect it would be even harder to debug this on Tru64
after conversion.
........
r51235 | georg.brandl | 2006-08-12 10:32:02 +0200 (Sat, 12 Aug 2006) | 3 lines
Repair logging test spew caused by rev. 51206.
........
r51236 | neal.norwitz | 2006-08-12 19:03:09 +0200 (Sat, 12 Aug 2006) | 8 lines
Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments. This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward. I don't want this to hold up release if possible.
........
r51238 | neal.norwitz | 2006-08-12 20:44:06 +0200 (Sat, 12 Aug 2006) | 10 lines
Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots
were failing due to inappropriate clipping of numbers larger than 2**31
with new-style classes. (typeobject.c) In reviewing the code for classic
classes, there were 2 problems. Any negative value return could be returned.
Always return -1 if there was an error. Also make the checks similar
with the new-style classes. I believe this is correct for 32 and 64 bit
boxes, including Windows64.
Add a test of classic classes too.
........
r51240 | neal.norwitz | 2006-08-13 02:20:49 +0200 (Sun, 13 Aug 2006) | 1 line
SF bug #1539336, distutils example code missing
........
r51245 | neal.norwitz | 2006-08-13 20:10:10 +0200 (Sun, 13 Aug 2006) | 6 lines
Move/copy assert for tstate != NULL before first use.
Verify that PyEval_Get{Globals,Locals} returned valid pointers.
Klocwork 231-232
........
r51246 | neal.norwitz | 2006-08-13 20:10:28 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle a whole lot of failures from PyString_FromInternedString().
Should fix most of Klocwork 234-272.
........
r51247 | neal.norwitz | 2006-08-13 20:10:47 +0200 (Sun, 13 Aug 2006) | 8 lines
cpathname could be NULL if it was longer than MAXPATHLEN. Don't try
to write the .pyc to NULL.
Check results of PyList_GetItem() and PyModule_GetDict() are not NULL.
Klocwork 282, 283, 285
........
r51248 | neal.norwitz | 2006-08-13 20:11:08 +0200 (Sun, 13 Aug 2006) | 6 lines
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.
Klocwork 308
........
r51250 | neal.norwitz | 2006-08-13 20:11:27 +0200 (Sun, 13 Aug 2006) | 5 lines
Check return result of PyModule_GetDict().
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51251 | neal.norwitz | 2006-08-13 20:11:43 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle malloc and fopen failures more gracefully.
Klocwork 180-181
........
r51252 | neal.norwitz | 2006-08-13 20:12:03 +0200 (Sun, 13 Aug 2006) | 7 lines
It's very unlikely, though possible that source is not a string. Verify
that PyString_AsString() returns a valid pointer. (The problem can
arise when zlib.decompress doesn't return a string.)
Klocwork 346
........
r51253 | neal.norwitz | 2006-08-13 20:12:26 +0200 (Sun, 13 Aug 2006) | 5 lines
Handle failures from lookup.
Klocwork 341-342
........
r51254 | neal.norwitz | 2006-08-13 20:12:45 +0200 (Sun, 13 Aug 2006) | 6 lines
Handle failure from PyModule_GetDict() (Klocwork 208).
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
........
r51255 | neal.norwitz | 2006-08-13 20:13:02 +0200 (Sun, 13 Aug 2006) | 4 lines
Really address the issue of where to place the assert for leftblock.
(Followup of Klocwork 274)
........
r51256 | neal.norwitz | 2006-08-13 20:13:36 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle malloc failure.
Klocwork 281
........
r51258 | neal.norwitz | 2006-08-13 20:40:39 +0200 (Sun, 13 Aug 2006) | 4 lines
Handle alloca failures.
Klocwork 225-228
........
r51259 | neal.norwitz | 2006-08-13 20:41:15 +0200 (Sun, 13 Aug 2006) | 1 line
Get rid of compiler warning
........
r51261 | neal.norwitz | 2006-08-14 02:51:15 +0200 (Mon, 14 Aug 2006) | 1 line
Ignore pgen.exe and kill_python.exe for cygwin
........
r51262 | neal.norwitz | 2006-08-14 02:59:03 +0200 (Mon, 14 Aug 2006) | 4 lines
Can't return NULL from a void function. If there is a memory error,
about the best we can do is call PyErr_WriteUnraisable and go on.
We won't be able to do the call below either, so verify delstr is valid.
........
r51263 | neal.norwitz | 2006-08-14 03:49:54 +0200 (Mon, 14 Aug 2006) | 1 line
Update purify doc some.
........
r51264 | thomas.heller | 2006-08-14 09:13:05 +0200 (Mon, 14 Aug 2006) | 2 lines
Remove unused, buggy test function.
Fixes klockwork issue #207.
........
r51265 | thomas.heller | 2006-08-14 09:14:09 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value from new_CArgObject().
Fixes klockwork issues #183, #184, #185.
........
r51266 | thomas.heller | 2006-08-14 09:50:14 +0200 (Mon, 14 Aug 2006) | 2 lines
Check for NULL return value of GenericCData_new().
Fixes klockwork issues #188, #189.
........
r51274 | thomas.heller | 2006-08-14 12:02:24 +0200 (Mon, 14 Aug 2006) | 2 lines
Revert the change that tries to zero out a closure's result storage
area because the size if unknown in source/callproc.c.
........
r51276 | marc-andre.lemburg | 2006-08-14 12:55:19 +0200 (Mon, 14 Aug 2006) | 11 lines
Slightly revised version of patch #1538956:
Replace UnicodeDecodeErrors raised during == and !=
compares of Unicode and other objects with a new
UnicodeWarning.
All other comparisons continue to raise exceptions.
Exceptions other than UnicodeDecodeErrors are also left
untouched.
........
r51277 | thomas.heller | 2006-08-14 13:17:48 +0200 (Mon, 14 Aug 2006) | 13 lines
Apply the patch #1532975 plus ideas from the patch #1533481.
ctypes instances no longer have the internal and undocumented
'_as_parameter_' attribute which was used to adapt them to foreign
function calls; this mechanism is replaced by a function pointer in
the type's stgdict.
In the 'from_param' class methods, try the _as_parameter_ attribute if
other conversions are not possible.
This makes the documented _as_parameter_ mechanism work as intended.
Change the ctypes version number to 1.0.1.
........
r51278 | marc-andre.lemburg | 2006-08-14 13:44:34 +0200 (Mon, 14 Aug 2006) | 3 lines
Readd NEWS items that were accidentally removed by r51276.
........
r51279 | georg.brandl | 2006-08-14 14:36:06 +0200 (Mon, 14 Aug 2006) | 3 lines
Improve markup in PyUnicode_RichCompare.
........
r51280 | marc-andre.lemburg | 2006-08-14 14:57:27 +0200 (Mon, 14 Aug 2006) | 3 lines
Correct an accidentally removed previous patch.
........
r51281 | thomas.heller | 2006-08-14 18:17:41 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536908: Add support for AMD64 / OpenBSD.
Remove the -no-stack-protector compiler flag for OpenBSD
as it has been reported to be unneeded.
........
r51282 | thomas.heller | 2006-08-14 18:20:04 +0200 (Mon, 14 Aug 2006) | 1 line
News item for rev 51281.
........
r51283 | georg.brandl | 2006-08-14 22:25:39 +0200 (Mon, 14 Aug 2006) | 3 lines
Fix refleak introduced in rev. 51248.
........
r51284 | georg.brandl | 2006-08-14 23:34:08 +0200 (Mon, 14 Aug 2006) | 5 lines
Make tabnanny recognize IndentationErrors raised by tokenize.
Add a test to test_inspect to make sure indented source
is recognized correctly. (fixes #1224621)
........
r51285 | georg.brandl | 2006-08-14 23:42:55 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
........
r51287 | georg.brandl | 2006-08-14 23:45:32 +0200 (Mon, 14 Aug 2006) | 3 lines
Add an additional test: BZ2File write methods should raise IOError
when file is read-only.
........
r51289 | georg.brandl | 2006-08-14 23:55:28 +0200 (Mon, 14 Aug 2006) | 3 lines
Patch #1536071: trace.py should now find the full module name of a
file correctly even on Windows.
........
r51290 | georg.brandl | 2006-08-15 00:01:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Cookie.py shouldn't "bogusly" use string._idmap.
........
r51291 | georg.brandl | 2006-08-15 00:10:24 +0200 (Tue, 15 Aug 2006) | 3 lines
Patch #1511317: don't crash on invalid hostname info
........
r51292 | tim.peters | 2006-08-15 02:25:04 +0200 (Tue, 15 Aug 2006) | 2 lines
Whitespace normalization.
........
r51293 | neal.norwitz | 2006-08-15 06:14:57 +0200 (Tue, 15 Aug 2006) | 3 lines
Georg fixed one of my bugs, so I'll repay him with 2 NEWS entries.
Now we're even. :-)
........
r51295 | neal.norwitz | 2006-08-15 06:58:28 +0200 (Tue, 15 Aug 2006) | 8 lines
Fix the test for SocketServer so it should pass on cygwin and not fail
sporadically on other platforms. This is really a band-aid that doesn't
fix the underlying issue in SocketServer. It's not clear if it's worth
it to fix SocketServer, however, I opened a bug to track it:
http://python.org/sf/1540386
........
r51296 | neal.norwitz | 2006-08-15 06:59:30 +0200 (Tue, 15 Aug 2006) | 3 lines
Update the docstring to use a version a little newer than 1999. This was
taken from a Debian patch. Should we update the version for each release?
........
r51298 | neal.norwitz | 2006-08-15 08:29:03 +0200 (Tue, 15 Aug 2006) | 2 lines
Subclasses of int/long are allowed to define an __index__.
........
r51300 | thomas.heller | 2006-08-15 15:07:21 +0200 (Tue, 15 Aug 2006) | 1 line
Check for NULL return value from new_CArgObject calls.
........
r51303 | kurt.kaiser | 2006-08-16 05:15:26 +0200 (Wed, 16 Aug 2006) | 2 lines
The 'with' statement is now a Code Context block opener
........
r51304 | anthony.baxter | 2006-08-16 05:42:26 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1
........
r51305 | anthony.baxter | 2006-08-16 05:58:37 +0200 (Wed, 16 Aug 2006) | 1 line
preparing for 2.5c1 - no, really this time
........
r51306 | kurt.kaiser | 2006-08-16 07:01:42 +0200 (Wed, 16 Aug 2006) | 9 lines
Patch #1540892: site.py Quitter() class attempts to close sys.stdin
before raising SystemExit, allowing IDLE to honor quit() and exit().
M Lib/site.py
M Lib/idlelib/PyShell.py
M Lib/idlelib/CREDITS.txt
M Lib/idlelib/NEWS.txt
M Misc/NEWS
........
r51307 | ka-ping.yee | 2006-08-16 09:02:50 +0200 (Wed, 16 Aug 2006) | 6 lines
Update code and tests to support the 'bytes_le' attribute (for
little-endian byte order on Windows), and to work around clocks
with low resolution yielding duplicate UUIDs.
Anthony Baxter has approved this change.
........
r51308 | kurt.kaiser | 2006-08-16 09:04:17 +0200 (Wed, 16 Aug 2006) | 2 lines
Get quit() and exit() to work cleanly when not using subprocess.
........
r51309 | marc-andre.lemburg | 2006-08-16 10:13:26 +0200 (Wed, 16 Aug 2006) | 2 lines
Revert to having static version numbers again.
........
r51310 | martin.v.loewis | 2006-08-16 14:55:10 +0200 (Wed, 16 Aug 2006) | 2 lines
Build _hashlib on Windows. Build OpenSSL with masm assembler code.
Fixes #1535502.
........
r51311 | thomas.heller | 2006-08-16 15:03:11 +0200 (Wed, 16 Aug 2006) | 6 lines
Add commented assert statements to check that the result of
PyObject_stgdict() and PyType_stgdict() calls are non-NULL before
dereferencing the result. Hopefully this fixes what klocwork is
complaining about.
Fix a few other nits as well.
........
r51312 | anthony.baxter | 2006-08-16 15:08:25 +0200 (Wed, 16 Aug 2006) | 1 line
news entry for 51307
........
r51313 | andrew.kuchling | 2006-08-16 15:22:20 +0200 (Wed, 16 Aug 2006) | 1 line
Add UnicodeWarning
........
r51314 | andrew.kuchling | 2006-08-16 15:41:52 +0200 (Wed, 16 Aug 2006) | 1 line
Bump document version to 1.0; remove pystone paragraph
........
r51315 | andrew.kuchling | 2006-08-16 15:51:32 +0200 (Wed, 16 Aug 2006) | 1 line
Link to docs; remove an XXX comment
........
r51316 | martin.v.loewis | 2006-08-16 15:58:51 +0200 (Wed, 16 Aug 2006) | 1 line
Make cl build step compile-only (/c). Remove libs from source list.
........
r51317 | thomas.heller | 2006-08-16 16:07:44 +0200 (Wed, 16 Aug 2006) | 5 lines
The __repr__ method of a NULL py_object does no longer raise an
exception. Remove a stray '?' character from the exception text
when the value is retrieved of such an object.
Includes tests.
........
r51318 | andrew.kuchling | 2006-08-16 16:18:23 +0200 (Wed, 16 Aug 2006) | 1 line
Update bug/patch counts
........
r51319 | andrew.kuchling | 2006-08-16 16:21:14 +0200 (Wed, 16 Aug 2006) | 1 line
Wording/typo fixes
........
r51320 | thomas.heller | 2006-08-16 17:10:12 +0200 (Wed, 16 Aug 2006) | 9 lines
Remove the special casing of Py_None when converting the return value
of the Python part of a callback function to C. If it cannot be
converted, call PyErr_WriteUnraisable with the exception we got.
Before, arbitrary data has been passed to the calling C code in this
case.
(I'm not really sure the NEWS entry is understandable, but I cannot
find better words)
........
r51321 | marc-andre.lemburg | 2006-08-16 18:11:01 +0200 (Wed, 16 Aug 2006) | 2 lines
Add NEWS item mentioning the reverted distutils version number patch.
........
r51322 | fredrik.lundh | 2006-08-16 18:47:07 +0200 (Wed, 16 Aug 2006) | 5 lines
SF#1534630
ignore data that arrives before the opening start tag
........
r51324 | andrew.kuchling | 2006-08-16 19:11:18 +0200 (Wed, 16 Aug 2006) | 1 line
Grammar fix
........
r51328 | thomas.heller | 2006-08-16 20:02:11 +0200 (Wed, 16 Aug 2006) | 12 lines
Tutorial:
Clarify somewhat how parameters are passed to functions
(especially explain what integer means).
Correct the table - Python integers and longs can both be used.
Further clarification to the table comparing ctypes types, Python
types, and C types.
Reference:
Replace integer by C ``int`` where it makes sense.
........
r51329 | kurt.kaiser | 2006-08-16 23:45:59 +0200 (Wed, 16 Aug 2006) | 8 lines
File menu hotkeys: there were three 'p' assignments. Reassign the
'Save Copy As' and 'Print' hotkeys to 'y' and 't'. Change the
Shell menu hotkey from 's' to 'l'.
M Bindings.py
M PyShell.py
M NEWS.txt
........
r51330 | neil.schemenauer | 2006-08-17 01:38:05 +0200 (Thu, 17 Aug 2006) | 3 lines
Fix a bug in the ``compiler`` package that caused invalid code to be
generated for generator expressions.
........
r51342 | martin.v.loewis | 2006-08-17 21:19:32 +0200 (Thu, 17 Aug 2006) | 3 lines
Merge 51340 and 51341 from 2.5 branch:
Leave tk build directory to restore original path.
Invoke debug mk1mf.pl after running Configure.
........
r51354 | martin.v.loewis | 2006-08-18 05:47:18 +0200 (Fri, 18 Aug 2006) | 3 lines
Bug #1541863: uuid.uuid1 failed to generate unique identifiers
on systems with low clock resolution.
........
r51355 | neal.norwitz | 2006-08-18 05:57:54 +0200 (Fri, 18 Aug 2006) | 1 line
Add template for 2.6 on HEAD
........
r51356 | neal.norwitz | 2006-08-18 06:01:38 +0200 (Fri, 18 Aug 2006) | 1 line
More post-release wibble
........
r51357 | neal.norwitz | 2006-08-18 06:58:33 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again
........
r51358 | neal.norwitz | 2006-08-18 07:10:00 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Windows bots working again. Take 2
........
r51359 | neal.norwitz | 2006-08-18 07:39:20 +0200 (Fri, 18 Aug 2006) | 1 line
Try to get Unix bots install working again.
........
r51360 | neal.norwitz | 2006-08-18 07:41:46 +0200 (Fri, 18 Aug 2006) | 1 line
Set version to 2.6a0, seems more consistent.
........
r51362 | neal.norwitz | 2006-08-18 08:14:52 +0200 (Fri, 18 Aug 2006) | 1 line
More version wibble
........
r51364 | georg.brandl | 2006-08-18 09:27:59 +0200 (Fri, 18 Aug 2006) | 4 lines
Bug #1541682: Fix example in the "Refcount details" API docs.
Additionally, remove a faulty example showing PySequence_SetItem applied
to a newly created list object and add notes that this isn't a good idea.
........
r51366 | anthony.baxter | 2006-08-18 09:29:02 +0200 (Fri, 18 Aug 2006) | 3 lines
Updating IDLE's version number to match Python's (as per python-dev
discussion).
........
r51367 | anthony.baxter | 2006-08-18 09:30:07 +0200 (Fri, 18 Aug 2006) | 1 line
RPM specfile updates
........
r51368 | georg.brandl | 2006-08-18 09:35:47 +0200 (Fri, 18 Aug 2006) | 2 lines
Typo in tp_clear docs.
........
r51378 | andrew.kuchling | 2006-08-18 15:57:13 +0200 (Fri, 18 Aug 2006) | 1 line
Minor edits
........
r51379 | thomas.heller | 2006-08-18 16:38:46 +0200 (Fri, 18 Aug 2006) | 6 lines
Add asserts to check for 'impossible' NULL values, with comments.
In one place where I'n not 1000% sure about the non-NULL, raise
a RuntimeError for safety.
This should fix the klocwork issues that Neal sent me. If so,
it should be applied to the release25-maint branch also.
........
r51400 | neal.norwitz | 2006-08-19 06:22:33 +0200 (Sat, 19 Aug 2006) | 5 lines
Move initialization of interned strings to before allocating the
object so we don't leak op. (Fixes an earlier patch to this code)
Klockwork #350
........
r51401 | neal.norwitz | 2006-08-19 06:23:04 +0200 (Sat, 19 Aug 2006) | 4 lines
Move assert to after NULL check, otherwise we deref NULL in the assert.
Klocwork #307
........
r51402 | neal.norwitz | 2006-08-19 06:25:29 +0200 (Sat, 19 Aug 2006) | 2 lines
SF #1542693: Remove semi-colon at end of PyImport_ImportModuleEx macro
........
r51403 | neal.norwitz | 2006-08-19 06:28:55 +0200 (Sat, 19 Aug 2006) | 6 lines
Move initialization to after the asserts for non-NULL values.
Klocwork 286-287.
(I'm not backporting this, but if someone wants to, feel free.)
........
r51404 | neal.norwitz | 2006-08-19 06:52:03 +0200 (Sat, 19 Aug 2006) | 6 lines
Handle PyString_FromInternedString() failing (unlikely, but possible).
Klocwork #325
(I'm not backporting this, but if someone wants to, feel free.)
........
r51416 | georg.brandl | 2006-08-20 15:15:39 +0200 (Sun, 20 Aug 2006) | 2 lines
Patch #1542948: fix urllib2 header casing issue. With new test.
........
r51428 | jeremy.hylton | 2006-08-21 18:19:37 +0200 (Mon, 21 Aug 2006) | 3 lines
Move peephole optimizer to separate file.
........
r51429 | jeremy.hylton | 2006-08-21 18:20:29 +0200 (Mon, 21 Aug 2006) | 2 lines
Move peephole optimizer to separate file. (Forgot .h in previous checkin.)
........
r51432 | neal.norwitz | 2006-08-21 19:59:46 +0200 (Mon, 21 Aug 2006) | 5 lines
Fix bug #1543303, tarfile adds padding that breaks gunzip.
Patch # 1543897.
Will backport to 2.5
........
r51433 | neal.norwitz | 2006-08-21 20:01:30 +0200 (Mon, 21 Aug 2006) | 2 lines
Add assert to make Klocwork happy (#276)
........
2006-08-21 16:07:27 -03:00
|
|
|
(unaryfunc)int_int, /* nb_index */
|
1990-10-14 09:07:46 -03:00
|
|
|
};
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyTypeObject PyInt_Type = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
1990-10-14 09:07:46 -03:00
|
|
|
0,
|
|
|
|
"int",
|
1997-05-02 00:12:38 -03:00
|
|
|
sizeof(PyIntObject),
|
1990-10-14 09:07:46 -03:00
|
|
|
0,
|
2001-08-02 01:15:00 -03:00
|
|
|
(destructor)int_dealloc, /* tp_dealloc */
|
|
|
|
(printfunc)int_print, /* tp_print */
|
|
|
|
0, /* tp_getattr */
|
|
|
|
0, /* tp_setattr */
|
2006-08-23 21:41:19 -03:00
|
|
|
0, /* tp_compare */
|
2001-08-02 01:15:00 -03:00
|
|
|
(reprfunc)int_repr, /* tp_repr */
|
|
|
|
&int_as_number, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
(hashfunc)int_hash, /* tp_hash */
|
|
|
|
0, /* tp_call */
|
2002-02-01 11:34:10 -04:00
|
|
|
(reprfunc)int_repr, /* tp_str */
|
2001-08-02 01:15:00 -03:00
|
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
|
|
0, /* tp_setattro */
|
|
|
|
0, /* tp_as_buffer */
|
2006-07-27 18:53:35 -03:00
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
2001-08-02 01:15:00 -03:00
|
|
|
int_doc, /* tp_doc */
|
|
|
|
0, /* tp_traverse */
|
|
|
|
0, /* tp_clear */
|
2006-08-23 21:41:19 -03:00
|
|
|
int_richcompare, /* tp_richcompare */
|
2001-08-02 01:15:00 -03:00
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
0, /* tp_iter */
|
|
|
|
0, /* tp_iternext */
|
2003-01-29 13:58:45 -04:00
|
|
|
int_methods, /* tp_methods */
|
2001-08-02 01:15:00 -03:00
|
|
|
0, /* tp_members */
|
|
|
|
0, /* tp_getset */
|
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
|
|
|
0, /* tp_descr_get */
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
0, /* tp_init */
|
|
|
|
0, /* tp_alloc */
|
|
|
|
int_new, /* tp_new */
|
2002-04-25 21:53:34 -03:00
|
|
|
(freefunc)int_free, /* tp_free */
|
1990-10-14 09:07:46 -03:00
|
|
|
};
|
1997-08-04 23:16:08 -03:00
|
|
|
|
2002-12-30 18:29:22 -04:00
|
|
|
int
|
2002-12-30 23:42:13 -04:00
|
|
|
_PyInt_Init(void)
|
2002-12-30 18:29:22 -04:00
|
|
|
{
|
|
|
|
PyIntObject *v;
|
|
|
|
int ival;
|
|
|
|
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
|
|
|
|
for (ival = -NSMALLNEGINTS; ival < NSMALLPOSINTS; ival++) {
|
2004-02-08 14:54:37 -04:00
|
|
|
if (!free_list && (free_list = fill_free_list()) == NULL)
|
2002-12-30 18:29:22 -04:00
|
|
|
return 0;
|
|
|
|
/* PyObject_New is inlined */
|
|
|
|
v = free_list;
|
|
|
|
free_list = (PyIntObject *)v->ob_type;
|
|
|
|
PyObject_INIT(v, &PyInt_Type);
|
|
|
|
v->ob_ival = ival;
|
|
|
|
small_ints[ival + NSMALLNEGINTS] = v;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1997-08-04 23:16:08 -03:00
|
|
|
void
|
2000-07-09 12:16:51 -03:00
|
|
|
PyInt_Fini(void)
|
1997-08-04 23:16:08 -03:00
|
|
|
{
|
1999-03-12 15:43:17 -04:00
|
|
|
PyIntObject *p;
|
|
|
|
PyIntBlock *list, *next;
|
1997-08-04 23:16:08 -03:00
|
|
|
int i;
|
2006-04-21 07:40:58 -03:00
|
|
|
unsigned int ctr;
|
1999-03-10 18:55:24 -04:00
|
|
|
int bc, bf; /* block count, number of freed blocks */
|
|
|
|
int irem, isum; /* remaining unfreed ints per block, total */
|
1997-08-04 23:16:08 -03:00
|
|
|
|
1999-03-10 18:55:24 -04:00
|
|
|
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
|
|
|
|
PyIntObject **q;
|
|
|
|
|
|
|
|
i = NSMALLNEGINTS + NSMALLPOSINTS;
|
|
|
|
q = small_ints;
|
|
|
|
while (--i >= 0) {
|
|
|
|
Py_XDECREF(*q);
|
|
|
|
*q++ = NULL;
|
|
|
|
}
|
1997-08-04 23:16:08 -03:00
|
|
|
#endif
|
1999-03-10 18:55:24 -04:00
|
|
|
bc = 0;
|
|
|
|
bf = 0;
|
|
|
|
isum = 0;
|
|
|
|
list = block_list;
|
|
|
|
block_list = NULL;
|
1999-03-19 16:30:39 -04:00
|
|
|
free_list = NULL;
|
1999-03-10 18:55:24 -04:00
|
|
|
while (list != NULL) {
|
|
|
|
bc++;
|
|
|
|
irem = 0;
|
2006-04-21 07:40:58 -03:00
|
|
|
for (ctr = 0, p = &list->objects[0];
|
|
|
|
ctr < N_INTOBJECTS;
|
|
|
|
ctr++, p++) {
|
2001-09-11 13:13:52 -03:00
|
|
|
if (PyInt_CheckExact(p) && p->ob_refcnt != 0)
|
1999-03-10 18:55:24 -04:00
|
|
|
irem++;
|
|
|
|
}
|
1999-03-12 15:43:17 -04:00
|
|
|
next = list->next;
|
1999-03-10 18:55:24 -04:00
|
|
|
if (irem) {
|
1999-03-12 15:43:17 -04:00
|
|
|
list->next = block_list;
|
|
|
|
block_list = list;
|
2006-04-21 07:40:58 -03:00
|
|
|
for (ctr = 0, p = &list->objects[0];
|
|
|
|
ctr < N_INTOBJECTS;
|
|
|
|
ctr++, p++) {
|
2001-09-11 13:13:52 -03:00
|
|
|
if (!PyInt_CheckExact(p) ||
|
2001-08-29 12:47:46 -03:00
|
|
|
p->ob_refcnt == 0) {
|
1999-03-19 16:30:39 -04:00
|
|
|
p->ob_type = (struct _typeobject *)
|
|
|
|
free_list;
|
|
|
|
free_list = p;
|
|
|
|
}
|
|
|
|
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
|
|
|
|
else if (-NSMALLNEGINTS <= p->ob_ival &&
|
|
|
|
p->ob_ival < NSMALLPOSINTS &&
|
|
|
|
small_ints[p->ob_ival +
|
|
|
|
NSMALLNEGINTS] == NULL) {
|
|
|
|
Py_INCREF(p);
|
|
|
|
small_ints[p->ob_ival +
|
|
|
|
NSMALLNEGINTS] = p;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1999-03-10 18:55:24 -04:00
|
|
|
}
|
|
|
|
else {
|
2002-04-28 13:57:34 -03:00
|
|
|
PyMem_FREE(list);
|
1999-03-10 18:55:24 -04:00
|
|
|
bf++;
|
|
|
|
}
|
|
|
|
isum += irem;
|
1999-03-12 15:43:17 -04:00
|
|
|
list = next;
|
1999-03-10 18:55:24 -04:00
|
|
|
}
|
1999-03-12 15:43:17 -04:00
|
|
|
if (!Py_VerboseFlag)
|
|
|
|
return;
|
|
|
|
fprintf(stderr, "# cleanup ints");
|
|
|
|
if (!isum) {
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr,
|
|
|
|
": %d unfreed int%s in %d out of %d block%s\n",
|
|
|
|
isum, isum == 1 ? "" : "s",
|
|
|
|
bc - bf, bc, bc == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
if (Py_VerboseFlag > 1) {
|
|
|
|
list = block_list;
|
|
|
|
while (list != NULL) {
|
2006-04-21 07:40:58 -03:00
|
|
|
for (ctr = 0, p = &list->objects[0];
|
|
|
|
ctr < N_INTOBJECTS;
|
|
|
|
ctr++, p++) {
|
2001-09-11 13:13:52 -03:00
|
|
|
if (PyInt_CheckExact(p) && p->ob_refcnt != 0)
|
2006-03-01 01:41:20 -04:00
|
|
|
/* XXX(twouters) cast refcount to
|
|
|
|
long until %zd is universally
|
|
|
|
available
|
|
|
|
*/
|
1999-03-12 15:43:17 -04:00
|
|
|
fprintf(stderr,
|
2006-03-01 01:41:20 -04:00
|
|
|
"# <int at %p, refcnt=%ld, val=%ld>\n",
|
|
|
|
p, (long)p->ob_refcnt,
|
|
|
|
p->ob_ival);
|
1999-03-12 15:43:17 -04:00
|
|
|
}
|
|
|
|
list = list->next;
|
1999-03-10 18:55:24 -04:00
|
|
|
}
|
|
|
|
}
|
1997-08-04 23:16:08 -03:00
|
|
|
}
|