From python-checkins at python.org Wed Mar 1 00:09:09 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 00:09:09 +0100 (CET) Subject: [Python-checkins] r42699 - python/trunk/Include/compile.h Message-ID: <20060228230909.F1A841E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 00:09:08 2006 New Revision: 42699 Modified: python/trunk/Include/compile.h Log: Move #include to outside "extern C {}", before Tim figures out it'll break VC++. Modified: python/trunk/Include/compile.h ============================================================================== --- python/trunk/Include/compile.h (original) +++ python/trunk/Include/compile.h Wed Mar 1 00:09:08 2006 @@ -1,12 +1,13 @@ #ifndef Py_COMPILE_H #define Py_COMPILE_H + +#include "code.h" + #ifdef __cplusplus extern "C" { #endif -#include "code.h" - /* Public interface */ struct _node; /* Declare the existence of this type */ PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *); From python-checkins at python.org Wed Mar 1 00:10:30 2006 From: python-checkins at python.org (neal.norwitz) Date: Wed, 1 Mar 2006 00:10:30 +0100 (CET) Subject: [Python-checkins] r42700 - peps/trunk/pep-0263.txt Message-ID: <20060228231030.80C6A1E401C@bag.python.org> Author: neal.norwitz Date: Wed Mar 1 00:10:27 2006 New Revision: 42700 Modified: peps/trunk/pep-0263.txt Log: Martin changed the encoding warning to an error Modified: peps/trunk/pep-0263.txt ============================================================================== --- peps/trunk/pep-0263.txt (original) +++ peps/trunk/pep-0263.txt Wed Mar 1 00:10:27 2006 @@ -205,6 +205,12 @@ SUZUKI Hisao is working on a patch; see [2] for details. A patch implementing only phase 1 is available at [1]. +Phases + Implemenation of steps 1 and 2 above were completed in 2.3, + except for changing the default encoding to "ascii". + + The default encoding was set to "ascii" in version 2.5. + Scope This PEP intends to provide an upgrade path from the current From python-checkins at python.org Wed Mar 1 00:41:19 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 00:41:19 +0100 (CET) Subject: [Python-checkins] r42702 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060228234119.4EC3D1E4009@bag.python.org> Author: tim.peters Date: Wed Mar 1 00:41:18 2006 New Revision: 42702 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: The code nesting here has gotten impossibly deep. Will probably need to refactor, but until then renaming "partially_allocated_arenas" to "usable_arenas" seems to help readability a lot. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Wed Mar 1 00:41:18 2006 @@ -276,8 +276,8 @@ * * When this arena_object is associated with an allocated arena * with at least one available pool, both members are used in the - * doubly-linked `partially_allocated_arenas` list, which is - * maintained in increasing order of `nfreepools` values. + * doubly-linked `usable_arenas` list, which is maintained in + * increasing order of `nfreepools` values. * * Else this arena_object is associated with an allocated arena * all of whose pools are in use. `nextarena` and `prevarena` @@ -452,7 +452,7 @@ head of the list in new_arena(), and are pushed on the head of the list in PyObject_Free() when the arena is empty. -partially_allocated_arenas +usable_arenas This is a doubly-linked list of the arena_objects associated with arenas that have pools available. These pools are either waiting to be reused, @@ -473,7 +473,7 @@ static struct arena_object* available_arenas = NULL; /* The head of the doubly-linked list of arenas with pools available. */ -static struct arena_object* partially_allocated_arenas = NULL; +static struct arena_object* usable_arenas = NULL; /* How many arena_objects do we initially allocate? * 16 = can allocate 16 arenas = 16 * ARENA_SIZE = 4MB before growing the @@ -533,7 +533,7 @@ * into the old array. Thus, we don't have to worry about * invalid pointers. Just to be sure, some asserts: */ - assert(partially_allocated_arenas == NULL); + assert(usable_arenas == NULL); assert(available_arenas == NULL); /* Zero fill the new section of the array. */ @@ -729,61 +729,53 @@ UNLOCK(); return (void *)bp; } - if (partially_allocated_arenas == NULL) { - /* - * Allocate new arena - */ + + /* There isn't a pool of the right size class immediately + * available: use a free pool from an arena. + */ + if (usable_arenas == NULL) { + /* No arena has a free pool: allocate a new arena. */ #ifdef WITH_MEMORY_LIMITS if (narenas_currently_allocated >= MAX_ARENAS) { UNLOCK(); goto redirect; } #endif - partially_allocated_arenas = new_arena(); - if (partially_allocated_arenas == NULL) { + usable_arenas = new_arena(); + if (usable_arenas == NULL) { UNLOCK(); goto redirect; } - assert(partially_allocated_arenas->address != - (uptr)NULL); - /* This is the beginning of a new list, and is - * initialized in new_arena. - */ - assert(partially_allocated_arenas->nextarena == NULL - && partially_allocated_arenas->prevarena == NULL); } + assert(usable_arenas->address != 0); - /* - * Try to get a cached free pool - */ - pool = partially_allocated_arenas->freepools; + /* Try to get a cached free pool. */ + pool = usable_arenas->freepools; if (pool != NULL) { - /* - * Unlink from cached pools - */ - partially_allocated_arenas->freepools = pool->nextpool; + /* Unlink from cached pools. */ + usable_arenas->freepools = pool->nextpool; /* This moves the arena *towards* the head of the list but it is already at the head of the list: do nothing */ /* XXX what did that mean? */ /* XXX reformat very long lines below */ - partially_allocated_arenas->nfreepools --; - if (partially_allocated_arenas->nfreepools == 0) { - assert(partially_allocated_arenas->freepools == NULL); - assert(partially_allocated_arenas->nextarena == NULL - || partially_allocated_arenas->nextarena->prevarena == partially_allocated_arenas); + usable_arenas->nfreepools --; + if (usable_arenas->nfreepools == 0) { + assert(usable_arenas->freepools == NULL); + assert(usable_arenas->nextarena == NULL + || usable_arenas->nextarena->prevarena == usable_arenas); /* Unlink the arena: it is completely allocated. This is a dequeue from the head operation. */ - partially_allocated_arenas = partially_allocated_arenas->nextarena; - if (partially_allocated_arenas != NULL) - partially_allocated_arenas->prevarena = NULL; - assert(partially_allocated_arenas == NULL || partially_allocated_arenas->address != (uptr) NULL); + usable_arenas = usable_arenas->nextarena; + if (usable_arenas != NULL) + usable_arenas->prevarena = NULL; + assert(usable_arenas == NULL || usable_arenas->address != (uptr) NULL); } else { - assert(partially_allocated_arenas->freepools != NULL - || partially_allocated_arenas->base_address <= ((block*) partially_allocated_arenas->address) + ARENA_SIZE - POOL_SIZE); + assert(usable_arenas->freepools != NULL + || usable_arenas->base_address <= ((block*) usable_arenas->address) + ARENA_SIZE - POOL_SIZE); } init_pool: /* @@ -824,42 +816,39 @@ /* * Allocate new pool */ - assert(partially_allocated_arenas->nfreepools > 0); - if (partially_allocated_arenas->nfreepools) { + assert(usable_arenas->nfreepools > 0); + if (usable_arenas->nfreepools) { /* Verify that the arenabase address is in range. */ /* XXX This assert appears to be equivalent to assert(POOL_SIZE <= ARENA_SIZE); what's it _trying_ to check? */ - assert(partially_allocated_arenas->base_address <= - partially_allocated_arenas->base_address + + assert(usable_arenas->base_address <= + usable_arenas->base_address + ARENA_SIZE - POOL_SIZE); - pool = (poolp)partially_allocated_arenas->base_address; - pool->arenaindex = partially_allocated_arenas - arenas; + pool = (poolp)usable_arenas->base_address; + pool->arenaindex = usable_arenas - arenas; assert(&arenas[pool->arenaindex] == - partially_allocated_arenas); + usable_arenas); pool->szidx = DUMMY_SIZE_IDX; - --partially_allocated_arenas->nfreepools; - partially_allocated_arenas->base_address += POOL_SIZE; + --usable_arenas->nfreepools; + usable_arenas->base_address += POOL_SIZE; - if (partially_allocated_arenas->nfreepools == 0) { - assert(partially_allocated_arenas->nextarena == + if (usable_arenas->nfreepools == 0) { + assert(usable_arenas->nextarena == NULL || - partially_allocated_arenas->nextarena->prevarena == - partially_allocated_arenas); + usable_arenas->nextarena->prevarena == + usable_arenas); /* Unlink the arena: it is completely * allocated. */ - partially_allocated_arenas = - partially_allocated_arenas->nextarena; - if (partially_allocated_arenas != NULL) - partially_allocated_arenas->prevarena = - NULL; - assert(partially_allocated_arenas == NULL || - partially_allocated_arenas->address != - (uptr) NULL); + usable_arenas = usable_arenas->nextarena; + if (usable_arenas != NULL) + usable_arenas->prevarena = NULL; + assert(usable_arenas == NULL || + usable_arenas->address != 0); } goto init_pool; @@ -953,15 +942,12 @@ (uptr)NULL); /* Fix the pointer in the prevarena, or the - * partially_allocated_arenas pointer + * usable_arenas pointer */ if (arenaobj->prevarena == NULL) { - partially_allocated_arenas = - arenaobj->nextarena; - assert(partially_allocated_arenas == - NULL || - partially_allocated_arenas->address - != (uptr)NULL); + usable_arenas = arenaobj->nextarena; + assert(usable_arenas == NULL || + usable_arenas->address != 0); } else { assert(arenaobj->prevarena->nextarena == @@ -996,17 +982,16 @@ * go link it to the head of the partially * allocated list. */ - arenaobj->nextarena = partially_allocated_arenas; + arenaobj->nextarena = usable_arenas; arenaobj->prevarena = NULL; - partially_allocated_arenas = arenaobj; + usable_arenas = arenaobj; /* Fix the pointer in the nextarena. */ if (arenaobj->nextarena != NULL) { arenaobj->nextarena->prevarena = arenaobj; } - assert(partially_allocated_arenas->address != - (uptr)NULL); + assert(usable_arenas->address != 0); } /* If this arena is now out of order, we need to keep * the list sorted. The list is kept sorted so that @@ -1025,7 +1010,7 @@ if (arenaobj->prevarena != NULL) lastPointer = &arenaobj->prevarena->nextarena; else - lastPointer = &partially_allocated_arenas; + lastPointer = &usable_arenas; assert(*lastPointer == arenaobj); /* Step one: unlink the arena from the list. */ @@ -1065,8 +1050,7 @@ assert(arenaobj->nextarena == NULL || arenaobj->nextarena->prevarena == arenaobj); - assert((partially_allocated_arenas == - arenaobj && + assert((usable_arenas == arenaobj && arenaobj->prevarena == NULL) || arenaobj->prevarena->nextarena == arenaobj); From python-checkins at python.org Wed Mar 1 01:25:13 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 01:25:13 +0100 (CET) Subject: [Python-checkins] r42703 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301002513.0F1741E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 01:25:12 2006 New Revision: 42703 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Simplification and reformatting. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Wed Mar 1 01:25:12 2006 @@ -256,7 +256,7 @@ uptr address; /* Pool-aligned pointer to the next pool to be carved off. */ - block* base_address; + block* pool_address; /* The number of available pools in the arena: free pools + never- * allocated pools. @@ -579,13 +579,13 @@ #endif /* base_address <- first pool-aligned address in the arena nfreepools <- number of whole pools that fit after alignment */ - arenaobj->base_address = (block*)arenaobj->address; + arenaobj->pool_address = (block*)arenaobj->address; arenaobj->nfreepools = ARENA_SIZE / POOL_SIZE; assert(POOL_SIZE * arenaobj->nfreepools == ARENA_SIZE); excess = (uint)((Py_uintptr_t)arenaobj->address & POOL_SIZE_MASK); if (excess != 0) { --arenaobj->nfreepools; - arenaobj->base_address += POOL_SIZE - excess; + arenaobj->pool_address += POOL_SIZE - excess; } arenaobj->ntotalpools = arenaobj->nfreepools; @@ -758,24 +758,27 @@ /* This moves the arena *towards* the head of the list but it is already at the head of the list: do nothing */ /* XXX what did that mean? */ - /* XXX reformat very long lines below */ - usable_arenas->nfreepools --; + --usable_arenas->nfreepools; if (usable_arenas->nfreepools == 0) { + /* Unlink the arena: it's completely + * allocated. + */ assert(usable_arenas->freepools == NULL); - assert(usable_arenas->nextarena == NULL - || usable_arenas->nextarena->prevarena == usable_arenas); + assert(usable_arenas->nextarena == NULL || + usable_arenas->nextarena->prevarena == + usable_arenas); - /* Unlink the arena: it is completely - allocated. This is a dequeue from the - head operation. */ usable_arenas = usable_arenas->nextarena; - if (usable_arenas != NULL) + if (usable_arenas != NULL) { usable_arenas->prevarena = NULL; - assert(usable_arenas == NULL || usable_arenas->address != (uptr) NULL); + assert(usable_arenas->address != 0); + } } else { - assert(usable_arenas->freepools != NULL - || usable_arenas->base_address <= ((block*) usable_arenas->address) + ARENA_SIZE - POOL_SIZE); + assert(usable_arenas->freepools != NULL || + usable_arenas->pool_address <= + ((block*) usable_arenas->address) + + ARENA_SIZE - POOL_SIZE); } init_pool: /* @@ -813,46 +816,38 @@ UNLOCK(); return (void *)bp; } - /* - * Allocate new pool - */ + /* Allocate new pool. */ assert(usable_arenas->nfreepools > 0); - if (usable_arenas->nfreepools) { - /* Verify that the arenabase address is in range. */ - /* XXX This assert appears to be equivalent to - assert(POOL_SIZE <= ARENA_SIZE); what's it - _trying_ to check? - */ - assert(usable_arenas->base_address <= - usable_arenas->base_address + - ARENA_SIZE - POOL_SIZE); - pool = (poolp)usable_arenas->base_address; - pool->arenaindex = usable_arenas - arenas; - assert(&arenas[pool->arenaindex] == - usable_arenas); - pool->szidx = DUMMY_SIZE_IDX; - - --usable_arenas->nfreepools; - usable_arenas->base_address += POOL_SIZE; - - if (usable_arenas->nfreepools == 0) { - assert(usable_arenas->nextarena == - NULL || - usable_arenas->nextarena->prevarena == - usable_arenas); - - /* Unlink the arena: it is completely - * allocated. - */ - usable_arenas = usable_arenas->nextarena; - if (usable_arenas != NULL) - usable_arenas->prevarena = NULL; - assert(usable_arenas == NULL || - usable_arenas->address != 0); + /* Verify that the arenabase address is in range. */ + /* XXX This assert appears to be equivalent to + assert(POOL_SIZE <= ARENA_SIZE); what's it + _trying_ to check? + */ + assert(usable_arenas->pool_address <= + usable_arenas->pool_address + + ARENA_SIZE - POOL_SIZE); + pool = (poolp)usable_arenas->pool_address; + pool->arenaindex = usable_arenas - arenas; + assert(&arenas[pool->arenaindex] == + usable_arenas); + pool->szidx = DUMMY_SIZE_IDX; + + --usable_arenas->nfreepools; + usable_arenas->pool_address += POOL_SIZE; + + if (usable_arenas->nfreepools == 0) { + assert(usable_arenas->nextarena == NULL || + usable_arenas->nextarena->prevarena == + usable_arenas); + /* Unlink the arena: it is completely allocated. */ + usable_arenas = usable_arenas->nextarena; + if (usable_arenas != NULL) { + usable_arenas->prevarena = NULL; + assert(usable_arenas->address != 0); } - - goto init_pool; } + + goto init_pool; } /* The small block allocator ends here. */ @@ -1618,9 +1613,9 @@ } /* visit every pool in the arena */ - assert(base <= (uptr) arenas[i].base_address); + assert(base <= (uptr) arenas[i].pool_address); for (j = 0; - base < (uptr) arenas[i].base_address; + base < (uptr) arenas[i].pool_address; ++j, base += POOL_SIZE) { poolp p = (poolp)base; const uint sz = p->szidx; From python-checkins at python.org Wed Mar 1 01:47:27 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 01:47:27 +0100 (CET) Subject: [Python-checkins] r42704 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301004727.4AF401E400F@bag.python.org> Author: tim.peters Date: Wed Mar 1 01:47:25 2006 New Revision: 42704 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Typo repair. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Wed Mar 1 01:47:25 2006 @@ -577,7 +577,7 @@ #ifdef PYMALLOC_DEBUG ++ntimes_arena_allocated; #endif - /* base_address <- first pool-aligned address in the arena + /* pool_address <- first pool-aligned address in the arena nfreepools <- number of whole pools that fit after alignment */ arenaobj->pool_address = (block*)arenaobj->address; arenaobj->nfreepools = ARENA_SIZE / POOL_SIZE; From python-checkins at python.org Wed Mar 1 02:01:56 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 02:01:56 +0100 (CET) Subject: [Python-checkins] r42705 - python/trunk/Modules/_bsddb.c Message-ID: <20060301010156.76EE51E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 02:01:55 2006 New Revision: 42705 Modified: python/trunk/Modules/_bsddb.c Log: Fix DBEnv's set_tx_timestamp wrapper to be slightly more correct on non-32bit platforms. Will still only allow 32 bits in a timestamp on Win64, but at least it won't crash, and it'll work right on platforms where longs are big enough to contain time_t's. (A better-working, although conceptually less-right fix would have been to use Py_ssize_t here, but Martin and Tim won't let me.) Modified: python/trunk/Modules/_bsddb.c ============================================================================== --- python/trunk/Modules/_bsddb.c (original) +++ python/trunk/Modules/_bsddb.c Wed Mar 1 02:01:55 2006 @@ -4190,13 +4190,14 @@ DBEnv_set_tx_timestamp(DBEnvObject* self, PyObject* args) { int err; - time_t stamp; + long stamp; + time_t timestamp; - if (!PyArg_ParseTuple(args, "i:set_tx_timestamp", &stamp)) + if (!PyArg_ParseTuple(args, "l:set_tx_timestamp", &stamp)) return NULL; CHECK_ENV_NOT_CLOSED(self); - - err = self->db_env->set_tx_timestamp(self->db_env, &stamp); + timestamp = (time_t)stamp; + err = self->db_env->set_tx_timestamp(self->db_env, ×tamp); RETURN_IF_ERR(); RETURN_NONE(); } From python-checkins at python.org Wed Mar 1 02:05:18 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 02:05:18 +0100 (CET) Subject: [Python-checkins] r42706 - python/trunk/Modules/posixmodule.c Message-ID: <20060301010518.4C38C1E401E@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 02:05:10 2006 New Revision: 42706 Modified: python/trunk/Modules/posixmodule.c Log: Py_ssize_t-ify. Modified: python/trunk/Modules/posixmodule.c ============================================================================== --- python/trunk/Modules/posixmodule.c (original) +++ python/trunk/Modules/posixmodule.c Wed Mar 1 02:05:10 2006 @@ -13,6 +13,8 @@ /* See also ../Dos/dosmodule.c */ +#define PY_SSIZE_T_CLEAN + #include "Python.h" #include "structseq.h" @@ -1759,7 +1761,7 @@ #define MAX_PATH CCHMAXPATH #endif char *name, *pt; - int len; + Py_ssize_t len; PyObject *d, *v; char namebuf[MAX_PATH+5]; HDIR hdir = 1; @@ -1899,7 +1901,7 @@ /* assume encoded strings wont more than double no of chars */ char inbuf[MAX_PATH*2]; char *inbufp = inbuf; - int insize = sizeof(inbuf)/sizeof(inbuf[0]); + Py_ssize_t insize; char outbuf[MAX_PATH*2]; char *temp; #ifdef Py_WIN_WIDE_FILENAMES @@ -1919,6 +1921,7 @@ PyErr_Clear(); } #endif + /* XXX(twouters) Why use 'et#' here at all? insize isn't used */ if (!PyArg_ParseTuple (args, "et#:_getfullpathname", Py_FileSystemDefaultEncoding, &inbufp, &insize)) @@ -5590,16 +5593,18 @@ static PyObject * posix_write(PyObject *self, PyObject *args) { - int fd, size; + int fd; + Py_ssize_t size; char *buffer; + if (!PyArg_ParseTuple(args, "is#:write", &fd, &buffer, &size)) return NULL; Py_BEGIN_ALLOW_THREADS - size = write(fd, buffer, size); + size = write(fd, buffer, (size_t)size); Py_END_ALLOW_THREADS if (size < 0) return posix_error(); - return PyInt_FromLong((long)size); + return PyInt_FromSsize_t(size); } From python-checkins at python.org Wed Mar 1 02:16:10 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 02:16:10 +0100 (CET) Subject: [Python-checkins] r42707 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301011610.3762C1E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 02:16:09 2006 New Revision: 42707 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Cleaned up an XXX -- figured out what the code intended to do here, and did it. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Wed Mar 1 02:16:09 2006 @@ -318,8 +318,9 @@ usedpools[0] corresponds to blocks of size 8, usedpools[2] to blocks of size 16, and so on: index 2*i <-> blocks of size (i+1)<nextoffset <= pool->maxnextoffset) { - /* - * There is room for another block - */ - pool->freeblock = (block *)pool + + /* There is room for another block. */ + pool->freeblock = (block*)pool + pool->nextoffset; pool->nextoffset += INDEX2SIZE(size); *(block **)(pool->freeblock) = NULL; UNLOCK(); return (void *)bp; } - /* - * Pool is full, unlink from used pools - */ + /* Pool is full, unlink from used pools. */ next = pool->nextpool; pool = pool->prevpool; next->prevpool = pool; @@ -731,7 +728,7 @@ } /* There isn't a pool of the right size class immediately - * available: use a free pool from an arena. + * available: use a free pool. */ if (usable_arenas == NULL) { /* No arena has a free pool: allocate a new arena. */ @@ -775,15 +772,18 @@ } } else { + /* nfreepools > 0: it must be that freepools + * isn't NULL, or that we haven't yet carved + * off all the arena's pools for the first + * time. + */ assert(usable_arenas->freepools != NULL || usable_arenas->pool_address <= - ((block*) usable_arenas->address) + + (block*)usable_arenas->address + ARENA_SIZE - POOL_SIZE); } init_pool: - /* - * Frontlink to used pools - */ + /* Frontlink to used pools. */ next = usedpools[size + size]; /* == prev */ pool->nextpool = next; pool->prevpool = next; @@ -791,8 +791,7 @@ next->prevpool = pool; pool->ref.count = 1; if (pool->szidx == size) { - /* - * Luckily, this pool last contained blocks + /* Luckily, this pool last contained blocks * of the same size class, so its header * and free list are already initialized. */ @@ -816,24 +815,18 @@ UNLOCK(); return (void *)bp; } - /* Allocate new pool. */ + + /* Carve off a new pool. */ assert(usable_arenas->nfreepools > 0); - /* Verify that the arenabase address is in range. */ - /* XXX This assert appears to be equivalent to - assert(POOL_SIZE <= ARENA_SIZE); what's it - _trying_ to check? - */ - assert(usable_arenas->pool_address <= - usable_arenas->pool_address + - ARENA_SIZE - POOL_SIZE); + assert(usable_arenas->freepools == NULL); pool = (poolp)usable_arenas->pool_address; + assert((block*)pool <= (block*)usable_arenas->address + + ARENA_SIZE - POOL_SIZE); pool->arenaindex = usable_arenas - arenas; - assert(&arenas[pool->arenaindex] == - usable_arenas); + assert(&arenas[pool->arenaindex] == usable_arenas); pool->szidx = DUMMY_SIZE_IDX; - - --usable_arenas->nfreepools; usable_arenas->pool_address += POOL_SIZE; + --usable_arenas->nfreepools; if (usable_arenas->nfreepools == 0) { assert(usable_arenas->nextarena == NULL || From python-checkins at python.org Wed Mar 1 05:02:50 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 05:02:50 +0100 (CET) Subject: [Python-checkins] r42708 - python/trunk/Include/object.h Message-ID: <20060301040250.B75381E4021@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 05:02:43 2006 New Revision: 42708 Modified: python/trunk/Include/object.h Log: Make ob_refcnt and tp_maxalloc (and friends) Py_ssize_t. Modified: python/trunk/Include/object.h ============================================================================== --- python/trunk/Include/object.h (original) +++ python/trunk/Include/object.h Wed Mar 1 05:02:43 2006 @@ -77,7 +77,7 @@ /* PyObject_HEAD defines the initial segment of every PyObject. */ #define PyObject_HEAD \ _PyObject_HEAD_EXTRA \ - int ob_refcnt; \ + Py_ssize_t ob_refcnt; \ struct _typeobject *ob_type; #define PyObject_HEAD_INIT(type) \ @@ -333,9 +333,9 @@ #ifdef COUNT_ALLOCS /* these must be last and never explicitly initialized */ - int tp_allocs; - int tp_frees; - int tp_maxalloc; + Py_ssize_t tp_allocs; + Py_ssize_t tp_frees; + Py_ssize_t tp_maxalloc; struct _typeobject *tp_next; #endif } PyTypeObject; From python-checkins at python.org Wed Mar 1 05:04:31 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 05:04:31 +0100 (CET) Subject: [Python-checkins] r42709 - python/trunk/Parser/tokenizer.h Message-ID: <20060301040431.98D2A1E4018@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 05:04:20 2006 New Revision: 42709 Modified: python/trunk/Parser/tokenizer.h Log: Remove unused field. Modified: python/trunk/Parser/tokenizer.h ============================================================================== --- python/trunk/Parser/tokenizer.h (original) +++ python/trunk/Parser/tokenizer.h Wed Mar 1 05:04:20 2006 @@ -43,7 +43,6 @@ int decoding_state; /* -1:decoding, 0:init, 1:raw */ int decoding_erred; /* whether erred in decoding */ int read_coding_spec; /* whether 'coding:...' has been read */ - int issued_encoding_warning; /* whether non-ASCII warning was issued */ char *encoding; int cont_line; /* whether we are in a continuation line. */ #ifndef PGEN From python-checkins at python.org Wed Mar 1 05:06:15 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 05:06:15 +0100 (CET) Subject: [Python-checkins] r42710 - in python/trunk: Include/modsupport.h Python/getargs.c Message-ID: <20060301040615.E00511E4022@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 05:06:10 2006 New Revision: 42710 Modified: python/trunk/Include/modsupport.h python/trunk/Python/getargs.c Log: Use Py_ssize_t for PyArg_UnpackTuple arguments. Modified: python/trunk/Include/modsupport.h ============================================================================== --- python/trunk/Include/modsupport.h (original) +++ python/trunk/Include/modsupport.h Wed Mar 1 05:06:10 2006 @@ -25,7 +25,7 @@ PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...); PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, const char *, char **, ...); -PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, int, int, ...); +PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...); PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...); PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw); Modified: python/trunk/Python/getargs.c ============================================================================== --- python/trunk/Python/getargs.c (original) +++ python/trunk/Python/getargs.c Wed Mar 1 05:06:10 2006 @@ -1662,9 +1662,9 @@ int -PyArg_UnpackTuple(PyObject *args, const char *name, int min, int max, ...) +PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...) { - int i, l; + Py_ssize_t i, l; PyObject **o; va_list vargs; From python-checkins at python.org Wed Mar 1 05:25:51 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 05:25:51 +0100 (CET) Subject: [Python-checkins] r42711 - in python/trunk: Include/pyerrors.h Lib/test/exception_hierarchy.txt Lib/test/output/test_logging Lib/test/test_coercion.py Lib/test/test_descr.py Lib/test/test_exceptions.py Lib/test/test_pep352.py Lib/traceback.py Lib/warnings.py Misc/NEWS Objects/genobject.c Python/ceval.c Python/codecs.c Python/errors.c Python/exceptions.c Python/pythonrun.c Message-ID: <20060301042551.47FE91E4002@bag.python.org> Author: brett.cannon Date: Wed Mar 1 05:25:17 2006 New Revision: 42711 Added: python/trunk/Lib/test/exception_hierarchy.txt (contents, props changed) python/trunk/Lib/test/test_pep352.py (contents, props changed) Modified: python/trunk/Include/pyerrors.h python/trunk/Lib/test/output/test_logging python/trunk/Lib/test/test_coercion.py python/trunk/Lib/test/test_descr.py python/trunk/Lib/test/test_exceptions.py python/trunk/Lib/traceback.py python/trunk/Lib/warnings.py python/trunk/Misc/NEWS python/trunk/Objects/genobject.c python/trunk/Python/ceval.c python/trunk/Python/codecs.c python/trunk/Python/errors.c python/trunk/Python/exceptions.c python/trunk/Python/pythonrun.c Log: PEP 352 implementation. Creates a new base class, BaseException, which has an added message attribute compared to the previous version of Exception. It is also a new-style class, making all exceptions now new-style. KeyboardInterrupt and SystemExit inherit from BaseException directly. String exceptions now raise DeprecationWarning. Applies patch 1104669, and closes bugs 1012952 and 518846. Modified: python/trunk/Include/pyerrors.h ============================================================================== --- python/trunk/Include/pyerrors.h (original) +++ python/trunk/Include/pyerrors.h Wed Mar 1 05:25:17 2006 @@ -26,9 +26,32 @@ PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); +/* */ +#define PyExceptionClass_Check(x) \ + (PyClass_Check((x)) \ + || (PyType_Check((x)) && PyType_IsSubtype( \ + (PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException))) + + +#define PyExceptionInstance_Check(x) \ + (PyInstance_Check((x)) || \ + (PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException))) + +#define PyExceptionClass_Name(x) \ + (PyClass_Check((x)) \ + ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \ + : (char *)(((PyTypeObject*)(x))->tp_name)) + +#define PyExceptionInstance_Class(x) \ + ((PyInstance_Check((x)) \ + ? (PyObject*)((PyInstanceObject*)(x))->in_class \ + : (PyObject*)((x)->ob_type))) + + /* Predefined exceptions */ +PyAPI_DATA(PyObject *) PyExc_BaseException; PyAPI_DATA(PyObject *) PyExc_Exception; PyAPI_DATA(PyObject *) PyExc_StopIteration; PyAPI_DATA(PyObject *) PyExc_GeneratorExit; Added: python/trunk/Lib/test/exception_hierarchy.txt ============================================================================== --- (empty file) +++ python/trunk/Lib/test/exception_hierarchy.txt Wed Mar 1 05:25:17 2006 @@ -0,0 +1,46 @@ +BaseException + +-- SystemExit + +-- KeyboardInterrupt + +-- Exception + +-- GeneratorExit + +-- StopIteration + +-- StandardError + | +-- ArithmeticError + | | +-- FloatingPointError + | | +-- OverflowError + | | +-- ZeroDivisionError + | +-- AssertionError + | +-- AttributeError + | +-- EnvironmentError + | | +-- IOError + | | +-- OSError + | | +-- WindowsError (Windows) + | +-- EOFError + | +-- ImportError + | +-- LookupError + | | +-- IndexError + | | +-- KeyError + | +-- MemoryError + | +-- NameError + | | +-- UnboundLocalError + | +-- ReferenceError + | +-- RuntimeError + | | +-- NotImplementedError + | +-- SyntaxError + | | +-- IndentationError + | | +-- TabError + | +-- SystemError + | +-- TypeError + | +-- ValueError + | | +-- UnicodeError + | | +-- UnicodeDecodeError + | | +-- UnicodeEncodeError + | | +-- UnicodeTranslateError + +-- Warning + +-- DeprecationWarning + +-- PendingDeprecationWarning + +-- RuntimeWarning + +-- SyntaxWarning + +-- UserWarning + +-- FutureWarning + +-- OverflowWarning [not generated by the interpreter] Modified: python/trunk/Lib/test/output/test_logging ============================================================================== --- python/trunk/Lib/test/output/test_logging (original) +++ python/trunk/Lib/test/output/test_logging Wed Mar 1 05:25:17 2006 @@ -488,12 +488,12 @@ -- log_test4 begin --------------------------------------------------- config0: ok. config1: ok. -config2: exceptions.AttributeError -config3: exceptions.KeyError +config2: +config3: -- log_test4 end --------------------------------------------------- -- log_test5 begin --------------------------------------------------- ERROR:root:just testing -exceptions.KeyError... Don't panic! +... Don't panic! -- log_test5 end --------------------------------------------------- -- logrecv output begin --------------------------------------------------- ERR -> CRITICAL: Message 0 (via logrecv.tcp.ERR) Modified: python/trunk/Lib/test/test_coercion.py ============================================================================== --- python/trunk/Lib/test/test_coercion.py (original) +++ python/trunk/Lib/test/test_coercion.py Wed Mar 1 05:25:17 2006 @@ -96,7 +96,7 @@ x = eval('a %s b' % op) except: error = sys.exc_info()[:2] - print '... %s' % error[0] + print '... %s.%s' % (error[0].__module__, error[0].__name__) else: print '=', format_result(x) try: @@ -108,7 +108,7 @@ exec('z %s= b' % op) except: error = sys.exc_info()[:2] - print '... %s' % error[0] + print '... %s.%s' % (error[0].__module__, error[0].__name__) else: print '=>', format_result(z) @@ -121,7 +121,7 @@ x = eval('%s(a, b)' % op) except: error = sys.exc_info()[:2] - print '... %s' % error[0] + print '... %s.%s' % (error[0].__module__, error[0].__name__) else: print '=', format_result(x) Modified: python/trunk/Lib/test/test_descr.py ============================================================================== --- python/trunk/Lib/test/test_descr.py (original) +++ python/trunk/Lib/test/test_descr.py Wed Mar 1 05:25:17 2006 @@ -3355,31 +3355,6 @@ vereq(NewClass.__doc__, 'object=None; type=NewClass') vereq(NewClass().__doc__, 'object=NewClass instance; type=NewClass') -def string_exceptions(): - if verbose: - print "Testing string exceptions ..." - - # Ensure builtin strings work OK as exceptions. - astring = "An exception string." - try: - raise astring - except astring: - pass - else: - raise TestFailed, "builtin string not usable as exception" - - # Ensure string subclass instances do not. - class MyStr(str): - pass - - newstring = MyStr("oops -- shouldn't work") - try: - raise newstring - except TypeError: - pass - except: - raise TestFailed, "string subclass allowed as exception" - def copy_setstate(): if verbose: print "Testing that copy.*copy() correctly uses __setstate__..." @@ -4172,7 +4147,6 @@ funnynew() imulbug() docdescriptor() - string_exceptions() copy_setstate() slices() subtype_resurrection() Modified: python/trunk/Lib/test/test_exceptions.py ============================================================================== --- python/trunk/Lib/test/test_exceptions.py (original) +++ python/trunk/Lib/test/test_exceptions.py Wed Mar 1 05:25:17 2006 @@ -29,10 +29,7 @@ def r(thing): test_raise_catch(thing) - if isinstance(thing, ClassType): - print thing.__name__ - else: - print thing + print getattr(thing, '__name__', thing) r(AttributeError) import sys Added: python/trunk/Lib/test/test_pep352.py ============================================================================== --- (empty file) +++ python/trunk/Lib/test/test_pep352.py Wed Mar 1 05:25:17 2006 @@ -0,0 +1,182 @@ +import unittest +import __builtin__ +import exceptions +import warnings +from test.test_support import run_unittest +import os +from platform import system as platform_system + +class ExceptionClassTests(unittest.TestCase): + + """Tests for anything relating to exception objects themselves (e.g., + inheritance hierarchy)""" + + def test_builtins_new_style(self): + self.failUnless(issubclass(Exception, object)) + + def verify_instance_interface(self, ins): + for attr in ("args", "message", "__str__", "__unicode__", "__repr__", + "__getitem__"): + self.failUnless(hasattr(ins, attr), "%s missing %s attribute" % + (ins.__class__.__name__, attr)) + + def test_inheritance(self): + # Make sure the inheritance hierarchy matches the documentation + exc_set = set(x for x in dir(exceptions) if not x.startswith('_')) + inheritance_tree = open(os.path.join(os.path.split(__file__)[0], + 'exception_hierarchy.txt')) + try: + superclass_name = inheritance_tree.readline().rstrip() + try: + last_exc = getattr(__builtin__, superclass_name) + except AttributeError: + self.fail("base class %s not a built-in" % superclass_name) + self.failUnless(superclass_name in exc_set) + exc_set.discard(superclass_name) + superclasses = [] # Loop will insert base exception + last_depth = 0 + for exc_line in inheritance_tree: + exc_line = exc_line.rstrip() + depth = exc_line.rindex('-') + exc_name = exc_line[depth+2:] # Slice past space + if '(' in exc_name: + paren_index = exc_name.index('(') + platform_name = exc_name[paren_index+1:-1] + if platform_system() != platform_name: + exc_set.discard(exc_name) + continue + if '[' in exc_name: + left_bracket = exc_name.index('[') + exc_name = exc_name[:left_bracket-1] # cover space + try: + exc = getattr(__builtin__, exc_name) + except AttributeError: + self.fail("%s not a built-in exception" % exc_name) + if last_depth < depth: + superclasses.append((last_depth, last_exc)) + elif last_depth > depth: + while superclasses[-1][0] >= depth: + superclasses.pop() + self.failUnless(issubclass(exc, superclasses[-1][1]), + "%s is not a subclass of %s" % (exc.__name__, + superclasses[-1][1].__name__)) + try: # Some exceptions require arguments; just skip them + self.verify_instance_interface(exc()) + except TypeError: + pass + self.failUnless(exc_name in exc_set) + exc_set.discard(exc_name) + last_exc = exc + last_depth = depth + finally: + inheritance_tree.close() + self.failUnlessEqual(len(exc_set), 0, "%s not accounted for" % exc_set) + + interface_tests = ("length", "args", "message", "str", "unicode", "repr", + "indexing") + + def interface_test_driver(self, results): + for test_name, (given, expected) in zip(self.interface_tests, results): + self.failUnlessEqual(given, expected, "%s: %s != %s" % (test_name, + given, expected)) + + def test_interface_single_arg(self): + # Make sure interface works properly when given a single argument + arg = "spam" + exc = Exception(arg) + results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg], + [str(exc), str(arg)], [unicode(exc), unicode(arg)], + [repr(exc), exc.__class__.__name__ + repr(exc.args)], [exc[0], arg]) + self.interface_test_driver(results) + + def test_interface_multi_arg(self): + # Make sure interface correct when multiple arguments given + arg_count = 3 + args = tuple(range(arg_count)) + exc = Exception(*args) + results = ([len(exc.args), arg_count], [exc.args, args], + [exc.message, ''], [str(exc), str(args)], + [unicode(exc), unicode(args)], + [repr(exc), exc.__class__.__name__ + repr(exc.args)], + [exc[-1], args[-1]]) + self.interface_test_driver(results) + + def test_interface_no_arg(self): + # Make sure that with no args that interface is correct + exc = Exception() + results = ([len(exc.args), 0], [exc.args, tuple()], [exc.message, ''], + [str(exc), ''], [unicode(exc), u''], + [repr(exc), exc.__class__.__name__ + '()'], [True, True]) + self.interface_test_driver(results) + +class UsageTests(unittest.TestCase): + + """Test usage of exceptions""" + + def setUp(self): + self._filters = warnings.filters[:] + + def tearDown(self): + warnings.filters = self._filters[:] + + def test_raise_classic(self): + class ClassicClass: + pass + try: + raise ClassicClass + except ClassicClass: + pass + except: + self.fail("unable to raise classic class") + try: + raise ClassicClass() + except ClassicClass: + pass + except: + self.fail("unable to raise class class instance") + + def test_raise_new_style_non_exception(self): + class NewStyleClass(object): + pass + try: + raise NewStyleClass + except TypeError: + pass + except: + self.fail("unable to raise new-style class") + try: + raise NewStyleClass() + except TypeError: + pass + except: + self.fail("unable to raise new-style class instance") + + def test_raise_string(self): + warnings.resetwarnings() + warnings.filterwarnings("error") + try: + raise "spam" + except DeprecationWarning: + pass + except: + self.fail("raising a string did not cause a DeprecationWarning") + + def test_catch_string(self): + # Test will be pertinent when catching exceptions raises a + # DeprecationWarning + warnings.filterwarnings("ignore", "raising") + str_exc = "spam" + try: + raise str_exc + except str_exc: + pass + except: + self.fail("catching a string exception failed") + +def test_main(): + run_unittest(ExceptionClassTests, UsageTests) + + + +if __name__ == '__main__': + test_main() Modified: python/trunk/Lib/traceback.py ============================================================================== --- python/trunk/Lib/traceback.py (original) +++ python/trunk/Lib/traceback.py Wed Mar 1 05:25:17 2006 @@ -157,7 +157,8 @@ which exception occurred is the always last string in the list. """ list = [] - if type(etype) == types.ClassType: + if (type(etype) == types.ClassType + or (isinstance(etype, type) and issubclass(etype, Exception))): stype = etype.__name__ else: stype = etype Modified: python/trunk/Lib/warnings.py ============================================================================== --- python/trunk/Lib/warnings.py (original) +++ python/trunk/Lib/warnings.py Wed Mar 1 05:25:17 2006 @@ -145,7 +145,8 @@ assert action in ("error", "ignore", "always", "default", "module", "once"), "invalid action: %r" % (action,) assert isinstance(message, basestring), "message must be a string" - assert isinstance(category, types.ClassType), "category must be a class" + assert isinstance(category, (type, types.ClassType)), \ + "category must be a class" assert issubclass(category, Warning), "category must be a Warning subclass" assert isinstance(module, basestring), "module must be a string" assert isinstance(lineno, int) and lineno >= 0, \ Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Wed Mar 1 05:25:17 2006 @@ -12,6 +12,11 @@ Core and builtins ----------------- +- PEP 352, patch #1104669: Make exceptions new-style objects. Introduced the + new exception base class, BaseException, which has a new message attribute. + KeyboardInterrupt and SystemExit to directly inherit from BaseException now. + Raising a string exception now raises a DeprecationWarning. + - Patch #1438387, PEP 328: relative and absolute imports. Imports can now be explicitly relative, using 'from .module import name' to mean 'from the same package as this module is in. Imports without dots still default to the Modified: python/trunk/Objects/genobject.c ============================================================================== --- python/trunk/Objects/genobject.c (original) +++ python/trunk/Objects/genobject.c Wed Mar 1 05:25:17 2006 @@ -230,11 +230,11 @@ Py_XINCREF(val); Py_XINCREF(tb); - if (PyClass_Check(typ)) { + if (PyExceptionClass_Check(typ)) { PyErr_NormalizeException(&typ, &val, &tb); } - else if (PyInstance_Check(typ)) { + else if (PyExceptionInstance_Check(typ)) { /* Raising an instance. The value should be a dummy. */ if (val && val != Py_None) { PyErr_SetString(PyExc_TypeError, @@ -245,7 +245,7 @@ /* Normalize to raise , */ Py_XDECREF(val); val = typ; - typ = (PyObject*) ((PyInstanceObject*)typ)->in_class; + typ = PyExceptionInstance_Class(typ); Py_INCREF(typ); } } Modified: python/trunk/Python/ceval.c ============================================================================== --- python/trunk/Python/ceval.c (original) +++ python/trunk/Python/ceval.c Wed Mar 1 05:25:17 2006 @@ -1685,7 +1685,7 @@ why == WHY_CONTINUE) retval = POP(); } - else if (PyClass_Check(v) || PyString_Check(v)) { + else if (PyExceptionClass_Check(v) || PyString_Check(v)) { w = POP(); u = POP(); PyErr_Restore(v, w, u); @@ -3026,14 +3026,14 @@ /* Raising builtin string is deprecated but still allowed -- * do nothing. Raising an instance of a new-style str * subclass is right out. */ - if (-1 == PyErr_Warn(PyExc_PendingDeprecationWarning, + if (PyErr_Warn(PyExc_DeprecationWarning, "raising a string exception is deprecated")) goto raise_error; } - else if (PyClass_Check(type)) + else if (PyExceptionClass_Check(type)) PyErr_NormalizeException(&type, &value, &tb); - else if (PyInstance_Check(type)) { + else if (PyExceptionInstance_Check(type)) { /* Raising an instance. The value should be a dummy. */ if (value != Py_None) { PyErr_SetString(PyExc_TypeError, @@ -3044,7 +3044,7 @@ /* Normalize to raise , */ Py_DECREF(value); value = type; - type = (PyObject*) ((PyInstanceObject*)type)->in_class; + type = PyExceptionInstance_Class(type); Py_INCREF(type); } } Modified: python/trunk/Python/codecs.c ============================================================================== --- python/trunk/Python/codecs.c (original) +++ python/trunk/Python/codecs.c Wed Mar 1 05:25:17 2006 @@ -448,9 +448,8 @@ PyObject *PyCodec_StrictErrors(PyObject *exc) { - if (PyInstance_Check(exc)) - PyErr_SetObject((PyObject*)((PyInstanceObject*)exc)->in_class, - exc); + if (PyExceptionInstance_Check(exc)) + PyErr_SetObject(PyExceptionInstance_Class(exc), exc); else PyErr_SetString(PyExc_TypeError, "codec must pass exception instance"); return NULL; Modified: python/trunk/Python/errors.c ============================================================================== --- python/trunk/Python/errors.c (original) +++ python/trunk/Python/errors.c Wed Mar 1 05:25:17 2006 @@ -97,11 +97,14 @@ return 0; } /* err might be an instance, so check its class. */ - if (PyInstance_Check(err)) - err = (PyObject*)((PyInstanceObject*)err)->in_class; + if (PyExceptionInstance_Check(err)) + err = PyExceptionInstance_Class(err); - if (PyClass_Check(err) && PyClass_Check(exc)) - return PyClass_IsSubclass(err, exc); + if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) { + /* problems here!? not sure PyObject_IsSubclass expects to + be called with an exception pending... */ + return PyObject_IsSubclass(err, exc); + } return err == exc; } @@ -138,19 +141,19 @@ Py_INCREF(value); } - if (PyInstance_Check(value)) - inclass = (PyObject*)((PyInstanceObject*)value)->in_class; + if (PyExceptionInstance_Check(value)) + inclass = PyExceptionInstance_Class(value); /* Normalize the exception so that if the type is a class, the value will be an instance. */ - if (PyClass_Check(type)) { + if (PyExceptionClass_Check(type)) { /* if the value was not an instance, or is not an instance whose class is (or is derived from) type, then use the value as an argument to instantiation of the type class. */ - if (!inclass || !PyClass_IsSubclass(inclass, type)) { + if (!inclass || !PyObject_IsSubclass(inclass, type)) { PyObject *args, *res; if (value == Py_None) @@ -282,7 +285,7 @@ { /* Note that the Win32 errors do not lineup with the errno error. So if the error is in the MSVC error - table, we use it, otherwise we assume it really _is_ + table, we use it, otherwise we assume it really _is_ a Win32 error code */ if (i > 0 && i < _sys_nerr) { @@ -302,7 +305,7 @@ 0, /* size not used */ NULL); /* no args */ if (len==0) { - /* Only ever seen this in out-of-mem + /* Only ever seen this in out-of-mem situations */ sprintf(s_small_buf, "Windows Error 0x%X", i); s = s_small_buf; @@ -345,8 +348,8 @@ PyObject * PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : + PyObject *name = filename ? + PyUnicode_FromUnicode(filename, wcslen(filename)) : NULL; PyObject *result = PyErr_SetFromErrnoWithFilenameObject(exc, name); Py_XDECREF(name); @@ -360,7 +363,7 @@ return PyErr_SetFromErrnoWithFilenameObject(exc, NULL); } -#ifdef MS_WINDOWS +#ifdef MS_WINDOWS /* Windows specific error code handling */ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( PyObject *exc, @@ -415,8 +418,8 @@ const char *filename) { PyObject *name = filename ? PyString_FromString(filename) : NULL; - PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, - ierr, + PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, + ierr, name); Py_XDECREF(name); return ret; @@ -428,11 +431,11 @@ int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : + PyObject *name = filename ? + PyUnicode_FromUnicode(filename, wcslen(filename)) : NULL; - PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, - ierr, + PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, + ierr, name); Py_XDECREF(name); return ret; @@ -466,8 +469,8 @@ int ierr, const Py_UNICODE *filename) { - PyObject *name = filename ? - PyUnicode_FromUnicode(filename, wcslen(filename)) : + PyObject *name = filename ? + PyUnicode_FromUnicode(filename, wcslen(filename)) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( PyExc_WindowsError, @@ -574,7 +577,24 @@ if (f != NULL) { PyFile_WriteString("Exception ", f); if (t) { - PyFile_WriteObject(t, f, Py_PRINT_RAW); + char* className = PyExceptionClass_Name(t); + PyObject* moduleName = + PyObject_GetAttrString(t, "__module__"); + + if (moduleName == NULL) + PyFile_WriteString("", f); + else { + char* modstr = PyString_AsString(moduleName); + if (modstr) + { + PyFile_WriteString(modstr, f); + PyFile_WriteString(".", f); + } + } + if (className == NULL) + PyFile_WriteString("", f); + else + PyFile_WriteString(className, f); if (v && v != Py_None) { PyFile_WriteString(": ", f); PyFile_WriteObject(v, f, 0); @@ -726,7 +746,7 @@ /* com_fetch_program_text will attempt to load the line of text that the exception refers to. If it fails, it will return NULL but will - not set an exception. + not set an exception. XXX The functionality of this function is quite similar to the functionality in tb_displayline() in traceback.c. Modified: python/trunk/Python/exceptions.c ============================================================================== --- python/trunk/Python/exceptions.c (original) +++ python/trunk/Python/exceptions.c Wed Mar 1 05:25:17 2006 @@ -11,6 +11,7 @@ * 98-08-19 fl created (for pyexe) * 00-02-08 fl updated for 1.5.2 * 26-May-2000 baw vetted for Python 1.6 + * XXX * * written by Fredrik Lundh * modifications, additions, cleanups, and proofreading by Barry Warsaw @@ -33,99 +34,19 @@ PyDoc_STRVAR(module__doc__, "Python's standard exception class hierarchy.\n\ \n\ -Before Python 1.5, the standard exceptions were all simple string objects.\n\ -In Python 1.5, the standard exceptions were converted to classes organized\n\ -into a relatively flat hierarchy. String-based standard exceptions were\n\ -optional, or used as a fallback if some problem occurred while importing\n\ -the exception module. With Python 1.6, optional string-based standard\n\ -exceptions were removed (along with the -X command line flag).\n\ -\n\ -The class exceptions were implemented in such a way as to be almost\n\ -completely backward compatible. Some tricky uses of IOError could\n\ -potentially have broken, but by Python 1.6, all of these should have\n\ -been fixed. As of Python 1.6, the class-based standard exceptions are\n\ -now implemented in C, and are guaranteed to exist in the Python\n\ -interpreter.\n\ -\n\ -Here is a rundown of the class hierarchy. The classes found here are\n\ -inserted into both the exceptions module and the `built-in' module. It is\n\ -recommended that user defined class based exceptions be derived from the\n\ -`Exception' class, although this is currently not enforced.\n" +Exceptions found here are defined both in the exceptions module and the \n\ +built-in namespace. It is recommended that user-defined exceptions inherit \n\ +from Exception.\n\ +" + /* keep string pieces "small" */ -"\n\ -Exception\n\ - |\n\ - +-- SystemExit\n\ - +-- StopIteration\n\ - +-- GeneratorExit\n\ - +-- StandardError\n\ - | |\n\ - | +-- KeyboardInterrupt\n\ - | +-- ImportError\n\ - | +-- EnvironmentError\n\ - | | |\n\ - | | +-- IOError\n\ - | | +-- OSError\n\ - | | |\n\ - | | +-- WindowsError\n\ - | | +-- VMSError\n\ - | |\n\ - | +-- EOFError\n\ - | +-- RuntimeError\n\ - | | |\n\ - | | +-- NotImplementedError\n\ - | |\n\ - | +-- NameError\n\ - | | |\n\ - | | +-- UnboundLocalError\n\ - | |\n\ - | +-- AttributeError\n\ - | +-- SyntaxError\n\ - | | |\n\ - | | +-- IndentationError\n\ - | | |\n\ - | | +-- TabError\n\ - | |\n\ - | +-- TypeError\n\ - | +-- AssertionError\n\ - | +-- LookupError\n\ - | | |\n\ - | | +-- IndexError\n\ - | | +-- KeyError\n\ - | |\n\ - | +-- ArithmeticError\n\ - | | |\n\ - | | +-- OverflowError\n\ - | | +-- ZeroDivisionError\n\ - | | +-- FloatingPointError\n\ - | |\n\ - | +-- ValueError\n\ - | | |\n\ - | | +-- UnicodeError\n\ - | | |\n\ - | | +-- UnicodeEncodeError\n\ - | | +-- UnicodeDecodeError\n\ - | | +-- UnicodeTranslateError\n\ - | |\n\ - | +-- ReferenceError\n\ - | +-- SystemError\n\ - | +-- MemoryError\n\ - |\n\ - +---Warning\n\ - |\n\ - +-- UserWarning\n\ - +-- DeprecationWarning\n\ - +-- PendingDeprecationWarning\n\ - +-- SyntaxWarning\n\ - +-- OverflowWarning\n\ - +-- RuntimeWarning\n\ - +-- FutureWarning" +/* XXX exception hierarchy from Lib/test/exception_hierarchy.txt */ ); /* Helper function for populating a dictionary with method wrappers. */ static int -populate_methods(PyObject *klass, PyObject *dict, PyMethodDef *methods) +populate_methods(PyObject *klass, PyMethodDef *methods) { PyObject *module; int status = -1; @@ -151,7 +72,7 @@ } /* add method to dictionary */ - status = PyDict_SetItemString(dict, methods->ml_name, meth); + status = PyObject_SetAttrString(klass, methods->ml_name, meth); Py_DECREF(meth); Py_DECREF(func); @@ -196,7 +117,7 @@ if (!(*klass = PyErr_NewException(name, base, dict))) goto finally; - if (populate_methods(*klass, dict, methods)) { + if (populate_methods(*klass, methods)) { Py_DECREF(*klass); *klass = NULL; goto finally; @@ -232,47 +153,81 @@ /* Notes on bootstrapping the exception classes. * * First thing we create is the base class for all exceptions, called - * appropriately enough: Exception. Creation of this class makes no + * appropriately BaseException. Creation of this class makes no * assumptions about the existence of any other exception class -- except * for TypeError, which can conditionally exist. * - * Next, StandardError is created (which is quite simple) followed by + * Next, Exception is created since it is the common subclass for the rest of + * the needed exceptions for this bootstrapping to work. StandardError is + * created (which is quite simple) followed by * TypeError, because the instantiation of other exceptions can potentially * throw a TypeError. Once these exceptions are created, all the others * can be created in any order. See the static exctable below for the * explicit bootstrap order. * - * All classes after Exception can be created using PyErr_NewException(). + * All classes after BaseException can be created using PyErr_NewException(). */ -PyDoc_STRVAR(Exception__doc__, "Common base class for all exceptions."); +PyDoc_STRVAR(BaseException__doc__, "Common base class for all exceptions"); +/* + Set args and message attributes. -static PyObject * -Exception__init__(PyObject *self, PyObject *args) + Assumes self and args have already been set properly with set_self, etc. +*/ +static int +set_args_and_message(PyObject *self, PyObject *args) { - int status; + PyObject *message_val; + Py_ssize_t args_len = PySequence_Length(args); + + if (args_len < 0) + return 0; + + /* set args */ + if (PyObject_SetAttrString(self, "args", args) < 0) + return 0; + + /* set message */ + if (args_len == 1) + message_val = PySequence_GetItem(args, 0); + else + message_val = PyString_FromString(""); + if (!message_val) + return 0; + + if (PyObject_SetAttrString(self, "message", message_val) < 0) { + Py_DECREF(message_val); + return 0; + } + + Py_DECREF(message_val); + return 1; +} +static PyObject * +BaseException__init__(PyObject *self, PyObject *args) +{ if (!(self = get_self(args))) return NULL; - /* set args attribute */ - /* XXX size is only a hint */ - args = PySequence_GetSlice(args, 1, PySequence_Size(args)); + /* set args and message attribute */ + args = PySequence_GetSlice(args, 1, PySequence_Length(args)); if (!args) return NULL; - status = PyObject_SetAttrString(self, "args", args); - Py_DECREF(args); - if (status < 0) - return NULL; - Py_INCREF(Py_None); - return Py_None; + if (!set_args_and_message(self, args)) { + Py_DECREF(args); + return NULL; + } + + Py_DECREF(args); + Py_RETURN_NONE; } static PyObject * -Exception__str__(PyObject *self, PyObject *args) +BaseException__str__(PyObject *self, PyObject *args) { PyObject *out; @@ -310,9 +265,116 @@ return out; } +#ifdef Py_USING_UNICODE +static PyObject * +BaseException__unicode__(PyObject *self, PyObject *args) +{ + Py_ssize_t args_len; + + if (!PyArg_ParseTuple(args, "O:__unicode__", &self)) + return NULL; + + args = PyObject_GetAttrString(self, "args"); + if (!args) + return NULL; + + args_len = PySequence_Size(args); + if (args_len < 0) { + Py_DECREF(args); + return NULL; + } + + if (args_len == 0) { + Py_DECREF(args); + return PyUnicode_FromUnicode(NULL, 0); + } + else if (args_len == 1) { + PyObject *temp = PySequence_GetItem(args, 0); + if (!temp) { + Py_DECREF(args); + return NULL; + } + Py_DECREF(args); + return PyObject_Unicode(temp); + } + else { + Py_DECREF(args); + return PyObject_Unicode(args); + } +} +#endif /* Py_USING_UNICODE */ + +static PyObject * +BaseException__repr__(PyObject *self, PyObject *args) +{ + PyObject *args_attr; + Py_ssize_t args_len; + PyObject *repr_suffix; + PyObject *repr; + + if (!PyArg_ParseTuple(args, "O:__repr__", &self)) + return NULL; + + args_attr = PyObject_GetAttrString(self, "args"); + if (!args_attr) + return NULL; + + args_len = PySequence_Length(args_attr); + if (args_len < 0) { + Py_DECREF(args_attr); + return NULL; + } + + if (args_len == 0) { + Py_DECREF(args_attr); + repr_suffix = PyString_FromString("()"); + if (!repr_suffix) + return NULL; + } + else { + PyObject *args_repr; + /*PyObject *right_paren; + + repr_suffix = PyString_FromString("(*"); + if (!repr_suffix) { + Py_DECREF(args_attr); + return NULL; + }*/ + + args_repr = PyObject_Repr(args_attr); + Py_DECREF(args_attr); + if (!args_repr) + return NULL; + + repr_suffix = args_repr; + + /*PyString_ConcatAndDel(&repr_suffix, args_repr); + if (!repr_suffix) + return NULL; + + right_paren = PyString_FromString(")"); + if (!right_paren) { + Py_DECREF(repr_suffix); + return NULL; + } + + PyString_ConcatAndDel(&repr_suffix, right_paren); + if (!repr_suffix) + return NULL;*/ + } + + repr = PyString_FromString(self->ob_type->tp_name); + if (!repr) { + Py_DECREF(repr_suffix); + return NULL; + } + + PyString_ConcatAndDel(&repr, repr_suffix); + return repr; +} static PyObject * -Exception__getitem__(PyObject *self, PyObject *args) +BaseException__getitem__(PyObject *self, PyObject *args) { PyObject *out; PyObject *index; @@ -331,21 +393,27 @@ static PyMethodDef -Exception_methods[] = { - /* methods for the Exception class */ - { "__getitem__", Exception__getitem__, METH_VARARGS}, - { "__str__", Exception__str__, METH_VARARGS}, - { "__init__", Exception__init__, METH_VARARGS}, - { NULL, NULL } +BaseException_methods[] = { + /* methods for the BaseException class */ + {"__getitem__", BaseException__getitem__, METH_VARARGS}, + {"__repr__", BaseException__repr__, METH_VARARGS}, + {"__str__", BaseException__str__, METH_VARARGS}, +#ifdef Py_USING_UNICODE + {"__unicode__", BaseException__unicode__, METH_VARARGS}, +#endif /* Py_USING_UNICODE */ + {"__init__", BaseException__init__, METH_VARARGS}, + {NULL, NULL } }; static int -make_Exception(char *modulename) +make_BaseException(char *modulename) { PyObject *dict = PyDict_New(); PyObject *str = NULL; PyObject *name = NULL; + PyObject *emptytuple = NULL; + PyObject *argstuple = NULL; int status = -1; if (!dict) @@ -360,20 +428,28 @@ if (PyDict_SetItemString(dict, "__module__", str)) goto finally; Py_DECREF(str); - if (!(str = PyString_FromString(Exception__doc__))) + + if (!(str = PyString_FromString(BaseException__doc__))) goto finally; if (PyDict_SetItemString(dict, "__doc__", str)) goto finally; - if (!(name = PyString_FromString("Exception"))) + if (!(name = PyString_FromString("BaseException"))) goto finally; - if (!(PyExc_Exception = PyClass_New(NULL, dict, name))) + if (!(emptytuple = PyTuple_New(0))) + goto finally; + + if (!(argstuple = PyTuple_Pack(3, name, emptytuple, dict))) + goto finally; + + if (!(PyExc_BaseException = PyType_Type.tp_new(&PyType_Type, argstuple, + NULL))) goto finally; /* Now populate the dictionary with the method suite */ - if (populate_methods(PyExc_Exception, dict, Exception_methods)) - /* Don't need to reclaim PyExc_Exception here because that'll + if (populate_methods(PyExc_BaseException, BaseException_methods)) + /* Don't need to reclaim PyExc_BaseException here because that'll * happen during interpreter shutdown. */ goto finally; @@ -384,13 +460,18 @@ Py_XDECREF(dict); Py_XDECREF(str); Py_XDECREF(name); + Py_XDECREF(emptytuple); + Py_XDECREF(argstuple); return status; } +PyDoc_STRVAR(Exception__doc__, "Common base class for all non-exit exceptions."); + PyDoc_STRVAR(StandardError__doc__, -"Base class for all standard Python exceptions."); +"Base class for all standard Python exceptions that do not represent" +"interpreter exiting."); PyDoc_STRVAR(TypeError__doc__, "Inappropriate argument type."); @@ -411,14 +492,12 @@ if (!(self = get_self(args))) return NULL; - /* Set args attribute. */ if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) return NULL; - status = PyObject_SetAttrString(self, "args", args); - if (status < 0) { - Py_DECREF(args); - return NULL; + if (!set_args_and_message(self, args)) { + Py_DECREF(args); + return NULL; } /* set code attribute */ @@ -445,8 +524,7 @@ if (status < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -482,8 +560,12 @@ if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) return NULL; - if (PyObject_SetAttrString(self, "args", args) || - PyObject_SetAttrString(self, "errno", Py_None) || + if (!set_args_and_message(self, args)) { + Py_DECREF(args); + return NULL; + } + + if (PyObject_SetAttrString(self, "errno", Py_None) || PyObject_SetAttrString(self, "strerror", Py_None) || PyObject_SetAttrString(self, "filename", Py_None)) { @@ -624,9 +706,9 @@ * return StandardError.__str__(self) * * but there is no StandardError__str__() function; we happen to - * know that's just a pass through to Exception__str__(). + * know that's just a pass through to BaseException__str__(). */ - rtnval = Exception__str__(originalself, args); + rtnval = BaseException__str__(originalself, args); finally: Py_XDECREF(filename); @@ -712,8 +794,10 @@ if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) return NULL; - if (PyObject_SetAttrString(self, "args", args)) - goto finally; + if (!set_args_and_message(self, args)) { + Py_DECREF(args); + return NULL; + } lenargs = PySequence_Size(args); if (lenargs >= 1) { @@ -879,8 +963,9 @@ if (!PyArg_ParseTuple(args, "O:__str__", &self)) return NULL; - if (!(argsattr = PyObject_GetAttrString(self, "args"))) - return NULL; + argsattr = PyObject_GetAttrString(self, "args"); + if (!argsattr) + return NULL; /* If args is a tuple of exactly one item, apply repr to args[0]. This is done so that e.g. the exception raised by {}[''] prints @@ -889,14 +974,14 @@ KeyError alone. The downside is that if KeyError is raised with an explanatory string, that string will be displayed in quotes. Too bad. - If args is anything else, use the default Exception__str__(). + If args is anything else, use the default BaseException__str__(). */ if (PyTuple_Check(argsattr) && PyTuple_GET_SIZE(argsattr) == 1) { PyObject *key = PyTuple_GET_ITEM(argsattr, 0); result = PyObject_Repr(key); } else - result = Exception__str__(self, args); + result = BaseException__str__(self, args); Py_DECREF(argsattr); return result; @@ -1193,6 +1278,11 @@ if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) return NULL; + if (!set_args_and_message(self, args)) { + Py_DECREF(args); + return NULL; + } + if (!PyArg_ParseTuple(args, "O!O!O!O!O!", &PyString_Type, &encoding, objecttype, &object, @@ -1201,9 +1291,6 @@ &PyString_Type, &reason)) goto finally; - if (PyObject_SetAttrString(self, "args", args)) - goto finally; - if (PyObject_SetAttrString(self, "encoding", encoding)) goto finally; if (PyObject_SetAttrString(self, "object", object)) @@ -1405,6 +1492,11 @@ if (!(args = PySequence_GetSlice(args, 1, PySequence_Size(args)))) return NULL; + if (!set_args_and_message(self, args)) { + Py_DECREF(args); + return NULL; + } + if (!PyArg_ParseTuple(args, "O!O!O!O!", &PyUnicode_Type, &object, &PyInt_Type, &start, @@ -1412,9 +1504,6 @@ &PyString_Type, &reason)) goto finally; - if (PyObject_SetAttrString(self, "args", args)) - goto finally; - if (PyObject_SetAttrString(self, "object", object)) goto finally; if (PyObject_SetAttrString(self, "start", start)) @@ -1424,8 +1513,8 @@ if (PyObject_SetAttrString(self, "reason", reason)) goto finally; - Py_INCREF(Py_None); rtnval = Py_None; + Py_INCREF(rtnval); finally: Py_DECREF(args); @@ -1591,6 +1680,7 @@ /* Global C API defined exceptions */ +PyObject *PyExc_BaseException; PyObject *PyExc_Exception; PyObject *PyExc_StopIteration; PyObject *PyExc_GeneratorExit; @@ -1636,7 +1726,7 @@ #endif /* Pre-computed MemoryError instance. Best to create this as early as - * possibly and not wait until a MemoryError is actually raised! + * possible and not wait until a MemoryError is actually raised! */ PyObject *PyExc_MemoryErrorInst; @@ -1663,9 +1753,10 @@ int (*classinit)(PyObject *); } exctable[] = { /* - * The first three classes MUST appear in exactly this order + * The first four classes MUST appear in exactly this order */ - {"Exception", &PyExc_Exception}, + {"BaseException", &PyExc_BaseException}, + {"Exception", &PyExc_Exception, &PyExc_BaseException, Exception__doc__}, {"StopIteration", &PyExc_StopIteration, &PyExc_Exception, StopIteration__doc__}, {"GeneratorExit", &PyExc_GeneratorExit, &PyExc_Exception, @@ -1676,9 +1767,10 @@ /* * The rest appear in depth-first order of the hierarchy */ - {"SystemExit", &PyExc_SystemExit, &PyExc_Exception, SystemExit__doc__, + {"SystemExit", &PyExc_SystemExit, &PyExc_BaseException, SystemExit__doc__, SystemExit_methods}, - {"KeyboardInterrupt", &PyExc_KeyboardInterrupt, 0, KeyboardInterrupt__doc__}, + {"KeyboardInterrupt", &PyExc_KeyboardInterrupt, &PyExc_BaseException, + KeyboardInterrupt__doc__}, {"ImportError", &PyExc_ImportError, 0, ImportError__doc__}, {"EnvironmentError", &PyExc_EnvironmentError, 0, EnvironmentError__doc__, EnvironmentError_methods}, @@ -1786,11 +1878,11 @@ } /* This is the base class of all exceptions, so make it first. */ - if (make_Exception(modulename) || - PyDict_SetItemString(mydict, "Exception", PyExc_Exception) || - PyDict_SetItemString(bdict, "Exception", PyExc_Exception)) + if (make_BaseException(modulename) || + PyDict_SetItemString(mydict, "BaseException", PyExc_BaseException) || + PyDict_SetItemString(bdict, "BaseException", PyExc_BaseException)) { - Py_FatalError("Base class `Exception' could not be created."); + Py_FatalError("Base class `BaseException' could not be created."); } /* Now we can programmatically create all the remaining exceptions. Modified: python/trunk/Python/pythonrun.c ============================================================================== --- python/trunk/Python/pythonrun.c (original) +++ python/trunk/Python/pythonrun.c Wed Mar 1 05:25:17 2006 @@ -976,7 +976,7 @@ fflush(stdout); if (value == NULL || value == Py_None) goto done; - if (PyInstance_Check(value)) { + if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ PyObject *code = PyObject_GetAttrString(value, "code"); if (code) { @@ -1106,11 +1106,10 @@ if (err) { /* Don't do anything else */ } - else if (PyClass_Check(exception)) { - PyClassObject* exc = (PyClassObject*)exception; - PyObject* className = exc->cl_name; + else if (PyExceptionClass_Check(exception)) { + char* className = PyExceptionClass_Name(exception); PyObject* moduleName = - PyDict_GetItemString(exc->cl_dict, "__module__"); + PyObject_GetAttrString(exception, "__module__"); if (moduleName == NULL) err = PyFile_WriteString("", f); @@ -1126,8 +1125,7 @@ if (className == NULL) err = PyFile_WriteString("", f); else - err = PyFile_WriteObject(className, f, - Py_PRINT_RAW); + err = PyFile_WriteString(className, f); } } else From python-checkins at python.org Wed Mar 1 05:28:45 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 05:28:45 +0100 (CET) Subject: [Python-checkins] r42712 - in python/trunk/Misc: NEWS Vim/vim_syntax.py Message-ID: <20060301042845.911D61E4002@bag.python.org> Author: brett.cannon Date: Wed Mar 1 05:28:00 2006 New Revision: 42712 Modified: python/trunk/Misc/NEWS python/trunk/Misc/Vim/vim_syntax.py Log: Add Misc/NEWS entry for Misc/Vim/vim_syntax.py . Also use conditional expression for the hell of it. Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Wed Mar 1 05:28:00 2006 @@ -911,6 +911,10 @@ Tools/Demos ----------- +- Created Misc/Vim/vim_syntax.py to auto-generate a python.vim file in that + directory for syntax highlighting in Vim. Vim directory was added and placed + vimrc to it (was previous up a level). + - Added two new files to Tools/scripts: pysource.py, which recursively finds Python source files, and findnocoding.py, which finds Python source files that need an encoding declaration. Modified: python/trunk/Misc/Vim/vim_syntax.py ============================================================================== --- python/trunk/Misc/Vim/vim_syntax.py (original) +++ python/trunk/Misc/Vim/vim_syntax.py Wed Mar 1 05:28:00 2006 @@ -65,10 +65,7 @@ skip = skip_regex.substitute(sep=separator) else: skip = '' - if not raw: - contains = 'contains=pythonEscape' - else: - contains = '' + contains = 'contains=pythonEscape' if not raw else '' yield regex_template.substitute(raw=raw, sep=separator, skip=skip, contains = contains) From python-checkins at python.org Wed Mar 1 05:35:50 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 05:35:50 +0100 (CET) Subject: [Python-checkins] r42713 - python/trunk/Modules/posixmodule.c Message-ID: <20060301043550.5C3761E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 05:35:45 2006 New Revision: 42713 Modified: python/trunk/Modules/posixmodule.c Log: Repair mangled code in the Windows flavor of posix__getfullpathname(). In partial answer to the now-deleted XXX comment: /* XXX(twouters) Why use 'et#' here at all? insize isn't used */ `insize` is an input parameter too, and it was left uninitialized, leading to seemingly random failures. Modified: python/trunk/Modules/posixmodule.c ============================================================================== --- python/trunk/Modules/posixmodule.c (original) +++ python/trunk/Modules/posixmodule.c Wed Mar 1 05:35:45 2006 @@ -1901,7 +1901,7 @@ /* assume encoded strings wont more than double no of chars */ char inbuf[MAX_PATH*2]; char *inbufp = inbuf; - Py_ssize_t insize; + Py_ssize_t insize = sizeof(inbuf); char outbuf[MAX_PATH*2]; char *temp; #ifdef Py_WIN_WIDE_FILENAMES @@ -1921,7 +1921,6 @@ PyErr_Clear(); } #endif - /* XXX(twouters) Why use 'et#' here at all? insize isn't used */ if (!PyArg_ParseTuple (args, "et#:_getfullpathname", Py_FileSystemDefaultEncoding, &inbufp, &insize)) From python-checkins at python.org Wed Mar 1 05:48:54 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 05:48:54 +0100 (CET) Subject: [Python-checkins] r42714 - peps/trunk/pep-0000.txt peps/trunk/pep-0352.txt Message-ID: <20060301044854.A6CEB1E4002@bag.python.org> Author: brett.cannon Date: Wed Mar 1 05:48:52 2006 New Revision: 42714 Modified: peps/trunk/pep-0000.txt peps/trunk/pep-0352.txt Log: Change status of PEP 352 to final. Also clarified wording to reflect the implementation; only exceptions are new-style class. Wording was ambiguous and suggested that you could raise any new-style class which was considered insane by everyone at the core sprint at PyCon 2006. And, most importantly, a Tim-channeled Guido thought that the current implementation was the way to go. No one should be able to ``raise 42``. Modified: peps/trunk/pep-0000.txt ============================================================================== --- peps/trunk/pep-0000.txt (original) +++ peps/trunk/pep-0000.txt Wed Mar 1 05:48:52 2006 @@ -67,7 +67,6 @@ SA 328 Imports: Multi-Line and Absolute/Relative Aahz SA 343 The "with" Statement GvR, Coghlan - SA 352 Required Superclass for Exceptions GvR, Cannon Open PEPs (under consideration) @@ -166,6 +165,7 @@ SF 327 Decimal Data Type Batista SF 341 Unifying try-except and try-finally Brandl SF 342 Coroutines via Enhanced Generators GvR, Eby + SF 352 Required Superclass for Exceptions GvR, Cannon SF 353 Using ssize_t as the index type von Loewis Empty PEPs (or containing only an abstract) Modified: peps/trunk/pep-0352.txt ============================================================================== --- peps/trunk/pep-0352.txt (original) +++ peps/trunk/pep-0352.txt Wed Mar 1 05:48:52 2006 @@ -3,7 +3,7 @@ Version: $Revision$ Last-Modified: $Date$ Author: Brett Cannon , Guido van Rossum -Status: Accepted +Status: Final Type: Standards Track Content-Type: text/x-rst Created: 27-Oct-2005 @@ -16,10 +16,11 @@ In Python 2.4 and before, any (classic) class can be raised as an exception. The plan is to allow new-style classes starting in Python 2.5, but this makes the problem worse -- it would mean *any* class (or -instance) can be raised! This is a problem since it prevents any -guarantees to be made about the interface of exceptions. This PEP -proposes introducing a new superclass that all raised objects must -inherit from. Imposing the restriction will allow a standard +instance) can be raised (this is not the case in the final version; +only built-in exceptions can be new-style)! This is a problem since it +prevents any guarantees to be made about the interface of exceptions. +This PEP proposes introducing a new superclass that all raised objects +must inherit from. Imposing the restriction will allow a standard interface for exceptions to exist that can be relied upon. One might counter that requiring a specific base class for a @@ -86,8 +87,6 @@ def __repr__(self): if not self.args: argss = "()" - elif len(self.args) <= 1: - argss = "(%s)" % repr(self.message) else: argss = repr(self.args) return self.__class__.__name__ + argss @@ -208,8 +207,6 @@ * Python 2.5 - - allow exceptions to be new-style classes - - all standard exceptions become new-style classes - introduce BaseException @@ -248,12 +245,7 @@ Implementation ============== -An initial patch to make exceptions new-style classes has been -authored by Michael Hudson can be found at SF patch #1104669 -[#SF_1104669]_. While it does not implement all points mentioned in -this PEP, it will most likely be used as a basis for the final path -to implement this PEP. - +The initial implementation of this PEP has been checked into Python 2.5 . References ========== From python-checkins at python.org Wed Mar 1 06:16:15 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 06:16:15 +0100 (CET) Subject: [Python-checkins] r42715 - python/trunk/Doc/api/abstract.tex python/trunk/Doc/api/concrete.tex python/trunk/Doc/api/exceptions.tex python/trunk/Doc/api/init.tex python/trunk/Doc/api/newtypes.tex python/trunk/Doc/api/utilities.tex Message-ID: <20060301051615.7AD611E4002@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 06:16:03 2006 New Revision: 42715 Modified: python/trunk/Doc/api/abstract.tex python/trunk/Doc/api/concrete.tex python/trunk/Doc/api/exceptions.tex python/trunk/Doc/api/init.tex python/trunk/Doc/api/newtypes.tex python/trunk/Doc/api/utilities.tex Log: Make documentation match the implementation. Modified: python/trunk/Doc/api/abstract.tex ============================================================================== --- python/trunk/Doc/api/abstract.tex (original) +++ python/trunk/Doc/api/abstract.tex Wed Mar 1 06:16:03 2006 @@ -16,7 +16,7 @@ object is written instead of the \function{repr()}. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyObject_HasAttrString}{PyObject *o, char *attr_name} +\begin{cfuncdesc}{int}{PyObject_HasAttrString}{PyObject *o, const char *attr_name} Returns \code{1} if \var{o} has the attribute \var{attr_name}, and \code{0} otherwise. This is equivalent to the Python expression \samp{hasattr(\var{o}, \var{attr_name})}. This function always @@ -24,7 +24,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyObject_GetAttrString}{PyObject *o, - char *attr_name} + const char *attr_name} Retrieve an attribute named \var{attr_name} from object \var{o}. Returns the attribute value on success, or \NULL{} on failure. This is the equivalent of the Python expression @@ -50,7 +50,7 @@ \begin{cfuncdesc}{int}{PyObject_SetAttrString}{PyObject *o, - char *attr_name, PyObject *v} + const char *attr_name, PyObject *v} Set the value of the attribute named \var{attr_name}, for object \var{o}, to the value \var{v}. Returns \code{-1} on failure. This is the equivalent of the Python statement @@ -67,7 +67,7 @@ \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyObject_DelAttrString}{PyObject *o, char *attr_name} +\begin{cfuncdesc}{int}{PyObject_DelAttrString}{PyObject *o, const char *attr_name} Delete attribute named \var{attr_name}, for object \var{o}. Returns \code{-1} on failure. This is the equivalent of the Python statement: \samp{del \var{o}.\var{attr_name}}. @@ -301,7 +301,7 @@ \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyObject_Hash}{PyObject *o} +\begin{cfuncdesc}{long}{PyObject_Hash}{PyObject *o} Compute and return the hash value of an object \var{o}. On failure, return \code{-1}. This is the equivalent of the Python expression \samp{hash(\var{o})}.\bifuncindex{hash} @@ -340,8 +340,8 @@ \versionadded{2.2} \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyObject_Length}{PyObject *o} -\cfuncline{int}{PyObject_Size}{PyObject *o} +\begin{cfuncdesc}{Py_ssize_t}{PyObject_Length}{PyObject *o} +\cfuncline{Py_ssize_t}{PyObject_Size}{PyObject *o} Return the length of object \var{o}. If the object \var{o} provides either the sequence and mapping protocols, the sequence length is returned. On error, \code{-1} is returned. This is the equivalent @@ -697,14 +697,14 @@ \code{0} otherwise. This function always succeeds. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySequence_Size}{PyObject *o} +\begin{cfuncdesc}{Py_ssize_t}{PySequence_Size}{PyObject *o} Returns the number of objects in sequence \var{o} on success, and \code{-1} on failure. For objects that do not provide sequence protocol, this is equivalent to the Python expression \samp{len(\var{o})}.\bifuncindex{len} \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySequence_Length}{PyObject *o} +\begin{cfuncdesc}{Py_ssize_t}{PySequence_Length}{PyObject *o} Alternate name for \cfunction{PySequence_Size()}. \end{cfuncdesc} @@ -715,7 +715,7 @@ \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PySequence_Repeat}{PyObject *o, int count} +\begin{cfuncdesc}{PyObject*}{PySequence_Repeat}{PyObject *o, Py_ssize_t count} Return the result of repeating sequence object \var{o} \var{count} times, or \NULL{} on failure. This is the equivalent of the Python expression \samp{\var{o} * \var{count}}. @@ -730,7 +730,7 @@ \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PySequence_InPlaceRepeat}{PyObject *o, int count} +\begin{cfuncdesc}{PyObject*}{PySequence_InPlaceRepeat}{PyObject *o, Py_ssize_t count} Return the result of repeating sequence object \var{o} \var{count} times, or \NULL{} on failure. The operation is done \emph{in-place} when \var{o} supports it. This is the equivalent of the Python @@ -738,41 +738,41 @@ \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PySequence_GetItem}{PyObject *o, int i} +\begin{cfuncdesc}{PyObject*}{PySequence_GetItem}{PyObject *o, Py_ssize_t i} Return the \var{i}th element of \var{o}, or \NULL{} on failure. This is the equivalent of the Python expression \samp{\var{o}[\var{i}]}. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PySequence_GetSlice}{PyObject *o, int i1, int i2} +\begin{cfuncdesc}{PyObject*}{PySequence_GetSlice}{PyObject *o, Py_ssize_t i1, Py_ssize_t i2} Return the slice of sequence object \var{o} between \var{i1} and \var{i2}, or \NULL{} on failure. This is the equivalent of the Python expression \samp{\var{o}[\var{i1}:\var{i2}]}. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySequence_SetItem}{PyObject *o, int i, PyObject *v} +\begin{cfuncdesc}{int}{PySequence_SetItem}{PyObject *o, Py_ssize_t i, PyObject *v} Assign object \var{v} to the \var{i}th element of \var{o}. Returns \code{-1} on failure. This is the equivalent of the Python statement \samp{\var{o}[\var{i}] = \var{v}}. This function \emph{does not} steal a reference to \var{v}. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySequence_DelItem}{PyObject *o, int i} +\begin{cfuncdesc}{int}{PySequence_DelItem}{PyObject *o, Py_ssize_t i} Delete the \var{i}th element of object \var{o}. Returns \code{-1} on failure. This is the equivalent of the Python statement \samp{del \var{o}[\var{i}]}. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySequence_SetSlice}{PyObject *o, int i1, - int i2, PyObject *v} +\begin{cfuncdesc}{int}{PySequence_SetSlice}{PyObject *o, Py_ssize_t i1, + Py_ssize_t i2, PyObject *v} Assign the sequence object \var{v} to the slice in sequence object \var{o} from \var{i1} to \var{i2}. This is the equivalent of the Python statement \samp{\var{o}[\var{i1}:\var{i2}] = \var{v}}. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySequence_DelSlice}{PyObject *o, int i1, int i2} +\begin{cfuncdesc}{int}{PySequence_DelSlice}{PyObject *o, Py_ssize_t i1, Py_ssize_t i2} Delete the slice in sequence object \var{o} from \var{i1} to \var{i2}. Returns \code{-1} on failure. This is the equivalent of the Python statement \samp{del \var{o}[\var{i1}:\var{i2}]}. @@ -821,7 +821,7 @@ text. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PySequence_Fast_GET_ITEM}{PyObject *o, int i} +\begin{cfuncdesc}{PyObject*}{PySequence_Fast_GET_ITEM}{PyObject *o, Py_ssize_t i} Return the \var{i}th element of \var{o}, assuming that \var{o} was returned by \cfunction{PySequence_Fast()}, \var{o} is not \NULL, and that \var{i} is within bounds. @@ -834,7 +834,7 @@ \versionadded{2.4} \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PySequence_ITEM}{PyObject *o, int i} +\begin{cfuncdesc}{PyObject*}{PySequence_ITEM}{PyObject *o, Py_ssize_t i} Return the \var{i}th element of \var{o} or \NULL{} on failure. Macro form of \cfunction{PySequence_GetItem()} but without checking that \cfunction{PySequence_Check(\var{o})} is true and without @@ -860,7 +860,7 @@ \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyMapping_Length}{PyObject *o} +\begin{cfuncdesc}{Py_ssize_t}{PyMapping_Length}{PyObject *o} Returns the number of keys in object \var{o} on success, and \code{-1} on failure. For objects that do not provide mapping protocol, this is equivalent to the Python expression @@ -986,7 +986,7 @@ \begin{cfuncdesc}{int}{PyObject_AsCharBuffer}{PyObject *obj, const char **buffer, - int *buffer_len} + Py_ssize_t *buffer_len} Returns a pointer to a read-only memory location useable as character- based input. The \var{obj} argument must support the single-segment character buffer interface. On success, returns \code{0}, sets @@ -997,7 +997,7 @@ \begin{cfuncdesc}{int}{PyObject_AsReadBuffer}{PyObject *obj, const void **buffer, - int *buffer_len} + Py_ssize_t *buffer_len} Returns a pointer to a read-only memory location containing arbitrary data. The \var{obj} argument must support the single-segment readable buffer interface. On success, returns @@ -1015,7 +1015,7 @@ \begin{cfuncdesc}{int}{PyObject_AsWriteBuffer}{PyObject *obj, void **buffer, - int *buffer_len} + Py_ssize_t *buffer_len} Returns a pointer to a writeable memory location. The \var{obj} argument must support the single-segment, character buffer interface. On success, returns \code{0}, sets \var{buffer} to the Modified: python/trunk/Doc/api/concrete.tex ============================================================================== --- python/trunk/Doc/api/concrete.tex (original) +++ python/trunk/Doc/api/concrete.tex Wed Mar 1 06:16:03 2006 @@ -65,7 +65,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyType_GenericAlloc}{PyTypeObject *type, - int nitems} + Py_ssize_t nitems} \versionadded{2.2} \end{cfuncdesc} @@ -179,7 +179,7 @@ \versionadded{2.3} \end{cfuncdesc} -\begin{cfuncdesc}{unsigned long long}{PyInt_AsUnsignedLongLongMask}{PyObject *io} +\begin{cfuncdesc}{unsigned PY_LONG_LONG}{PyInt_AsUnsignedLongLongMask}{PyObject *io} Will first attempt to cast the object to a \ctype{PyIntObject} or \ctype{PyLongObject}, if it is not already one, and then return its value as unsigned long long, without checking for overflow. @@ -268,12 +268,12 @@ long}, or \NULL{} on failure. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyLong_FromLongLong}{long long v} +\begin{cfuncdesc}{PyObject*}{PyLong_FromLongLong}{PY_LONG_LONG v} Return a new \ctype{PyLongObject} object from a C \ctype{long long}, or \NULL{} on failure. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyLong_FromUnsignedLongLong}{unsigned long long v} +\begin{cfuncdesc}{PyObject*}{PyLong_FromUnsignedLongLong}{unsigned PY_LONG_LONG v} Return a new \ctype{PyLongObject} object from a C \ctype{unsigned long long}, or \NULL{} on failure. \end{cfuncdesc} @@ -300,7 +300,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyLong_FromUnicode}{Py_UNICODE *u, - int length, int base} + Py_ssize_t length, int base} Convert a sequence of Unicode digits to a Python long integer value. The first parameter, \var{u}, points to the first character of the Unicode string, \var{length} gives the number of characters, @@ -333,14 +333,14 @@ \withsubitem{(built-in exception)}{\ttindex{OverflowError}} \end{cfuncdesc} -\begin{cfuncdesc}{long long}{PyLong_AsLongLong}{PyObject *pylong} +\begin{cfuncdesc}{PY_LONG_LONG}{PyLong_AsLongLong}{PyObject *pylong} Return a C \ctype{long long} from a Python long integer. If \var{pylong} cannot be represented as a \ctype{long long}, an \exception{OverflowError} will be raised. \versionadded{2.2} \end{cfuncdesc} -\begin{cfuncdesc}{unsigned long long}{PyLong_AsUnsignedLongLong}{PyObject +\begin{cfuncdesc}{unsigned PY_LONG_LONG}{PyLong_AsUnsignedLongLong}{PyObject *pylong} Return a C \ctype{unsigned long long} from a Python long integer. If \var{pylong} cannot be represented as an \ctype{unsigned long @@ -582,7 +582,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyString_FromStringAndSize}{const char *v, - int len} + Py_ssize_t len} Return a new string object with the value \var{v} and length \var{len} on success, and \NULL{} on failure. If \var{v} is \NULL{}, the contents of the string are uninitialized. @@ -601,6 +601,7 @@ \lineiii{\%c}{int}{A single character, represented as an C int.} \lineiii{\%d}{int}{Exactly equivalent to \code{printf("\%d")}.} \lineiii{\%ld}{long}{Exactly equivalent to \code{printf("\%ld")}.} + \lineiii{\%zd}{long}{Exactly equivalent to \code{printf("\%zd")}.} \lineiii{\%i}{int}{Exactly equivalent to \code{printf("\%i")}.} \lineiii{\%x}{int}{Exactly equivalent to \code{printf("\%x")}.} \lineiii{\%s}{char*}{A null-terminated C character array.} @@ -617,11 +618,11 @@ exactly two arguments. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyString_Size}{PyObject *string} +\begin{cfuncdesc}{Py_ssize_t}{PyString_Size}{PyObject *string} Return the length of the string in string object \var{string}. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyString_GET_SIZE}{PyObject *string} +\begin{cfuncdesc}{Py_ssize_t}{PyString_GET_SIZE}{PyObject *string} Macro form of \cfunction{PyString_Size()} but without error checking. \end{cfuncdesc} @@ -647,7 +648,7 @@ \begin{cfuncdesc}{int}{PyString_AsStringAndSize}{PyObject *obj, char **buffer, - int *length} + Py_ssize_t *length} Return a NUL-terminated representation of the contents of the object \var{obj} through the output variables \var{buffer} and \var{length}. @@ -686,7 +687,7 @@ the reference count of \var{newpart}. \end{cfuncdesc} -\begin{cfuncdesc}{int}{_PyString_Resize}{PyObject **string, int newsize} +\begin{cfuncdesc}{int}{_PyString_Resize}{PyObject **string, Py_ssize_t newsize} A way to resize a string object even though it is ``immutable''. Only use this to build up a brand new string object; don't use this if the string may already be known in other parts of the code. It @@ -730,7 +731,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyString_Decode}{const char *s, - int size, + Py_ssize_t size, const char *encoding, const char *errors} Create an object by decoding \var{size} bytes of the encoded @@ -754,7 +755,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyString_Encode}{const char *s, - int size, + Py_ssize_t size, const char *encoding, const char *errors} Encode the \ctype{char} buffer of the given size by passing it to @@ -829,12 +830,12 @@ \versionadded{2.2} \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyUnicode_GET_SIZE}{PyObject *o} +\begin{cfuncdesc}{Py_ssize_t}{PyUnicode_GET_SIZE}{PyObject *o} Return the size of the object. \var{o} has to be a \ctype{PyUnicodeObject} (not checked). \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyUnicode_GET_DATA_SIZE}{PyObject *o} +\begin{cfuncdesc}{Py_ssize_t}{PyUnicode_GET_DATA_SIZE}{PyObject *o} Return the size of the object's internal buffer in bytes. \var{o} has to be a \ctype{PyUnicodeObject} (not checked). \end{cfuncdesc} @@ -937,7 +938,7 @@ use these APIs: \begin{cfuncdesc}{PyObject*}{PyUnicode_FromUnicode}{const Py_UNICODE *u, - int size} + Py_ssize_t size} Create a Unicode Object from the Py_UNICODE buffer \var{u} of the given size. \var{u} may be \NULL{} which causes the contents to be undefined. It is the user's responsibility to fill in the needed @@ -953,7 +954,7 @@ object. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyUnicode_GetSize}{PyObject *unicode} +\begin{cfuncdesc}{Py_ssize_t}{PyUnicode_GetSize}{PyObject *unicode} Return the length of the Unicode object. \end{cfuncdesc} @@ -996,14 +997,14 @@ \ctype{Py_UNICODE} type is identical to the system's \ctype{wchar_t}. \begin{cfuncdesc}{PyObject*}{PyUnicode_FromWideChar}{const wchar_t *w, - int size} + Py_ssize_t size} Create a Unicode object from the \ctype{wchar_t} buffer \var{w} of the given size. Return \NULL{} on failure. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyUnicode_AsWideChar}{PyUnicodeObject *unicode, +\begin{cfuncdesc}{Py_ssize_t}{PyUnicode_AsWideChar}{PyUnicodeObject *unicode, wchar_t *w, - int size} + Py_ssize_t size} Copy the Unicode object contents into the \ctype{wchar_t} buffer \var{w}. At most \var{size} \ctype{wchar_t} characters are copied (excluding a possibly trailing 0-termination character). Return @@ -1045,7 +1046,7 @@ These are the generic codec APIs: \begin{cfuncdesc}{PyObject*}{PyUnicode_Decode}{const char *s, - int size, + Py_ssize_t size, const char *encoding, const char *errors} Create a Unicode object by decoding \var{size} bytes of the encoded @@ -1057,7 +1058,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_Encode}{const Py_UNICODE *s, - int size, + Py_ssize_t size, const char *encoding, const char *errors} Encode the \ctype{Py_UNICODE} buffer of the given size and return @@ -1083,7 +1084,7 @@ These are the UTF-8 codec APIs: \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeUTF8}{const char *s, - int size, + Py_ssize_t size, const char *errors} Create a Unicode object by decoding \var{size} bytes of the UTF-8 encoded string \var{s}. Return \NULL{} if an exception was raised @@ -1091,9 +1092,9 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeUTF8Stateful}{const char *s, - int size, + Py_ssize_t size, const char *errors, - int *consumed} + Py_ssize_t *consumed} If \var{consumed} is \NULL{}, behave like \cfunction{PyUnicode_DecodeUTF8()}. If \var{consumed} is not \NULL{}, trailing incomplete UTF-8 byte sequences will not be treated as an error. Those bytes will not be decoded and the @@ -1102,7 +1103,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeUTF8}{const Py_UNICODE *s, - int size, + Py_ssize_t size, const char *errors} Encode the \ctype{Py_UNICODE} buffer of the given size using UTF-8 and return a Python string object. Return \NULL{} if an exception @@ -1120,7 +1121,7 @@ These are the UTF-16 codec APIs: \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeUTF16}{const char *s, - int size, + Py_ssize_t size, const char *errors, int *byteorder} Decode \var{length} bytes from a UTF-16 encoded buffer string and @@ -1147,10 +1148,10 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeUTF16Stateful}{const char *s, - int size, + Py_ssize_t size, const char *errors, int *byteorder, - int *consumed} + Py_ssize_t *consumed} If \var{consumed} is \NULL{}, behave like \cfunction{PyUnicode_DecodeUTF16()}. If \var{consumed} is not \NULL{}, \cfunction{PyUnicode_DecodeUTF16Stateful()} will not treat trailing incomplete @@ -1161,7 +1162,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeUTF16}{const Py_UNICODE *s, - int size, + Py_ssize_t size, const char *errors, int byteorder} Return a Python string object holding the UTF-16 encoded value of @@ -1198,7 +1199,7 @@ These are the ``Unicode Escape'' codec APIs: \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeUnicodeEscape}{const char *s, - int size, + Py_ssize_t size, const char *errors} Create a Unicode object by decoding \var{size} bytes of the Unicode-Escape encoded string \var{s}. Return \NULL{} if an @@ -1206,8 +1207,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeUnicodeEscape}{const Py_UNICODE *s, - int size, - const char *errors} + Py_ssize_t size} Encode the \ctype{Py_UNICODE} buffer of the given size using Unicode-Escape and return a Python string object. Return \NULL{} if an exception was raised by the codec. @@ -1224,7 +1224,7 @@ These are the ``Raw Unicode Escape'' codec APIs: \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeRawUnicodeEscape}{const char *s, - int size, + Py_ssize_t size, const char *errors} Create a Unicode object by decoding \var{size} bytes of the Raw-Unicode-Escape encoded string \var{s}. Return \NULL{} if an @@ -1232,7 +1232,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeRawUnicodeEscape}{const Py_UNICODE *s, - int size, + Py_ssize_t size, const char *errors} Encode the \ctype{Py_UNICODE} buffer of the given size using Raw-Unicode-Escape and return a Python string object. Return @@ -1252,7 +1252,7 @@ are accepted by the codecs during encoding. \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeLatin1}{const char *s, - int size, + Py_ssize_t size, const char *errors} Create a Unicode object by decoding \var{size} bytes of the Latin-1 encoded string \var{s}. Return \NULL{} if an exception was raised @@ -1260,7 +1260,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeLatin1}{const Py_UNICODE *s, - int size, + Py_ssize_t size, const char *errors} Encode the \ctype{Py_UNICODE} buffer of the given size using Latin-1 and return a Python string object. Return \NULL{} if an @@ -1279,7 +1279,7 @@ accepted. All other codes generate errors. \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeASCII}{const char *s, - int size, + Py_ssize_t size, const char *errors} Create a Unicode object by decoding \var{size} bytes of the \ASCII{} encoded string \var{s}. Return \NULL{} if an exception @@ -1287,7 +1287,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeASCII}{const Py_UNICODE *s, - int size, + Py_ssize_t size, const char *errors} Encode the \ctype{Py_UNICODE} buffer of the given size using \ASCII{} and return a Python string object. Return \NULL{} if an @@ -1327,7 +1327,7 @@ points. \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeCharmap}{const char *s, - int size, + Py_ssize_t size, PyObject *mapping, const char *errors} Create a Unicode object by decoding \var{size} bytes of the encoded @@ -1341,7 +1341,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeCharmap}{const Py_UNICODE *s, - int size, + Py_ssize_t size, PyObject *mapping, const char *errors} Encode the \ctype{Py_UNICODE} buffer of the given size using the @@ -1360,7 +1360,7 @@ The following codec API is special in that maps Unicode to Unicode. \begin{cfuncdesc}{PyObject*}{PyUnicode_TranslateCharmap}{const Py_UNICODE *s, - int size, + Py_ssize_t size, PyObject *table, const char *errors} Translate a \ctype{Py_UNICODE} buffer of the given length by @@ -1386,7 +1386,7 @@ machine running the codec. \begin{cfuncdesc}{PyObject*}{PyUnicode_DecodeMBCS}{const char *s, - int size, + Py_ssize_t size, const char *errors} Create a Unicode object by decoding \var{size} bytes of the MBCS encoded string \var{s}. Return \NULL{} if an exception was @@ -1394,7 +1394,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyUnicode_EncodeMBCS}{const Py_UNICODE *s, - int size, + Py_ssize_t size, const char *errors} Encode the \ctype{Py_UNICODE} buffer of the given size using MBCS and return a Python string object. Return \NULL{} if an exception @@ -1424,7 +1424,7 @@ \begin{cfuncdesc}{PyObject*}{PyUnicode_Split}{PyObject *s, PyObject *sep, - int maxsplit} + Py_ssize_t maxsplit} Split a string giving a list of Unicode strings. If sep is \NULL{}, splitting will be done at all whitespace substrings. Otherwise, splits occur at the given separator. At most \var{maxsplit} splits @@ -1466,8 +1466,8 @@ \begin{cfuncdesc}{int}{PyUnicode_Tailmatch}{PyObject *str, PyObject *substr, - int start, - int end, + Py_ssize_t start, + Py_ssize_t end, int direction} Return 1 if \var{substr} matches \var{str}[\var{start}:\var{end}] at the given tail end (\var{direction} == -1 means to do a prefix @@ -1475,10 +1475,10 @@ Return \code{-1} if an error occurred. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyUnicode_Find}{PyObject *str, +\begin{cfuncdesc}{Py_ssize_t}{PyUnicode_Find}{PyObject *str, PyObject *substr, - int start, - int end, + Py_ssize_t start, + Py_ssize_t end, int direction} Return the first position of \var{substr} in \var{str}[\var{start}:\var{end}] using the given \var{direction} @@ -1489,10 +1489,10 @@ an exception has been set. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyUnicode_Count}{PyObject *str, +\begin{cfuncdesc}{Py_ssize_t}{PyUnicode_Count}{PyObject *str, PyObject *substr, - int start, - int end} + Py_ssize_t start, + Py_ssize_t end} Return the number of non-overlapping occurrences of \var{substr} in \code{\var{str}[\var{start}:\var{end}]}. Return \code{-1} if an error occurred. @@ -1501,7 +1501,7 @@ \begin{cfuncdesc}{PyObject*}{PyUnicode_Replace}{PyObject *str, PyObject *substr, PyObject *replstr, - int maxcount} + Py_ssize_t maxcount} Replace at most \var{maxcount} occurrences of \var{substr} in \var{str} with \var{replstr} and return the resulting Unicode object. \var{maxcount} == -1 means replace all occurrences. @@ -1599,7 +1599,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyBuffer_FromObject}{PyObject *base, - int offset, int size} + Py_ssize_t offset, Py_ssize_t size} Return a new read-only buffer object. This raises \exception{TypeError} if \var{base} doesn't support the read-only buffer protocol or doesn't provide exactly one buffer segment, or it @@ -1613,15 +1613,15 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyBuffer_FromReadWriteObject}{PyObject *base, - int offset, - int size} + Py_ssize_t offset, + Py_ssize_t size} Return a new writable buffer object. Parameters and exceptions are similar to those for \cfunction{PyBuffer_FromObject()}. If the \var{base} object does not export the writeable buffer protocol, then \exception{TypeError} is raised. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyBuffer_FromMemory}{void *ptr, int size} +\begin{cfuncdesc}{PyObject*}{PyBuffer_FromMemory}{void *ptr, Py_ssize_t size} Return a new read-only buffer object that reads from a specified location in memory, with a specified size. The caller is responsible for ensuring that the memory buffer, passed in as @@ -1632,12 +1632,12 @@ raised in that case. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyBuffer_FromReadWriteMemory}{void *ptr, int size} +\begin{cfuncdesc}{PyObject*}{PyBuffer_FromReadWriteMemory}{void *ptr, Py_ssize_t size} Similar to \cfunction{PyBuffer_FromMemory()}, but the returned buffer is writable. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyBuffer_New}{int size} +\begin{cfuncdesc}{PyObject*}{PyBuffer_New}{Py_ssize_t size} Return a new writable buffer object that maintains its own memory buffer of \var{size} bytes. \exception{ValueError} is returned if \var{size} is not zero or positive. Note that the memory buffer (as @@ -1671,11 +1671,11 @@ \versionadded{2.2} \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyTuple_New}{int len} +\begin{cfuncdesc}{PyObject*}{PyTuple_New}{Py_ssize_t len} Return a new tuple object of size \var{len}, or \NULL{} on failure. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyTuple_Pack}{int n, \moreargs} +\begin{cfuncdesc}{PyObject*}{PyTuple_Pack}{Py_ssize_t n, \moreargs} Return a new tuple object of size \var{n}, or \NULL{} on failure. The tuple values are initialized to the subsequent \var{n} C arguments pointing to Python objects. \samp{PyTuple_Pack(2, \var{a}, \var{b})} @@ -1693,38 +1693,38 @@ point to a tuple; no error checking is performed. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyTuple_GetItem}{PyObject *p, int pos} +\begin{cfuncdesc}{PyObject*}{PyTuple_GetItem}{PyObject *p, Py_ssize_t pos} Return the object at position \var{pos} in the tuple pointed to by \var{p}. If \var{pos} is out of bounds, return \NULL{} and sets an \exception{IndexError} exception. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyTuple_GET_ITEM}{PyObject *p, int pos} +\begin{cfuncdesc}{PyObject*}{PyTuple_GET_ITEM}{PyObject *p, Py_ssize_t pos} Like \cfunction{PyTuple_GetItem()}, but does no checking of its arguments. \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyTuple_GetSlice}{PyObject *p, - int low, int high} + Py_ssize_t low, Py_ssize_t high} Take a slice of the tuple pointed to by \var{p} from \var{low} to \var{high} and return it as a new tuple. \end{cfuncdesc} \begin{cfuncdesc}{int}{PyTuple_SetItem}{PyObject *p, - int pos, PyObject *o} + Py_ssize_t pos, PyObject *o} Insert a reference to object \var{o} at position \var{pos} of the tuple pointed to by \var{p}. Return \code{0} on success. \note{This function ``steals'' a reference to \var{o}.} \end{cfuncdesc} \begin{cfuncdesc}{void}{PyTuple_SET_ITEM}{PyObject *p, - int pos, PyObject *o} + Py_ssize_t pos, PyObject *o} Like \cfunction{PyTuple_SetItem()}, but does no error checking, and should \emph{only} be used to fill in brand new tuples. \note{This function ``steals'' a reference to \var{o}.} \end{cfuncdesc} -\begin{cfuncdesc}{int}{_PyTuple_Resize}{PyObject **p, int newsize} +\begin{cfuncdesc}{int}{_PyTuple_Resize}{PyObject **p, Py_ssize_t newsize} Can be used to resize a tuple. \var{newsize} will be the new length of the tuple. Because tuples are \emph{supposed} to be immutable, this should only be used if there is only one reference to the @@ -1768,32 +1768,32 @@ \versionadded{2.2} \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyList_New}{int len} +\begin{cfuncdesc}{PyObject*}{PyList_New}{Py_ssize_t len} Return a new list of length \var{len} on success, or \NULL{} on failure. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyList_Size}{PyObject *list} +\begin{cfuncdesc}{Py_ssize_t}{PyList_Size}{PyObject *list} Return the length of the list object in \var{list}; this is equivalent to \samp{len(\var{list})} on a list object. \bifuncindex{len} \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyList_GET_SIZE}{PyObject *list} +\begin{cfuncdesc}{Py_ssize_t}{PyList_GET_SIZE}{PyObject *list} Macro form of \cfunction{PyList_Size()} without error checking. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyList_GetItem}{PyObject *list, int index} +\begin{cfuncdesc}{PyObject*}{PyList_GetItem}{PyObject *list, Py_ssize_t index} Return the object at position \var{pos} in the list pointed to by \var{p}. If \var{pos} is out of bounds, return \NULL{} and set an \exception{IndexError} exception. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyList_GET_ITEM}{PyObject *list, int i} +\begin{cfuncdesc}{PyObject*}{PyList_GET_ITEM}{PyObject *list, Py_ssize_t i} Macro form of \cfunction{PyList_GetItem()} without error checking. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyList_SetItem}{PyObject *list, int index, +\begin{cfuncdesc}{int}{PyList_SetItem}{PyObject *list, Py_ssize_t index, PyObject *item} Set the item at index \var{index} in list to \var{item}. Return \code{0} on success or \code{-1} on failure. \note{This function @@ -1801,7 +1801,7 @@ item already in the list at the affected position.} \end{cfuncdesc} -\begin{cfuncdesc}{void}{PyList_SET_ITEM}{PyObject *list, int i, +\begin{cfuncdesc}{void}{PyList_SET_ITEM}{PyObject *list, Py_ssize_t i, PyObject *o} Macro form of \cfunction{PyList_SetItem()} without error checking. This is normally only used to fill in new lists where there is no @@ -1812,7 +1812,7 @@ \var{list} at position \var{i} will be leaked.} \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyList_Insert}{PyObject *list, int index, +\begin{cfuncdesc}{int}{PyList_Insert}{PyObject *list, Py_ssize_t index, PyObject *item} Insert the item \var{item} into list \var{list} in front of index \var{index}. Return \code{0} if successful; return \code{-1} and @@ -1828,7 +1828,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyList_GetSlice}{PyObject *list, - int low, int high} + Py_ssize_t low, Py_ssize_t high} Return a list of the objects in \var{list} containing the objects \emph{between} \var{low} and \var{high}. Return \NULL{} and set an exception if unsuccessful. @@ -1836,7 +1836,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{int}{PyList_SetSlice}{PyObject *list, - int low, int high, + Py_ssize_t low, Py_ssize_t high, PyObject *itemlist} Set the slice of \var{list} between \var{low} and \var{high} to the contents of \var{itemlist}. Analogous to @@ -1934,7 +1934,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{int}{PyDict_SetItemString}{PyObject *p, - char *key, + const char *key, PyObject *val} Insert \var{value} into the dictionary \var{p} using \var{key} as a key. \var{key} should be a \ctype{char*}. The key object is created @@ -1961,7 +1961,7 @@ \emph{without} setting an exception. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyDict_GetItemString}{PyObject *p, char *key} +\begin{cfuncdesc}{PyObject*}{PyDict_GetItemString}{PyObject *p, const char *key} This is the same as \cfunction{PyDict_GetItem()}, but \var{key} is specified as a \ctype{char*}, rather than a \ctype{PyObject*}. \end{cfuncdesc} @@ -1984,12 +1984,12 @@ (see the \citetitle[../lib/lib.html]{Python Library Reference}). \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyDict_Size}{PyObject *p} +\begin{cfuncdesc}{Py_ssize_t}{PyDict_Size}{PyObject *p} Return the number of items in the dictionary. This is equivalent to \samp{len(\var{p})} on a dictionary.\bifuncindex{len} \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyDict_Next}{PyObject *p, int *ppos, +\begin{cfuncdesc}{int}{PyDict_Next}{PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue} Iterate over all key-value pairs in the dictionary \var{p}. The \ctype{int} referred to by \var{ppos} must be initialized to @@ -2126,7 +2126,7 @@ when the file should be closed. Return \NULL{} on failure. \end{cfuncdesc} -\begin{cfuncdesc}{FILE*}{PyFile_AsFile}{PyFileObject *p} +\begin{cfuncdesc}{FILE*}{PyFile_AsFile}{PyObject *p} Return the file object associated with \var{p} as a \ctype{FILE*}. \end{cfuncdesc} @@ -2175,7 +2175,7 @@ function, but doing so should not be needed. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyFile_WriteObject}{PyObject *obj, PyFileObject *p, +\begin{cfuncdesc}{int}{PyFile_WriteObject}{PyObject *obj, PyObject *p, int flags} Write object \var{obj} to file object \var{p}. The only supported flag for \var{flags} is @@ -2185,7 +2185,7 @@ failure; the appropriate exception will be set. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyFile_WriteString}{const char *s, PyFileObject *p} +\begin{cfuncdesc}{int}{PyFile_WriteString}{const char *s, PyObject *p} Write string \var{s} to file object \var{p}. Return \code{0} on success or \code{-1} on failure; the appropriate exception will be set. @@ -2313,7 +2313,7 @@ \cdata{PyMethod_Type}). The parameter must not be \NULL{}. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyMethod_New}{PyObject *func. +\begin{cfuncdesc}{PyObject*}{PyMethod_New}{PyObject *func, PyObject *self, PyObject *class} Return a new method object, with \var{func} being any callable object; this is the function that will be called when the method is @@ -2378,7 +2378,7 @@ \versionadded{2.2} \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyModule_New}{char *name} +\begin{cfuncdesc}{PyObject*}{PyModule_New}{const char *name} Return a new module object with the \member{__name__} attribute set to \var{name}. Only the module's \member{__doc__} and \member{__name__} attributes are filled in; the caller is @@ -2415,7 +2415,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{int}{PyModule_AddObject}{PyObject *module, - char *name, PyObject *value} + const char *name, PyObject *value} Add an object to \var{module} as \var{name}. This is a convenience function which can be used from the module's initialization function. This steals a reference to \var{value}. Return @@ -2424,7 +2424,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{int}{PyModule_AddIntConstant}{PyObject *module, - char *name, long value} + const char *name, long value} Add an integer constant to \var{module} as \var{name}. This convenience function can be used from the module's initialization function. Return \code{-1} on error, \code{0} on success. @@ -2432,7 +2432,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{int}{PyModule_AddStringConstant}{PyObject *module, - char *name, char *value} + const char *name, const char *value} Add a string constant to \var{module} as \var{name}. This convenience function can be used from the module's initialization function. The string \var{value} must be null-terminated. Return @@ -2503,17 +2503,17 @@ \end{cvardesc} \begin{cfuncdesc}{PyObject*}{PyDescr_NewGetSet}{PyTypeObject *type, - PyGetSetDef *getset} + struct PyGetSetDef *getset} \versionadded{2.2} \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyDescr_NewMember}{PyTypeObject *type, - PyMemberDef *meth} + struct PyMemberDef *meth} \versionadded{2.2} \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyDescr_NewMethod}{PyTypeObject *type, - PyMethodDef *meth} + struct PyMethodDef *meth} \versionadded{2.2} \end{cfuncdesc} @@ -2563,8 +2563,8 @@ not be allocated. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySlice_GetIndices}{PySliceObject *slice, int length, - int *start, int *stop, int *step} +\begin{cfuncdesc}{int}{PySlice_GetIndices}{PySliceObject *slice, Py_ssize_t length, + Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step} Retrieve the start, stop and step indices from the slice object \var{slice}, assuming a sequence of length \var{length}. Treats indices greater than \var{length} as errors. @@ -2579,9 +2579,9 @@ suitably renamed, in the source of your extension. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySlice_GetIndicesEx}{PySliceObject *slice, int length, - int *start, int *stop, int *step, - int *slicelength} +\begin{cfuncdesc}{int}{PySlice_GetIndicesEx}{PySliceObject *slice, Py_ssize_t length, + Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, + Py_ssize_t *slicelength} Usable replacement for \cfunction{PySlice_GetIndices}. Retrieve the start, stop, and step indices from the slice object \var{slice} assuming a sequence of length \var{length}, and store the length of Modified: python/trunk/Doc/api/exceptions.tex ============================================================================== --- python/trunk/Doc/api/exceptions.tex (original) +++ python/trunk/Doc/api/exceptions.tex Wed Mar 1 06:16:03 2006 @@ -113,7 +113,7 @@ exception state.} \end{cfuncdesc} -\begin{cfuncdesc}{void}{PyErr_SetString}{PyObject *type, char *message} +\begin{cfuncdesc}{void}{PyErr_SetString}{PyObject *type, const char *message} This is the most common way to set the error indicator. The first argument specifies the exception type; it is normally one of the standard exceptions, e.g. \cdata{PyExc_RuntimeError}. You need not @@ -184,7 +184,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyErr_SetFromErrnoWithFilename}{PyObject *type, - char *filename} + const char *filename} Similar to \cfunction{PyErr_SetFromErrno()}, with the additional behavior that if \var{filename} is not \NULL, it is passed to the constructor of \var{type} as a third parameter. In the case of @@ -217,7 +217,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyErr_SetFromWindowsErrWithFilename}{int ierr, - char *filename} + const char *filename} Similar to \cfunction{PyErr_SetFromWindowsErr()}, with the additional behavior that if \var{filename} is not \NULL, it is passed to the constructor of \exception{WindowsError} as a third @@ -275,8 +275,9 @@ command line documentation. There is no C API for warning control. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyErr_WarnExplicit}{PyObject *category, char *message, - char *filename, int lineno, char *module, PyObject *registry} +\begin{cfuncdesc}{int}{PyErr_WarnExplicit}{PyObject *category, + const char *message, const char *filename, int lineno, + const char *module, PyObject *registry} Issue a warning message with explicit control over all warning attributes. This is a straightforward wrapper around the Python function \function{warnings.warn_explicit()}, see there for more Modified: python/trunk/Doc/api/init.tex ============================================================================== --- python/trunk/Doc/api/init.tex (original) +++ python/trunk/Doc/api/init.tex Wed Mar 1 06:16:03 2006 @@ -331,7 +331,7 @@ \withsubitem{(in module sys)}{\ttindex{version}} \end{cfuncdesc} -\begin{cfuncdesc}{int}{PySys_SetArgv}{int argc, char **argv} +\begin{cfuncdesc}{void}{PySys_SetArgv}{int argc, char **argv} Set \code{sys.argv} based on \var{argc} and \var{argv}. These parameters are similar to those passed to the program's \cfunction{main()}\ttindex{main()} function with the difference that Modified: python/trunk/Doc/api/newtypes.tex ============================================================================== --- python/trunk/Doc/api/newtypes.tex (original) +++ python/trunk/Doc/api/newtypes.tex Wed Mar 1 06:16:03 2006 @@ -11,7 +11,7 @@ \begin{cfuncdesc}{PyObject*}{_PyObject_New}{PyTypeObject *type} \end{cfuncdesc} -\begin{cfuncdesc}{PyVarObject*}{_PyObject_NewVar}{PyTypeObject *type, int size} +\begin{cfuncdesc}{PyVarObject*}{_PyObject_NewVar}{PyTypeObject *type, Py_ssize_t size} \end{cfuncdesc} \begin{cfuncdesc}{void}{_PyObject_Del}{PyObject *op} @@ -27,7 +27,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyVarObject*}{PyObject_InitVar}{PyVarObject *op, - PyTypeObject *type, int size} + PyTypeObject *type, Py_ssize_t size} This does everything \cfunction{PyObject_Init()} does, and also initializes the length information for a variable-size object. \end{cfuncdesc} @@ -42,7 +42,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{\var{TYPE}*}{PyObject_NewVar}{TYPE, PyTypeObject *type, - int size} + Py_ssize_t size} Allocate a new Python object using the C structure type \var{TYPE} and the Python type object \var{type}. Fields not defined by the Python object header are not initialized. The allocated memory @@ -69,7 +69,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{\var{TYPE}*}{PyObject_NEW_VAR}{TYPE, PyTypeObject *type, - int size} + Py_ssize_t size} Macro version of \cfunction{PyObject_NewVar()}, to gain performance at the expense of safety. This does not check \var{type} for a \NULL{} value. @@ -170,13 +170,13 @@ \csimplemacro{Py_TRACE_REFS}. By default, that macro is not defined, and \csimplemacro{PyObject_HEAD} expands to: \begin{verbatim} - int ob_refcnt; + Py_ssize_t ob_refcnt; PyTypeObject *ob_type; \end{verbatim} When \csimplemacro{Py_TRACE_REFS} is defined, it expands to: \begin{verbatim} PyObject *_ob_next, *_ob_prev; - int ob_refcnt; + Py_ssize_t ob_refcnt; PyTypeObject *ob_type; \end{verbatim} \end{csimplemacrodesc} @@ -383,7 +383,7 @@ These fields are not inherited by subtypes. \end{cmemberdesc} -\begin{cmemberdesc}{PyObject}{int}{ob_refcnt} +\begin{cmemberdesc}{PyObject}{Py_ssize_t}{ob_refcnt} This is the type object's reference count, initialized to \code{1} by the \code{PyObject_HEAD_INIT} macro. Note that for statically allocated type objects, the type's instances (objects whose @@ -421,7 +421,7 @@ and in 2.3 and beyond, it is inherited by subtypes. \end{cmemberdesc} -\begin{cmemberdesc}{PyVarObject}{int}{ob_size} +\begin{cmemberdesc}{PyVarObject}{Py_ssize_t}{ob_size} For statically allocated type objects, this should be initialized to zero. For dynamically allocated type objects, this field has a special internal meaning. @@ -457,8 +457,8 @@ This field is not inherited by subtypes. \end{cmemberdesc} -\begin{cmemberdesc}{PyTypeObject}{int}{tp_basicsize} -\cmemberline{PyTypeObject}{int}{tp_itemsize} +\begin{cmemberdesc}{PyTypeObject}{Py_ssize_t}{tp_basicsize} +\cmemberline{PyTypeObject}{Py_ssize_t}{tp_itemsize} These fields allow calculating the size in bytes of instances of the type. @@ -1234,7 +1234,7 @@ The function signature is \begin{verbatim} -PyObject *tp_alloc(PyTypeObject *self, int nitems) +PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems) \end{verbatim} The purpose of this function is to separate memory allocation from @@ -1386,15 +1386,15 @@ They are documented here for completeness. None of these fields are inherited by subtypes. -\begin{cmemberdesc}{PyTypeObject}{int}{tp_allocs} +\begin{cmemberdesc}{PyTypeObject}{Py_ssize_t}{tp_allocs} Number of allocations. \end{cmemberdesc} -\begin{cmemberdesc}{PyTypeObject}{int}{tp_frees} +\begin{cmemberdesc}{PyTypeObject}{Py_ssize_t}{tp_frees} Number of frees. \end{cmemberdesc} -\begin{cmemberdesc}{PyTypeObject}{int}{tp_maxalloc} +\begin{cmemberdesc}{PyTypeObject}{Py_ssize_t}{tp_maxalloc} Maximum simultaneously allocated objects. \end{cmemberdesc} @@ -1509,8 +1509,8 @@ \member{bf_getcharbuffer} slot is non-\NULL. \end{datadesc} -\begin{ctypedesc}[getreadbufferproc]{int (*getreadbufferproc) - (PyObject *self, int segment, void **ptrptr)} +\begin{ctypedesc}[getreadbufferproc]{Py_ssize_t (*readbufferproc) + (PyObject *self, Py_ssize_t segment, void **ptrptr)} Return a pointer to a readable segment of the buffer. This function is allowed to raise an exception, in which case it must return \code{-1}. The \var{segment} which is passed must be zero or @@ -1520,8 +1520,8 @@ pointer to that memory. \end{ctypedesc} -\begin{ctypedesc}[getwritebufferproc]{int (*getwritebufferproc) - (PyObject *self, int segment, void **ptrptr)} +\begin{ctypedesc}[getwritebufferproc]{Py_ssize_t (*writebufferproc) + (PyObject *self, Py_ssize_t segment, void **ptrptr)} Return a pointer to a writable memory buffer in \code{*\var{ptrptr}}, and the length of that segment as the function return value. The memory buffer must correspond to buffer segment @@ -1535,16 +1535,16 @@ % code. \end{ctypedesc} -\begin{ctypedesc}[getsegcountproc]{int (*getsegcountproc) - (PyObject *self, int *lenp)} +\begin{ctypedesc}[getsegcountproc]{Py_ssize_t (*segcountproc) + (PyObject *self, Py_ssize_t *lenp)} Return the number of memory segments which comprise the buffer. If \var{lenp} is not \NULL, the implementation must report the sum of the sizes (in bytes) of all segments in \code{*\var{lenp}}. The function cannot fail. \end{ctypedesc} -\begin{ctypedesc}[getcharbufferproc]{int (*getcharbufferproc) - (PyObject *self, int segment, const char **ptrptr)} +\begin{ctypedesc}[getcharbufferproc]{Py_ssize_t (*charbufferproc) + (PyObject *self, Py_ssize_t segment, const char **ptrptr)} Return the size of the memory buffer in \var{ptrptr} for segment \var{segment}. \code{*\var{ptrptr}} is set to the memory buffer. \end{ctypedesc} @@ -1599,12 +1599,12 @@ \end{cfuncdesc} \begin{cfuncdesc}{\var{TYPE}*}{PyObject_GC_NewVar}{TYPE, PyTypeObject *type, - int size} + Py_ssize_t size} Analogous to \cfunction{PyObject_NewVar()} but for container objects with the \constant{Py_TPFLAGS_HAVE_GC} flag set. \end{cfuncdesc} -\begin{cfuncdesc}{PyVarObject *}{PyObject_GC_Resize}{PyVarObject *op, int} +\begin{cfuncdesc}{PyVarObject *}{PyObject_GC_Resize}{PyVarObject *op, Py_ssize_t} Resize an object allocated by \cfunction{PyObject_NewVar()}. Returns the resized object or \NULL{} on failure. \end{cfuncdesc} @@ -1633,12 +1633,12 @@ \cfunction{PyObject_GC_Del()}. \end{enumerate} -\begin{cfuncdesc}{void}{PyObject_GC_Del}{PyObject *op} +\begin{cfuncdesc}{void}{PyObject_GC_Del}{void *op} Releases memory allocated to an object using \cfunction{PyObject_GC_New()} or \cfunction{PyObject_GC_NewVar()}. \end{cfuncdesc} -\begin{cfuncdesc}{void}{PyObject_GC_UnTrack}{PyObject *op} +\begin{cfuncdesc}{void}{PyObject_GC_UnTrack}{void *op} Remove the object \var{op} from the set of container objects tracked by the collector. Note that \cfunction{PyObject_GC_Track()} can be called again on this object to add it back to the set of tracked Modified: python/trunk/Doc/api/utilities.tex ============================================================================== --- python/trunk/Doc/api/utilities.tex (original) +++ python/trunk/Doc/api/utilities.tex Wed Mar 1 06:16:03 2006 @@ -8,7 +8,7 @@ \section{Operating System Utilities \label{os}} -\begin{cfuncdesc}{int}{Py_FdIsInteractive}{FILE *fp, char *filename} +\begin{cfuncdesc}{int}{Py_FdIsInteractive}{FILE *fp, const char *filename} Return true (nonzero) if the standard I/O file \var{fp} with name \var{filename} is deemed interactive. This is the case for files for which \samp{isatty(fileno(\var{fp}))} is true. If the global @@ -91,7 +91,7 @@ \section{Importing Modules \label{importing}} -\begin{cfuncdesc}{PyObject*}{PyImport_ImportModule}{char *name} +\begin{cfuncdesc}{PyObject*}{PyImport_ImportModule}{const char *name} This is a simplified interface to \cfunction{PyImport_ImportModuleEx()} below, leaving the \var{globals} and \var{locals} arguments set to \NULL. When the @@ -148,7 +148,7 @@ case). \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyImport_AddModule}{char *name} +\begin{cfuncdesc}{PyObject*}{PyImport_AddModule}{const char *name} Return the module object corresponding to a module name. The \var{name} argument may be of the form \code{package.module}. First check the modules dictionary if there's one there, and if not, @@ -369,7 +369,7 @@ \end{cfuncdesc} \begin{cfuncdesc}{PyObject*}{PyMarshal_ReadObjectFromString}{char *string, - int len} + Py_ssize_t len} Return a Python object from the data stream in a character buffer containing \var{len} bytes pointed to by \var{string}. On error, sets the appropriate exception (\exception{EOFError} or @@ -687,21 +687,21 @@ \cfunction{PyArg_Parse*()} functions return true, otherwise they return false and raise an appropriate exception. -\begin{cfuncdesc}{int}{PyArg_ParseTuple}{PyObject *args, char *format, +\begin{cfuncdesc}{int}{PyArg_ParseTuple}{PyObject *args, const char *format, \moreargs} Parse the parameters of a function that takes only positional parameters into local variables. Returns true on success; on failure, it returns false and raises the appropriate exception. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyArg_VaParse}{PyObject *args, char *format, +\begin{cfuncdesc}{int}{PyArg_VaParse}{PyObject *args, const char *format, va_list vargs} Identical to \cfunction{PyArg_ParseTuple()}, except that it accepts a va_list rather than a variable number of arguments. \end{cfuncdesc} \begin{cfuncdesc}{int}{PyArg_ParseTupleAndKeywords}{PyObject *args, - PyObject *kw, char *format, char *keywords[], + PyObject *kw, const char *format, char *keywords[], \moreargs} Parse the parameters of a function that takes both positional and keyword parameters into local variables. Returns true on success; @@ -709,13 +709,13 @@ \end{cfuncdesc} \begin{cfuncdesc}{int}{PyArg_VaParseTupleAndKeywords}{PyObject *args, - PyObject *kw, char *format, char *keywords[], + PyObject *kw, const char *format, char *keywords[], va_list vargs} Identical to \cfunction{PyArg_ParseTupleAndKeywords()}, except that it accepts a va_list rather than a variable number of arguments. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyArg_Parse}{PyObject *args, char *format, +\begin{cfuncdesc}{int}{PyArg_Parse}{PyObject *args, const char *format, \moreargs} Function used to deconstruct the argument lists of ``old-style'' functions --- these are functions which use the @@ -727,8 +727,8 @@ purpose. \end{cfuncdesc} -\begin{cfuncdesc}{int}{PyArg_UnpackTuple}{PyObject *args, char *name, - int min, int max, \moreargs} +\begin{cfuncdesc}{int}{PyArg_UnpackTuple}{PyObject *args, const char *name, + Py_ssize_t min, Py_ssize_t max, \moreargs} A simpler form of parameter retrieval which does not use a format string to specify the types of the arguments. Functions which use this method to retrieve their parameters should be declared as @@ -774,7 +774,7 @@ \versionadded{2.2} \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{Py_BuildValue}{char *format, +\begin{cfuncdesc}{PyObject*}{Py_BuildValue}{const char *format, \moreargs} Create a new value based on a format string similar to those accepted by the \cfunction{PyArg_Parse*()} family of functions and a From python-checkins at python.org Wed Mar 1 06:18:14 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 06:18:14 +0100 (CET) Subject: [Python-checkins] r42716 - python/trunk/Doc/tools/cmpcsyms Message-ID: <20060301051814.018D01E4002@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 06:18:07 2006 New Revision: 42716 Added: python/trunk/Doc/tools/cmpcsyms - copied, changed from r42684, python/trunk/Doc/tools/findcsyms Log: Add tool to check documentation against declaration. Copied: python/trunk/Doc/tools/cmpcsyms (from r42684, python/trunk/Doc/tools/findcsyms) ============================================================================== --- python/trunk/Doc/tools/findcsyms (original) +++ python/trunk/Doc/tools/cmpcsyms Wed Mar 1 06:18:07 2006 @@ -1,9 +1,10 @@ #! /usr/bin/env python - +from __future__ import with_statement import errno import os import re import sys +import string if __name__ == "__main__": _base = sys.argv[0] @@ -23,24 +24,19 @@ def list_headers(): """Return a list of headers.""" incdir = os.path.join(srcdir, "Include") - return [fn for fn in os.listdir(incdir) + return [os.path.join(incdir, fn) for fn in os.listdir(incdir) if fn.endswith(".h") and fn not in EXCLUDES] def matcher(pattern): - return re.compile(pattern).match + return re.compile(pattern).search MATCHERS = [ - matcher(r"\\begin\{cfuncdesc\}\{[^{]*\}\{(?P[^{]*)\}"), - matcher(r"\\cfuncline\{[^{]*\}\{(?P[^{]*)\}"), - matcher(r"\\begin\{ctypedesc\}(\[[^{]*\])?\{(?P[^{]*)\}"), - matcher(r"\\begin\{cvardesc\}\{[^{]*\}\{(?P[^{]*)\}"), - matcher(r"\\begin\{cmemberdesc\}\{[^{]*\}\{(?P[^{]*)\}"), - matcher(r"\\cmemberline\{[^{]*\}\{(?P[^{]*)\}"), - matcher(r"\\begin\{csimplemacrodesc\}\{(?P[^{]*)\}"), + # XXX this should also deal with ctypedesc, cvardesc and cmemberdesc + matcher(r"\\begin\{cfuncdesc\}\{(?P[^}]*)\}\{(?P[^}]*)\}{(?P[^}]*)\}"), + matcher(r"\\cfuncline\{(?P[^})]*)\}\{(?P[^}]*)\}{(?P[^}]*)\}"), ] - def list_documented_items(): """Return a list of everything that's already documented.""" apidir = os.path.join(srcdir, "Doc", "api") @@ -48,89 +44,114 @@ L = [] for fn in files: fullname = os.path.join(apidir, fn) - for line in open(fullname): - line = line.lstrip() - if not line.startswith("\\"): - continue - for matcher in MATCHERS: - m = matcher(line) - if m: - L.append(m.group("sym")) - break + data = open(fullname).read() + for matcher in MATCHERS: + pos = 0 + while 1: + m = matcher(data, pos) + if not m: break + pos = m.end() + sym = m.group("sym") + result = m.group("result") + params = m.group("params") + # replace all whitespace with a single one + params = " ".join(params.split()) + L.append((sym, result, params, fn)) return L -def split_documented(all, documented): - """Split the list of all symbols into documented and undocumented - categories.""" - doc = [] - undoc = [] - for t in all: - if t[0] in documented: - doc.append(t) - else: - undoc.append(t) - return doc, undoc - -def print_list(L, title=None): - """Dump a list to stdout.""" - if title: - print title + ":" - print "-" * (len(title) + 1) - w = 0 - for sym, filename in L: - w = max(w, len(sym)) - if w % 4 == 0: - w += 4 - else: - w += (4 - (w % 4)) - for sym, filename in L: - print "%-*s%s" % (w, sym, filename) - - -_spcjoin = ' '.join +def normalize_type(t): + t = t.strip() + s = t.rfind("*") + if s != -1: + # strip everything after the pointer name + t = t[:s+1] + # Drop the variable name + s = t.split() + typenames = 1 + if len(s)>1 and s[0]=='unsigned' and s[1]=='int': + typenames = 2 + if len(s) > typenames and s[-1][0] in string.letters: + del s[-1] + if not s: + print "XXX", t + return "" + # Drop register + if s[0] == "register": + del s[0] + # discard all spaces + return ''.join(s) + +def compare_type(t1, t2): + t1 = normalize_type(t1) + t2 = normalize_type(t2) + if t1 == r'\moreargs' and t2 == '...': + return False + if t1 != t2: + #print "different:", t1, t2 + return False + return True + + +def compare_types(ret, params, hret, hparams): + if not compare_type(ret, hret): + return False + params = params.split(",") + hparams = hparams.split(",") + if not params and hparams == ['void']: + return True + if not hparams and params == ['void']: + return True + if len(params) != len(hparams): + return False + for p1, p2 in zip(params, hparams): + if not compare_type(p1, p2): + return False + return True def main(): - args = sys.argv[1:] - if args: - headers = args - documented = [] - else: - os.chdir(os.path.join(srcdir, "Include")) - headers = list_headers() - documented = list_documented_items() - - cmd = ("ctags -f - --file-scope=no --c-types=dgpstux " - "-Istaticforward -Istatichere=static " - + _spcjoin(headers)) - fp = os.popen(cmd) - L = [] + headers = list_headers() + documented = list_documented_items() + + lines = [] + for h in headers: + data = open(h).read() + data, n = re.subn(r"PyAPI_FUNC\(([^)]*)\)", r"\1", data) + name = os.path.basename(h) + with open(name, "w") as f: + f.write(data) + cmd = ("ctags -f - --file-scope=no --c-kinds=p --fields=S " + "-Istaticforward -Istatichere=static " + name) + with os.popen(cmd) as f: + lines.extend(f.readlines()) + os.unlink(name) + L = {} prevsym = None - while 1: - line = fp.readline() + for line in lines: if not line: break - sym, filename = line.split()[:2] + sym, filename, signature = line.split(None, 2) if sym == prevsym: continue - if not sym.endswith("_H"): - L.append((sym, filename)) - prevsym = sym - L.sort() - fp.close() - - try: - if documented: - documented, undocumented = split_documented(L, documented) - print_list(documented, "Documented symbols") - if undocumented: - print - print_list(undocumented, "Undocumented symbols") - else: - print_list(L) - except IOError, e: - if e.errno != errno.EPIPE: - raise - + expr = "\^(.*)%s" % sym + m = re.search(expr, signature) + if not m: + print "Could not split",signature, "using",expr + rettype = m.group(1).strip() + m = re.search("signature:\(([^)]*)\)", signature) + if not m: + print "Could not get signature from", signature + params = m.group(1) + L[sym] = (rettype, params) + + for sym, ret, params, fn in documented: + if sym not in L: + print "No declaration for '%s'" % sym + continue + hret, hparams = L[sym] + if not compare_types(ret, params, hret, hparams): + print "Declaration error for %s (%s):" % (sym, fn) + print ret+": "+params + print hret+": "+hparams if __name__ == "__main__": main() From python-checkins at python.org Wed Mar 1 06:32:37 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 06:32:37 +0100 (CET) Subject: [Python-checkins] r42717 - python/trunk/Python/ceval.c Message-ID: <20060301053237.8169F1E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 06:32:33 2006 New Revision: 42717 Modified: python/trunk/Python/ceval.c Log: Put back the essence of Jeremy's original XXX comment. Modified: python/trunk/Python/ceval.c ============================================================================== --- python/trunk/Python/ceval.c (original) +++ python/trunk/Python/ceval.c Wed Mar 1 06:32:33 2006 @@ -3654,7 +3654,9 @@ } /* Clear the stack of the function object and the arguments, - in case they weren't consumed already */ + in case they weren't consumed already. + XXX(twouters) when are they not consumed already? + */ while ((*pp_stack) > pfunc) { w = EXT_POP(*pp_stack); Py_DECREF(w); From python-checkins at python.org Wed Mar 1 06:32:51 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 06:32:51 +0100 (CET) Subject: [Python-checkins] r42718 - peps/trunk/pep-3000.txt Message-ID: <20060301053251.39C231E4002@bag.python.org> Author: brett.cannon Date: Wed Mar 1 06:32:44 2006 New Revision: 42718 Modified: peps/trunk/pep-3000.txt Log: Reorganize: move stuff from core language to atomic types, add Influencing PEPs section. Modified: peps/trunk/pep-3000.txt ============================================================================== --- peps/trunk/pep-3000.txt (original) +++ peps/trunk/pep-3000.txt Wed Mar 1 06:32:44 2006 @@ -38,18 +38,22 @@ obvious way of doing something is enough. [1]_ +Influencing PEPs +================ + +* PEP 238 (Changing the Division Operator) [#pep238]_ +* PEP 328 (Imports: Multi-Line and Absolute/Relative) [#pep328]_ +* PEP 343 (The "with" Statement) [#pep343]_ +* PEP 352 (Required Superclass for Exceptions) [#pep352]_ + + Core language ============= -* Remove distinction between int and long types [1]_ * True division becomes default behavior [10]_ -* Make all strings be Unicode, and have a separate bytes() type [1]_ * ``exec`` as a statement is not worth it -- make it a function * Add optional declarations for static typing [11]_ * Support only new-style classes; classic classes will be gone [1]_ -* Return iterators instead of lists where appropriate for atomic type methods - (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) - (Do we keep iter*() methods or remove them? I vote remove. -- nn) * Replace ``print`` by a function [16]_ * Do something so you can catch multiple exceptions using ``except E1, E2, E3:``. Maybe use ``except E1, E2, E3 as err:`` if you want the @@ -70,12 +74,13 @@ be required for top-level packages. * Cleanup the Py_InitModule() variants {,3,4} (also import and parser APIs) * Cleanup the APIs exported in pythonrun, etc. -* Fix (or remove) {}.setdefault() [21]_ * Some expressions will require parentheses that didn't in 2.x: + - List comprehensions will require parentheses around the iterables. This will make list comprehensions more similar to generator comprehensions. [x for x in 1, 2] will need to be: [x for x in (1, 2)] - Lambdas will have to be parenthesized [23]_ + * Builtin module init function names (PyMODINIT_FUNC) will be prefixed with _Py (or Py). Currently they aren't namespace safe since the names start with init. @@ -95,9 +100,26 @@ PySequence_In, PyEval_EvalFrame, PyEval_CallObject, _PyObject_Del, _PyObject_GC_Del, _PyObject_GC_Track, _PyObject_GC_UnTrack PyString_AsEncodedString, PyString_AsDecodedString - PyArg_NoArgs, PyArg_GetInt + PyArg_NoArgs, PyArg_GetInt, intargfunc, intintargfunc + + +Atomic Types +============ + +* Remove distinction between int and long types [1]_ +* Make all strings be Unicode, and have a separate bytes() type [1]_ +* Return iterators instead of lists where appropriate for atomic type methods + (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) + (Do we keep iter*() methods or remove them? I vote remove. -- nn) + +To be removed: + +* ``basestring.find()`` and ``basestring.rfind()``; use ``basestring.index()`` + or ``basestring.rindex()`` in a try/except block [15]_ +* ``file.xreadlines()`` method [17]_ +* ``dict.setdefault()`` [22]_ +* ``dict.has_key()`` method - typedefs: intargfunc, intintargfunc Built-in Namespace ================== @@ -127,18 +149,6 @@ * ``xrange()``: use ``range()`` instead [1]_ -Atomic Types -============ - -To be removed: - -* ``basestring.find()`` and ``basestring.rfind()``; use ``basestring.index()`` - or ``basestring.rindex()`` in a try/except block [15]_ -* ``file.xreadlines()`` method [17]_ -* ``dict.setdefault()`` [22]_ -* ``dict.has_key()`` method - - Standard library ================ @@ -253,6 +263,18 @@ .. [23] PEP 308 ("Conditional Expressions") http://www.python.org/peps/pep-0308.html +.. [#pep238] PEP 238 (Changing the Division Operator) + http://www.python.org/peps/pep-0238.html + +.. [#pep328] PEP 328 (Imports: Multi-Line and Absolute/Relative) + http://www.python.org/peps/pep-0328.html + +.. [#pep343] PEP 343 (The "with" Statement) + http://www.python.org/peps/pep-0343.html + +.. [#pep352] PEP 352 (Required Superclass for Exceptions) + http://www.python.org/peps/pep-0352.html + Copyright ========= From python-checkins at python.org Wed Mar 1 06:34:28 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 06:34:28 +0100 (CET) Subject: [Python-checkins] r42719 - python/trunk/Lib/traceback.py Message-ID: <20060301053428.9AE791E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 06:34:22 2006 New Revision: 42719 Modified: python/trunk/Lib/traceback.py Log: Remove redundant isinstance() check. Modified: python/trunk/Lib/traceback.py ============================================================================== --- python/trunk/Lib/traceback.py (original) +++ python/trunk/Lib/traceback.py Wed Mar 1 06:34:22 2006 @@ -158,7 +158,7 @@ """ list = [] if (type(etype) == types.ClassType - or (isinstance(etype, type) and issubclass(etype, Exception))): + or issubclass(etype, Exception)): stype = etype.__name__ else: stype = etype From python-checkins at python.org Wed Mar 1 06:38:42 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 06:38:42 +0100 (CET) Subject: [Python-checkins] r42720 - python/trunk/Python/getargs.c Message-ID: <20060301053842.7D8481E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 06:38:39 2006 New Revision: 42720 Modified: python/trunk/Python/getargs.c Log: Use %zd format characters for Py_ssize_t types. Modified: python/trunk/Python/getargs.c ============================================================================== --- python/trunk/Python/getargs.c (original) +++ python/trunk/Python/getargs.c Wed Mar 1 06:38:39 2006 @@ -1686,13 +1686,13 @@ if (name != NULL) PyErr_Format( PyExc_TypeError, - "%s expected %s%d arguments, got %d", + "%s expected %s%zd arguments, got %zd", name, (min == max ? "" : "at least "), min, l); else PyErr_Format( PyExc_TypeError, - "unpacked tuple should have %s%d elements," - " but has %d", + "unpacked tuple should have %s%zd elements," + " but has %zd", (min == max ? "" : "at least "), min, l); va_end(vargs); return 0; @@ -1701,13 +1701,13 @@ if (name != NULL) PyErr_Format( PyExc_TypeError, - "%s expected %s%d arguments, got %d", + "%s expected %s%zd arguments, got %zd", name, (min == max ? "" : "at most "), max, l); else PyErr_Format( PyExc_TypeError, - "unpacked tuple should have %s%d elements," - " but has %d", + "unpacked tuple should have %s%zd elements," + " but has %zd", (min == max ? "" : "at most "), max, l); va_end(vargs); return 0; From python-checkins at python.org Wed Mar 1 06:41:26 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 06:41:26 +0100 (CET) Subject: [Python-checkins] r42721 - python/trunk/Objects/floatobject.c python/trunk/Objects/intobject.c python/trunk/Objects/object.c Message-ID: <20060301054126.3F8331E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 06:41:20 2006 New Revision: 42721 Modified: python/trunk/Objects/floatobject.c python/trunk/Objects/intobject.c python/trunk/Objects/object.c Log: Use %ld and casts to long for refcount printing, in absense of a universally available %zd format character. Mark with an XXX comment so we can fix this, later. Modified: python/trunk/Objects/floatobject.c ============================================================================== --- python/trunk/Objects/floatobject.c (original) +++ python/trunk/Objects/floatobject.c Wed Mar 1 06:41:20 2006 @@ -1326,9 +1326,13 @@ p->ob_refcnt != 0) { char buf[100]; PyFloat_AsString(buf, p); + /* XXX(twouters) cast refcount to + long until %zd is universally + available + */ fprintf(stderr, - "# \n", - p, p->ob_refcnt, buf); + "# \n", + p, (long)p->ob_refcnt, buf); } } list = list->next; Modified: python/trunk/Objects/intobject.c ============================================================================== --- python/trunk/Objects/intobject.c (original) +++ python/trunk/Objects/intobject.c Wed Mar 1 06:41:20 2006 @@ -1220,9 +1220,14 @@ i < N_INTOBJECTS; i++, p++) { if (PyInt_CheckExact(p) && p->ob_refcnt != 0) + /* XXX(twouters) cast refcount to + long until %zd is universally + available + */ fprintf(stderr, - "# \n", - p, p->ob_refcnt, p->ob_ival); + "# \n", + p, (long)p->ob_refcnt, + p->ob_ival); } list = list->next; } Modified: python/trunk/Objects/object.c ============================================================================== --- python/trunk/Objects/object.c (original) +++ python/trunk/Objects/object.c Wed Mar 1 06:41:20 2006 @@ -138,9 +138,11 @@ { char buf[300]; + /* XXX(twouters) cast refcount to long until %zd is universally + available */ PyOS_snprintf(buf, sizeof(buf), - "%s:%i object at %p has negative ref count %i", - fname, lineno, op, op->ob_refcnt); + "%s:%i object at %p has negative ref count %ld", + fname, lineno, op, (long)op->ob_refcnt); Py_FatalError(buf); } @@ -233,8 +235,10 @@ } else { if (op->ob_refcnt <= 0) - fprintf(fp, "", - op->ob_refcnt, op); + /* XXX(twouters) cast refcount to long until %zd is + universally available */ + fprintf(fp, "", + (long)op->ob_refcnt, op); else if (op->ob_type->tp_print == NULL) { PyObject *s; if (flags & Py_PRINT_RAW) @@ -277,12 +281,14 @@ else { fprintf(stderr, "object : "); (void)PyObject_Print(op, stderr, 0); + /* XXX(twouters) cast refcount to long until %zd is + universally available */ fprintf(stderr, "\n" "type : %s\n" - "refcount: %d\n" + "refcount: %ld\n" "address : %p\n", op->ob_type==NULL ? "NULL" : op->ob_type->tp_name, - op->ob_refcnt, + (long)op->ob_refcnt, op); } } @@ -1893,7 +1899,9 @@ PyObject *op; fprintf(fp, "Remaining objects:\n"); for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) { - fprintf(fp, "%p [%d] ", op, op->ob_refcnt); + /* XXX(twouters) cast refcount to long until %zd is + universally available */ + fprintf(fp, "%p [%ld] ", op, (long)op->ob_refcnt); if (PyObject_Print(op, fp, 0) != 0) PyErr_Clear(); putc('\n', fp); @@ -1909,7 +1917,9 @@ PyObject *op; fprintf(fp, "Remaining object addresses:\n"); for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) - fprintf(fp, "%p [%d] %s\n", op, op->ob_refcnt, + /* XXX(twouters) cast refcount to long until %zd is + universally available */ + fprintf(fp, "%p [%ld] %s\n", op, (long)op->ob_refcnt, op->ob_type->tp_name); } From python-checkins at python.org Wed Mar 1 06:47:12 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 06:47:12 +0100 (CET) Subject: [Python-checkins] r42722 - python/trunk/Doc/api/concrete.tex python/trunk/Doc/api/utilities.tex Message-ID: <20060301054712.8FCF41E4002@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 06:47:11 2006 New Revision: 42722 Modified: python/trunk/Doc/api/concrete.tex python/trunk/Doc/api/utilities.tex Log: Document new Py_ssize_t API. Modified: python/trunk/Doc/api/concrete.tex ============================================================================== --- python/trunk/Doc/api/concrete.tex (original) +++ python/trunk/Doc/api/concrete.tex Wed Mar 1 06:47:11 2006 @@ -162,9 +162,20 @@ suspect the behaviour of Python in this case is undefined. :-) \end{cfuncdesc} +\begin{cfuncdesc}{PyObject*}{PyInt_FromSsize_t}{Py_ssize_t ival} + Create a new integer object with a value of \var{ival}. + If the value exceeds \code{LONG_MAX}, a long integer object is + returned. + + \versionadded{2.5} +\end{cfuncdesc} + \begin{cfuncdesc}{long}{PyInt_AsLong}{PyObject *io} Will first attempt to cast the object to a \ctype{PyIntObject}, if - it is not already one, and then return its value. + it is not already one, and then return its value. If there is an + error, \code{-1} is returned, and the caller should check + \code{PyErr_Occurred()} to find out whether there was an error, or + whether the value just happened to be -1. \end{cfuncdesc} \begin{cfuncdesc}{long}{PyInt_AS_LONG}{PyObject *io} @@ -186,6 +197,13 @@ \versionadded{2.3} \end{cfuncdesc} +\begin{cfuncdesc}{Py_ssize_t}{PyInt_AsSsize_t}{PyObject *io} + Will first attempt to cast the object to a \ctype{PyIntObject} or + \ctype{PyLongObject}, if it is not already one, and then return its + value as \ctype{Py_ssize_t}. + \versionadded{2.5} +\end{cfuncdesc} + \begin{cfuncdesc}{long}{PyInt_GetMax}{} Return the system's idea of the largest integer it can handle (\constant{LONG_MAX}\ttindex{LONG_MAX}, as defined in the system Modified: python/trunk/Doc/api/utilities.tex ============================================================================== --- python/trunk/Doc/api/utilities.tex (original) +++ python/trunk/Doc/api/utilities.tex Wed Mar 1 06:47:11 2006 @@ -553,6 +553,10 @@ platforms that support \ctype{unsigned long long} (or \ctype{unsigned _int64} on Windows). \versionadded{2.3} + \item[\samp{n} (integer) {[Py_ssize_t]}] + Convert a Python integer or long integer to a C \ctype{Py_ssize_t}. + \versionadded{2.5} + \item[\samp{c} (string of length 1) {[char]}] Convert a Python character, represented as a string of length 1, to a C \ctype{char}. @@ -866,6 +870,10 @@ Convert a C \ctype{unsigned long long} to a Python long integer object. Only available on platforms that support \ctype{unsigned long long}. + \item[\samp{n} (int) {[Py_ssize_t]}] + Convert a C \ctype{Py_ssize_t) to a Python integer or long integer. + \versionadded{2.5} + \item[\samp{c} (string of length 1) {[char]}] Convert a C \ctype{int} representing a character to a Python string of length 1. From python at rcn.com Wed Mar 1 06:50:28 2006 From: python at rcn.com (Raymond Hettinger) Date: Wed, 1 Mar 2006 00:50:28 -0500 Subject: [Python-checkins] r42718 - peps/trunk/pep-3000.txt References: <20060301053251.39C231E4002@bag.python.org> Message-ID: <004901c63cf4$0b6e90c0$6a01a8c0@RaymondLaptop1> > -* Return iterators instead of lists where appropriate for atomic type methods > - (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) > - (Do we keep iter*() methods or remove them? I vote remove. -- nn) The last line doesn't make sense to me. I had thought the direction was to keep simple names like range(), dict.items(), dict.keys(), and dict.values() and have them return an iterator instead of a list. When that is done, then the current iterator versions will be redundant and we can kill-off the weird names like xrange(), dict.iter_items(), dict.iter_keys(), and dict.iter_values(). IOW, we still need some method to iterator over dictionary items and the name should be dict.items() rather than the long-winded, dict.iter_items() Raymond From thomas at python.org Wed Mar 1 06:56:41 2006 From: thomas at python.org (Thomas Wouters) Date: Wed, 1 Mar 2006 06:56:41 +0100 Subject: [Python-checkins] r42718 - peps/trunk/pep-3000.txt In-Reply-To: <004901c63cf4$0b6e90c0$6a01a8c0@RaymondLaptop1> References: <20060301053251.39C231E4002@bag.python.org> <004901c63cf4$0b6e90c0$6a01a8c0@RaymondLaptop1> Message-ID: <9e804ac0602282156s65daf829j208f073146570861@mail.gmail.com> On 3/1/06, Raymond Hettinger wrote: > > -* Return iterators instead of lists where appropriate for atomic type methods > > - (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) > > - (Do we keep iter*() methods or remove them? I vote remove. -- nn) > > The last line doesn't make sense to me. I had thought the direction was to keep > simple names like range(), dict.items(), dict.keys(), and dict.values() and have > them return an iterator instead of a list. When that is done, then the current > iterator versions will be redundant and we can kill-off the weird names like > xrange(), dict.iter_items(), dict.iter_keys(), and dict.iter_values(). I can't read Neal's original question as anything other than a suggestion to do exactly that, asking for confirmation. I agree with his suggestion, and I guess you do too :-) -- Thomas Wouters Hi! I'm a .signature virus! copy me into your .signature file to help me spread! From python-checkins at python.org Wed Mar 1 07:10:50 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 07:10:50 +0100 (CET) Subject: [Python-checkins] r42723 - python/trunk/Lib/test/test_pep352.py Message-ID: <20060301061050.6F4891E4042@bag.python.org> Author: brett.cannon Date: Wed Mar 1 07:10:48 2006 New Revision: 42723 Modified: python/trunk/Lib/test/test_pep352.py Log: Fix parsing of exception_hierarchy.txt when a platform-specific exception is specified. Hopefully this wll bring warming to Tim's Windows-loving heart. Modified: python/trunk/Lib/test/test_pep352.py ============================================================================== --- python/trunk/Lib/test/test_pep352.py (original) +++ python/trunk/Lib/test/test_pep352.py Wed Mar 1 07:10:48 2006 @@ -42,6 +42,7 @@ if '(' in exc_name: paren_index = exc_name.index('(') platform_name = exc_name[paren_index+1:-1] + exc_name = exc_name[:paren_index-1] # Slice off space if platform_system() != platform_name: exc_set.discard(exc_name) continue From python-checkins at python.org Wed Mar 1 07:19:10 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 07:19:10 +0100 (CET) Subject: [Python-checkins] r42724 - in python/trunk: Lib/bsddb/test/test_1413192.py Lib/email/test/data/msg_44.txt Lib/encodings/utf_8_sig.py Lib/test/bad_coding2.py Lib/test/crashers/coerce.py Lib/test/crashers/dangerous_subclassing.py Lib/test/crashers/infinite_rec_1.py Lib/test/crashers/infinite_rec_2.py Lib/test/crashers/infinite_rec_3.py Lib/test/crashers/infinite_rec_4.py Lib/test/crashers/infinite_rec_5.py Lib/test/crashers/loosing_dict_ref.py Lib/test/crashers/modify_dict_attr.py Lib/test/crashers/recursive_call.py Lib/test/crashers/weakref_in_del.py Lib/test/crashers/xml_parsers.py Lib/test/outstanding_bugs.py Lib/test/test_defaultdict.py Lib/test/test_exception_variations.py Lib/test/test_platform.py Lib/xmlcore/etree/cElementTree.py Modules/zlib/algorithm.txt Message-ID: <20060301061910.545251E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 07:19:04 2006 New Revision: 42724 Modified: python/trunk/Lib/bsddb/test/test_1413192.py (props changed) python/trunk/Lib/email/test/data/msg_44.txt (props changed) python/trunk/Lib/encodings/utf_8_sig.py (props changed) python/trunk/Lib/test/bad_coding2.py (contents, props changed) python/trunk/Lib/test/crashers/coerce.py (props changed) python/trunk/Lib/test/crashers/dangerous_subclassing.py (props changed) python/trunk/Lib/test/crashers/infinite_rec_1.py (props changed) python/trunk/Lib/test/crashers/infinite_rec_2.py (props changed) python/trunk/Lib/test/crashers/infinite_rec_3.py (props changed) python/trunk/Lib/test/crashers/infinite_rec_4.py (props changed) python/trunk/Lib/test/crashers/infinite_rec_5.py (props changed) python/trunk/Lib/test/crashers/loosing_dict_ref.py (props changed) python/trunk/Lib/test/crashers/modify_dict_attr.py (props changed) python/trunk/Lib/test/crashers/recursive_call.py (props changed) python/trunk/Lib/test/crashers/weakref_in_del.py (contents, props changed) python/trunk/Lib/test/crashers/xml_parsers.py (contents, props changed) python/trunk/Lib/test/outstanding_bugs.py (contents, props changed) python/trunk/Lib/test/test_defaultdict.py (props changed) python/trunk/Lib/test/test_exception_variations.py (contents, props changed) python/trunk/Lib/test/test_platform.py (props changed) python/trunk/Lib/xmlcore/etree/cElementTree.py (props changed) python/trunk/Modules/zlib/algorithm.txt (props changed) Log: Set svn:eol-style to native. Modified: python/trunk/Lib/test/bad_coding2.py ============================================================================== --- python/trunk/Lib/test/bad_coding2.py (original) +++ python/trunk/Lib/test/bad_coding2.py Wed Mar 1 07:19:04 2006 @@ -1,2 +1,2 @@ -?#coding: utf8 -print '?' +?#coding: utf8 +print '?' Modified: python/trunk/Lib/test/crashers/weakref_in_del.py ============================================================================== --- python/trunk/Lib/test/crashers/weakref_in_del.py (original) +++ python/trunk/Lib/test/crashers/weakref_in_del.py Wed Mar 1 07:19:04 2006 @@ -1,16 +1,16 @@ -import weakref - -# http://python.org/sf/1377858 - -ref = None - -def test_weakref_in_del(): - class Target(object): - def __del__(self): - global ref - ref = weakref.ref(self) - - w = Target() - -if __name__ == '__main__': - test_weakref_in_del() +import weakref + +# http://python.org/sf/1377858 + +ref = None + +def test_weakref_in_del(): + class Target(object): + def __del__(self): + global ref + ref = weakref.ref(self) + + w = Target() + +if __name__ == '__main__': + test_weakref_in_del() Modified: python/trunk/Lib/test/crashers/xml_parsers.py ============================================================================== --- python/trunk/Lib/test/crashers/xml_parsers.py (original) +++ python/trunk/Lib/test/crashers/xml_parsers.py Wed Mar 1 07:19:04 2006 @@ -1,56 +1,56 @@ -from xml.parsers import expat - -# http://python.org/sf/1296433 - -def test_parse_only_xml_data(): - # - xml = "%s" % ('a' * 1025) - # this one doesn't crash - #xml = "%s" % ('a' * 10000) - - def handler(text): - raise Exception - - parser = expat.ParserCreate() - parser.CharacterDataHandler = handler - - try: - parser.Parse(xml) - except: - pass - -if __name__ == '__main__': - test_parse_only_xml_data() - -# Invalid read of size 4 -# at 0x43F936: PyObject_Free (obmalloc.c:735) -# by 0x45A7C7: unicode_dealloc (unicodeobject.c:246) -# by 0x1299021D: PyUnknownEncodingHandler (pyexpat.c:1314) -# by 0x12993A66: processXmlDecl (xmlparse.c:3330) -# by 0x12999211: doProlog (xmlparse.c:3678) -# by 0x1299C3F0: prologInitProcessor (xmlparse.c:3550) -# by 0x12991EA3: XML_ParseBuffer (xmlparse.c:1562) -# by 0x1298F8EC: xmlparse_Parse (pyexpat.c:895) -# by 0x47B3A1: PyEval_EvalFrameEx (ceval.c:3565) -# by 0x47CCAC: PyEval_EvalCodeEx (ceval.c:2739) -# by 0x47CDE1: PyEval_EvalCode (ceval.c:490) -# by 0x499820: PyRun_SimpleFileExFlags (pythonrun.c:1198) -# by 0x4117F1: Py_Main (main.c:492) -# by 0x12476D1F: __libc_start_main (in /lib/libc-2.3.5.so) -# by 0x410DC9: (within /home/neal/build/python/svn/clean/python) -# Address 0x12704020 is 264 bytes inside a block of size 592 free'd -# at 0x11B1BA8A: free (vg_replace_malloc.c:235) -# by 0x124B5F18: (within /lib/libc-2.3.5.so) -# by 0x48DE43: find_module (import.c:1320) -# by 0x48E997: import_submodule (import.c:2249) -# by 0x48EC15: load_next (import.c:2083) -# by 0x48F091: import_module_ex (import.c:1914) -# by 0x48F385: PyImport_ImportModuleEx (import.c:1955) -# by 0x46D070: builtin___import__ (bltinmodule.c:44) -# by 0x4186CF: PyObject_Call (abstract.c:1777) -# by 0x474E9B: PyEval_CallObjectWithKeywords (ceval.c:3432) -# by 0x47928E: PyEval_EvalFrameEx (ceval.c:2038) -# by 0x47CCAC: PyEval_EvalCodeEx (ceval.c:2739) -# by 0x47CDE1: PyEval_EvalCode (ceval.c:490) -# by 0x48D0F7: PyImport_ExecCodeModuleEx (import.c:635) -# by 0x48D4F4: load_source_module (import.c:913) +from xml.parsers import expat + +# http://python.org/sf/1296433 + +def test_parse_only_xml_data(): + # + xml = "%s" % ('a' * 1025) + # this one doesn't crash + #xml = "%s" % ('a' * 10000) + + def handler(text): + raise Exception + + parser = expat.ParserCreate() + parser.CharacterDataHandler = handler + + try: + parser.Parse(xml) + except: + pass + +if __name__ == '__main__': + test_parse_only_xml_data() + +# Invalid read of size 4 +# at 0x43F936: PyObject_Free (obmalloc.c:735) +# by 0x45A7C7: unicode_dealloc (unicodeobject.c:246) +# by 0x1299021D: PyUnknownEncodingHandler (pyexpat.c:1314) +# by 0x12993A66: processXmlDecl (xmlparse.c:3330) +# by 0x12999211: doProlog (xmlparse.c:3678) +# by 0x1299C3F0: prologInitProcessor (xmlparse.c:3550) +# by 0x12991EA3: XML_ParseBuffer (xmlparse.c:1562) +# by 0x1298F8EC: xmlparse_Parse (pyexpat.c:895) +# by 0x47B3A1: PyEval_EvalFrameEx (ceval.c:3565) +# by 0x47CCAC: PyEval_EvalCodeEx (ceval.c:2739) +# by 0x47CDE1: PyEval_EvalCode (ceval.c:490) +# by 0x499820: PyRun_SimpleFileExFlags (pythonrun.c:1198) +# by 0x4117F1: Py_Main (main.c:492) +# by 0x12476D1F: __libc_start_main (in /lib/libc-2.3.5.so) +# by 0x410DC9: (within /home/neal/build/python/svn/clean/python) +# Address 0x12704020 is 264 bytes inside a block of size 592 free'd +# at 0x11B1BA8A: free (vg_replace_malloc.c:235) +# by 0x124B5F18: (within /lib/libc-2.3.5.so) +# by 0x48DE43: find_module (import.c:1320) +# by 0x48E997: import_submodule (import.c:2249) +# by 0x48EC15: load_next (import.c:2083) +# by 0x48F091: import_module_ex (import.c:1914) +# by 0x48F385: PyImport_ImportModuleEx (import.c:1955) +# by 0x46D070: builtin___import__ (bltinmodule.c:44) +# by 0x4186CF: PyObject_Call (abstract.c:1777) +# by 0x474E9B: PyEval_CallObjectWithKeywords (ceval.c:3432) +# by 0x47928E: PyEval_EvalFrameEx (ceval.c:2038) +# by 0x47CCAC: PyEval_EvalCodeEx (ceval.c:2739) +# by 0x47CDE1: PyEval_EvalCode (ceval.c:490) +# by 0x48D0F7: PyImport_ExecCodeModuleEx (import.c:635) +# by 0x48D4F4: load_source_module (import.c:913) Modified: python/trunk/Lib/test/outstanding_bugs.py ============================================================================== --- python/trunk/Lib/test/outstanding_bugs.py (original) +++ python/trunk/Lib/test/outstanding_bugs.py Wed Mar 1 07:19:04 2006 @@ -1,27 +1,27 @@ -# -# This file is for everybody to add tests for bugs that aren't -# fixed yet. Please add a test case and appropriate bug description. -# -# When you fix one of the bugs, please move the test to the correct -# test_ module. -# - -import unittest -from test import test_support - -class TestBug1385040(unittest.TestCase): - def testSyntaxError(self): - import compiler - - # The following snippet gives a SyntaxError in the interpreter - # - # If you compile and exec it, the call foo(7) returns (7, 1) - self.assertRaises(SyntaxError, compiler.compile, - "def foo(a=1, b): return a, b\n\n", "", "exec") - - -def test_main(): - test_support.run_unittest(TestBug1385040) - -if __name__ == "__main__": - test_main() +# +# This file is for everybody to add tests for bugs that aren't +# fixed yet. Please add a test case and appropriate bug description. +# +# When you fix one of the bugs, please move the test to the correct +# test_ module. +# + +import unittest +from test import test_support + +class TestBug1385040(unittest.TestCase): + def testSyntaxError(self): + import compiler + + # The following snippet gives a SyntaxError in the interpreter + # + # If you compile and exec it, the call foo(7) returns (7, 1) + self.assertRaises(SyntaxError, compiler.compile, + "def foo(a=1, b): return a, b\n\n", "", "exec") + + +def test_main(): + test_support.run_unittest(TestBug1385040) + +if __name__ == "__main__": + test_main() Modified: python/trunk/Lib/test/test_exception_variations.py ============================================================================== --- python/trunk/Lib/test/test_exception_variations.py (original) +++ python/trunk/Lib/test/test_exception_variations.py Wed Mar 1 07:19:04 2006 @@ -1,180 +1,180 @@ - -from test.test_support import run_unittest -import unittest - -class ExceptionTestCase(unittest.TestCase): - def test_try_except_else_finally(self): - hit_except = False - hit_else = False - hit_finally = False - - try: - raise Exception, 'nyaa!' - except: - hit_except = True - else: - hit_else = True - finally: - hit_finally = True - - self.assertTrue(hit_except) - self.assertTrue(hit_finally) - self.assertFalse(hit_else) - - def test_try_except_else_finally_no_exception(self): - hit_except = False - hit_else = False - hit_finally = False - - try: - pass - except: - hit_except = True - else: - hit_else = True - finally: - hit_finally = True - - self.assertFalse(hit_except) - self.assertTrue(hit_finally) - self.assertTrue(hit_else) - - def test_try_except_finally(self): - hit_except = False - hit_finally = False - - try: - raise Exception, 'yarr!' - except: - hit_except = True - finally: - hit_finally = True - - self.assertTrue(hit_except) - self.assertTrue(hit_finally) - - def test_try_except_finally_no_exception(self): - hit_except = False - hit_finally = False - - try: - pass - except: - hit_except = True - finally: - hit_finally = True - - self.assertFalse(hit_except) - self.assertTrue(hit_finally) - - def test_try_except(self): - hit_except = False - - try: - raise Exception, 'ahoy!' - except: - hit_except = True - - self.assertTrue(hit_except) - - def test_try_except_no_exception(self): - hit_except = False - - try: - pass - except: - hit_except = True - - self.assertFalse(hit_except) - - def test_try_except_else(self): - hit_except = False - hit_else = False - - try: - raise Exception, 'foo!' - except: - hit_except = True - else: - hit_else = True - - self.assertFalse(hit_else) - self.assertTrue(hit_except) - - def test_try_except_else_no_exception(self): - hit_except = False - hit_else = False - - try: - pass - except: - hit_except = True - else: - hit_else = True - - self.assertFalse(hit_except) - self.assertTrue(hit_else) - - def test_try_finally_no_exception(self): - hit_finally = False - - try: - pass - finally: - hit_finally = True - - self.assertTrue(hit_finally) - - def test_nested(self): - hit_finally = False - hit_inner_except = False - hit_inner_finally = False - - try: - try: - raise Exception, 'inner exception' - except: - hit_inner_except = True - finally: - hit_inner_finally = True - finally: - hit_finally = True - - self.assertTrue(hit_inner_except) - self.assertTrue(hit_inner_finally) - self.assertTrue(hit_finally) - - def test_nested_else(self): - hit_else = False - hit_finally = False - hit_except = False - hit_inner_except = False - hit_inner_else = False - - try: - try: - pass - except: - hit_inner_except = True - else: - hit_inner_else = True - - raise Exception, 'outer exception' - except: - hit_except = True - else: - hit_else = True - finally: - hit_finally = True - - self.assertFalse(hit_inner_except) - self.assertTrue(hit_inner_else) - self.assertFalse(hit_else) - self.assertTrue(hit_finally) - self.assertTrue(hit_except) - -def test_main(): - run_unittest(ExceptionTestCase) - -if __name__ == '__main__': - test_main() + +from test.test_support import run_unittest +import unittest + +class ExceptionTestCase(unittest.TestCase): + def test_try_except_else_finally(self): + hit_except = False + hit_else = False + hit_finally = False + + try: + raise Exception, 'nyaa!' + except: + hit_except = True + else: + hit_else = True + finally: + hit_finally = True + + self.assertTrue(hit_except) + self.assertTrue(hit_finally) + self.assertFalse(hit_else) + + def test_try_except_else_finally_no_exception(self): + hit_except = False + hit_else = False + hit_finally = False + + try: + pass + except: + hit_except = True + else: + hit_else = True + finally: + hit_finally = True + + self.assertFalse(hit_except) + self.assertTrue(hit_finally) + self.assertTrue(hit_else) + + def test_try_except_finally(self): + hit_except = False + hit_finally = False + + try: + raise Exception, 'yarr!' + except: + hit_except = True + finally: + hit_finally = True + + self.assertTrue(hit_except) + self.assertTrue(hit_finally) + + def test_try_except_finally_no_exception(self): + hit_except = False + hit_finally = False + + try: + pass + except: + hit_except = True + finally: + hit_finally = True + + self.assertFalse(hit_except) + self.assertTrue(hit_finally) + + def test_try_except(self): + hit_except = False + + try: + raise Exception, 'ahoy!' + except: + hit_except = True + + self.assertTrue(hit_except) + + def test_try_except_no_exception(self): + hit_except = False + + try: + pass + except: + hit_except = True + + self.assertFalse(hit_except) + + def test_try_except_else(self): + hit_except = False + hit_else = False + + try: + raise Exception, 'foo!' + except: + hit_except = True + else: + hit_else = True + + self.assertFalse(hit_else) + self.assertTrue(hit_except) + + def test_try_except_else_no_exception(self): + hit_except = False + hit_else = False + + try: + pass + except: + hit_except = True + else: + hit_else = True + + self.assertFalse(hit_except) + self.assertTrue(hit_else) + + def test_try_finally_no_exception(self): + hit_finally = False + + try: + pass + finally: + hit_finally = True + + self.assertTrue(hit_finally) + + def test_nested(self): + hit_finally = False + hit_inner_except = False + hit_inner_finally = False + + try: + try: + raise Exception, 'inner exception' + except: + hit_inner_except = True + finally: + hit_inner_finally = True + finally: + hit_finally = True + + self.assertTrue(hit_inner_except) + self.assertTrue(hit_inner_finally) + self.assertTrue(hit_finally) + + def test_nested_else(self): + hit_else = False + hit_finally = False + hit_except = False + hit_inner_except = False + hit_inner_else = False + + try: + try: + pass + except: + hit_inner_except = True + else: + hit_inner_else = True + + raise Exception, 'outer exception' + except: + hit_except = True + else: + hit_else = True + finally: + hit_finally = True + + self.assertFalse(hit_inner_except) + self.assertTrue(hit_inner_else) + self.assertFalse(hit_else) + self.assertTrue(hit_finally) + self.assertTrue(hit_except) + +def test_main(): + run_unittest(ExceptionTestCase) + +if __name__ == '__main__': + test_main() From python-checkins at python.org Wed Mar 1 07:28:58 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 07:28:58 +0100 (CET) Subject: [Python-checkins] r42725 - in python/trunk/PC: example_nt/readme.txt os2vacpp/readme.txt readme.txt testpy.py Message-ID: <20060301062858.A21541E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 07:28:58 2006 New Revision: 42725 Modified: python/trunk/PC/example_nt/readme.txt (contents, props changed) python/trunk/PC/os2vacpp/readme.txt (props changed) python/trunk/PC/readme.txt (contents, props changed) python/trunk/PC/testpy.py (contents, props changed) Log: Remove svn:mime-type (inexplicably set to a binary type), and set svn:eol-style to native, on some text files. Modified: python/trunk/PC/example_nt/readme.txt ============================================================================== Binary files. No diff available. Modified: python/trunk/PC/readme.txt ============================================================================== Binary files. No diff available. Modified: python/trunk/PC/testpy.py ============================================================================== Binary files. No diff available. From python-checkins at python.org Wed Mar 1 09:59:13 2006 From: python-checkins at python.org (neal.norwitz) Date: Wed, 1 Mar 2006 09:59:13 +0100 (CET) Subject: [Python-checkins] r42726 - peps/trunk/pep-0000.txt Message-ID: <20060301085913.B74F91E4002@bag.python.org> Author: neal.norwitz Date: Wed Mar 1 09:59:06 2006 New Revision: 42726 Modified: peps/trunk/pep-0000.txt Log: Forgot to update both places for the status Modified: peps/trunk/pep-0000.txt ============================================================================== --- peps/trunk/pep-0000.txt (original) +++ peps/trunk/pep-0000.txt Wed Mar 1 09:59:06 2006 @@ -405,7 +405,7 @@ SD 349 Allow str() to return unicode strings Schemenauer I 350 Codetags Elliott SR 351 The freeze protocol Warsaw - SA 352 Required Superclass for Exceptions GvR, Cannon + SF 352 Required Superclass for Exceptions GvR, Cannon SA 353 Using ssize_t as the index type von Loewis S 354 Enumerations in Python Finney S 355 Path - Object oriented filesystem paths Lindqvist From nnorwitz at gmail.com Wed Mar 1 10:07:12 2006 From: nnorwitz at gmail.com (Neal Norwitz) Date: Wed, 1 Mar 2006 01:07:12 -0800 Subject: [Python-checkins] r42718 - peps/trunk/pep-3000.txt In-Reply-To: <9e804ac0602282156s65daf829j208f073146570861@mail.gmail.com> References: <20060301053251.39C231E4002@bag.python.org> <004901c63cf4$0b6e90c0$6a01a8c0@RaymondLaptop1> <9e804ac0602282156s65daf829j208f073146570861@mail.gmail.com> Message-ID: On 2/28/06, Thomas Wouters wrote: > On 3/1/06, Raymond Hettinger wrote: > > > -* Return iterators instead of lists where appropriate for atomic type methods > > > - (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) > > > - (Do we keep iter*() methods or remove them? I vote remove. -- nn) > > > > The last line doesn't make sense to me. I had thought the direction was to keep > > simple names like range(), dict.items(), dict.keys(), and dict.values() and have > > them return an iterator instead of a list. When that is done, then the current > > iterator versions will be redundant and we can kill-off the weird names like > > xrange(), dict.iter_items(), dict.iter_keys(), and dict.iter_values(). > > I can't read Neal's original question as anything other than a > suggestion to do exactly that, asking for confirmation. I agree with > his suggestion, and I guess you do too :-) Right and so does Guido. dict.iter*() methods will be removed in 3. We made a bunch more modifications to the PEP, but we didn't have internet access while in the airport. n From neal at metaslash.com Wed Mar 1 11:30:20 2006 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 1 Mar 2006 05:30:20 -0500 Subject: [Python-checkins] Python Regression Test Failures refleak (80) Message-ID: <20060301103020.GA5496@python.psfb.org> test_opcodes leaked [32, 32, 32] references test_builtin leaked [109, 109, 109] references test_exceptions leaked [1, 1, 1] references test___all__ leaked [397, 397, 397] references test__locale leaked [2, 2, 2] references test_array leaked [134, 134, 134] references test_ast leaked [175, 175, 175] references test_audioop leaked [77, 77, 77] references test_binop leaked [51, 51, 51] references test_bisect leaked [26, 26, 26] references test_bool leaked [2, 2, 2] references test_cProfile leaked [1, 1, 1] references test_cfgparser leaked [0, 0, -54] references test_class leaked [193, 193, 193] references test_cmd_line leaked [0, 15, -15] references test_code leaked [41, 41, 41] references test_codecmaps_cn leaked [58985, 58985, 58985] references test_codecmaps_hk leaked [9636, 9636, 9636] references test_codecmaps_jp leaked [101531, 101531, 101531] references test_codecmaps_kr leaked [85342, 85342, 85342] references test_codecmaps_tw leaked [54682, 54682, 54682] references test_codeop leaked [220, 220, 220] references test_coercion leaked [2187, 2187, 2187] references test_compile leaked [25175, 25175, 25175] references test_compiler leaked [3736, 2016, 978] references test_cookie leaked [132, 132, 132] references test_datetime leaked [60, 60, 60] references test_decorators leaked [26, 26, 26] references test_deque leaked [317, 317, 317] references test_descr leaked [5830, 5830, 5830] references test_descrtut leaked [355, 355, 355] references test_distutils leaked [45, 45, 45] references test_doctest leaked [2736, 2736, 2736] references test_doctest2 leaked [37, 37, 37] references test_dumbdbm leaked [351, 345, 324] references test_extcall leaked [689, 689, 689] references test_funcattrs leaked [3, 3, 3] references test_future leaked [110, 110, 110] references test_gc leaked [1, 1, 1] references test_generators leaked [1459, 1459, 1459] references test_genexps leaked [307, 307, 307] references test_getopt leaked [90, 90, 90] references test_gettext leaked [130, 130, 130] references test_global leaked [18, 18, 18] references test_import leaked [65027, 65027, 65027] references test_itertools leaked [372, 372, 372] references test_long leaked [86, 86, 86] references test_long_future leaked [36, 36, 36] references test_longexp leaked [65580, 65580, 65580] references test_math leaked [1, 1, 1] references test_new leaked [8, 8, 8] references test_ntpath leaked [280, 280, 280] references test_parser leaked [8, 8, 8] references test_peepholer leaked [97, 97, 97] references test_pep352 leaked [1, 1, 1] references test_pickle leaked [28, 28, 28] references test_pickletools leaked [324, 324, 324] references test_pkg leaked [143, 143, 143] references test_pkgimport leaked [3, 3, 3] references test_popen leaked [11, 11, 11] references test_profile leaked [1, 1, 1] references test_re leaked [680, 680, 680] references test_regex leaked [225, 225, 225] references test_scope leaked [67, 67, 67] references test_set leaked [120, 120, 120] references test_sets leaked [183, 183, 183] references test_site leaked [2, 2, 2] references test_socket_ssl leaked [20, 0, 0] references test_symtable leaked [5, 5, 5] references test_syntax leaked [85, 85, 85] references test_sys leaked [3, 3, 3] references test_threadedtempfile leaked [4, 1, 0] references test_threading_local leaked [278, 270, 278] references test_traceback leaked [9, 9, 9] references test_transformer leaked [14, 14, 14] references test_ucn leaked [49, 49, 49] references test_unary leaked [14, 14, 14] references test_unittest leaked [22, 22, 22] references test_univnewlines leaked [35, 35, 35] references test_unpack leaked [123, 123, 123] references test_urllib2 leaked [80, -130, 70] references test_weakref leaked [128, 128, 128] references test_xml_etree leaked [323, 323, 323] references test_xml_etree_c leaked [280, 280, 280] references test_zipimport leaked [50, 50, 50] references test_inspect leaked [30, 30, 30] references test_grammar leaked [49, 49, 49] references From neal at metaslash.com Wed Mar 1 11:52:52 2006 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 1 Mar 2006 05:52:52 -0500 Subject: [Python-checkins] Python Regression Test Failures doc (1) Message-ID: <20060301105252.GA7271@python.psfb.org> TEXINPUTS=/home/neal/python/trunk/Doc/commontex: python /home/neal/python/trunk/Doc/tools/mkhowto --html --about html/stdabout.dat --iconserver ../icons --favicon ../icons/pyfav.png --address "See About this document... for information on suggesting changes." --up-link ../index.html --up-title "Python Documentation Index" --global-module-index "../modindex.html" --dvips-safe --dir html/api api/api.tex *** Session transcript and error messages are in /home/neal/python/trunk/Doc/html/api/api.how. *** Exited with status 1. The relevant lines from the transcript are: ------------------------------------------------------------------------ +++ latex api This is TeX, Version 3.14159 (Web2C 7.4.5) (/home/neal/python/trunk/Doc/api/api.tex LaTeX2e <2001/06/01> Babel and hyphenation patterns for american, french, german, ngerman, n ohyphenation, loaded. (/home/neal/python/trunk/Doc/texinputs/manual.cls Document Class: manual 1998/03/03 Document class (Python manual) (/home/neal/python/trunk/Doc/texinputs/pypaper.sty (/usr/share/texmf/tex/latex/psnfss/times.sty) Using Times instead of Computer Modern. ) (/usr/share/texmf/tex/latex/misc/fancybox.sty Style option: `fancybox' v1.3 <2000/09/19> (tvz) ) (/usr/share/texmf/tex/latex/base/report.cls Document Class: report 2001/04/21 v1.4e Standard LaTeX document class (/usr/share/texmf/tex/latex/base/size10.clo)) (/home/neal/python/trunk/Doc/texinputs/fancyhdr.sty) Using fancier footers than usual. (/home/neal/python/trunk/Doc/texinputs/fncychap.sty) Using fancy chapter headings. (/home/neal/python/trunk/Doc/texinputs/python.sty (/usr/share/texmf/tex/latex/tools/longtable.sty) (/home/neal/python/trunk/Doc/texinputs/underscore.sty) (/usr/share/texmf/tex/latex/tools/verbatim.sty) (/usr/share/texmf/tex/latex/base/alltt.sty))) (/home/neal/python/trunk/Doc/commontex/boilerplate.tex (/home/neal/python/trunk/Doc/commontex/patchlevel.tex)) Writing index file api.idx No file api.aux. (/usr/share/texmf/tex/latex/psnfss/ot1ptm.fd) (/usr/share/texmf/tex/latex/psnfss/ot1phv.fd) [1] (/home/neal/python/trunk/Doc/commontex/copyright.tex (/usr/share/texmf/tex/latex/psnfss/omsptm.fd)) [2] Adding blank page after the abstract. [1] [2] No file api.toc. Adding blank page after the table of contents. [1] [2] (/home/neal/python/trunk/Doc/api/intro.tex Chapter 1. (/usr/share/texmf/tex/latex/psnfss/ot1pcr.fd) Underfull \hbox (badness 10000) in paragraph at lines 45--46 [1] [2] [3] [4] [5] [6] [7]) (/home/neal/python/trunk/Doc/api/veryhigh.tex [8] Chapter 2. [9] [10]) (/home/neal/python/trunk/Doc/api/refcounting.tex [11] [12] Chapter 3. ) (/home/neal/python/trunk/Doc/api/exceptions.tex [13] [14] Chapter 4. [15] [16] [17] [18]) (/home/neal/python/trunk/Doc/api/utilities.tex [19] [20] Chapter 5. [21] [22] [23] [24] Underfull \hbox (badness 10000) in paragraph at lines 450--453 []\OT1/ptm/m/n/10 This [25] Underfull \hbox (badness 10000) in paragraph at lines 471--474 [] Overfull \hbox (68.01pt too wide) in paragraph at lines 477--481 [] Underfull \hbox (badness 10000) in paragraph at lines 513--516 [] [26] [27] [28] [29]) Runaway argument? {Py_ssize_t) to a Python integer or long integer. \versionadded {2.5}\ETC. ! File ended while scanning use of \ctype. \par l.43 \input{utilities} ? ! Emergency stop. \par l.43 \input{utilities} Output written on api.dvi (35 pages, 111836 bytes). Transcript written on api.log. *** Session transcript and error messages are in /home/neal/python/trunk/Doc/html/api/api.how. *** Exited with status 1. +++ TEXINPUTS=/home/neal/python/trunk/Doc/api:/home/neal/python/trunk/Doc/commontex:/home/neal/python/trunk/Doc/paper-letter:/home/neal/python/trunk/Doc/texinputs: +++ latex api make: *** [html/api/api.html] Error 1 From dynkin at gmail.com Wed Mar 1 12:29:18 2006 From: dynkin at gmail.com (George Yoshida) Date: Wed, 1 Mar 2006 20:29:18 +0900 Subject: [Python-checkins] Python Regression Test Failures doc (1) In-Reply-To: <20060301105252.GA7271@python.psfb.org> References: <20060301105252.GA7271@python.psfb.org> Message-ID: <2f188ee80603010329i57c0cd19wf49447fdb6d51fe3@mail.gmail.com> Index: Doc/api/utilities.tex =================================================================== --- Doc/api/utilities.tex (revision 42726) +++ Doc/api/utilities.tex (working copy) @@ -871,7 +871,7 @@ Only available on platforms that support \ctype{unsigned long long}. \item[\samp{n} (int) {[Py_ssize_t]}] - Convert a C \ctype{Py_ssize_t) to a Python integer or long integer. + Convert a C \ctype{Py_ssize_t} to a Python integer or long integer. \versionadded{2.5} -- george On 3/1/06, Neal Norwitz wrote: > TEXINPUTS=/home/neal/python/trunk/Doc/commontex: python /home/neal/python/trunk/Doc/tools/mkhowto --html --about html/stdabout.dat --iconserver ../icons --favicon ../icons/pyfav.png --address "See About this document... for information on suggesting changes." --up-link ../index.html --up-title "Python Documentation Index" --global-module-index "../modindex.html" --dvips-safe --dir html/api api/api.tex > *** Session transcript and error messages are in /home/neal/python/trunk/Doc/html/api/api.how. > *** Exited with status 1. From python-checkins at python.org Wed Mar 1 13:43:55 2006 From: python-checkins at python.org (fredrik.lundh) Date: Wed, 1 Mar 2006 13:43:55 +0100 (CET) Subject: [Python-checkins] r42727 - python/trunk/Doc/api/utilities.tex Message-ID: <20060301124355.DB8BC1E4002@bag.python.org> Author: fredrik.lundh Date: Wed Mar 1 13:43:53 2006 New Revision: 42727 Modified: python/trunk/Doc/api/utilities.tex Log: markup glitch (spotted by George Yoshida) Modified: python/trunk/Doc/api/utilities.tex ============================================================================== --- python/trunk/Doc/api/utilities.tex (original) +++ python/trunk/Doc/api/utilities.tex Wed Mar 1 13:43:53 2006 @@ -871,7 +871,7 @@ Only available on platforms that support \ctype{unsigned long long}. \item[\samp{n} (int) {[Py_ssize_t]}] - Convert a C \ctype{Py_ssize_t) to a Python integer or long integer. + Convert a C \ctype{Py_ssize_t} to a Python integer or long integer. \versionadded{2.5} \item[\samp{c} (string of length 1) {[char]}] From python-checkins at python.org Wed Mar 1 16:02:25 2006 From: python-checkins at python.org (jeremy.hylton) Date: Wed, 1 Mar 2006 16:02:25 +0100 (CET) Subject: [Python-checkins] r42728 - python/trunk/Python/pyarena.c Message-ID: <20060301150225.75D2F1E4002@bag.python.org> Author: jeremy.hylton Date: Wed Mar 1 16:02:24 2006 New Revision: 42728 Modified: python/trunk/Python/pyarena.c Log: Add missing DECREF. Modified: python/trunk/Python/pyarena.c ============================================================================== --- python/trunk/Python/pyarena.c (original) +++ python/trunk/Python/pyarena.c Wed Mar 1 16:02:24 2006 @@ -159,5 +159,9 @@ int PyArena_AddPyObject(PyArena *arena, PyObject *obj) { - return PyList_Append(arena->a_objects, obj) >= 0; + int r = PyList_Append(arena->a_objects, obj); + if (r >= 0) { + Py_DECREF(obj); + } + return r; } From python-checkins at python.org Wed Mar 1 16:47:07 2006 From: python-checkins at python.org (jeremy.hylton) Date: Wed, 1 Mar 2006 16:47:07 +0100 (CET) Subject: [Python-checkins] r42729 - python/trunk/Python/compile.c Message-ID: <20060301154707.488C01E42A8@bag.python.org> Author: jeremy.hylton Date: Wed Mar 1 16:47:05 2006 New Revision: 42729 Modified: python/trunk/Python/compile.c Log: Tabify and reflow some long lines. Much of the peephole optimizer is now indented badly, but it's about to be revised anyway. Modified: python/trunk/Python/compile.c ============================================================================== --- python/trunk/Python/compile.c (original) +++ python/trunk/Python/compile.c Wed Mar 1 16:47:05 2006 @@ -5,18 +5,18 @@ * PyCodeObject. The compiler makes several passes to build the code * object: * 1. Checks for future statements. See future.c - * 2. Builds a symbol table. See symtable.c. - * 3. Generate code for basic blocks. See compiler_mod() in this file. + * 2. Builds a symbol table. See symtable.c. + * 3. Generate code for basic blocks. See compiler_mod() in this file. * 4. Assemble the basic blocks into final code. See assemble() in - * this file. + * this file. * * Note that compiler_mod() suggests module, but the module ast type * (mod_ty) has cases for expressions and interactive statements. * - * CAUTION: The VISIT_* macros abort the current function when they encounter - * a problem. So don't invoke them when there is memory which needs to be - * released. Code blocks are OK, as the compiler structure takes care of - * releasing those. + * CAUTION: The VISIT_* macros abort the current function when they + * encounter a problem. So don't invoke them when there is memory + * which needs to be released. Code blocks are OK, as the compiler + * structure takes care of releasing those. */ #include "Python.h" @@ -33,16 +33,16 @@ int Py_OptimizeFlag = 0; /* - ISSUES: + ISSUES: - character encodings aren't handled + character encodings aren't handled - ref leaks in interpreter when press return on empty line + ref leaks in interpreter when press return on empty line - opcode_stack_effect() function should be reviewed since stack depth bugs - could be really hard to find later. + opcode_stack_effect() function should be reviewed since stack depth bugs + could be really hard to find later. - Dead code is being generated (i.e. after unconditional jumps). + Dead code is being generated (i.e. after unconditional jumps). */ #define DEFAULT_BLOCK_SIZE 16 @@ -80,20 +80,20 @@ /* depth of stack upon entry of block, computed by stackdepth() */ int b_startdepth; /* instruction offset for block, computed by assemble_jump_offsets() */ - int b_offset; + int b_offset; } basicblock; /* fblockinfo tracks the current frame block. - A frame block is used to handle loops, try/except, and try/finally. - It's called a frame block to distinguish it from a basic block in the - compiler IR. +A frame block is used to handle loops, try/except, and try/finally. +It's called a frame block to distinguish it from a basic block in the +compiler IR. */ enum fblocktype { LOOP, EXCEPT, FINALLY_TRY, FINALLY_END }; struct fblockinfo { - enum fblocktype fb_type; + enum fblocktype fb_type; basicblock *fb_block; }; @@ -105,7 +105,7 @@ PyObject *u_name; /* The following fields are dicts that map objects to - the index of them in co_XXX. The index is used as + the index of them in co_XXX. The index is used as the argument for opcodes that refer to those collections. */ PyObject *u_consts; /* all constants */ @@ -116,50 +116,50 @@ PyObject *u_private; /* for private name mangling */ - int u_argcount; /* number of arguments for block */ + int u_argcount; /* number of arguments for block */ basicblock *u_blocks; /* pointer to list of blocks */ basicblock *u_curblock; /* pointer to current block */ - int u_tmpname; /* temporary variables for list comps */ + int u_tmpname; /* temporary variables for list comps */ int u_nfblocks; struct fblockinfo u_fblock[CO_MAXBLOCKS]; int u_firstlineno; /* the first lineno of the block */ - int u_lineno; /* the lineno for the current stmt */ + int u_lineno; /* the lineno for the current stmt */ bool u_lineno_set; /* boolean to indicate whether instr has been generated with current lineno */ }; /* This struct captures the global state of a compilation. - The u pointer points to the current compilation unit, while units - for enclosing blocks are stored in c_stack. The u and c_stack are - managed by compiler_enter_scope() and compiler_exit_scope(). +The u pointer points to the current compilation unit, while units +for enclosing blocks are stored in c_stack. The u and c_stack are +managed by compiler_enter_scope() and compiler_exit_scope(). */ struct compiler { const char *c_filename; struct symtable *c_st; - PyFutureFeatures *c_future; /* pointer to module's __future__ */ + PyFutureFeatures *c_future; /* pointer to module's __future__ */ PyCompilerFlags *c_flags; int c_interactive; - int c_nestlevel; + int c_nestlevel; - struct compiler_unit *u; /* compiler state for current block */ - PyObject *c_stack; /* Python list holding compiler_unit ptrs */ + struct compiler_unit *u; /* compiler state for current block */ + PyObject *c_stack; /* Python list holding compiler_unit ptrs */ char *c_encoding; /* source encoding (a borrowed reference) */ - PyArena *c_arena; /* pointer to memory allocation arena */ + PyArena *c_arena; /* pointer to memory allocation arena */ }; struct assembler { PyObject *a_bytecode; /* string containing bytecode */ - int a_offset; /* offset into bytecode */ - int a_nblocks; /* number of reachable blocks */ + int a_offset; /* offset into bytecode */ + int a_nblocks; /* number of reachable blocks */ basicblock **a_postorder; /* list of blocks in dfs postorder */ PyObject *a_lnotab; /* string containing lnotab */ int a_lnotab_off; /* offset into lnotab */ - int a_lineno; /* last lineno of emitted instruction */ + int a_lineno; /* last lineno of emitted instruction */ int a_lineno_off; /* bytecode offset of last lineno */ }; @@ -201,33 +201,34 @@ { /* Name mangling: __private becomes _classname__private. This is independent from how the name is used. */ - const char *p, *name = PyString_AsString(ident); - char *buffer; + const char *p, *name = PyString_AsString(ident); + char *buffer; size_t nlen, plen; - if (private == NULL || name == NULL || name[0] != '_' || name[1] != '_') { - Py_INCREF(ident); + if (private == NULL || name == NULL || name[0] != '_' || + name[1] != '_') { + Py_INCREF(ident); return ident; - } - p = PyString_AsString(private); + } + p = PyString_AsString(private); nlen = strlen(name); if (name[nlen-1] == '_' && name[nlen-2] == '_') { - Py_INCREF(ident); + Py_INCREF(ident); return ident; /* Don't mangle __whatever__ */ - } + } /* Strip leading underscores from class name */ while (*p == '_') p++; if (*p == '\0') { - Py_INCREF(ident); + Py_INCREF(ident); return ident; /* Don't mangle if class is just underscores */ - } + } plen = strlen(p); - ident = PyString_FromStringAndSize(NULL, 1 + nlen + plen); - if (!ident) - return 0; + ident = PyString_FromStringAndSize(NULL, 1 + nlen + plen); + if (!ident) + return 0; /* ident = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */ - buffer = PyString_AS_STRING(ident); - buffer[0] = '_'; + buffer = PyString_AS_STRING(ident); + buffer[0] = '_'; strncpy(buffer+1, p, plen); strcpy(buffer+1+plen, name); return ident; @@ -247,35 +248,35 @@ PyCodeObject * PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags, - PyArena *arena) + PyArena *arena) { struct compiler c; PyCodeObject *co = NULL; - PyCompilerFlags local_flags; - int merged; + PyCompilerFlags local_flags; + int merged; - if (!__doc__) { - __doc__ = PyString_InternFromString("__doc__"); - if (!__doc__) - return NULL; - } + if (!__doc__) { + __doc__ = PyString_InternFromString("__doc__"); + if (!__doc__) + return NULL; + } if (!compiler_init(&c)) return NULL; c.c_filename = filename; - c.c_arena = arena; + c.c_arena = arena; c.c_future = PyFuture_FromAST(mod, filename); if (c.c_future == NULL) goto finally; if (!flags) { - local_flags.cf_flags = 0; - flags = &local_flags; - } - merged = c.c_future->ff_features | flags->cf_flags; - c.c_future->ff_features = merged; - flags->cf_flags = merged; - c.c_flags = flags; - c.c_nestlevel = 0; + local_flags.cf_flags = 0; + flags = &local_flags; + } + merged = c.c_future->ff_features | flags->cf_flags; + c.c_future->ff_features = merged; + flags->cf_flags = merged; + c.c_flags = flags; + c.c_nestlevel = 0; c.c_st = PySymtable_Build(mod, filename, c.c_future); if (c.c_st == NULL) { @@ -299,11 +300,11 @@ PyNode_Compile(struct _node *n, const char *filename) { PyCodeObject *co = NULL; - PyArena *arena = PyArena_New(); + PyArena *arena = PyArena_New(); mod_ty mod = PyAST_FromNode(n, NULL, filename, arena); if (mod) co = PyAST_Compile(mod, filename, NULL, arena); - PyArena_Free(arena); + PyArena_Free(arena); return co; } @@ -330,8 +331,8 @@ Py_DECREF(dict); return NULL; } - k = PyList_GET_ITEM(list, i); - k = Py_BuildValue("(OO)", k, k->ob_type); + k = PyList_GET_ITEM(list, i); + k = Py_BuildValue("(OO)", k, k->ob_type); if (k == NULL || PyDict_SetItem(dict, k, v) < 0) { Py_XDECREF(k); Py_DECREF(v); @@ -346,10 +347,10 @@ /* Return new dict containing names from src that match scope(s). - src is a symbol table dictionary. If the scope of a name matches - either scope_type or flag is set, insert it into the new dict. The - values are integers, starting at offset and increasing by one for - each key. +src is a symbol table dictionary. If the scope of a name matches +either scope_type or flag is set, insert it into the new dict. The +values are integers, starting at offset and increasing by one for +each key. */ static PyObject * @@ -358,32 +359,32 @@ Py_ssize_t pos = 0, i = offset, scope; PyObject *k, *v, *dest = PyDict_New(); - assert(offset >= 0); - if (dest == NULL) - return NULL; + assert(offset >= 0); + if (dest == NULL) + return NULL; while (PyDict_Next(src, &pos, &k, &v)) { - /* XXX this should probably be a macro in symtable.h */ - assert(PyInt_Check(v)); - scope = (PyInt_AS_LONG(v) >> SCOPE_OFF) & SCOPE_MASK; - - if (scope == scope_type || PyInt_AS_LONG(v) & flag) { - PyObject *tuple, *item = PyInt_FromLong(i); - if (item == NULL) { - Py_DECREF(dest); - return NULL; - } - i++; - tuple = Py_BuildValue("(OO)", k, k->ob_type); - if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) { + /* XXX this should probably be a macro in symtable.h */ + assert(PyInt_Check(v)); + scope = (PyInt_AS_LONG(v) >> SCOPE_OFF) & SCOPE_MASK; + + if (scope == scope_type || PyInt_AS_LONG(v) & flag) { + PyObject *tuple, *item = PyInt_FromLong(i); + if (item == NULL) { + Py_DECREF(dest); + return NULL; + } + i++; + tuple = Py_BuildValue("(OO)", k, k->ob_type); + if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) { + Py_DECREF(item); + Py_DECREF(dest); + Py_XDECREF(tuple); + return NULL; + } Py_DECREF(item); - Py_DECREF(dest); - Py_XDECREF(tuple); - return NULL; + Py_DECREF(tuple); } - Py_DECREF(item); - Py_DECREF(tuple); - } } return dest; } @@ -391,17 +392,18 @@ /* Begin: Peephole optimizations ----------------------------------------- */ #define GETARG(arr, i) ((int)((arr[i+2]<<8) + arr[i+1])) -#define UNCONDITIONAL_JUMP(op) (op==JUMP_ABSOLUTE || op==JUMP_FORWARD) +#define UNCONDITIONAL_JUMP(op) (op==JUMP_ABSOLUTE || op==JUMP_FORWARD) #define ABSOLUTE_JUMP(op) (op==JUMP_ABSOLUTE || op==CONTINUE_LOOP) #define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3)) #define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255 #define CODESIZE(op) (HAS_ARG(op) ? 3 : 1) -#define ISBASICBLOCK(blocks, start, bytes) (blocks[start]==blocks[start+bytes-1]) +#define ISBASICBLOCK(blocks, start, bytes) \ + (blocks[start]==blocks[start+bytes-1]) /* Replace LOAD_CONST c1. LOAD_CONST c2 ... LOAD_CONST cn BUILD_TUPLE n - with LOAD_CONST (c1, c2, ... cn). + with LOAD_CONST (c1, c2, ... cn). The consts table must still be in list form so that the - new constant (c1, c2, ... cn) can be appended. + new constant (c1, c2, ... cn) can be appended. Called with codestr pointing to the first LOAD_CONST. Bails out with no change if one or more of the LOAD_CONSTs is missing. Also works for BUILD_LIST when followed by an "in" or "not in" test. @@ -448,14 +450,14 @@ } /* Replace LOAD_CONST c1. LOAD_CONST c2 BINOP - with LOAD_CONST binop(c1,c2) + with LOAD_CONST binop(c1,c2) The consts table must still be in list form so that the - new constant can be appended. + new constant can be appended. Called with codestr pointing to the first LOAD_CONST. Abandons the transformation if the folding fails (i.e. 1+'a'). If the new constant is a sequence, only folds when the size - is below a threshold value. That keeps pyc files from - becoming large in the presence of code like: (None,)*1000. + is below a threshold value. That keeps pyc files from + becoming large in the presence of code like: (None,)*1000. */ static int fold_binops_on_constants(unsigned char *codestr, PyObject *consts) @@ -474,55 +476,56 @@ w = PyList_GET_ITEM(consts, GETARG(codestr, 3)); opcode = codestr[6]; switch (opcode) { - case BINARY_POWER: - newconst = PyNumber_Power(v, w, Py_None); - break; - case BINARY_MULTIPLY: - newconst = PyNumber_Multiply(v, w); - break; - case BINARY_DIVIDE: - /* Cannot fold this operation statically since - the result can depend on the run-time presence of the -Qnew flag */ - return 0; - case BINARY_TRUE_DIVIDE: - newconst = PyNumber_TrueDivide(v, w); - break; - case BINARY_FLOOR_DIVIDE: - newconst = PyNumber_FloorDivide(v, w); - break; - case BINARY_MODULO: - newconst = PyNumber_Remainder(v, w); - break; - case BINARY_ADD: - newconst = PyNumber_Add(v, w); - break; - case BINARY_SUBTRACT: - newconst = PyNumber_Subtract(v, w); - break; - case BINARY_SUBSCR: - newconst = PyObject_GetItem(v, w); - break; - case BINARY_LSHIFT: - newconst = PyNumber_Lshift(v, w); - break; - case BINARY_RSHIFT: - newconst = PyNumber_Rshift(v, w); - break; - case BINARY_AND: - newconst = PyNumber_And(v, w); - break; - case BINARY_XOR: - newconst = PyNumber_Xor(v, w); - break; - case BINARY_OR: - newconst = PyNumber_Or(v, w); - break; - default: - /* Called with an unknown opcode */ - PyErr_Format(PyExc_SystemError, + case BINARY_POWER: + newconst = PyNumber_Power(v, w, Py_None); + break; + case BINARY_MULTIPLY: + newconst = PyNumber_Multiply(v, w); + break; + case BINARY_DIVIDE: + /* Cannot fold this operation statically since + the result can depend on the run-time presence + of the -Qnew flag */ + return 0; + case BINARY_TRUE_DIVIDE: + newconst = PyNumber_TrueDivide(v, w); + break; + case BINARY_FLOOR_DIVIDE: + newconst = PyNumber_FloorDivide(v, w); + break; + case BINARY_MODULO: + newconst = PyNumber_Remainder(v, w); + break; + case BINARY_ADD: + newconst = PyNumber_Add(v, w); + break; + case BINARY_SUBTRACT: + newconst = PyNumber_Subtract(v, w); + break; + case BINARY_SUBSCR: + newconst = PyObject_GetItem(v, w); + break; + case BINARY_LSHIFT: + newconst = PyNumber_Lshift(v, w); + break; + case BINARY_RSHIFT: + newconst = PyNumber_Rshift(v, w); + break; + case BINARY_AND: + newconst = PyNumber_And(v, w); + break; + case BINARY_XOR: + newconst = PyNumber_Xor(v, w); + break; + case BINARY_OR: + newconst = PyNumber_Or(v, w); + break; + default: + /* Called with an unknown opcode */ + PyErr_Format(PyExc_SystemError, "unexpected binary operation %d on a constant", - opcode); - return 0; + opcode); + return 0; } if (newconst == NULL) { PyErr_Clear(); @@ -566,23 +569,23 @@ v = PyList_GET_ITEM(consts, GETARG(codestr, 0)); opcode = codestr[3]; switch (opcode) { - case UNARY_NEGATIVE: - /* Preserve the sign of -0.0 */ - if (PyObject_IsTrue(v) == 1) - newconst = PyNumber_Negative(v); - break; - case UNARY_CONVERT: - newconst = PyObject_Repr(v); - break; - case UNARY_INVERT: - newconst = PyNumber_Invert(v); - break; - default: - /* Called with an unknown opcode */ - PyErr_Format(PyExc_SystemError, + case UNARY_NEGATIVE: + /* Preserve the sign of -0.0 */ + if (PyObject_IsTrue(v) == 1) + newconst = PyNumber_Negative(v); + break; + case UNARY_CONVERT: + newconst = PyObject_Repr(v); + break; + case UNARY_INVERT: + newconst = PyNumber_Invert(v); + break; + default: + /* Called with an unknown opcode */ + PyErr_Format(PyExc_SystemError, "unexpected unary operation %d on a constant", - opcode); - return 0; + opcode); + return 0; } if (newconst == NULL) { PyErr_Clear(); @@ -629,12 +632,12 @@ case SETUP_FINALLY: j = GETJUMPTGT(code, i); blocks[j] = 1; - break; + break; } } /* Build block numbers in the second pass */ for (i=0 ; i= 255. Optimizations are restricted to simple transformations occuring within a - single basic block. All transformations keep the code size the same or + single basic block. All transformations keep the code size the same or smaller. For those that reduce size, the gaps are initially filled with NOPs. Later those NOPs are removed and the jump addresses retargeted in a single pass. Line numbering is adjusted accordingly. */ static PyObject * -optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *lineno_obj) +optimize_code(PyObject *code, PyObject* consts, PyObject *names, + PyObject *lineno_obj) { Py_ssize_t i, j, codelen; int nops, h, adj; @@ -665,7 +669,7 @@ unsigned char *lineno; int *addrmap = NULL; int new_line, cum_orig_line, last_line, tabsiz; - int cumlc=0, lastlc=0; /* Count runs of consecutive LOAD_CONST codes */ + int cumlc=0, lastlc=0; /* Count runs of consecutive LOAD_CONSTs */ unsigned int *blocks = NULL; char *name; @@ -692,7 +696,7 @@ goto exitUnchanged; codestr = memcpy(codestr, PyString_AS_STRING(code), codelen); - /* Verify that RETURN_VALUE terminates the codestring. This allows + /* Verify that RETURN_VALUE terminates the codestring. This allows the various transformation patterns to look ahead several instructions without additional checks to make sure they are not looking beyond the end of the code string. @@ -718,206 +722,208 @@ switch (opcode) { - /* Replace UNARY_NOT JUMP_IF_FALSE POP_TOP with - with JUMP_IF_TRUE POP_TOP */ - case UNARY_NOT: - if (codestr[i+1] != JUMP_IF_FALSE || - codestr[i+4] != POP_TOP || - !ISBASICBLOCK(blocks,i,5)) - continue; - tgt = GETJUMPTGT(codestr, (i+1)); - if (codestr[tgt] != POP_TOP) - continue; - j = GETARG(codestr, i+1) + 1; - codestr[i] = JUMP_IF_TRUE; - SETARG(codestr, i, j); - codestr[i+3] = POP_TOP; - codestr[i+4] = NOP; - break; + /* Replace UNARY_NOT JUMP_IF_FALSE POP_TOP with + with JUMP_IF_TRUE POP_TOP */ + case UNARY_NOT: + if (codestr[i+1] != JUMP_IF_FALSE || + codestr[i+4] != POP_TOP || + !ISBASICBLOCK(blocks,i,5)) + continue; + tgt = GETJUMPTGT(codestr, (i+1)); + if (codestr[tgt] != POP_TOP) + continue; + j = GETARG(codestr, i+1) + 1; + codestr[i] = JUMP_IF_TRUE; + SETARG(codestr, i, j); + codestr[i+3] = POP_TOP; + codestr[i+4] = NOP; + break; - /* not a is b --> a is not b - not a in b --> a not in b - not a is not b --> a is b - not a not in b --> a in b - */ - case COMPARE_OP: - j = GETARG(codestr, i); - if (j < 6 || j > 9 || - codestr[i+3] != UNARY_NOT || - !ISBASICBLOCK(blocks,i,4)) - continue; - SETARG(codestr, i, (j^1)); - codestr[i+3] = NOP; - break; + /* not a is b --> a is not b + not a in b --> a not in b + not a is not b --> a is b + not a not in b --> a in b + */ + case COMPARE_OP: + j = GETARG(codestr, i); + if (j < 6 || j > 9 || + codestr[i+3] != UNARY_NOT || + !ISBASICBLOCK(blocks,i,4)) + continue; + SETARG(codestr, i, (j^1)); + codestr[i+3] = NOP; + break; - /* Replace LOAD_GLOBAL/LOAD_NAME None with LOAD_CONST None */ - case LOAD_NAME: - case LOAD_GLOBAL: - j = GETARG(codestr, i); - name = PyString_AsString(PyTuple_GET_ITEM(names, j)); - if (name == NULL || strcmp(name, "None") != 0) - continue; - for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) { - if (PyList_GET_ITEM(consts, j) == Py_None) { - codestr[i] = LOAD_CONST; - SETARG(codestr, i, j); - cumlc = lastlc + 1; - break; + /* Replace LOAD_GLOBAL/LOAD_NAME None + with LOAD_CONST None */ + case LOAD_NAME: + case LOAD_GLOBAL: + j = GETARG(codestr, i); + name = PyString_AsString(PyTuple_GET_ITEM(names, j)); + if (name == NULL || strcmp(name, "None") != 0) + continue; + for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) { + if (PyList_GET_ITEM(consts, j) == Py_None) { + codestr[i] = LOAD_CONST; + SETARG(codestr, i, j); + cumlc = lastlc + 1; + break; + } } - } - break; - - /* Skip over LOAD_CONST trueconst JUMP_IF_FALSE xx POP_TOP */ - case LOAD_CONST: - cumlc = lastlc + 1; - j = GETARG(codestr, i); - if (codestr[i+3] != JUMP_IF_FALSE || - codestr[i+6] != POP_TOP || - !ISBASICBLOCK(blocks,i,7) || - !PyObject_IsTrue(PyList_GET_ITEM(consts, j))) - continue; - memset(codestr+i, NOP, 7); - cumlc = 0; - break; + break; - /* Try to fold tuples of constants (includes a case for lists - which are only used for "in" and "not in" tests). - Skip over BUILD_SEQN 1 UNPACK_SEQN 1. - Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2. - Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */ - case BUILD_TUPLE: - case BUILD_LIST: - j = GETARG(codestr, i); - h = i - 3 * j; - if (h >= 0 && - j <= lastlc && - ((opcode == BUILD_TUPLE && - ISBASICBLOCK(blocks, h, 3*(j+1))) || - (opcode == BUILD_LIST && - codestr[i+3]==COMPARE_OP && - ISBASICBLOCK(blocks, h, 3*(j+2)) && - (GETARG(codestr,i+3)==6 || - GETARG(codestr,i+3)==7))) && - tuple_of_constants(&codestr[h], j, consts)) { - assert(codestr[i] == LOAD_CONST); - cumlc = 1; + /* Skip over LOAD_CONST trueconst + JUMP_IF_FALSE xx POP_TOP */ + case LOAD_CONST: + cumlc = lastlc + 1; + j = GETARG(codestr, i); + if (codestr[i+3] != JUMP_IF_FALSE || + codestr[i+6] != POP_TOP || + !ISBASICBLOCK(blocks,i,7) || + !PyObject_IsTrue(PyList_GET_ITEM(consts, j))) + continue; + memset(codestr+i, NOP, 7); + cumlc = 0; break; - } - if (codestr[i+3] != UNPACK_SEQUENCE || - !ISBASICBLOCK(blocks,i,6) || - j != GETARG(codestr, i+3)) - continue; - if (j == 1) { - memset(codestr+i, NOP, 6); - } else if (j == 2) { - codestr[i] = ROT_TWO; - memset(codestr+i+1, NOP, 5); - } else if (j == 3) { - codestr[i] = ROT_THREE; - codestr[i+1] = ROT_TWO; - memset(codestr+i+2, NOP, 4); - } - break; - /* Fold binary ops on constants. - LOAD_CONST c1 LOAD_CONST c2 BINOP --> LOAD_CONST binop(c1,c2) */ - case BINARY_POWER: - case BINARY_MULTIPLY: - case BINARY_TRUE_DIVIDE: - case BINARY_FLOOR_DIVIDE: - case BINARY_MODULO: - case BINARY_ADD: - case BINARY_SUBTRACT: - case BINARY_SUBSCR: - case BINARY_LSHIFT: - case BINARY_RSHIFT: - case BINARY_AND: - case BINARY_XOR: - case BINARY_OR: - if (lastlc >= 2 && - ISBASICBLOCK(blocks, i-6, 7) && - fold_binops_on_constants(&codestr[i-6], consts)) { - i -= 2; - assert(codestr[i] == LOAD_CONST); - cumlc = 1; - } - break; + /* Try to fold tuples of constants (includes a case for lists + which are only used for "in" and "not in" tests). + Skip over BUILD_SEQN 1 UNPACK_SEQN 1. + Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2. + Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */ + case BUILD_TUPLE: + case BUILD_LIST: + j = GETARG(codestr, i); + h = i - 3 * j; + if (h >= 0 && + j <= lastlc && + ((opcode == BUILD_TUPLE && + ISBASICBLOCK(blocks, h, 3*(j+1))) || + (opcode == BUILD_LIST && + codestr[i+3]==COMPARE_OP && + ISBASICBLOCK(blocks, h, 3*(j+2)) && + (GETARG(codestr,i+3)==6 || + GETARG(codestr,i+3)==7))) && + tuple_of_constants(&codestr[h], j, consts)) { + assert(codestr[i] == LOAD_CONST); + cumlc = 1; + break; + } + if (codestr[i+3] != UNPACK_SEQUENCE || + !ISBASICBLOCK(blocks,i,6) || + j != GETARG(codestr, i+3)) + continue; + if (j == 1) { + memset(codestr+i, NOP, 6); + } else if (j == 2) { + codestr[i] = ROT_TWO; + memset(codestr+i+1, NOP, 5); + } else if (j == 3) { + codestr[i] = ROT_THREE; + codestr[i+1] = ROT_TWO; + memset(codestr+i+2, NOP, 4); + } + break; - /* Fold unary ops on constants. - LOAD_CONST c1 UNARY_OP --> LOAD_CONST unary_op(c) */ - case UNARY_NEGATIVE: - case UNARY_CONVERT: - case UNARY_INVERT: - if (lastlc >= 1 && - ISBASICBLOCK(blocks, i-3, 4) && - fold_unaryops_on_constants(&codestr[i-3], consts)) { - i -= 2; - assert(codestr[i] == LOAD_CONST); - cumlc = 1; - } - break; + /* Fold binary ops on constants. + LOAD_CONST c1 LOAD_CONST c2 BINOP --> LOAD_CONST binop(c1,c2) */ + case BINARY_POWER: + case BINARY_MULTIPLY: + case BINARY_TRUE_DIVIDE: + case BINARY_FLOOR_DIVIDE: + case BINARY_MODULO: + case BINARY_ADD: + case BINARY_SUBTRACT: + case BINARY_SUBSCR: + case BINARY_LSHIFT: + case BINARY_RSHIFT: + case BINARY_AND: + case BINARY_XOR: + case BINARY_OR: + if (lastlc >= 2 && + ISBASICBLOCK(blocks, i-6, 7) && + fold_binops_on_constants(&codestr[i-6], consts)) { + i -= 2; + assert(codestr[i] == LOAD_CONST); + cumlc = 1; + } + break; - /* Simplify conditional jump to conditional jump where the - result of the first test implies the success of a similar - test or the failure of the opposite test. - Arises in code like: - "if a and b:" - "if a or b:" - "a and b or c" - "(a and b) and c" - x:JUMP_IF_FALSE y y:JUMP_IF_FALSE z --> x:JUMP_IF_FALSE z - x:JUMP_IF_FALSE y y:JUMP_IF_TRUE z --> x:JUMP_IF_FALSE y+3 - where y+3 is the instruction following the second test. - */ - case JUMP_IF_FALSE: - case JUMP_IF_TRUE: - tgt = GETJUMPTGT(codestr, i); - j = codestr[tgt]; - if (j == JUMP_IF_FALSE || j == JUMP_IF_TRUE) { - if (j == opcode) { - tgttgt = GETJUMPTGT(codestr, tgt) - i - 3; - SETARG(codestr, i, tgttgt); - } else { - tgt -= i; - SETARG(codestr, i, tgt); + /* Fold unary ops on constants. + LOAD_CONST c1 UNARY_OP --> LOAD_CONST unary_op(c) */ + case UNARY_NEGATIVE: + case UNARY_CONVERT: + case UNARY_INVERT: + if (lastlc >= 1 && + ISBASICBLOCK(blocks, i-3, 4) && + fold_unaryops_on_constants(&codestr[i-3], consts)) { + i -= 2; + assert(codestr[i] == LOAD_CONST); + cumlc = 1; } break; - } - /* Intentional fallthrough */ - /* Replace jumps to unconditional jumps */ - case FOR_ITER: - case JUMP_FORWARD: - case JUMP_ABSOLUTE: - case CONTINUE_LOOP: - case SETUP_LOOP: - case SETUP_EXCEPT: - case SETUP_FINALLY: - tgt = GETJUMPTGT(codestr, i); - if (!UNCONDITIONAL_JUMP(codestr[tgt])) - continue; - tgttgt = GETJUMPTGT(codestr, tgt); - if (opcode == JUMP_FORWARD) /* JMP_ABS can go backwards */ - opcode = JUMP_ABSOLUTE; - if (!ABSOLUTE_JUMP(opcode)) - tgttgt -= i + 3; /* Calc relative jump addr */ - if (tgttgt < 0) /* No backward relative jumps */ - continue; - codestr[i] = opcode; - SETARG(codestr, i, tgttgt); - break; + /* Simplify conditional jump to conditional jump where the + result of the first test implies the success of a similar + test or the failure of the opposite test. + Arises in code like: + "if a and b:" + "if a or b:" + "a and b or c" + "(a and b) and c" + x:JUMP_IF_FALSE y y:JUMP_IF_FALSE z --> x:JUMP_IF_FALSE z + x:JUMP_IF_FALSE y y:JUMP_IF_TRUE z --> x:JUMP_IF_FALSE y+3 + where y+3 is the instruction following the second test. + */ + case JUMP_IF_FALSE: + case JUMP_IF_TRUE: + tgt = GETJUMPTGT(codestr, i); + j = codestr[tgt]; + if (j == JUMP_IF_FALSE || j == JUMP_IF_TRUE) { + if (j == opcode) { + tgttgt = GETJUMPTGT(codestr, tgt) - i - 3; + SETARG(codestr, i, tgttgt); + } else { + tgt -= i; + SETARG(codestr, i, tgt); + } + break; + } + /* Intentional fallthrough */ - case EXTENDED_ARG: - goto exitUnchanged; + /* Replace jumps to unconditional jumps */ + case FOR_ITER: + case JUMP_FORWARD: + case JUMP_ABSOLUTE: + case CONTINUE_LOOP: + case SETUP_LOOP: + case SETUP_EXCEPT: + case SETUP_FINALLY: + tgt = GETJUMPTGT(codestr, i); + if (!UNCONDITIONAL_JUMP(codestr[tgt])) + continue; + tgttgt = GETJUMPTGT(codestr, tgt); + if (opcode == JUMP_FORWARD) /* JMP_ABS can go backwards */ + opcode = JUMP_ABSOLUTE; + if (!ABSOLUTE_JUMP(opcode)) + tgttgt -= i + 3; /* Calc relative jump addr */ + if (tgttgt < 0) /* No backward relative jumps */ + continue; + codestr[i] = opcode; + SETARG(codestr, i, tgttgt); + break; - /* Replace RETURN LOAD_CONST None RETURN with just RETURN */ - case RETURN_VALUE: - if (i+4 >= codelen || - codestr[i+4] != RETURN_VALUE || - !ISBASICBLOCK(blocks,i,5)) - continue; - memset(codestr+i+1, NOP, 4); - break; + case EXTENDED_ARG: + goto exitUnchanged; + + /* Replace RETURN LOAD_CONST None RETURN with just RETURN */ + case RETURN_VALUE: + if (i+4 >= codelen || + codestr[i+4] != RETURN_VALUE || + !ISBASICBLOCK(blocks,i,5)) + continue; + memset(codestr+i+1, NOP, 4); + break; } } @@ -974,7 +980,7 @@ PyMem_Free(blocks); return code; -exitUnchanged: + exitUnchanged: if (blocks != NULL) PyMem_Free(blocks); if (addrmap != NULL) @@ -994,36 +1000,36 @@ static void compiler_display_symbols(PyObject *name, PyObject *symbols) { - PyObject *key, *value; - int flags; - Py_ssize_t pos = 0; - - fprintf(stderr, "block %s\n", PyString_AS_STRING(name)); - while (PyDict_Next(symbols, &pos, &key, &value)) { - flags = PyInt_AsLong(value); - fprintf(stderr, "var %s:", PyString_AS_STRING(key)); - if (flags & DEF_GLOBAL) - fprintf(stderr, " declared_global"); - if (flags & DEF_LOCAL) - fprintf(stderr, " local"); - if (flags & DEF_PARAM) - fprintf(stderr, " param"); - if (flags & DEF_STAR) - fprintf(stderr, " stararg"); - if (flags & DEF_DOUBLESTAR) - fprintf(stderr, " starstar"); - if (flags & DEF_INTUPLE) - fprintf(stderr, " tuple"); - if (flags & DEF_FREE) - fprintf(stderr, " free"); - if (flags & DEF_FREE_GLOBAL) - fprintf(stderr, " global"); - if (flags & DEF_FREE_CLASS) - fprintf(stderr, " free/class"); - if (flags & DEF_IMPORT) - fprintf(stderr, " import"); - fprintf(stderr, "\n"); - } +PyObject *key, *value; +int flags; +Py_ssize_t pos = 0; + +fprintf(stderr, "block %s\n", PyString_AS_STRING(name)); +while (PyDict_Next(symbols, &pos, &key, &value)) { +flags = PyInt_AsLong(value); +fprintf(stderr, "var %s:", PyString_AS_STRING(key)); +if (flags & DEF_GLOBAL) +fprintf(stderr, " declared_global"); +if (flags & DEF_LOCAL) +fprintf(stderr, " local"); +if (flags & DEF_PARAM) +fprintf(stderr, " param"); +if (flags & DEF_STAR) +fprintf(stderr, " stararg"); +if (flags & DEF_DOUBLESTAR) +fprintf(stderr, " starstar"); +if (flags & DEF_INTUPLE) +fprintf(stderr, " tuple"); +if (flags & DEF_FREE) +fprintf(stderr, " free"); +if (flags & DEF_FREE_GLOBAL) +fprintf(stderr, " global"); +if (flags & DEF_FREE_CLASS) +fprintf(stderr, " free/class"); +if (flags & DEF_IMPORT) +fprintf(stderr, " import"); +fprintf(stderr, "\n"); +} fprintf(stderr, "\n"); } */ @@ -1081,22 +1087,22 @@ u = PyObject_Malloc(sizeof(struct compiler_unit)); if (!u) { - PyErr_NoMemory(); - return 0; + PyErr_NoMemory(); + return 0; } - memset(u, 0, sizeof(struct compiler_unit)); + memset(u, 0, sizeof(struct compiler_unit)); u->u_argcount = 0; u->u_ste = PySymtable_Lookup(c->c_st, key); if (!u->u_ste) { - compiler_unit_free(u); - return 0; + compiler_unit_free(u); + return 0; } Py_INCREF(name); u->u_name = name; u->u_varnames = list2dict(u->u_ste->ste_varnames); u->u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, 0, 0); u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE, DEF_FREE_CLASS, - PyDict_Size(u->u_cellvars)); + PyDict_Size(u->u_cellvars)); u->u_blocks = NULL; u->u_tmpname = 0; @@ -1106,31 +1112,31 @@ u->u_lineno_set = false; u->u_consts = PyDict_New(); if (!u->u_consts) { - compiler_unit_free(u); + compiler_unit_free(u); return 0; } u->u_names = PyDict_New(); if (!u->u_names) { - compiler_unit_free(u); + compiler_unit_free(u); return 0; } - u->u_private = NULL; + u->u_private = NULL; /* Push the old compiler_unit on the stack. */ if (c->u) { PyObject *wrapper = PyCObject_FromVoidPtr(c->u, NULL); if (PyList_Append(c->c_stack, wrapper) < 0) { - compiler_unit_free(u); + compiler_unit_free(u); return 0; } Py_DECREF(wrapper); - u->u_private = c->u->u_private; - Py_XINCREF(u->u_private); + u->u_private = c->u->u_private; + Py_XINCREF(u->u_private); } c->u = u; - c->c_nestlevel++; + c->c_nestlevel++; if (compiler_use_new_block(c) == NULL) return 0; @@ -1143,7 +1149,7 @@ int n; PyObject *wrapper; - c->c_nestlevel--; + c->c_nestlevel--; compiler_unit_free(c->u); /* Restore c->u to the parent unit. */ n = PyList_GET_SIZE(c->c_stack) - 1; @@ -1234,7 +1240,7 @@ compiler_next_instr(struct compiler *c, basicblock *b) { assert(b != NULL); - if (b->b_instr == NULL) { + if (b->b_instr == NULL) { b->b_instr = PyObject_Malloc(sizeof(struct instr) * DEFAULT_BLOCK_SIZE); if (b->b_instr == NULL) { @@ -1244,7 +1250,7 @@ b->b_ialloc = DEFAULT_BLOCK_SIZE; memset((char *)b->b_instr, 0, sizeof(struct instr) * DEFAULT_BLOCK_SIZE); - } + } else if (b->b_iused == b->b_ialloc) { size_t oldsize, newsize; oldsize = b->b_ialloc * sizeof(struct instr); @@ -1270,7 +1276,7 @@ return; c->u->u_lineno_set = true; b = c->u->u_curblock; - b->b_instr[off].i_lineno = c->u->u_lineno; + b->b_instr[off].i_lineno = c->u->u_lineno; } static int @@ -1520,10 +1526,10 @@ PyObject *t, *v; Py_ssize_t arg; - /* necessary to make sure types aren't coerced (e.g., int and long) */ - t = PyTuple_Pack(2, o, o->ob_type); - if (t == NULL) - return -1; + /* necessary to make sure types aren't coerced (e.g., int and long) */ + t = PyTuple_Pack(2, o, o->ob_type); + if (t == NULL) + return -1; v = PyDict_GetItem(dict, t); if (!v) { @@ -1532,7 +1538,7 @@ if (!v) { Py_DECREF(t); return -1; - } + } if (PyDict_SetItem(dict, t, v) < 0) { Py_DECREF(t); Py_DECREF(v); @@ -1543,7 +1549,7 @@ else arg = PyInt_AsLong(v); Py_DECREF(t); - return arg; + return arg; } static int @@ -1552,22 +1558,22 @@ { int arg = compiler_add_o(c, dict, o); if (arg < 0) - return 0; + return 0; return compiler_addop_i(c, opcode, arg); } static int compiler_addop_name(struct compiler *c, int opcode, PyObject *dict, - PyObject *o) + PyObject *o) { int arg; PyObject *mangled = _Py_Mangle(c->u->u_private, o); if (!mangled) - return 0; + return 0; arg = compiler_add_o(c, dict, mangled); Py_DECREF(mangled); if (arg < 0) - return 0; + return 0; return compiler_addop_i(c, opcode, arg); } @@ -1613,8 +1619,8 @@ return 1; } -/* The distinction between NEW_BLOCK and NEXT_BLOCK is subtle. (I'd - like to find better names.) NEW_BLOCK() creates a new block and sets +/* The distinction between NEW_BLOCK and NEXT_BLOCK is subtle. (I'd + like to find better names.) NEW_BLOCK() creates a new block and sets it as the current block. NEXT_BLOCK() also creates an implicit jump from the current block to the new block. */ @@ -1625,13 +1631,13 @@ #define NEW_BLOCK(C) { \ - if (compiler_use_new_block((C)) == NULL) \ - return 0; \ + if (compiler_use_new_block((C)) == NULL) \ + return 0; \ } #define NEXT_BLOCK(C) { \ - if (compiler_next_block((C)) == NULL) \ - return 0; \ + if (compiler_next_block((C)) == NULL) \ + return 0; \ } #define ADDOP(C, OP) { \ @@ -1718,7 +1724,7 @@ compiler_isdocstring(stmt_ty s) { if (s->kind != Expr_kind) - return 0; + return 0; return s->v.Expr.value->kind == Str_kind; } @@ -1739,8 +1745,8 @@ if (!compiler_nameop(c, __doc__, Store)) return 0; } - for (; i < asdl_seq_LEN(stmts); i++) - VISIT(c, stmt, asdl_seq_GET(stmts, i)); + for (; i < asdl_seq_LEN(stmts); i++) + VISIT(c, stmt, asdl_seq_GET(stmts, i)); return 1; } @@ -1748,7 +1754,7 @@ compiler_mod(struct compiler *c, mod_ty mod) { PyCodeObject *co; - int addNone = 1; + int addNone = 1; static PyObject *module; if (!module) { module = PyString_FromString(""); @@ -1770,13 +1776,13 @@ break; case Expression_kind: VISIT_IN_SCOPE(c, expr, mod->v.Expression.body); - addNone = 0; + addNone = 0; break; case Suite_kind: PyErr_SetString(PyExc_SystemError, "suite should not be possible"); return 0; - default: + default: PyErr_Format(PyExc_SystemError, "module kind %d should not be possible", mod->kind); @@ -1796,23 +1802,23 @@ get_ref_type(struct compiler *c, PyObject *name) { int scope = PyST_GetScope(c->u->u_ste, name); - if (scope == 0) { - char buf[350]; - PyOS_snprintf(buf, sizeof(buf), - "unknown scope for %.100s in %.100s(%s) in %s\n" - "symbols: %s\nlocals: %s\nglobals: %s\n", - PyString_AS_STRING(name), - PyString_AS_STRING(c->u->u_name), - PyObject_REPR(c->u->u_ste->ste_id), - c->c_filename, - PyObject_REPR(c->u->u_ste->ste_symbols), - PyObject_REPR(c->u->u_varnames), - PyObject_REPR(c->u->u_names) + if (scope == 0) { + char buf[350]; + PyOS_snprintf(buf, sizeof(buf), + "unknown scope for %.100s in %.100s(%s) in %s\n" + "symbols: %s\nlocals: %s\nglobals: %s\n", + PyString_AS_STRING(name), + PyString_AS_STRING(c->u->u_name), + PyObject_REPR(c->u->u_ste->ste_id), + c->c_filename, + PyObject_REPR(c->u->u_ste->ste_symbols), + PyObject_REPR(c->u->u_varnames), + PyObject_REPR(c->u->u_names) ); - Py_FatalError(buf); - } + Py_FatalError(buf); + } - return scope; + return scope; } static int @@ -1821,11 +1827,11 @@ PyObject *k, *v; k = Py_BuildValue("(OO)", name, name->ob_type); if (k == NULL) - return -1; + return -1; v = PyDict_GetItem(dict, k); Py_DECREF(k); if (v == NULL) - return -1; + return -1; return PyInt_AS_LONG(v); } @@ -1834,10 +1840,10 @@ { int i, free = PyCode_GetNumFree(co); if (free == 0) { - ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts); - ADDOP_I(c, MAKE_FUNCTION, args); - return 1; - } + ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts); + ADDOP_I(c, MAKE_FUNCTION, args); + return 1; + } for (i = 0; i < free; ++i) { /* Bypass com_addop_varname because it will generate LOAD_DEREF but LOAD_CLOSURE is needed. @@ -1868,10 +1874,10 @@ } ADDOP_I(c, LOAD_CLOSURE, arg); } - ADDOP_I(c, BUILD_TUPLE, free); + ADDOP_I(c, BUILD_TUPLE, free); ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts); - ADDOP_I(c, MAKE_CLOSURE, args); - return 1; + ADDOP_I(c, MAKE_CLOSURE, args); + return 1; } static int @@ -1906,7 +1912,7 @@ return 0; } Py_DECREF(id); - VISIT(c, expr, arg); + VISIT(c, expr, arg); } } return 1; @@ -1916,10 +1922,10 @@ compiler_function(struct compiler *c, stmt_ty s) { PyCodeObject *co; - PyObject *first_const = Py_None; + PyObject *first_const = Py_None; arguments_ty args = s->v.FunctionDef.args; asdl_seq* decos = s->v.FunctionDef.decorators; - stmt_ty st; + stmt_ty st; int i, n, docstring; assert(s->kind == FunctionDef_kind); @@ -1932,21 +1938,21 @@ s->lineno)) return 0; - st = asdl_seq_GET(s->v.FunctionDef.body, 0); - docstring = compiler_isdocstring(st); - if (docstring) - first_const = st->v.Expr.value->v.Str.s; - if (compiler_add_o(c, c->u->u_consts, first_const) < 0) { + st = asdl_seq_GET(s->v.FunctionDef.body, 0); + docstring = compiler_isdocstring(st); + if (docstring) + first_const = st->v.Expr.value->v.Str.s; + if (compiler_add_o(c, c->u->u_consts, first_const) < 0) { compiler_exit_scope(c); - return 0; + return 0; } - /* unpack nested arguments */ + /* unpack nested arguments */ compiler_arguments(c, args); c->u->u_argcount = asdl_seq_LEN(args->args); n = asdl_seq_LEN(s->v.FunctionDef.body); - /* if there was a docstring, we need to skip the first statement */ + /* if there was a docstring, we need to skip the first statement */ for (i = docstring; i < n; i++) { stmt_ty s2 = asdl_seq_GET(s->v.FunctionDef.body, i); if (i == 0 && s2->kind == Expr_kind && @@ -1959,7 +1965,7 @@ if (co == NULL) return 0; - compiler_make_closure(c, co, asdl_seq_LEN(args->defaults)); + compiler_make_closure(c, co, asdl_seq_LEN(args->defaults)); Py_DECREF(co); for (i = 0; i < asdl_seq_LEN(decos); i++) { @@ -1974,7 +1980,7 @@ { int n; PyCodeObject *co; - PyObject *str; + PyObject *str; /* push class name on stack, needed by BUILD_CLASS */ ADDOP_O(c, LOAD_CONST, s->v.ClassDef.name, consts); /* push the tuple of base classes on the stack */ @@ -1985,23 +1991,23 @@ if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s, s->lineno)) return 0; - c->u->u_private = s->v.ClassDef.name; - Py_INCREF(c->u->u_private); - str = PyString_InternFromString("__name__"); + c->u->u_private = s->v.ClassDef.name; + Py_INCREF(c->u->u_private); + str = PyString_InternFromString("__name__"); if (!str || !compiler_nameop(c, str, Load)) { Py_XDECREF(str); compiler_exit_scope(c); return 0; - } - - Py_DECREF(str); - str = PyString_InternFromString("__module__"); + } + + Py_DECREF(str); + str = PyString_InternFromString("__module__"); if (!str || !compiler_nameop(c, str, Store)) { Py_XDECREF(str); compiler_exit_scope(c); return 0; - } - Py_DECREF(str); + } + Py_DECREF(str); if (!compiler_body(c, s->v.ClassDef.body)) { compiler_exit_scope(c); @@ -2015,7 +2021,7 @@ if (co == NULL) return 0; - compiler_make_closure(c, co, 0); + compiler_make_closure(c, co, 0); Py_DECREF(co); ADDOP_I(c, CALL_FUNCTION, 0); @@ -2068,7 +2074,7 @@ if (!compiler_enter_scope(c, name, (void *)e, e->lineno)) return 0; - /* unpack nested arguments */ + /* unpack nested arguments */ compiler_arguments(c, args); c->u->u_argcount = asdl_seq_LEN(args->args); @@ -2079,7 +2085,7 @@ if (co == NULL) return 0; - compiler_make_closure(c, co, asdl_seq_LEN(args->defaults)); + compiler_make_closure(c, co, asdl_seq_LEN(args->defaults)); Py_DECREF(co); return 1; @@ -2131,18 +2137,18 @@ end = compiler_new_block(c); if (end == NULL) return 0; - next = compiler_new_block(c); - if (next == NULL) - return 0; - VISIT(c, expr, s->v.If.test); - ADDOP_JREL(c, JUMP_IF_FALSE, next); - ADDOP(c, POP_TOP); - VISIT_SEQ(c, stmt, s->v.If.body); - ADDOP_JREL(c, JUMP_FORWARD, end); - compiler_use_next_block(c, next); - ADDOP(c, POP_TOP); - if (s->v.If.orelse) - VISIT_SEQ(c, stmt, s->v.If.orelse); + next = compiler_new_block(c); + if (next == NULL) + return 0; + VISIT(c, expr, s->v.If.test); + ADDOP_JREL(c, JUMP_IF_FALSE, next); + ADDOP(c, POP_TOP); + VISIT_SEQ(c, stmt, s->v.If.body); + ADDOP_JREL(c, JUMP_FORWARD, end); + compiler_use_next_block(c, next); + ADDOP(c, POP_TOP); + if (s->v.If.orelse) + VISIT_SEQ(c, stmt, s->v.If.orelse); compiler_use_next_block(c, end); return 1; } @@ -2251,7 +2257,7 @@ ADDOP_JABS(c, CONTINUE_LOOP, c->u->u_fblock[i].fb_block); break; case FINALLY_END: - return compiler_error(c, + return compiler_error(c, "'continue' not supported inside 'finally' clause"); } @@ -2340,14 +2346,14 @@ [tb, val] (or POP if no V1) [tb] POP [] - JUMP_FORWARD L0 + JUMP_FORWARD L0 [tb, val, exc, 0] L2: POP [tb, val, exc] DUP .............................etc....................... [tb, val, exc, 0] Ln+1: POP - [tb, val, exc] END_FINALLY # re-raise exception + [tb, val, exc] END_FINALLY # re-raise exception [] L0: @@ -2356,7 +2362,7 @@ static int compiler_try_except(struct compiler *c, stmt_ty s) { - basicblock *body, *orelse, *except, *end; + basicblock *body, *orelse, *except, *end; int i, n; body = compiler_new_block(c); @@ -2473,10 +2479,10 @@ if (alias->asname) { r = compiler_import_as(c, alias->name, alias->asname); - if (!r) - return r; - } - else { + if (!r) + return r; + } + else { identifier tmp = alias->name; const char *base = PyString_AS_STRING(alias->name); char *dot = strchr(base, '.'); @@ -2529,7 +2535,7 @@ Py_DECREF(names); return compiler_error(c, "from __future__ imports must occur " - "at the beginning of the file"); + "at the beginning of the file"); } } @@ -2604,11 +2610,11 @@ c->u->u_lineno = s->lineno; c->u->u_lineno_set = false; switch (s->kind) { - case FunctionDef_kind: + case FunctionDef_kind: return compiler_function(c, s); - case ClassDef_kind: + case ClassDef_kind: return compiler_class(c, s); - case Return_kind: + case Return_kind: if (c->u->u_ste->ste_type != FunctionBlock) return compiler_error(c, "'return' outside function"); if (s->v.Return.value) { @@ -2622,10 +2628,10 @@ ADDOP_O(c, LOAD_CONST, Py_None, consts); ADDOP(c, RETURN_VALUE); break; - case Delete_kind: + case Delete_kind: VISIT_SEQ(c, expr, s->v.Delete.targets) break; - case Assign_kind: + case Assign_kind: n = asdl_seq_LEN(s->v.Assign.targets); VISIT(c, expr, s->v.Assign.value); for (i = 0; i < n; i++) { @@ -2635,17 +2641,17 @@ (expr_ty)asdl_seq_GET(s->v.Assign.targets, i)); } break; - case AugAssign_kind: + case AugAssign_kind: return compiler_augassign(c, s); - case Print_kind: + case Print_kind: return compiler_print(c, s); - case For_kind: + case For_kind: return compiler_for(c, s); - case While_kind: + case While_kind: return compiler_while(c, s); - case If_kind: + case If_kind: return compiler_if(c, s); - case Raise_kind: + case Raise_kind: n = 0; if (s->v.Raise.type) { VISIT(c, expr, s->v.Raise.type); @@ -2661,17 +2667,17 @@ } ADDOP_I(c, RAISE_VARARGS, n); break; - case TryExcept_kind: + case TryExcept_kind: return compiler_try_except(c, s); - case TryFinally_kind: + case TryFinally_kind: return compiler_try_finally(c, s); - case Assert_kind: + case Assert_kind: return compiler_assert(c, s); - case Import_kind: + case Import_kind: return compiler_import(c, s); - case ImportFrom_kind: + case ImportFrom_kind: return compiler_from_import(c, s); - case Exec_kind: + case Exec_kind: VISIT(c, expr, s->v.Exec.body); if (s->v.Exec.globals) { VISIT(c, expr, s->v.Exec.globals); @@ -2686,9 +2692,9 @@ } ADDOP(c, EXEC_STMT); break; - case Global_kind: + case Global_kind: break; - case Expr_kind: + case Expr_kind: VISIT(c, expr, s->v.Expr.value); if (c->c_interactive && c->c_nestlevel <= 1) { ADDOP(c, PRINT_EXPR); @@ -2697,17 +2703,17 @@ ADDOP(c, POP_TOP); } break; - case Pass_kind: + case Pass_kind: break; - case Break_kind: + case Break_kind: if (!c->u->u_nfblocks) return compiler_error(c, "'break' outside loop"); ADDOP(c, BREAK_LOOP); break; - case Continue_kind: + case Continue_kind: return compiler_continue(c); - case With_kind: - return compiler_with(c, s); + case With_kind: + return compiler_with(c, s); } return 1; } @@ -2834,7 +2840,7 @@ int op, scope, arg; enum { OP_FAST, OP_GLOBAL, OP_DEREF, OP_NAME } optype; - PyObject *dict = c->u->u_names; + PyObject *dict = c->u->u_names; PyObject *mangled; /* XXX AugStore isn't used anywhere! */ @@ -2853,11 +2859,11 @@ scope = PyST_GetScope(c->u->u_ste, mangled); switch (scope) { case FREE: - dict = c->u->u_freevars; + dict = c->u->u_freevars; optype = OP_DEREF; break; case CELL: - dict = c->u->u_cellvars; + dict = c->u->u_cellvars; optype = OP_DEREF; break; case LOCAL: @@ -3018,7 +3024,7 @@ compiler_compare(struct compiler *c, expr_ty e) { int i, n; - basicblock *cleanup = NULL; + basicblock *cleanup = NULL; /* XXX the logic can be cleaned up for 1 or multiple comparisons */ VISIT(c, expr, e->v.Compare.left); @@ -3026,8 +3032,8 @@ assert(n > 0); if (n > 1) { cleanup = compiler_new_block(c); - if (cleanup == NULL) - return 0; + if (cleanup == NULL) + return 0; VISIT(c, expr, asdl_seq_GET(e->v.Compare.comparators, 0)); } for (i = 1; i < n; i++) { @@ -3048,8 +3054,8 @@ cmpop((cmpop_ty)asdl_seq_GET(e->v.Compare.ops, n - 1))); if (n > 1) { basicblock *end = compiler_new_block(c); - if (end == NULL) - return 0; + if (end == NULL) + return 0; ADDOP_JREL(c, JUMP_FORWARD, end); compiler_use_next_block(c, cleanup); ADDOP(c, ROT_TWO); @@ -3098,24 +3104,24 @@ static int compiler_listcomp_generator(struct compiler *c, PyObject *tmpname, - asdl_seq *generators, int gen_index, - expr_ty elt) + asdl_seq *generators, int gen_index, + expr_ty elt) { /* generate code for the iterator, then each of the ifs, and then write to the element */ comprehension_ty l; basicblock *start, *anchor, *skip, *if_cleanup; - int i, n; + int i, n; start = compiler_new_block(c); skip = compiler_new_block(c); if_cleanup = compiler_new_block(c); anchor = compiler_new_block(c); - if (start == NULL || skip == NULL || if_cleanup == NULL || - anchor == NULL) - return 0; + if (start == NULL || skip == NULL || if_cleanup == NULL || + anchor == NULL) + return 0; l = asdl_seq_GET(generators, gen_index); VISIT(c, expr, l->iter); @@ -3125,7 +3131,7 @@ NEXT_BLOCK(c); VISIT(c, expr, l->target); - /* XXX this needs to be cleaned up...a lot! */ + /* XXX this needs to be cleaned up...a lot! */ n = asdl_seq_LEN(l->ifs); for (i = 0; i < n; i++) { expr_ty e = asdl_seq_GET(l->ifs, i); @@ -3135,32 +3141,32 @@ ADDOP(c, POP_TOP); } - if (++gen_index < asdl_seq_LEN(generators)) - if (!compiler_listcomp_generator(c, tmpname, - generators, gen_index, elt)) - return 0; - - /* only append after the last for generator */ - if (gen_index >= asdl_seq_LEN(generators)) { - if (!compiler_nameop(c, tmpname, Load)) - return 0; - VISIT(c, expr, elt); - ADDOP_I(c, CALL_FUNCTION, 1); - ADDOP(c, POP_TOP); + if (++gen_index < asdl_seq_LEN(generators)) + if (!compiler_listcomp_generator(c, tmpname, + generators, gen_index, elt)) + return 0; + + /* only append after the last for generator */ + if (gen_index >= asdl_seq_LEN(generators)) { + if (!compiler_nameop(c, tmpname, Load)) + return 0; + VISIT(c, expr, elt); + ADDOP_I(c, CALL_FUNCTION, 1); + ADDOP(c, POP_TOP); - compiler_use_next_block(c, skip); - } + compiler_use_next_block(c, skip); + } for (i = 0; i < n; i++) { ADDOP_I(c, JUMP_FORWARD, 1); - if (i == 0) - compiler_use_next_block(c, if_cleanup); + if (i == 0) + compiler_use_next_block(c, if_cleanup); ADDOP(c, POP_TOP); } ADDOP_JABS(c, JUMP_ABSOLUTE, start); compiler_use_next_block(c, anchor); - /* delete the append method added to locals */ + /* delete the append method added to locals */ if (gen_index == 1) - if (!compiler_nameop(c, tmpname, Del)) + if (!compiler_nameop(c, tmpname, Del)) return 0; return 1; @@ -3170,7 +3176,7 @@ compiler_listcomp(struct compiler *c, expr_ty e) { identifier tmp; - int rc = 0; + int rc = 0; static identifier append; asdl_seq *generators = e->v.ListComp.generators; @@ -3187,23 +3193,23 @@ ADDOP(c, DUP_TOP); ADDOP_O(c, LOAD_ATTR, append, names); if (compiler_nameop(c, tmp, Store)) - rc = compiler_listcomp_generator(c, tmp, generators, 0, - e->v.ListComp.elt); - Py_DECREF(tmp); + rc = compiler_listcomp_generator(c, tmp, generators, 0, + e->v.ListComp.elt); + Py_DECREF(tmp); return rc; } static int compiler_genexp_generator(struct compiler *c, - asdl_seq *generators, int gen_index, - expr_ty elt) + asdl_seq *generators, int gen_index, + expr_ty elt) { /* generate code for the iterator, then each of the ifs, and then write to the element */ comprehension_ty ge; basicblock *start, *anchor, *skip, *if_cleanup, *end; - int i, n; + int i, n; start = compiler_new_block(c); skip = compiler_new_block(c); @@ -3211,7 +3217,7 @@ anchor = compiler_new_block(c); end = compiler_new_block(c); - if (start == NULL || skip == NULL || if_cleanup == NULL || + if (start == NULL || skip == NULL || if_cleanup == NULL || anchor == NULL || end == NULL) return 0; @@ -3235,7 +3241,7 @@ NEXT_BLOCK(c); VISIT(c, expr, ge->target); - /* XXX this needs to be cleaned up...a lot! */ + /* XXX this needs to be cleaned up...a lot! */ n = asdl_seq_LEN(ge->ifs); for (i = 0; i < n; i++) { expr_ty e = asdl_seq_GET(ge->ifs, i); @@ -3245,21 +3251,21 @@ ADDOP(c, POP_TOP); } - if (++gen_index < asdl_seq_LEN(generators)) + if (++gen_index < asdl_seq_LEN(generators)) if (!compiler_genexp_generator(c, generators, gen_index, elt)) return 0; - /* only append after the last 'for' generator */ - if (gen_index >= asdl_seq_LEN(generators)) { + /* only append after the last 'for' generator */ + if (gen_index >= asdl_seq_LEN(generators)) { VISIT(c, expr, elt); ADDOP(c, YIELD_VALUE); ADDOP(c, POP_TOP); compiler_use_next_block(c, skip); - } + } for (i = 0; i < n; i++) { ADDOP_I(c, JUMP_FORWARD, 1); - if (i == 0) + if (i == 0) compiler_use_next_block(c, if_cleanup); ADDOP(c, POP_TOP); @@ -3297,7 +3303,7 @@ if (co == NULL) return 0; - compiler_make_closure(c, co, 0); + compiler_make_closure(c, co, 0); Py_DECREF(co); VISIT(c, expr, outermost_iter); @@ -3315,7 +3321,7 @@ return 1; } -/* Test whether expression is constant. For constants, report +/* Test whether expression is constant. For constants, report whether they are true or false. Return values: 1 for true, 0 for false, -1 for non-constant. @@ -3352,9 +3358,9 @@ BLOCK finally: if an exception was raised: - exc = copy of (exception, instance, traceback) + exc = copy of (exception, instance, traceback) else: - exc = (None, None, None) + exc = (None, None, None) exit(*exc) */ static int @@ -3367,34 +3373,34 @@ assert(s->kind == With_kind); if (!context_attr) { - context_attr = PyString_InternFromString("__context__"); - if (!context_attr) - return 0; + context_attr = PyString_InternFromString("__context__"); + if (!context_attr) + return 0; } if (!enter_attr) { - enter_attr = PyString_InternFromString("__enter__"); - if (!enter_attr) - return 0; + enter_attr = PyString_InternFromString("__enter__"); + if (!enter_attr) + return 0; } if (!exit_attr) { - exit_attr = PyString_InternFromString("__exit__"); - if (!exit_attr) - return 0; + exit_attr = PyString_InternFromString("__exit__"); + if (!exit_attr) + return 0; } block = compiler_new_block(c); finally = compiler_new_block(c); if (!block || !finally) - return 0; + return 0; /* Create a temporary variable to hold context.__exit__ */ tmpexit = compiler_new_tmpname(c); if (tmpexit == NULL) - return 0; + return 0; PyArena_AddPyObject(c->c_arena, tmpexit); if (s->v.With.optional_vars) { - /* Create a temporary variable to hold context.__enter__(). + /* Create a temporary variable to hold context.__enter__(). We need to do this rather than preserving it on the stack because SETUP_FINALLY remembers the stack level. We need to do the assignment *inside* the try/finally @@ -3403,7 +3409,7 @@ the try/finally so that if it fails we won't call context.__exit__(). */ - tmpvalue = compiler_new_tmpname(c); + tmpvalue = compiler_new_tmpname(c); if (tmpvalue == NULL) return 0; PyArena_AddPyObject(c->c_arena, tmpvalue); @@ -3425,13 +3431,13 @@ ADDOP_I(c, CALL_FUNCTION, 0); if (s->v.With.optional_vars) { - /* Store it in tmpvalue */ - if (!compiler_nameop(c, tmpvalue, Store)) + /* Store it in tmpvalue */ + if (!compiler_nameop(c, tmpvalue, Store)) return 0; } else { - /* Discard result from context.__enter__() */ - ADDOP(c, POP_TOP); + /* Discard result from context.__enter__() */ + ADDOP(c, POP_TOP); } /* Start the try block */ @@ -3439,15 +3445,15 @@ compiler_use_next_block(c, block); if (!compiler_push_fblock(c, FINALLY_TRY, block)) { - return 0; + return 0; } if (s->v.With.optional_vars) { - /* Bind saved result of context.__enter__() to VAR */ - if (!compiler_nameop(c, tmpvalue, Load) || + /* Bind saved result of context.__enter__() to VAR */ + if (!compiler_nameop(c, tmpvalue, Load) || !compiler_nameop(c, tmpvalue, Del)) return 0; - VISIT(c, expr, s->v.With.optional_vars); + VISIT(c, expr, s->v.With.optional_vars); } /* BLOCK code */ @@ -3460,12 +3466,12 @@ ADDOP_O(c, LOAD_CONST, Py_None, consts); compiler_use_next_block(c, finally); if (!compiler_push_fblock(c, FINALLY_END, finally)) - return 0; + return 0; /* Finally block starts; push tmpexit and issue our magic opcode. */ if (!compiler_nameop(c, tmpexit, Load) || !compiler_nameop(c, tmpexit, Del)) - return 0; + return 0; ADDOP(c, WITH_CLEANUP); ADDOP_I(c, CALL_FUNCTION, 3); ADDOP(c, POP_TOP); @@ -3486,22 +3492,22 @@ c->u->u_lineno_set = false; } switch (e->kind) { - case BoolOp_kind: + case BoolOp_kind: return compiler_boolop(c, e); - case BinOp_kind: + case BinOp_kind: VISIT(c, expr, e->v.BinOp.left); VISIT(c, expr, e->v.BinOp.right); ADDOP(c, binop(c, e->v.BinOp.op)); break; - case UnaryOp_kind: + case UnaryOp_kind: VISIT(c, expr, e->v.UnaryOp.operand); ADDOP(c, unaryop(e->v.UnaryOp.op)); break; - case Lambda_kind: + case Lambda_kind: return compiler_lambda(c, e); case IfExp_kind: return compiler_ifexp(c, e); - case Dict_kind: + case Dict_kind: /* XXX get rid of arg? */ ADDOP_I(c, BUILD_MAP, 0); n = asdl_seq_LEN(e->v.Dict.values); @@ -3515,13 +3521,13 @@ ADDOP(c, STORE_SUBSCR); } break; - case ListComp_kind: + case ListComp_kind: return compiler_listcomp(c, e); - case GeneratorExp_kind: + case GeneratorExp_kind: return compiler_genexp(c, e); case Yield_kind: if (c->u->u_ste->ste_type != FunctionBlock) - return compiler_error(c, "'yield' outside function"); + return compiler_error(c, "'yield' outside function"); /* for (i = 0; i < c->u->u_nfblocks; i++) { if (c->u->u_fblock[i].fb_type == FINALLY_TRY) @@ -3538,22 +3544,22 @@ } ADDOP(c, YIELD_VALUE); break; - case Compare_kind: + case Compare_kind: return compiler_compare(c, e); - case Call_kind: + case Call_kind: return compiler_call(c, e); - case Repr_kind: + case Repr_kind: VISIT(c, expr, e->v.Repr.value); ADDOP(c, UNARY_CONVERT); break; - case Num_kind: + case Num_kind: ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts); break; - case Str_kind: + case Str_kind: ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts); break; /* The following exprs can be assignment targets. */ - case Attribute_kind: + case Attribute_kind: if (e->v.Attribute.ctx != AugStore) VISIT(c, expr, e->v.Attribute.value); switch (e->v.Attribute.ctx) { @@ -3579,7 +3585,7 @@ return 0; } break; - case Subscript_kind: + case Subscript_kind: switch (e->v.Subscript.ctx) { case AugLoad: VISIT(c, expr, e->v.Subscript.value); @@ -3603,16 +3609,16 @@ case Param: default: PyErr_SetString(PyExc_SystemError, - "param invalid in subscript expression"); + "param invalid in subscript expression"); return 0; } break; - case Name_kind: + case Name_kind: return compiler_nameop(c, e->v.Name.id, e->v.Name.ctx); /* child nodes of List and Tuple will have expr_context set */ - case List_kind: + case List_kind: return compiler_list(c, e); - case Tuple_kind: + case Tuple_kind: return compiler_tuple(c, e); } return 1; @@ -3627,11 +3633,11 @@ assert(s->kind == AugAssign_kind); switch (e->kind) { - case Attribute_kind: + case Attribute_kind: auge = Attribute(e->v.Attribute.value, e->v.Attribute.attr, AugLoad, e->lineno, c->c_arena); - if (auge == NULL) - return 0; + if (auge == NULL) + return 0; VISIT(c, expr, auge); VISIT(c, expr, s->v.AugAssign.value); ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); @@ -3641,14 +3647,14 @@ case Subscript_kind: auge = Subscript(e->v.Subscript.value, e->v.Subscript.slice, AugLoad, e->lineno, c->c_arena); - if (auge == NULL) - return 0; + if (auge == NULL) + return 0; VISIT(c, expr, auge); VISIT(c, expr, s->v.AugAssign.value); ADDOP(c, inplace_binop(c, s->v.AugAssign.op)); - auge->v.Subscript.ctx = AugStore; + auge->v.Subscript.ctx = AugStore; VISIT(c, expr, auge); - break; + break; case Name_kind: VISIT(c, expr, s->v.AugAssign.target); VISIT(c, expr, s->v.AugAssign.value); @@ -3658,7 +3664,7 @@ PyErr_Format(PyExc_SystemError, "invalid node type (%d) for augmented assignment", e->kind); - return 0; + return 0; } return 1; } @@ -3717,31 +3723,31 @@ static int compiler_handle_subscr(struct compiler *c, const char *kind, - expr_context_ty ctx) + expr_context_ty ctx) { - int op = 0; + int op = 0; - /* XXX this code is duplicated */ - switch (ctx) { - case AugLoad: /* fall through to Load */ - case Load: op = BINARY_SUBSCR; break; - case AugStore:/* fall through to Store */ - case Store: op = STORE_SUBSCR; break; - case Del: op = DELETE_SUBSCR; break; - case Param: - PyErr_Format(PyExc_SystemError, + /* XXX this code is duplicated */ + switch (ctx) { + case AugLoad: /* fall through to Load */ + case Load: op = BINARY_SUBSCR; break; + case AugStore:/* fall through to Store */ + case Store: op = STORE_SUBSCR; break; + case Del: op = DELETE_SUBSCR; break; + case Param: + PyErr_Format(PyExc_SystemError, "invalid %s kind %d in subscript\n", kind, ctx); - return 0; - } - if (ctx == AugLoad) { - ADDOP_I(c, DUP_TOPX, 2); - } - else if (ctx == AugStore) { - ADDOP(c, ROT_THREE); - } - ADDOP(c, op); - return 1; + return 0; + } + if (ctx == AugLoad) { + ADDOP_I(c, DUP_TOPX, 2); + } + else if (ctx == AugStore) { + ADDOP(c, ROT_THREE); + } + ADDOP(c, op); + return 1; } static int @@ -3752,17 +3758,17 @@ /* only handles the cases where BUILD_SLICE is emitted */ if (s->v.Slice.lower) { - VISIT(c, expr, s->v.Slice.lower); + VISIT(c, expr, s->v.Slice.lower); } else { - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_O(c, LOAD_CONST, Py_None, consts); } - + if (s->v.Slice.upper) { - VISIT(c, expr, s->v.Slice.upper); + VISIT(c, expr, s->v.Slice.upper); } else { - ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP_O(c, LOAD_CONST, Py_None, consts); } if (s->v.Slice.step) { @@ -3792,20 +3798,20 @@ VISIT(c, expr, s->v.Slice.upper); } - if (ctx == AugLoad) { - switch (stack_count) { - case 0: ADDOP(c, DUP_TOP); break; - case 1: ADDOP_I(c, DUP_TOPX, 2); break; - case 2: ADDOP_I(c, DUP_TOPX, 3); break; - } - } - else if (ctx == AugStore) { - switch (stack_count) { - case 0: ADDOP(c, ROT_TWO); break; - case 1: ADDOP(c, ROT_THREE); break; - case 2: ADDOP(c, ROT_FOUR); break; - } - } + if (ctx == AugLoad) { + switch (stack_count) { + case 0: ADDOP(c, DUP_TOP); break; + case 1: ADDOP_I(c, DUP_TOPX, 2); break; + case 2: ADDOP_I(c, DUP_TOPX, 3); break; + } + } + else if (ctx == AugStore) { + switch (stack_count) { + case 0: ADDOP(c, ROT_TWO); break; + case 1: ADDOP(c, ROT_THREE); break; + case 2: ADDOP(c, ROT_FOUR); break; + } + } switch (ctx) { case AugLoad: /* fall through to Load */ @@ -3857,7 +3863,7 @@ case Slice_kind: if (!s->v.Slice.step) return compiler_simple_slice(c, s, ctx); - if (!compiler_slice(c, s, ctx)) + if (!compiler_slice(c, s, ctx)) return 0; if (ctx == AugLoad) { ADDOP_I(c, DUP_TOPX, 2); @@ -3874,12 +3880,12 @@ return 0; } ADDOP_I(c, BUILD_TUPLE, n); - return compiler_handle_subscr(c, "extended slice", ctx); + return compiler_handle_subscr(c, "extended slice", ctx); } case Index_kind: - if (ctx != AugStore) + if (ctx != AugStore) VISIT(c, expr, s->v.Index.value); - return compiler_handle_subscr(c, "index", ctx); + return compiler_handle_subscr(c, "index", ctx); default: PyErr_Format(PyExc_SystemError, "invalid slice %d", s->kind); @@ -3972,7 +3978,7 @@ if (!a->a_lnotab) return 0; a->a_postorder = (basicblock **)PyObject_Malloc( - sizeof(basicblock *) * nblocks); + sizeof(basicblock *) * nblocks); if (!a->a_postorder) { PyErr_NoMemory(); return 0; @@ -4020,14 +4026,14 @@ The array is conceptually a list of (bytecode offset increment, line number increment) -pairs. The details are important and delicate, best illustrated by example: +pairs. The details are important and delicate, best illustrated by example: - byte code offset source code line number - 0 1 - 6 2 + byte code offset source code line number + 0 1 + 6 2 50 7 - 350 307 - 361 308 + 350 307 + 361 308 The first trick is that these numbers aren't stored, only the increments from one row to the next (this doesn't really work, but it's a start): @@ -4039,22 +4045,22 @@ offsets and their corresponding line #s both increase monotonically, and (b) if at least one column jumps by more than 255 from one row to the next, more than one pair is written to the table. In case #b, there's no way to know -from looking at the table later how many were written. That's the delicate +from looking at the table later how many were written. That's the delicate part. A user of c_lnotab desiring to find the source line number corresponding to a bytecode address A should do something like this lineno = addr = 0 for addr_incr, line_incr in c_lnotab: - addr += addr_incr - if addr > A: - return lineno - lineno += line_incr + addr += addr_incr + if addr > A: + return lineno + lineno += line_incr In order for this to work, when the addr field increments by more than 255, the line # increment in each pair generated must be 0 until the remaining addr increment is < 256. So, in the example above, com_set_lineno should not (as was actually done until 2.2) expand 300, 300 to 255, 255, 45, 45, but to -255, 0, 45, 255, 0, 45. +255, 0, 45, 255, 0, 45. */ static int @@ -4130,7 +4136,7 @@ *lnotab++ = d_bytecode; *lnotab++ = d_lineno; } - else { /* First line of a block; def stmt, etc. */ + else { /* First line of a block; def stmt, etc. */ *lnotab++ = 0; *lnotab++ = d_lineno; } @@ -4221,7 +4227,7 @@ } /* XXX: This is an awful hack that could hurt performance, but - on the bright side it should work until we come up + on the bright side it should work until we come up with a better solution. In the meantime, should the goto be dropped in favor @@ -4229,7 +4235,7 @@ The issue is that in the first loop blocksize() is called which calls instrsize() which requires i_oparg be set - appropriately. There is a bootstrap problem because + appropriately. There is a bootstrap problem because i_oparg is calculated in the second loop above. So we loop until we stop seeing new EXTENDED_ARGs. @@ -4254,10 +4260,10 @@ return NULL; while (PyDict_Next(dict, &pos, &k, &v)) { i = PyInt_AS_LONG(v); - k = PyTuple_GET_ITEM(k, 0); + k = PyTuple_GET_ITEM(k, 0); Py_INCREF(k); assert((i - offset) < size); - assert((i - offset) >= 0); + assert((i - offset) >= 0); PyTuple_SET_ITEM(tuple, i - offset, k); } return tuple; @@ -4286,7 +4292,7 @@ flags |= CO_GENERATOR; /* (Only) inherit compilerflags in PyCF_MASK */ - flags |= (c->c_flags->cf_flags & PyCF_MASK); + flags |= (c->c_flags->cf_flags & PyCF_MASK); n = PyDict_Size(c->u->u_freevars); if (n < 0) @@ -4315,7 +4321,7 @@ PyObject *name = NULL; PyObject *freevars = NULL; PyObject *cellvars = NULL; - PyObject *bytecode = NULL; + PyObject *bytecode = NULL; int nlocals, flags; tmp = dict_keys_inorder(c->u->u_consts, 0); @@ -4329,17 +4335,17 @@ if (!consts || !names || !varnames) goto error; - cellvars = dict_keys_inorder(c->u->u_cellvars, 0); - if (!cellvars) - goto error; - freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_Size(cellvars)); - if (!freevars) - goto error; + cellvars = dict_keys_inorder(c->u->u_cellvars, 0); + if (!cellvars) + goto error; + freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_Size(cellvars)); + if (!freevars) + goto error; filename = PyString_FromString(c->c_filename); if (!filename) goto error; - nlocals = PyDict_Size(c->u->u_varnames); + nlocals = PyDict_Size(c->u->u_varnames); flags = compute_code_flags(c); if (flags < 0) goto error; From python-checkins at python.org Wed Mar 1 17:37:55 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 17:37:55 +0100 (CET) Subject: [Python-checkins] r42730 - python/trunk/Doc/api/init.tex Message-ID: <20060301163755.D95211E402A@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 17:37:55 2006 New Revision: 42730 Modified: python/trunk/Doc/api/init.tex Log: Fix warning that texcheck complained about. Modified: python/trunk/Doc/api/init.tex ============================================================================== --- python/trunk/Doc/api/init.tex (original) +++ python/trunk/Doc/api/init.tex Wed Mar 1 17:37:55 2006 @@ -184,7 +184,7 @@ variable in the top-level \file{Makefile} and the \longprogramopt{prefix} argument to the \program{configure} script at build time. The value is available to Python code as - \code{sys.prefix}. It is only useful on \UNIX. See also the next + \code{sys.prefix}. It is only useful on \UNIX{}. See also the next function. \end{cfuncdesc} From python-checkins at python.org Wed Mar 1 17:55:44 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 17:55:44 +0100 (CET) Subject: [Python-checkins] r42731 - in python/trunk: Include/pythonrun.h Python/pythonrun.c Message-ID: <20060301165544.A394D1E4024@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 17:55:42 2006 New Revision: 42731 Modified: python/trunk/Include/pythonrun.h python/trunk/Python/pythonrun.c Log: Reconst parameters that lost their const in the AST merge. Modified: python/trunk/Include/pythonrun.h ============================================================================== --- python/trunk/Include/pythonrun.h (original) +++ python/trunk/Include/pythonrun.h Wed Mar 1 17:55:42 2006 @@ -31,8 +31,8 @@ PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *); -PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, char *, PyCompilerFlags *); -PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, char *, int, PyCompilerFlags *); +PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); +PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *); PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *); PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *); PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *); Modified: python/trunk/Python/pythonrun.c ============================================================================== --- python/trunk/Python/pythonrun.c (original) +++ python/trunk/Python/pythonrun.c Wed Mar 1 17:55:42 2006 @@ -638,7 +638,7 @@ /* Parse input from a file and execute it */ int -PyRun_AnyFileExFlags(FILE *fp, char *filename, int closeit, +PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags) { if (filename == NULL) From python-checkins at python.org Wed Mar 1 17:56:29 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 17:56:29 +0100 (CET) Subject: [Python-checkins] r42732 - in python/trunk: Include/objimpl.h Modules/gcmodule.c Message-ID: <20060301165629.CD7DE1E4009@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 17:56:25 2006 New Revision: 42732 Modified: python/trunk/Include/objimpl.h python/trunk/Modules/gcmodule.c Log: Change GC refcount to Py_ssize_t. Modified: python/trunk/Include/objimpl.h ============================================================================== --- python/trunk/Include/objimpl.h (original) +++ python/trunk/Include/objimpl.h Wed Mar 1 17:56:25 2006 @@ -250,7 +250,7 @@ struct { union _gc_head *gc_next; union _gc_head *gc_prev; - int gc_refs; + Py_ssize_t gc_refs; } gc; long double dummy; /* force worst-case alignment */ } PyGC_Head; Modified: python/trunk/Modules/gcmodule.c ============================================================================== --- python/trunk/Modules/gcmodule.c (original) +++ python/trunk/Modules/gcmodule.c Wed Mar 1 17:56:25 2006 @@ -303,7 +303,7 @@ { if (PyObject_IS_GC(op)) { PyGC_Head *gc = AS_GC(op); - const int gc_refs = gc->gc.gc_refs; + const Py_ssize_t gc_refs = gc->gc.gc_refs; if (gc_refs == 0) { /* This is in move_unreachable's 'young' list, but From python-checkins at python.org Wed Mar 1 18:06:48 2006 From: python-checkins at python.org (guido.van.rossum) Date: Wed, 1 Mar 2006 18:06:48 +0100 (CET) Subject: [Python-checkins] r42733 - peps/trunk/pep-0343.txt peps/trunk/pep-0356.txt peps/trunk/pep-3000.txt Message-ID: <20060301170648.DD3781E4009@bag.python.org> Author: guido.van.rossum Date: Wed Mar 1 18:06:46 2006 New Revision: 42733 Modified: peps/trunk/pep-0343.txt peps/trunk/pep-0356.txt peps/trunk/pep-3000.txt Log: 343: fix bug in nested(). 356: add some tentative future keywords. 3000: add some new ideas. Modified: peps/trunk/pep-0343.txt ============================================================================== --- peps/trunk/pep-0343.txt (original) +++ peps/trunk/pep-0343.txt Wed Mar 1 18:06:46 2006 @@ -827,7 +827,6 @@ def nested(*contexts): exits = [] vars = [] - exc = (None, None, None) try: try: for context in contexts: @@ -839,6 +838,8 @@ yield vars except: exc = sys.exc_info() + else: + exc = (None, None, None) finally: while exits: exit = exits.pop() @@ -846,6 +847,8 @@ exit(*exc) except: exc = sys.exc_info() + else: + exc = (None, None, None) if exc != (None, None, None): raise Modified: peps/trunk/pep-0356.txt ============================================================================== --- peps/trunk/pep-0356.txt (original) +++ peps/trunk/pep-0356.txt Wed Mar 1 18:06:46 2006 @@ -75,6 +75,13 @@ Target for inclusion of each feature by March 16. At that point, we should re-evaluate schedule or consider dropping feature. + Prepare for 'do' becoming a keyword in 2.6 (PEP 315)? + And as long as we're going wild, how about 'super'? + And what about 'interface' and 'implements'? (PEP 245) + Or 'switch' and 'case'? (PEP 275) + + Add builtin @deprecated decorator? + PEP 352: Required Superclass for Exceptions (Brett Cannon is expected to implement this.) Modified: peps/trunk/pep-3000.txt ============================================================================== --- peps/trunk/pep-3000.txt (original) +++ peps/trunk/pep-3000.txt Wed Mar 1 18:06:46 2006 @@ -54,12 +54,17 @@ * ``exec`` as a statement is not worth it -- make it a function * Add optional declarations for static typing [11]_ * Support only new-style classes; classic classes will be gone [1]_ +* Return iterators instead of lists where appropriate for atomic type methods + (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) + iter*() methods will be removed. +* OR... Make keys() etc. return "views" a la Java collections??? * Replace ``print`` by a function [16]_ * Do something so you can catch multiple exceptions using ``except E1, E2, E3:``. Maybe use ``except E1, E2, E3 as err:`` if you want the error variable? [3]_ * ``None``, ``True`` and ``False`` become keywords [4]_ -* ``as`` becomes a keyword [5]_ + (Or perhaps just ``None``?) +* ``as`` becomes a keyword [5]_ (probably in 2.6 already) * Have list comprehensions be syntactic sugar for passing an equivalent generator expression to ``list()``; as a consequence the loop variable will no longer be exposed [12]_ From python-checkins at python.org Wed Mar 1 18:10:03 2006 From: python-checkins at python.org (guido.van.rossum) Date: Wed, 1 Mar 2006 18:10:03 +0100 (CET) Subject: [Python-checkins] r42734 - in python/trunk/Lib: contextlib.py test/test_contextlib.py Message-ID: <20060301171003.A51681E400A@bag.python.org> Author: guido.van.rossum Date: Wed Mar 1 18:10:01 2006 New Revision: 42734 Modified: python/trunk/Lib/contextlib.py python/trunk/Lib/test/test_contextlib.py Log: Fix a bug in nested() - if one of the sub-context-managers swallows the exception, it should not be propagated up. With unit tests. Modified: python/trunk/Lib/contextlib.py ============================================================================== --- python/trunk/Lib/contextlib.py (original) +++ python/trunk/Lib/contextlib.py Wed Mar 1 18:10:01 2006 @@ -91,7 +91,6 @@ """ exits = [] vars = [] - exc = (None, None, None) try: try: for context in contexts: @@ -103,6 +102,8 @@ yield vars except: exc = sys.exc_info() + else: + exc = (None, None, None) finally: while exits: exit = exits.pop() @@ -110,6 +111,8 @@ exit(*exc) except: exc = sys.exc_info() + else: + exc = (None, None, None) if exc != (None, None, None): raise Modified: python/trunk/Lib/test/test_contextlib.py ============================================================================== --- python/trunk/Lib/test/test_contextlib.py (original) +++ python/trunk/Lib/test/test_contextlib.py Wed Mar 1 18:10:01 2006 @@ -107,6 +107,60 @@ else: self.fail("Didn't raise ZeroDivisionError") + def test_nested_b_swallows(self): + @contextmanager + def a(): + yield + @contextmanager + def b(): + try: + yield + except: + # Swallow the exception + pass + try: + with nested(a(), b()): + 1/0 + except ZeroDivisionError: + self.fail("Didn't swallow ZeroDivisionError") + + def test_nested_break(self): + @contextmanager + def a(): + yield + state = 0 + while True: + state += 1 + with nested(a(), a()): + break + state += 10 + self.assertEqual(state, 1) + + def test_nested_continue(self): + @contextmanager + def a(): + yield + state = 0 + while state < 3: + state += 1 + with nested(a(), a()): + continue + state += 10 + self.assertEqual(state, 3) + + def test_nested_return(self): + @contextmanager + def a(): + try: + yield + except: + pass + def foo(): + with nested(a(), a()): + return 1 + return 10 + self.assertEqual(foo(), 1) + class ClosingTestCase(unittest.TestCase): # XXX This needs more work From python-checkins at python.org Wed Mar 1 19:32:38 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 19:32:38 +0100 (CET) Subject: [Python-checkins] r42735 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301183238.1748E1E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 19:32:31 2006 New Revision: 42735 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Close an XXX (+ misc.): track and report debug info about total # of arenas allocated, # reclaimed, # currently allocated, and highwater mark. >From a -uall debug-build test run(*) w/ the PYTHONMALLOCSTATS envar set, it's clear that arenas do get reclaimed. This is part of the output at the end of the run: # times object malloc called = 138,387,107 # arenas allocated total = 1,841 # arenas reclaimed = 1,733 # arenas highwater mark = 212 # arenas allocated current = 108 (*) The branch was created before the sprints started, so this doesn't reflect the current trunk tests. test_subprocess was excluded, because it hangs with PYTHONMALLOCSTATS set (the debug output gets written to stderr, and at least one of the test_subprocess tests doesn't expect anything in the spawned process's stderr, and the pipe it sets up for stderr fills). Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Wed Mar 1 19:32:31 2006 @@ -487,8 +487,9 @@ #ifdef PYMALLOC_DEBUG /* Total number of times malloc() called to allocate an arena. */ -/* XXX Teach the debug malloc output about this. */ static ulong ntimes_arena_allocated = 0; +/* High water mark (max value ever seen) for narenas_currently_allocated. */ +static ulong narenas_highwater = 0; #endif /* Allocate a new arena. If we run out of memory, return NULL. Else @@ -577,6 +578,8 @@ ++narenas_currently_allocated; #ifdef PYMALLOC_DEBUG ++ntimes_arena_allocated; + if (narenas_currently_allocated > narenas_highwater) + narenas_highwater = narenas_currently_allocated; #endif /* pool_address <- first pool-aligned address in the arena nfreepools <- number of whole pools that fit after alignment */ @@ -875,8 +878,7 @@ if (Py_ADDRESS_IN_RANGE(p, pool)) { /* We allocated this address. */ LOCK(); - /* - * Link p to the start of the pool's freeblock list. Since + /* Link p to the start of the pool's freeblock list. Since * the pool had at least the p block outstanding, the pool * wasn't empty (so it's already in a usedpools[] list, or * was full and is in no list -- it's not in the freeblocks @@ -888,8 +890,7 @@ if (lastfree) { struct arena_object* arenaobj; - /* - * freeblock wasn't NULL, so the pool wasn't full, + /* freeblock wasn't NULL, so the pool wasn't full, * and the pool is in a usedpools[] list. */ if (--pool->ref.count != 0) { @@ -897,8 +898,7 @@ UNLOCK(); return; } - /* - * Pool is now empty: unlink from usedpools, and + /* Pool is now empty: unlink from usedpools, and * link to the front of freepools. This ensures that * previously freed pools will be allocated later * (being not referenced, they are perhaps paged out). @@ -914,7 +914,7 @@ arenaobj = &arenas[pool->arenaindex]; pool->nextpool = arenaobj->freepools; arenaobj->freepools = pool; - arenaobj->nfreepools ++; + ++arenaobj->nfreepools; if (arenaobj->nfreepools == arenaobj->ntotalpools) { void* address; @@ -975,9 +975,8 @@ usable_arenas = arenaobj; /* Fix the pointer in the nextarena. */ - if (arenaobj->nextarena != NULL) { + if (arenaobj->nextarena != NULL) arenaobj->nextarena->prevarena = arenaobj; - } assert(usable_arenas->address != 0); } @@ -1047,8 +1046,7 @@ UNLOCK(); return; } - /* - * Pool was full, so doesn't currently live in any list: + /* Pool was full, so doesn't currently live in any list: * link it to the front of the appropriate usedpools[] list. * This mimics LRU pool usage for new allocations and * targets optimal filling when several pools contain @@ -1570,7 +1568,7 @@ */ ulong quantization = 0; /* # of arenas actually allocated. */ - uint narenas = 0; + ulong narenas = 0; /* running total -- should equal narenas * ARENA_SIZE */ ulong total; char buf[128]; @@ -1629,6 +1627,7 @@ #endif } } + assert(narenas == narenas_currently_allocated); fputc('\n', stderr); fputs("class size num pools blocks in use avail blocks\n" @@ -1654,9 +1653,14 @@ fputc('\n', stderr); (void)printone("# times object malloc called", serialno); + (void)printone("# arenas allocated total", ntimes_arena_allocated); + (void)printone("# arenas reclaimed", ntimes_arena_allocated - narenas); + (void)printone("# arenas highwater mark", narenas_highwater); + (void)printone("# arenas allocated current", narenas); + PyOS_snprintf(buf, sizeof(buf), - "%u arenas * %d bytes/arena", narenas, ARENA_SIZE); - (void)printone(buf, (ulong)narenas * ARENA_SIZE); + "%lu arenas * %d bytes/arena", narenas, ARENA_SIZE); + (void)printone(buf, narenas * ARENA_SIZE); fputc('\n', stderr); From python-checkins at python.org Wed Mar 1 19:47:47 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 19:47:47 +0100 (CET) Subject: [Python-checkins] r42736 - peps/trunk/pep-3000.txt Message-ID: <20060301184747.E71821E4002@bag.python.org> Author: brett.cannon Date: Wed Mar 1 19:47:47 2006 New Revision: 42736 Modified: peps/trunk/pep-3000.txt Log: Move an edited idea from the core language section down to atomic types section. Modified: peps/trunk/pep-3000.txt ============================================================================== --- peps/trunk/pep-3000.txt (original) +++ peps/trunk/pep-3000.txt Wed Mar 1 19:47:47 2006 @@ -54,9 +54,6 @@ * ``exec`` as a statement is not worth it -- make it a function * Add optional declarations for static typing [11]_ * Support only new-style classes; classic classes will be gone [1]_ -* Return iterators instead of lists where appropriate for atomic type methods - (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) - iter*() methods will be removed. * OR... Make keys() etc. return "views" a la Java collections??? * Replace ``print`` by a function [16]_ * Do something so you can catch multiple exceptions using ``except E1, @@ -114,8 +111,9 @@ * Remove distinction between int and long types [1]_ * Make all strings be Unicode, and have a separate bytes() type [1]_ * Return iterators instead of lists where appropriate for atomic type methods - (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) - (Do we keep iter*() methods or remove them? I vote remove. -- nn) + (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.); iter* + methods will be removed + OR make keys(), etc. return views ala Java collections??? To be removed: From python-checkins at python.org Wed Mar 1 21:53:08 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 21:53:08 +0100 (CET) Subject: [Python-checkins] r42737 - python/trunk/Misc/Vim/python.vim python/trunk/Misc/Vim/syntax_test.py python/trunk/Misc/Vim/vim_syntax.py Message-ID: <20060301205308.031F51E4039@bag.python.org> Author: brett.cannon Date: Wed Mar 1 21:53:08 2006 New Revision: 42737 Modified: python/trunk/Misc/Vim/python.vim python/trunk/Misc/Vim/syntax_test.py python/trunk/Misc/Vim/vim_syntax.py Log: Update for 'with' statement. Modified: python/trunk/Misc/Vim/python.vim ============================================================================== --- python/trunk/Misc/Vim/python.vim (original) +++ python/trunk/Misc/Vim/python.vim Wed Mar 1 21:53:08 2006 @@ -14,8 +14,9 @@ let python_highlight_space_errors = 1 endif -syn keyword pythonStatement assert break continue del except exec finally -syn keyword pythonStatement global lambda pass print raise return try yield +syn keyword pythonStatement as assert break continue del except exec finally +syn keyword pythonStatement global lambda pass print raise return try with +syn keyword pythonStatement yield syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite @@ -82,8 +83,9 @@ syn keyword pythonException UnicodeTranslateError MemoryError StopIteration syn keyword pythonException PendingDeprecationWarning EnvironmentError syn keyword pythonException LookupError OSError DeprecationWarning - syn keyword pythonException UnicodeError FloatingPointError ReferenceError - syn keyword pythonException NameError OverflowWarning IOError SyntaxError + syn keyword pythonException UnicodeError UnicodeEncodeError + syn keyword pythonException FloatingPointError ReferenceError NameError + syn keyword pythonException OverflowWarning IOError SyntaxError syn keyword pythonException FutureWarning SystemExit Exception EOFError syn keyword pythonException StandardError ValueError TabError KeyError syn keyword pythonException ZeroDivisionError SystemError @@ -92,7 +94,7 @@ syn keyword pythonException RuntimeWarning KeyboardInterrupt UserWarning syn keyword pythonException SyntaxWarning UnboundLocalError ArithmeticError syn keyword pythonException Warning NotImplementedError AttributeError - syn keyword pythonException OverflowError UnicodeEncodeError + syn keyword pythonException OverflowError BaseException endif Modified: python/trunk/Misc/Vim/syntax_test.py ============================================================================== --- python/trunk/Misc/Vim/syntax_test.py (original) +++ python/trunk/Misc/Vim/syntax_test.py Wed Mar 1 21:53:08 2006 @@ -13,20 +13,28 @@ # OPTIONAL: XXX catch your attention # Statements +from __future__ import with_statement # Import +from sys import path as thing assert True # keyword def foo(): # function definition return [] class Bar(object): # Class definition - pass + def __context__(self): + return self + def __enter__(self): + pass + def __exit__(self, *args): + pass foo() # UNCOLOURED: function call while False: # 'while' continue for x in foo(): # 'for' break +with Bar() as stuff: + pass if False: pass # 'if' elif False: pass -else False: pass -from sys import path as thing # Import +else: pass # Constants 'single-quote', u'unicode' # Strings of all kinds; prefixes not highlighted Modified: python/trunk/Misc/Vim/vim_syntax.py ============================================================================== --- python/trunk/Misc/Vim/vim_syntax.py (original) +++ python/trunk/Misc/Vim/vim_syntax.py Wed Mar 1 21:53:08 2006 @@ -1,3 +1,5 @@ +from __future__ import with_statement + import keyword import exceptions import __builtin__ @@ -143,11 +145,9 @@ except StopIteration: if buffer_: break - if not buffer_ and overflow: - yield buffer_ - return - else: - return + if overflow: + yield overflow + return if total_len > fill_len: overflow = buffer_.pop() total_len -= len(overflow) - 1 @@ -158,8 +158,7 @@ FILL = 80 def main(file_path): - FILE = open(file_path, 'w') - try: + with open(file_path, 'w') as FILE: # Comment for file print>>FILE, comment_header print>>FILE, '' @@ -222,8 +221,6 @@ print>>FILE, '' # Statements at the end of the file print>>FILE, statement_footer - finally: - FILE.close() if __name__ == '__main__': main("python.vim") From python-checkins at python.org Wed Mar 1 22:11:50 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 22:11:50 +0100 (CET) Subject: [Python-checkins] r42738 - python/trunk/Lib/test/test_compiler.py Message-ID: <20060301211150.07C7C1E4002@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 22:11:49 2006 New Revision: 42738 Modified: python/trunk/Lib/test/test_compiler.py Log: Make failures in test cases print failing source file. Modified: python/trunk/Lib/test/test_compiler.py ============================================================================== --- python/trunk/Lib/test/test_compiler.py (original) +++ python/trunk/Lib/test/test_compiler.py Wed Mar 1 22:11:49 2006 @@ -32,7 +32,11 @@ self.assertRaises(SyntaxError, compiler.compile, buf, basename, "exec") else: - compiler.compile(buf, basename, "exec") + try: + compiler.compile(buf, basename, "exec") + except Exception, e: + e.args[0] += "[in file %s]" % basename + raise def testNewClassSyntax(self): compiler.compile("class foo():pass\n\n","","exec") From python-checkins at python.org Wed Mar 1 22:31:23 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 22:31:23 +0100 (CET) Subject: [Python-checkins] r42739 - python/trunk/Python/getargs.c Message-ID: <20060301213123.3FE001E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 22:31:21 2006 New Revision: 42739 Modified: python/trunk/Python/getargs.c Log: Fix C99-ism, and add XXX to comment Modified: python/trunk/Python/getargs.c ============================================================================== --- python/trunk/Python/getargs.c (original) +++ python/trunk/Python/getargs.c Wed Mar 1 22:31:21 2006 @@ -849,7 +849,7 @@ arg, msgbuf, bufsize); if (*format == '#') { FETCH_SIZE; - assert(0); // redundant with if-case + assert(0); /* XXX redundant with if-case */ if (arg == Py_None) *q = 0; else From python-checkins at python.org Wed Mar 1 22:33:54 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 22:33:54 +0100 (CET) Subject: [Python-checkins] r42740 - python/trunk/Python/modsupport.c Message-ID: <20060301213354.8A7F11E4002@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 22:33:54 2006 New Revision: 42740 Modified: python/trunk/Python/modsupport.c Log: Fix more memory leaks. Will backport to 2.4. Modified: python/trunk/Python/modsupport.c ============================================================================== --- python/trunk/Python/modsupport.c (original) +++ python/trunk/Python/modsupport.c Wed Mar 1 22:33:54 2006 @@ -71,13 +71,17 @@ PyErr_SetString(PyExc_ValueError, "module functions cannot set" " METH_CLASS or METH_STATIC"); + Py_DECREF(n); return NULL; } v = PyCFunction_NewEx(ml, passthrough, n); - if (v == NULL) + if (v == NULL) { + Py_DECREF(n); return NULL; + } if (PyDict_SetItemString(d, ml->ml_name, v) != 0) { Py_DECREF(v); + Py_DECREF(n); return NULL; } Py_DECREF(v); From python-checkins at python.org Wed Mar 1 22:36:35 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 22:36:35 +0100 (CET) Subject: [Python-checkins] r42741 - python/branches/release24-maint/Python/modsupport.c Message-ID: <20060301213635.931291E4002@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 22:36:32 2006 New Revision: 42741 Modified: python/branches/release24-maint/Python/modsupport.c Log: Backport of memory leak fixes. Modified: python/branches/release24-maint/Python/modsupport.c ============================================================================== --- python/branches/release24-maint/Python/modsupport.c (original) +++ python/branches/release24-maint/Python/modsupport.c Wed Mar 1 22:36:32 2006 @@ -71,13 +71,17 @@ PyErr_SetString(PyExc_ValueError, "module functions cannot set" " METH_CLASS or METH_STATIC"); + Py_DECREF(n); return NULL; } v = PyCFunction_NewEx(ml, passthrough, n); - if (v == NULL) + if (v == NULL) { + Py_DECREF(n); return NULL; + } if (PyDict_SetItemString(d, ml->ml_name, v) != 0) { Py_DECREF(v); + Py_DECREF(n); return NULL; } Py_DECREF(v); From python-checkins at python.org Wed Mar 1 22:37:34 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 22:37:34 +0100 (CET) Subject: [Python-checkins] r42742 - python/trunk/Modules/binascii.c Message-ID: <20060301213734.03E6F1E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 22:37:32 2006 New Revision: 42742 Modified: python/trunk/Modules/binascii.c Log: Make Py_ssize_t-clean. Modified: python/trunk/Modules/binascii.c ============================================================================== --- python/trunk/Modules/binascii.c (original) +++ python/trunk/Modules/binascii.c Wed Mar 1 22:37:32 2006 @@ -53,6 +53,7 @@ ** Brandon Long, September 2001. */ +#include PY_SSIZE_T_CLEAN #include "Python.h" @@ -189,7 +190,7 @@ unsigned char this_ch; unsigned int leftchar = 0; PyObject *rv; - int ascii_len, bin_len; + Py_ssize_t ascii_len, bin_len; if ( !PyArg_ParseTuple(args, "t#:a2b_uu", &ascii_data, &ascii_len) ) return NULL; @@ -265,7 +266,7 @@ unsigned char this_ch; unsigned int leftchar = 0; PyObject *rv; - int bin_len; + Py_ssize_t bin_len; if ( !PyArg_ParseTuple(args, "s#:b2a_uu", &bin_data, &bin_len) ) return NULL; @@ -307,7 +308,7 @@ static int -binascii_find_valid(unsigned char *s, int slen, int num) +binascii_find_valid(unsigned char *s, Py_ssize_t slen, int num) { /* Finds & returns the (num+1)th ** valid character for base64, or -1 if none. @@ -341,7 +342,7 @@ unsigned char this_ch; unsigned int leftchar = 0; PyObject *rv; - int ascii_len, bin_len; + Py_ssize_t ascii_len, bin_len; int quad_pos = 0; if ( !PyArg_ParseTuple(args, "t#:a2b_base64", &ascii_data, &ascii_len) ) @@ -432,7 +433,7 @@ unsigned char this_ch; unsigned int leftchar = 0; PyObject *rv; - int bin_len; + Py_ssize_t bin_len; if ( !PyArg_ParseTuple(args, "s#:b2a_base64", &bin_data, &bin_len) ) return NULL; @@ -485,7 +486,7 @@ unsigned char this_ch; unsigned int leftchar = 0; PyObject *rv; - int len; + Py_ssize_t len; int done = 0; if ( !PyArg_ParseTuple(args, "t#:a2b_hqx", &ascii_data, &len) ) @@ -549,7 +550,7 @@ unsigned char *in_data, *out_data; PyObject *rv; unsigned char ch; - int in, inend, len; + Py_ssize_t in, inend, len; if ( !PyArg_ParseTuple(args, "s#:rlecode_hqx", &in_data, &len) ) return NULL; @@ -598,7 +599,7 @@ unsigned char this_ch; unsigned int leftchar = 0; PyObject *rv; - int len; + Py_ssize_t len; if ( !PyArg_ParseTuple(args, "s#:b2a_hqx", &bin_data, &len) ) return NULL; @@ -636,7 +637,7 @@ unsigned char *in_data, *out_data; unsigned char in_byte, in_repeat; PyObject *rv; - int in_len, out_len, out_len_left; + Py_ssize_t in_len, out_len, out_len_left; if ( !PyArg_ParseTuple(args, "s#:rledecode_hqx", &in_data, &in_len) ) return NULL; @@ -732,7 +733,7 @@ { unsigned char *bin_data; unsigned int crc; - int len; + Py_ssize_t len; if ( !PyArg_ParseTuple(args, "s#i:crc_hqx", &bin_data, &len, &crc) ) return NULL; @@ -870,7 +871,7 @@ { /* By Jim Ahlstrom; All rights transferred to CNRI */ unsigned char *bin_data; unsigned long crc = 0UL; /* initial value of CRC */ - int len; + Py_ssize_t len; long result; if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) ) @@ -903,10 +904,10 @@ binascii_hexlify(PyObject *self, PyObject *args) { char* argbuf; - int arglen; + Py_ssize_t arglen; PyObject *retval; char* retbuf; - int i, j; + Py_ssize_t i, j; if (!PyArg_ParseTuple(args, "t#:b2a_hex", &argbuf, &arglen)) return NULL; @@ -960,10 +961,10 @@ binascii_unhexlify(PyObject *self, PyObject *args) { char* argbuf; - int arglen; + Py_ssize_t arglen; PyObject *retval; char* retbuf; - int i, j; + Py_ssize_t i, j; if (!PyArg_ParseTuple(args, "s#:a2b_hex", &argbuf, &arglen)) return NULL; @@ -1030,7 +1031,7 @@ unsigned int in, out; char ch; unsigned char *data, *odata; - unsigned int datalen = 0; + Py_ssize_t datalen = 0; PyObject *rv; static char *kwlist[] = {"data", "header", NULL}; int header = 0; @@ -1130,7 +1131,7 @@ { unsigned int in, out; unsigned char *data, *odata; - unsigned int datalen = 0, odatalen = 0; + Py_ssize_t datalen = 0, odatalen = 0; PyObject *rv; unsigned int linelen = 0; static char *kwlist[] = {"data", "quotetabs", "istext", From python-checkins at python.org Wed Mar 1 22:50:09 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 22:50:09 +0100 (CET) Subject: [Python-checkins] r42743 - python/trunk/Modules/_hashopenssl.c Message-ID: <20060301215009.5E5CE1E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 22:50:07 2006 New Revision: 42743 Modified: python/trunk/Modules/_hashopenssl.c Log: Make Py_ssize_t-clean. Modified: python/trunk/Modules/_hashopenssl.c ============================================================================== --- python/trunk/Modules/_hashopenssl.c (original) +++ python/trunk/Modules/_hashopenssl.c Wed Mar 1 22:50:07 2006 @@ -11,6 +11,8 @@ * */ +#define PY_SSIZE_T_CLEAN + #include "Python.h" #include "structmember.h" @@ -166,12 +168,13 @@ EVP_update(EVPobject *self, PyObject *args) { unsigned char *cp; - int len; + Py_ssize_t len; if (!PyArg_ParseTuple(args, "s#:update", &cp, &len)) return NULL; - EVP_DigestUpdate(&self->ctx, cp, len); + EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, + unsigned int)); Py_INCREF(Py_None); return Py_None; @@ -238,7 +241,7 @@ PyObject *name_obj = NULL; char *nameStr; unsigned char *cp = NULL; - unsigned int len; + Py_ssize_t len; const EVP_MD *digest; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s#:HASH", kwlist, @@ -262,7 +265,8 @@ Py_INCREF(self->name); if (cp && len) - EVP_DigestUpdate(&self->ctx, cp, len); + EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, + unsigned int)); return 0; } @@ -375,7 +379,7 @@ char *name; const EVP_MD *digest; unsigned char *cp = NULL; - unsigned int len; + Py_ssize_t len; if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O|s#:new", kwlist, &name_obj, &cp, &len)) { @@ -389,7 +393,8 @@ digest = EVP_get_digestbyname(name); - return EVPnew(name_obj, digest, NULL, cp, len); + return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, + unsigned int)); } /* @@ -404,7 +409,7 @@ EVP_new_ ## NAME (PyObject *self, PyObject *args) \ { \ unsigned char *cp = NULL; \ - unsigned int len; \ + Py_ssize_t len; \ \ if (!PyArg_ParseTuple(args, "|s#:" #NAME , &cp, &len)) { \ return NULL; \ @@ -414,7 +419,7 @@ CONST_ ## NAME ## _name_obj, \ NULL, \ CONST_new_ ## NAME ## _ctx_p, \ - cp, len); \ + cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \ } /* a PyMethodDef structure for the constructor */ From python-checkins at python.org Wed Mar 1 22:58:31 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 22:58:31 +0100 (CET) Subject: [Python-checkins] r42744 - python/trunk/Modules/unicodedata.c Message-ID: <20060301215831.03F261E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 22:58:30 2006 New Revision: 42744 Modified: python/trunk/Modules/unicodedata.c Log: Remove gcc (4.0.x) warning about uninitialized value by explicitly setting the sentinel value in the main function, rather than the helper. This function could possibly do with an early-out if any of the helper calls ends up with a len of 0, but I doubt it really matters (how common are malformed hangul syllables, really?) Modified: python/trunk/Modules/unicodedata.c ============================================================================== --- python/trunk/Modules/unicodedata.c (original) +++ python/trunk/Modules/unicodedata.c Wed Mar 1 22:58:30 2006 @@ -799,7 +799,6 @@ } if (*len == -1) { *len = 0; - *pos = -1; } } @@ -812,7 +811,7 @@ /* Check for hangul syllables. */ if (strncmp(name, "HANGUL SYLLABLE ", 16) == 0) { - int L, V, T, len; + int len, L = -1, V = -1, T = -1; const char *pos = name + 16; find_syllable(pos, &len, &L, LCount, 0); pos += len; From python-checkins at python.org Wed Mar 1 22:59:45 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 22:59:45 +0100 (CET) Subject: [Python-checkins] r42745 - python/trunk/Modules/binascii.c Message-ID: <20060301215945.0222D1E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 22:59:44 2006 New Revision: 42745 Modified: python/trunk/Modules/binascii.c Log: Fix brainfart. Modified: python/trunk/Modules/binascii.c ============================================================================== --- python/trunk/Modules/binascii.c (original) +++ python/trunk/Modules/binascii.c Wed Mar 1 22:59:44 2006 @@ -53,7 +53,7 @@ ** Brandon Long, September 2001. */ -#include PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN #include "Python.h" From python-checkins at python.org Wed Mar 1 23:01:39 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 23:01:39 +0100 (CET) Subject: [Python-checkins] r42746 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301220139.8651B1E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 23:01:38 2006 New Revision: 42746 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Heroic attempts to get lines under 80 columns. Resolved all new XXX except for the critical one: Py_ADDRESS_IN_RANGE is still broken in an endcase by the new logic, and I still haven't thought of a way to fix that "for free". Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Wed Mar 1 23:01:38 2006 @@ -494,10 +494,8 @@ /* Allocate a new arena. If we run out of memory, return NULL. Else * allocate a new arena, and return the address of an arena_object - * descriptor describing the new arena. The `prevarena` and `freepools` - * members of the arena_object are left as uninitialized trash. XXX - * That last sentence isn't true right now (it's all zero filled, but don't - * know yet why we bother to do that). + * descriptor describing the new arena. It's expected that the caller will + * set `usable_arenas` to the return value. */ static struct arena_object* new_arena(void) @@ -509,7 +507,6 @@ if (Py_GETENV("PYTHONMALLOCSTATS")) _PyObject_DebugMallocStats(); #endif - if (available_arenas == NULL) { uint i; uint numarenas; @@ -538,16 +535,12 @@ assert(usable_arenas == NULL); assert(available_arenas == NULL); - /* Zero fill the new section of the array. */ - /* XXX Why? */ - memset(&(arenas[maxarenas]), 0, - sizeof(*arenas) * (numarenas - maxarenas)); - /* Put the new arenas on the available_arenas list. */ - for (i = maxarenas; i < numarenas-1; ++i) - arenas[i].nextarena = &arenas[i+1]; - /* The last new arenaobj still points to NULL. */ - assert(arenas[numarenas-1].nextarena == NULL); + for (i = maxarenas; i < numarenas; ++i) { + arenas[i].address = 0; /* mark as unassociated */ + arenas[i].nextarena = i < numarenas - 1 ? + &arenas[i+1] : NULL; + } /* Update globals. */ available_arenas = &arenas[maxarenas]; @@ -557,16 +550,10 @@ /* Take the next available arena object off the head of the list. */ assert(available_arenas != NULL); arenaobj = available_arenas; - available_arenas = available_arenas->nextarena; - - assert(arenaobj->address == (uptr)NULL); - - /* Fill the newly allocated or reused arena object with zeros. */ - /* XXX Why? */ - memset(arenaobj, 0, sizeof(*arenaobj)); - + available_arenas = arenaobj->nextarena; + assert(arenaobj->address == 0); arenaobj->address = (uptr)malloc(ARENA_SIZE); - if (arenaobj->address == (uptr)NULL) { + if (arenaobj->address == 0) { /* The allocation failed: return NULL after putting the * arenaobj back. */ @@ -581,12 +568,13 @@ if (narenas_currently_allocated > narenas_highwater) narenas_highwater = narenas_currently_allocated; #endif + arenaobj->freepools = NULL; /* pool_address <- first pool-aligned address in the arena nfreepools <- number of whole pools that fit after alignment */ arenaobj->pool_address = (block*)arenaobj->address; arenaobj->nfreepools = ARENA_SIZE / POOL_SIZE; assert(POOL_SIZE * arenaobj->nfreepools == ARENA_SIZE); - excess = (uint)((Py_uintptr_t)arenaobj->address & POOL_SIZE_MASK); + excess = (uint)(arenaobj->address & POOL_SIZE_MASK); if (excess != 0) { --arenaobj->nfreepools; arenaobj->pool_address += POOL_SIZE - excess; @@ -746,6 +734,8 @@ UNLOCK(); goto redirect; } + usable_arenas->nextarena = + usable_arenas->prevarena = NULL; } assert(usable_arenas->address != 0); @@ -888,7 +878,8 @@ *(block **)p = lastfree = pool->freeblock; pool->freeblock = (block *)p; if (lastfree) { - struct arena_object* arenaobj; + struct arena_object* ao; + uint nf; /* ao->nfreepools */ /* freeblock wasn't NULL, so the pool wasn't full, * and the pool is in a usedpools[] list. @@ -911,72 +902,65 @@ /* Link the pool to freepools. This is a singly-linked * list, and pool->prevpool isn't used there. */ - arenaobj = &arenas[pool->arenaindex]; - pool->nextpool = arenaobj->freepools; - arenaobj->freepools = pool; - ++arenaobj->nfreepools; + ao = &arenas[pool->arenaindex]; + pool->nextpool = ao->freepools; + ao->freepools = pool; + nf = ++ao->nfreepools; - if (arenaobj->nfreepools == arenaobj->ntotalpools) { - void* address; + if (nf == ao->ntotalpools) { /* This arena is completely deallocated. * Unlink it from the partially allocated * arenas. */ - assert(arenaobj->prevarena == NULL || - arenaobj->prevarena->address != - (uptr)NULL); - assert(arenaobj->nextarena == NULL || - arenaobj->nextarena->address != - (uptr)NULL); + assert(ao->prevarena == NULL || + ao->prevarena->address != 0); + assert(ao ->nextarena == NULL || + ao->nextarena->address != 0); /* Fix the pointer in the prevarena, or the - * usable_arenas pointer + * usable_arenas pointer. */ - if (arenaobj->prevarena == NULL) { - usable_arenas = arenaobj->nextarena; + if (ao->prevarena == NULL) { + usable_arenas = ao->nextarena; assert(usable_arenas == NULL || usable_arenas->address != 0); } else { - assert(arenaobj->prevarena->nextarena == - arenaobj); - arenaobj->prevarena->nextarena = - arenaobj->nextarena; + assert(ao->prevarena->nextarena == ao); + ao->prevarena->nextarena = + ao->nextarena; } /* Fix the pointer in the nextarena. */ - if (arenaobj->nextarena != NULL) { - assert(arenaobj->nextarena->prevarena == - arenaobj); - arenaobj->nextarena->prevarena = - arenaobj->prevarena; + if (ao->nextarena != NULL) { + assert(ao->nextarena->prevarena == ao); + ao->nextarena->prevarena = + ao->prevarena; } - /* Record that this arena slot is available to - * be reused. + /* Record that this arena_object slot is + * available to be reused. */ - arenaobj->nextarena = available_arenas; - available_arenas = arenaobj; + ao->nextarena = available_arenas; + available_arenas = ao; /* Free the entire arena. */ - address = (void *)arenaobj->address; - arenaobj->address = (uptr)NULL; - free(address); + free((void *)ao->address); + ao->address = 0; --narenas_currently_allocated; - } - else if (arenaobj->nfreepools == 1) { + else if (nf == 1) { /* If this arena was completely allocated, * go link it to the head of the partially * allocated list. */ - arenaobj->nextarena = usable_arenas; - arenaobj->prevarena = NULL; - usable_arenas = arenaobj; + ao->nextarena = usable_arenas; + ao->prevarena = NULL; + usable_arenas = ao; /* Fix the pointer in the nextarena. */ - if (arenaobj->nextarena != NULL) - arenaobj->nextarena->prevarena = arenaobj; + if (ao->nextarena != NULL) + ao->nextarena->prevarena = ao; assert(usable_arenas->address != 0); } @@ -987,60 +971,56 @@ * a few un-scientific tests, it seems like this * approach allowed a lot more memory to be freed. */ - else if (arenaobj->nextarena != NULL && - arenaobj->nfreepools > - arenaobj->nextarena->nfreepools) { + else if (ao->nextarena != NULL && + nf > ao->nextarena->nfreepools) { /* We have to move the arena towards the end * of the list. */ struct arena_object** lastPointer; - if (arenaobj->prevarena != NULL) - lastPointer = &arenaobj->prevarena->nextarena; + if (ao->prevarena != NULL) + lastPointer = + &ao->prevarena->nextarena; else lastPointer = &usable_arenas; - assert(*lastPointer == arenaobj); + assert(*lastPointer == ao); /* Step one: unlink the arena from the list. */ - *lastPointer = arenaobj->nextarena; - arenaobj->nextarena->prevarena = arenaobj->prevarena; + *lastPointer = ao->nextarena; + ao->nextarena->prevarena = ao->prevarena; /* Step two: Locate the new insertion point by * iterating over the list, using our nextarena * pointer. */ - while (arenaobj->nextarena != NULL && - arenaobj->nfreepools > - arenaobj->nextarena->nfreepools) { - arenaobj->prevarena = arenaobj->nextarena; - arenaobj->nextarena = arenaobj->nextarena->nextarena; + while (ao->nextarena != NULL && + nf > ao->nextarena->nfreepools) { + ao->prevarena = ao->nextarena; + ao->nextarena = + ao->nextarena->nextarena; } /* Step three: insert the arena at this point. */ - assert(arenaobj->nextarena == NULL || - arenaobj->prevarena == - arenaobj->nextarena->prevarena); - assert(arenaobj->prevarena->nextarena == - arenaobj->nextarena); - - arenaobj->prevarena->nextarena = arenaobj; - if (arenaobj->nextarena != NULL) { - arenaobj->nextarena->prevarena = arenaobj; + assert(ao->nextarena == NULL || + ao->prevarena == + ao->nextarena->prevarena); + assert(ao->prevarena->nextarena == + ao->nextarena); + + ao->prevarena->nextarena = ao; + if (ao->nextarena != NULL) { + ao->nextarena->prevarena = ao; } /* Verify that the swaps worked. */ - assert(arenaobj->nextarena == NULL || - arenaobj->nfreepools <= - arenaobj->nextarena->nfreepools); - assert(arenaobj->prevarena == NULL || - arenaobj->nfreepools > - arenaobj->prevarena->nfreepools); - assert(arenaobj->nextarena == NULL || - arenaobj->nextarena->prevarena == - arenaobj); - assert((usable_arenas == arenaobj && - arenaobj->prevarena == NULL) || - arenaobj->prevarena->nextarena == - arenaobj); + assert(ao->nextarena == NULL || + nf <= ao->nextarena->nfreepools); + assert(ao->prevarena == NULL || + nf > ao->prevarena->nfreepools); + assert(ao->nextarena == NULL || + ao->nextarena->prevarena == ao); + assert((usable_arenas == ao && + ao->prevarena == NULL) || + ao->prevarena->nextarena == ao); } UNLOCK(); From python-checkins at python.org Wed Mar 1 23:06:23 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 23:06:23 +0100 (CET) Subject: [Python-checkins] r42747 - python/trunk/Python/ast.c Message-ID: <20060301220623.8E1731E400A@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 23:06:23 2006 New Revision: 42747 Modified: python/trunk/Python/ast.c Log: Fix uninitialized value. (Why are we using bools instead of ints, like we do everywhere else?) Modified: python/trunk/Python/ast.c ============================================================================== --- python/trunk/Python/ast.c (original) +++ python/trunk/Python/ast.c Wed Mar 1 23:06:23 2006 @@ -1415,7 +1415,7 @@ int j; slice_ty slc; expr_ty e; - bool simple; + bool simple = true; asdl_seq *slices, *elts; slices = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena); if (!slices) From python-checkins at python.org Wed Mar 1 23:10:51 2006 From: python-checkins at python.org (brett.cannon) Date: Wed, 1 Mar 2006 23:10:51 +0100 (CET) Subject: [Python-checkins] r42748 - in python/trunk: Doc/api/exceptions.tex Doc/lib/libexcs.tex Doc/tut/tut.tex Python/exceptions.c Message-ID: <20060301221051.30A3D1E4014@bag.python.org> Author: brett.cannon Date: Wed Mar 1 23:10:49 2006 New Revision: 42748 Modified: python/trunk/Doc/api/exceptions.tex python/trunk/Doc/lib/libexcs.tex python/trunk/Doc/tut/tut.tex python/trunk/Python/exceptions.c Log: Document PEP 352 changes. Also added GeneratorExit. Modified: python/trunk/Doc/api/exceptions.tex ============================================================================== --- python/trunk/Doc/api/exceptions.tex (original) +++ python/trunk/Doc/api/exceptions.tex Wed Mar 1 23:10:49 2006 @@ -346,6 +346,7 @@ completeness, here are all the variables: \begin{tableiii}{l|l|c}{cdata}{C Name}{Python Name}{Notes} + \lineiii{PyExc_BaseException\ttindex{PyExc_BaseException}}{\exception{BaseException}}{(1), (4)} \lineiii{PyExc_Exception\ttindex{PyExc_Exception}}{\exception{Exception}}{(1)} \lineiii{PyExc_StandardError\ttindex{PyExc_StandardError}}{\exception{StandardError}}{(1)} \lineiii{PyExc_ArithmeticError\ttindex{PyExc_ArithmeticError}}{\exception{ArithmeticError}}{(1)} @@ -388,14 +389,17 @@ \item[(3)] Only defined on Windows; protect code that uses this by testing that the preprocessor macro \code{MS_WINDOWS} is defined. + +\item[(4)] + \versionadded{2.5} \end{description} \section{Deprecation of String Exceptions} All exceptions built into Python or provided in the standard library -are derived from \exception{Exception}. -\withsubitem{(built-in exception)}{\ttindex{Exception}} +are derived from \exception{BaseException}. +\withsubitem{(built-in exception)}{\ttindex{BaseException}} String exceptions are still supported in the interpreter to allow existing code to run unmodified, but this will also change in a future Modified: python/trunk/Doc/lib/libexcs.tex ============================================================================== --- python/trunk/Doc/lib/libexcs.tex (original) +++ python/trunk/Doc/lib/libexcs.tex Wed Mar 1 23:10:49 2006 @@ -14,7 +14,8 @@ In past versions of Python string exceptions were supported. In Python 1.5 and newer versions, all standard exceptions have been converted to class objects and users are encouraged to do the same. -String exceptions will raise a \code{PendingDeprecationWarning}. +String exceptions will raise a \code{DeprecationWarning} in Python 2.5 and +newer. In future versions, support for string exceptions will be removed. Two distinct string objects with the same value are considered different @@ -43,9 +44,9 @@ second argument of the \keyword{except} clause (if any). For class exceptions, that variable receives the exception instance. If the exception class is derived from the standard root class -\exception{Exception}, the associated value is present as the -exception instance's \member{args} attribute, and possibly on other -attributes as well. +\exception{BaseException}, the associated value is present as the +exception instance's \member{args} attribute. If there is a single argument +(as is preferred), it is bound to the \member{message} attribute. User code can raise built-in exceptions. This can be used to test an exception handler or to report an error condition ``just like'' the @@ -55,7 +56,8 @@ The built-in exception classes can be sub-classed to define new exceptions; programmers are encouraged to at least derive new -exceptions from the \exception{Exception} base class. More +exceptions from the \exception{Exception} class and not +\exception{BaseException}. More information on defining exceptions is available in the \citetitle[../tut/tut.html]{Python Tutorial} under the heading ``User-defined Exceptions.'' @@ -65,23 +67,33 @@ The following exceptions are only used as base classes for other exceptions. +\begin{excdesc}{BaseException} +The base class for all built-in exceptions. It is not meant to be directly +inherited by user-defined classes (for that use \exception{Exception}). If +\function{str()} or \function{unicode()} is called on an instance of this +class, the representation of the argument(s) to the instance are returned or +the emptry string when there were no arguments. If only a single argument is +passed in, it is stored in the \member{message} attribute. If more than one +argument is passed in, \member{message} is set to the empty string. These +semantics are meant to reflect the fact that \member{message} is to store a +text message explaining why the exception had been raised. If more data needs +to be attached to the exception, attach it through arbitrary attributes on the +instance. All arguments are also stored in \member{args} as a tuple, but it will +eventually be deprecated and thus its use is discouraged. +\versionchanged[Changed to inherit from \exception{BaseException}]{2.5} +\versionadded{2.5} + \begin{excdesc}{Exception} -The root class for exceptions. All built-in exceptions are derived +All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived -from this class, but this is not (yet) enforced. The \function{str()} -function, when applied to an instance of this class (or most derived -classes) returns the string value of the argument or arguments, or an -empty string if no arguments were given to the constructor. When used -as a sequence, this accesses the arguments given to the constructor -(handy for backward compatibility with old code). The arguments are -also available on the instance's \member{args} attribute, as a tuple. +from this class. \end{excdesc} \begin{excdesc}{StandardError} The base class for all built-in exceptions except -\exception{StopIteration} and \exception{SystemExit}. -\exception{StandardError} itself is derived from the root class -\exception{Exception}. +\exception{StopIteration}, \exception{GeneratorExit}, +\exception{KeyboardInterrupt} and \exception{SystemExit}. +\exception{StandardError} itself is derived from \exception{Exception}. \end{excdesc} \begin{excdesc}{ArithmeticError} @@ -156,6 +168,12 @@ \file{pyconfig.h} file. \end{excdesc} +\begin{excdesv}{GeneratorExit} + Raise when a generator's \method{close()} method is called. + It directly inherits from \exception{Exception} instead of + \exception{StandardError} since it is technically not an error. + \versionadded{2.5} + \begin{excdesc}{IOError} % XXXJH xrefs here Raised when an I/O operation (such as a \keyword{print} statement, @@ -192,10 +210,14 @@ Raised when the user hits the interrupt key (normally \kbd{Control-C} or \kbd{Delete}). During execution, a check for interrupts is made regularly. -% XXXJH xrefs here +% XXX(hylton) xrefs here Interrupts typed when a built-in function \function{input()} or \function{raw_input()} is waiting for input also raise this exception. + The exception inherits from \exception{BaseException} so as to not be + accidentally caught by code that catches \exception{Exception} and thus + prevent the interpreter from exiting. + \versionchanged[Changed to inherit from \exception{BaseException}]{2.5} \end{excdesc} \begin{excdesc}{MemoryError} @@ -270,6 +292,7 @@ \versionadded{2.2} \end{excdesc} + \begin{excdesc}{SyntaxError} % XXXJH xref to these functions? Raised when the parser encounters a syntax error. This may occur in @@ -299,7 +322,7 @@ \end{excdesc} \begin{excdesc}{SystemExit} -% XXXJH xref to module sys? +% XXX(hylton) xref to module sys? This exception is raised by the \function{sys.exit()} function. When it is not handled, the Python interpreter exits; no stack traceback is printed. If the associated value is a plain integer, it specifies the @@ -309,7 +332,7 @@ Instances have an attribute \member{code} which is set to the proposed exit status or error message (defaulting to \code{None}). - Also, this exception derives directly from \exception{Exception} and + Also, this exception derives directly from \exception{BaseException} and not \exception{StandardError}, since it is not technically an error. A call to \function{sys.exit()} is translated into an exception so that @@ -319,6 +342,12 @@ can be used if it is absolutely positively necessary to exit immediately (for example, in the child process after a call to \function{fork()}). + + The exception inherits from \exception{BaseException} instead of + \exception{StandardError} or \exception{Exception} so that it is not + accidentally caught by code that catches \exception{Exception}. This allows + the exception to properly propagate up and cause the interpreter to exit. + \versionchanged[Changed to inherit from \exception{BaseException}]{2.5} \end{excdesc} \begin{excdesc}{TypeError} @@ -418,49 +447,4 @@ The class hierarchy for built-in exceptions is: -\begin{verbatim} - Exception - +-- SystemExit - +-- StopIteration - +-- StandardError - | +-- KeyboardInterrupt - | +-- ImportError - | +-- EnvironmentError - | | +-- IOError - | | +-- OSError - | | +-- WindowsError - | +-- EOFError - | +-- RuntimeError - | | +-- NotImplementedError - | +-- NameError - | | +-- UnboundLocalError - | +-- AttributeError - | +-- SyntaxError - | | +-- IndentationError - | | +-- TabError - | +-- TypeError - | +-- AssertionError - | +-- LookupError - | | +-- IndexError - | | +-- KeyError - | +-- ArithmeticError - | | +-- OverflowError - | | +-- ZeroDivisionError - | | +-- FloatingPointError - | +-- ValueError - | | +-- UnicodeError - | | +-- UnicodeEncodeError - | | +-- UnicodeDecodeError - | | +-- UnicodeTranslateError - | +-- ReferenceError - | +-- SystemError - | +-- MemoryError - +---Warning - +-- UserWarning - +-- DeprecationWarning - +-- PendingDeprecationWarning - +-- SyntaxWarning - +-- OverflowWarning (not generated in 2.4; won't exist in 2.5) - +-- RuntimeWarning - +-- FutureWarning -\end{verbatim} +\verbatiminput{../../Lib/test/exception_hierarchy.txt} Modified: python/trunk/Doc/tut/tut.tex ============================================================================== --- python/trunk/Doc/tut/tut.tex (original) +++ python/trunk/Doc/tut/tut.tex Wed Mar 1 23:10:49 2006 @@ -3512,6 +3512,12 @@ defines \method{__getitem__} and \method{__str__} so the arguments can be accessed or printed directly without having to reference \code{.args}. +But use of \code{.args} is discouraged. Instead, the preferred use is to pass +a single argument to an exception (which can be a tuple if multiple arguments +are needed) and have it bound to the \code{message} attribute. One my also +instantiate an exception first before raising it and add any attributes to it +as desired. + \begin{verbatim} >>> try: ... raise Exception('spam', 'eggs') Modified: python/trunk/Python/exceptions.c ============================================================================== --- python/trunk/Python/exceptions.c (original) +++ python/trunk/Python/exceptions.c Wed Mar 1 23:10:49 2006 @@ -7,11 +7,6 @@ * By moving the exceptions into C and statically linking, we can guarantee * that the standard exceptions will always be available. * - * history: - * 98-08-19 fl created (for pyexe) - * 00-02-08 fl updated for 1.5.2 - * 26-May-2000 baw vetted for Python 1.6 - * XXX * * written by Fredrik Lundh * modifications, additions, cleanups, and proofreading by Barry Warsaw @@ -36,11 +31,11 @@ \n\ Exceptions found here are defined both in the exceptions module and the \n\ built-in namespace. It is recommended that user-defined exceptions inherit \n\ -from Exception.\n\ +from Exception. See the documentation for the exception inheritance hierarchy.\n\ " /* keep string pieces "small" */ -/* XXX exception hierarchy from Lib/test/exception_hierarchy.txt */ +/* XXX(bcannon): exception hierarchy in Lib/test/exception_hierarchy.txt */ ); From python-checkins at python.org Wed Mar 1 23:15:15 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 23:15:15 +0100 (CET) Subject: [Python-checkins] r42749 - python/trunk/Modules/cStringIO.c Message-ID: <20060301221515.6C95B1E4026@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 23:15:15 2006 New Revision: 42749 Modified: python/trunk/Modules/cStringIO.c Log: Silence gcc (4.0.x) warning about use of uninitialized value. Modified: python/trunk/Modules/cStringIO.c ============================================================================== --- python/trunk/Modules/cStringIO.c (original) +++ python/trunk/Modules/cStringIO.c Wed Mar 1 23:15:15 2006 @@ -173,7 +173,7 @@ static PyObject * IO_read(IOobject *self, PyObject *args) { Py_ssize_t n = -1; - char *output; + char *output = NULL; UNLESS (PyArg_ParseTuple(args, "|n:read", &n)) return NULL; From python-checkins at python.org Wed Mar 1 23:30:48 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 23:30:48 +0100 (CET) Subject: [Python-checkins] r42750 - python/trunk/Python/marshal.c Message-ID: <20060301223048.344C81E4050@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 23:30:47 2006 New Revision: 42750 Modified: python/trunk/Python/marshal.c Log: Fix gcc (4.0.x) warning about use of uninitialized variables. (PyMarshal_ReadShortFromFile() is only used in zipimport.c, I don't believe the extra initializations will matter one way or another.) Modified: python/trunk/Python/marshal.c ============================================================================== --- python/trunk/Python/marshal.c (original) +++ python/trunk/Python/marshal.c Wed Mar 1 23:30:47 2006 @@ -885,8 +885,9 @@ PyMarshal_ReadShortFromFile(FILE *fp) { RFILE rf; + assert(fp); rf.fp = fp; - rf.strings = NULL; + rf.strings = rf.end = rf.ptr = NULL; return r_short(&rf); } From python-checkins at python.org Wed Mar 1 23:34:10 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 23:34:10 +0100 (CET) Subject: [Python-checkins] r42751 - python/trunk/Python/marshal.c Message-ID: <20060301223410.8500F1E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 23:34:09 2006 New Revision: 42751 Modified: python/trunk/Python/marshal.c Log: Fix incompatible assignment warning from previous checkin. Modified: python/trunk/Python/marshal.c ============================================================================== --- python/trunk/Python/marshal.c (original) +++ python/trunk/Python/marshal.c Wed Mar 1 23:34:09 2006 @@ -887,7 +887,8 @@ RFILE rf; assert(fp); rf.fp = fp; - rf.strings = rf.end = rf.ptr = NULL; + rf.strings = NULL; + rf.end = rf.ptr = NULL; return r_short(&rf); } From python-checkins at python.org Wed Mar 1 23:45:36 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 23:45:36 +0100 (CET) Subject: [Python-checkins] r42752 - python/trunk/Modules/linuxaudiodev.c python/trunk/Modules/ossaudiodev.c Message-ID: <20060301224536.857BB1E4029@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 23:45:36 2006 New Revision: 42752 Modified: python/trunk/Modules/linuxaudiodev.c python/trunk/Modules/ossaudiodev.c Log: Rework channelnumber/samplesize detetion code's output variables a bit to convince gcc (4.0.x) the variables are never used uninitialized (and raising a proper exception if they ever are.) Modified: python/trunk/Modules/linuxaudiodev.c ============================================================================== --- python/trunk/Modules/linuxaudiodev.c (original) +++ python/trunk/Modules/linuxaudiodev.c Wed Mar 1 23:45:36 2006 @@ -332,7 +332,6 @@ default: return -EOPNOTSUPP; } - *nchannels = 0; if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) return -errno; return 0; @@ -345,11 +344,11 @@ lad_bufsize(lad_t *self, PyObject *args) { audio_buf_info ai; - int nchannels, ssize; + int nchannels=0, ssize=0; if (!PyArg_ParseTuple(args, ":bufsize")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0) { + if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { PyErr_SetFromErrno(LinuxAudioError); return NULL; } @@ -366,12 +365,12 @@ lad_obufcount(lad_t *self, PyObject *args) { audio_buf_info ai; - int nchannels, ssize; + int nchannels=0, ssize=0; if (!PyArg_ParseTuple(args, ":obufcount")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0) { + if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { PyErr_SetFromErrno(LinuxAudioError); return NULL; } @@ -389,12 +388,12 @@ lad_obuffree(lad_t *self, PyObject *args) { audio_buf_info ai; - int nchannels, ssize; + int nchannels=0, ssize=0; if (!PyArg_ParseTuple(args, ":obuffree")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0) { + if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { PyErr_SetFromErrno(LinuxAudioError); return NULL; } Modified: python/trunk/Modules/ossaudiodev.c ============================================================================== --- python/trunk/Modules/ossaudiodev.c (original) +++ python/trunk/Modules/ossaudiodev.c Wed Mar 1 23:45:36 2006 @@ -569,7 +569,6 @@ default: return -EOPNOTSUPP; } - *nchannels = 0; if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) return -errno; return 0; @@ -582,11 +581,11 @@ oss_bufsize(oss_audio_t *self, PyObject *args) { audio_buf_info ai; - int nchannels, ssize; + int nchannels=0, ssize=0; if (!PyArg_ParseTuple(args, ":bufsize")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0) { + if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -603,12 +602,12 @@ oss_obufcount(oss_audio_t *self, PyObject *args) { audio_buf_info ai; - int nchannels, ssize; + int nchannels=0, ssize=0; if (!PyArg_ParseTuple(args, ":obufcount")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0) { + if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -626,12 +625,12 @@ oss_obuffree(oss_audio_t *self, PyObject *args) { audio_buf_info ai; - int nchannels, ssize; + int nchannels=0, ssize=0; if (!PyArg_ParseTuple(args, ":obuffree")) return NULL; - if (_ssize(self, &nchannels, &ssize) < 0) { + if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } From python-checkins at python.org Wed Mar 1 23:49:09 2006 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Mar 2006 23:49:09 +0100 (CET) Subject: [Python-checkins] r42753 - in python/trunk: Doc/lib/libast.tex Include/Python-ast.h Include/node.h Lib/test/test_ast.py Modules/parsermodule.c Parser/Python.asdl Parser/asdl.py Parser/node.c Parser/parser.c Parser/parser.h Parser/parsetok.c Parser/tokenizer.c Parser/tokenizer.h Python/Python-ast.c Python/ast.c Python/compile.c Message-ID: <20060301224909.7DB371E4002@bag.python.org> Author: martin.v.loewis Date: Wed Mar 1 23:49:05 2006 New Revision: 42753 Modified: python/trunk/Doc/lib/libast.tex python/trunk/Include/Python-ast.h python/trunk/Include/node.h python/trunk/Lib/test/test_ast.py python/trunk/Modules/parsermodule.c python/trunk/Parser/Python.asdl python/trunk/Parser/asdl.py python/trunk/Parser/node.c python/trunk/Parser/parser.c python/trunk/Parser/parser.h python/trunk/Parser/parsetok.c python/trunk/Parser/tokenizer.c python/trunk/Parser/tokenizer.h python/trunk/Python/Python-ast.c python/trunk/Python/ast.c python/trunk/Python/compile.c Log: Patch #1440601: Add col_offset attribute to AST nodes. Modified: python/trunk/Doc/lib/libast.tex ============================================================================== --- python/trunk/Doc/lib/libast.tex (original) +++ python/trunk/Doc/lib/libast.tex Wed Mar 1 23:49:05 2006 @@ -34,7 +34,13 @@ Each instance of a concrete class has one attribute for each child node, of the type as defined in the grammar. For example, \code{_ast.BinOp} -instances have an attribute \code{left} of type \code{_ast.expr}. +instances have an attribute \code{left} of type \code{_ast.expr}. +Instances of \code{_ast.expr} and \code{_ast.stmt} subclasses also +have lineno and col_offset attributes. The lineno is the line number +of source text (1 indexed so the first line is line 1) and the +col_offset is the utf8 byte offset of the first token that generated +the node. The utf8 offset is recorded because the parser uses utf8 +internally. If these attributes are marked as optional in the grammar (using a question mark), the value might be \code{None}. If the attributes Modified: python/trunk/Include/Python-ast.h ============================================================================== --- python/trunk/Include/Python-ast.h (original) +++ python/trunk/Include/Python-ast.h Wed Mar 1 23:49:05 2006 @@ -178,6 +178,7 @@ } v; int lineno; + int col_offset; }; struct _expr { @@ -288,6 +289,7 @@ } v; int lineno; + int col_offset; }; struct _slice { @@ -346,68 +348,79 @@ mod_ty Expression(expr_ty body, PyArena *arena); mod_ty Suite(asdl_seq * body, PyArena *arena); stmt_ty FunctionDef(identifier name, arguments_ty args, asdl_seq * body, - asdl_seq * decorators, int lineno, PyArena *arena); + asdl_seq * decorators, int lineno, int col_offset, PyArena + *arena); stmt_ty ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int - lineno, PyArena *arena); -stmt_ty Return(expr_ty value, int lineno, PyArena *arena); -stmt_ty Delete(asdl_seq * targets, int lineno, PyArena *arena); -stmt_ty Assign(asdl_seq * targets, expr_ty value, int lineno, PyArena *arena); + lineno, int col_offset, PyArena *arena); +stmt_ty Return(expr_ty value, int lineno, int col_offset, PyArena *arena); +stmt_ty Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena); +stmt_ty Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, + PyArena *arena); stmt_ty AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, - PyArena *arena); -stmt_ty Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, PyArena - *arena); + int col_offset, PyArena *arena); +stmt_ty Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int + col_offset, PyArena *arena); stmt_ty For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, - int lineno, PyArena *arena); -stmt_ty While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, - PyArena *arena); -stmt_ty If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, - PyArena *arena); + int lineno, int col_offset, PyArena *arena); +stmt_ty While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int + col_offset, PyArena *arena); +stmt_ty If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int + col_offset, PyArena *arena); stmt_ty With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int - lineno, PyArena *arena); -stmt_ty Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, PyArena - *arena); + lineno, int col_offset, PyArena *arena); +stmt_ty Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int + col_offset, PyArena *arena); stmt_ty TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int - lineno, PyArena *arena); -stmt_ty TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, PyArena - *arena); -stmt_ty Assert(expr_ty test, expr_ty msg, int lineno, PyArena *arena); -stmt_ty Import(asdl_seq * names, int lineno, PyArena *arena); + lineno, int col_offset, PyArena *arena); +stmt_ty TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int + col_offset, PyArena *arena); +stmt_ty Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena + *arena); +stmt_ty Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena); stmt_ty ImportFrom(identifier module, asdl_seq * names, int level, int lineno, - PyArena *arena); -stmt_ty Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, PyArena - *arena); -stmt_ty Global(asdl_seq * names, int lineno, PyArena *arena); -stmt_ty Expr(expr_ty value, int lineno, PyArena *arena); -stmt_ty Pass(int lineno, PyArena *arena); -stmt_ty Break(int lineno, PyArena *arena); -stmt_ty Continue(int lineno, PyArena *arena); -expr_ty BoolOp(boolop_ty op, asdl_seq * values, int lineno, PyArena *arena); -expr_ty BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, PyArena - *arena); -expr_ty UnaryOp(unaryop_ty op, expr_ty operand, int lineno, PyArena *arena); -expr_ty Lambda(arguments_ty args, expr_ty body, int lineno, PyArena *arena); -expr_ty IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, PyArena - *arena); -expr_ty Dict(asdl_seq * keys, asdl_seq * values, int lineno, PyArena *arena); -expr_ty ListComp(expr_ty elt, asdl_seq * generators, int lineno, PyArena - *arena); -expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, PyArena - *arena); -expr_ty Yield(expr_ty value, int lineno, PyArena *arena); + int col_offset, PyArena *arena); +stmt_ty Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int + col_offset, PyArena *arena); +stmt_ty Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena); +stmt_ty Expr(expr_ty value, int lineno, int col_offset, PyArena *arena); +stmt_ty Pass(int lineno, int col_offset, PyArena *arena); +stmt_ty Break(int lineno, int col_offset, PyArena *arena); +stmt_ty Continue(int lineno, int col_offset, PyArena *arena); +expr_ty BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, + PyArena *arena); +expr_ty BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int + col_offset, PyArena *arena); +expr_ty UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, + PyArena *arena); +expr_ty Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, + PyArena *arena); +expr_ty IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int + col_offset, PyArena *arena); +expr_ty Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, + PyArena *arena); +expr_ty ListComp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, PyArena *arena); +expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int + col_offset, PyArena *arena); +expr_ty Yield(expr_ty value, int lineno, int col_offset, PyArena *arena); expr_ty Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int - lineno, PyArena *arena); + lineno, int col_offset, PyArena *arena); expr_ty Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty - starargs, expr_ty kwargs, int lineno, PyArena *arena); -expr_ty Repr(expr_ty value, int lineno, PyArena *arena); -expr_ty Num(object n, int lineno, PyArena *arena); -expr_ty Str(string s, int lineno, PyArena *arena); + starargs, expr_ty kwargs, int lineno, int col_offset, PyArena + *arena); +expr_ty Repr(expr_ty value, int lineno, int col_offset, PyArena *arena); +expr_ty Num(object n, int lineno, int col_offset, PyArena *arena); +expr_ty Str(string s, int lineno, int col_offset, PyArena *arena); expr_ty Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int - lineno, PyArena *arena); + lineno, int col_offset, PyArena *arena); expr_ty Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int - lineno, PyArena *arena); -expr_ty Name(identifier id, expr_context_ty ctx, int lineno, PyArena *arena); -expr_ty List(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena); -expr_ty Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena); + lineno, int col_offset, PyArena *arena); +expr_ty Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, + PyArena *arena); +expr_ty List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, + PyArena *arena); +expr_ty Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, + PyArena *arena); slice_ty Ellipsis(PyArena *arena); slice_ty Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena); slice_ty ExtSlice(asdl_seq * dims, PyArena *arena); Modified: python/trunk/Include/node.h ============================================================================== --- python/trunk/Include/node.h (original) +++ python/trunk/Include/node.h Wed Mar 1 23:49:05 2006 @@ -11,13 +11,14 @@ short n_type; char *n_str; int n_lineno; + int n_col_offset; int n_nchildren; struct _node *n_child; } node; PyAPI_FUNC(node *) PyNode_New(int type); PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, - char *str, int lineno); + char *str, int lineno, int col_offset); PyAPI_FUNC(void) PyNode_Free(node *n); /* Node access functions */ Modified: python/trunk/Lib/test/test_ast.py ============================================================================== --- python/trunk/Lib/test/test_ast.py (original) +++ python/trunk/Lib/test/test_ast.py Wed Mar 1 23:49:05 2006 @@ -1,4 +1,5 @@ import sys, itertools +import _ast def to_tuple(t): if t is None or isinstance(t, (basestring, int, long, complex)): @@ -6,6 +7,8 @@ elif isinstance(t, list): return [to_tuple(e) for e in t] result = [t.__class__.__name__] + if hasattr(t, 'lineno') and hasattr(t, 'col_offset'): + result.append((t.lineno, t.col_offset)) if t._fields is None: return tuple(result) for f in t._fields: @@ -106,7 +109,10 @@ # List "[1,2,3]", # Tuple - "1,2,3" + "1,2,3", + # Combination + "a.b.c.d(a.b[1:2])", + ] # TODO: expr_context, slice, boolop, operator, unaryop, cmpop, comprehension @@ -121,58 +127,77 @@ print "run_tests()" raise SystemExit +def test_order(ast_node, parent_pos): + + if not isinstance(ast_node, _ast.AST) or ast_node._fields == None: + return + if isinstance(ast_node, (_ast.expr, _ast.stmt)): + node_pos = (ast_node.lineno, ast_node.col_offset) + assert node_pos >= parent_pos, (node_pos, parent_pos) + parent_pos = (ast_node.lineno, ast_node.col_offset) + for name in ast_node._fields: + value = getattr(ast_node, name) + if isinstance(value, list): + for child in value: + test_order(child, parent_pos) + elif value != None: + test_order(value, parent_pos) + def run_tests(): for input, output, kind in ((exec_tests, exec_results, "exec"), (single_tests, single_results, "single"), (eval_tests, eval_results, "eval")): for i, o in itertools.izip(input, output): - assert to_tuple(compile(i, "?", kind, 0x400)) == o + ast_tree = compile(i, "?", kind, 0x400) + assert to_tuple(ast_tree) == o + test_order(ast_tree, (0, 0)) #### EVERYTHING BELOW IS GENERATED ##### exec_results = [ -('Module', [('FunctionDef', 'f', ('arguments', [], None, None, []), [('Pass',)], [])]), -('Module', [('ClassDef', 'C', [], [('Pass',)])]), -('Module', [('FunctionDef', 'f', ('arguments', [], None, None, []), [('Return', ('Num', 1))], [])]), -('Module', [('Delete', [('Name', 'v', ('Del',))])]), -('Module', [('Assign', [('Name', 'v', ('Store',))], ('Num', 1))]), -('Module', [('AugAssign', ('Name', 'v', ('Load',)), ('Add',), ('Num', 1))]), -('Module', [('Print', ('Name', 'f', ('Load',)), [('Num', 1)], False)]), -('Module', [('For', ('Name', 'v', ('Store',)), ('Name', 'v', ('Load',)), [('Pass',)], [])]), -('Module', [('While', ('Name', 'v', ('Load',)), [('Pass',)], [])]), -('Module', [('If', ('Name', 'v', ('Load',)), [('Pass',)], [])]), -('Module', [('Raise', ('Name', 'Exception', ('Load',)), ('Str', 'string'), None)]), -('Module', [('TryExcept', [('Pass',)], [('excepthandler', ('Name', 'Exception', ('Load',)), None, [('Pass',)])], [])]), -('Module', [('TryFinally', [('Pass',)], [('Pass',)])]), -('Module', [('Assert', ('Name', 'v', ('Load',)), None)]), -('Module', [('Import', [('alias', 'sys', None)])]), -('Module', [('ImportFrom', 'sys', [('alias', 'v', None)], 0)]), -('Module', [('Exec', ('Str', 'v'), None, None)]), -('Module', [('Global', ['v'])]), -('Module', [('Expr', ('Num', 1))]), -('Module', [('Pass',)]), -('Module', [('Break',)]), -('Module', [('Continue',)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Pass', (1, 9))], [])]), +('Module', [('ClassDef', (1, 0), 'C', [], [('Pass', (1, 8))])]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Return', (1, 8), ('Num', (1, 15), 1))], [])]), +('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), +('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), +('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Load',)), ('Add',), ('Num', (1, 5), 1))]), +('Module', [('Print', (1, 0), ('Name', (1, 8), 'f', ('Load',)), [('Num', (1, 11), 1)], False)]), +('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]), +('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]), +('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), +('Module', [('Raise', (1, 0), ('Name', (1, 6), 'Exception', ('Load',)), ('Str', (1, 17), 'string'), None)]), +('Module', [('TryExcept', (1, 0), [('Pass', (2, 2))], [('excepthandler', ('Name', (3, 7), 'Exception', ('Load',)), None, [('Pass', (4, 2))])], [])]), +('Module', [('TryFinally', (1, 0), [('Pass', (2, 2))], [('Pass', (4, 2))])]), +('Module', [('Assert', (1, 0), ('Name', (1, 7), 'v', ('Load',)), None)]), +('Module', [('Import', (1, 0), [('alias', 'sys', None)])]), +('Module', [('ImportFrom', (1, 0), 'sys', [('alias', 'v', None)], 0)]), +('Module', [('Exec', (1, 0), ('Str', (1, 5), 'v'), None, None)]), +('Module', [('Global', (1, 0), ['v'])]), +('Module', [('Expr', (1, 0), ('Num', (1, 0), 1))]), +('Module', [('Pass', (1, 0))]), +('Module', [('Break', (1, 0))]), +('Module', [('Continue', (1, 0))]), ] single_results = [ -('Interactive', [('Expr', ('BinOp', ('Num', 1), ('Add',), ('Num', 2)))]), +('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]), ] eval_results = [ -('Expression', ('BoolOp', ('And',), [('Name', 'a', ('Load',)), ('Name', 'b', ('Load',))])), -('Expression', ('BinOp', ('Name', 'a', ('Load',)), ('Add',), ('Name', 'b', ('Load',)))), -('Expression', ('UnaryOp', ('Not',), ('Name', 'v', ('Load',)))), -('Expression', ('Lambda', ('arguments', [], None, None, []), ('Name', 'None', ('Load',)))), -('Expression', ('Dict', [('Num', 1)], [('Num', 2)])), -('Expression', ('ListComp', ('Name', 'a', ('Load',)), [('comprehension', ('Name', 'b', ('Store',)), ('Name', 'c', ('Load',)), [('Name', 'd', ('Load',))])])), -('Expression', ('GeneratorExp', ('Name', 'a', ('Load',)), [('comprehension', ('Name', 'b', ('Store',)), ('Name', 'c', ('Load',)), [('Name', 'd', ('Load',))])])), -('Expression', ('Compare', ('Num', 1), [('Lt',), ('Lt',)], [('Num', 2), ('Num', 3)])), -('Expression', ('Call', ('Name', 'f', ('Load',)), [('Num', 1), ('Num', 2)], [('keyword', 'c', ('Num', 3))], ('Name', 'd', ('Load',)), ('Name', 'e', ('Load',)))), -('Expression', ('Repr', ('Name', 'v', ('Load',)))), -('Expression', ('Num', 10L)), -('Expression', ('Str', 'string')), -('Expression', ('Attribute', ('Name', 'a', ('Load',)), 'b', ('Load',))), -('Expression', ('Subscript', ('Name', 'a', ('Load',)), ('Slice', ('Name', 'b', ('Load',)), ('Name', 'c', ('Load',)), None), ('Load',))), -('Expression', ('Name', 'v', ('Load',))), -('Expression', ('List', [('Num', 1), ('Num', 2), ('Num', 3)], ('Load',))), -('Expression', ('Tuple', [('Num', 1), ('Num', 2), ('Num', 3)], ('Load',))), +('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ('Name', (1, 6), 'b', ('Load',))])), +('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('Name', (1, 4), 'b', ('Load',)))), +('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))), +('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, []), ('Name', (1, 7), 'None', ('Load',)))), +('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])), +('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), +('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), +('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])), +('Expression', ('Call', (1, 0), ('Name', (1, 0), 'f', ('Load',)), [('Num', (1, 2), 1), ('Num', (1, 4), 2)], [('keyword', 'c', ('Num', (1, 8), 3))], ('Name', (1, 11), 'd', ('Load',)), ('Name', (1, 15), 'e', ('Load',)))), +('Expression', ('Repr', (1, 0), ('Name', (1, 1), 'v', ('Load',)))), +('Expression', ('Num', (1, 0), 10L)), +('Expression', ('Str', (1, 0), 'string')), +('Expression', ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',))), +('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))), +('Expression', ('Name', (1, 0), 'v', ('Load',))), +('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), +('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num', (1, 4), 3)], ('Load',))), +('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)), ] run_tests() Modified: python/trunk/Modules/parsermodule.c ============================================================================== --- python/trunk/Modules/parsermodule.c (original) +++ python/trunk/Modules/parsermodule.c Wed Mar 1 23:49:05 2006 @@ -715,7 +715,7 @@ Py_XDECREF(elem); return (0); } - err = PyNode_AddChild(root, type, strn, *line_num); + err = PyNode_AddChild(root, type, strn, *line_num, 0); if (err == E_NOMEM) { PyMem_DEL(strn); return (node *) PyErr_NoMemory(); Modified: python/trunk/Parser/Python.asdl ============================================================================== --- python/trunk/Parser/Python.asdl (original) +++ python/trunk/Parser/Python.asdl Wed Mar 1 23:49:05 2006 @@ -46,7 +46,8 @@ | Pass | Break | Continue -- XXX Jython will be different - attributes (int lineno) + -- col_offset is the byte offset in the utf8 string the parser uses + attributes (int lineno, int col_offset) -- BoolOp() can use left & right? expr = BoolOp(boolop op, expr* values) @@ -76,7 +77,8 @@ | List(expr* elts, expr_context ctx) | Tuple(expr *elts, expr_context ctx) - attributes (int lineno) + -- col_offset is the byte offset in the utf8 string the parser uses + attributes (int lineno, int col_offset) expr_context = Load | Store | Del | AugLoad | AugStore | Param Modified: python/trunk/Parser/asdl.py ============================================================================== --- python/trunk/Parser/asdl.py (original) +++ python/trunk/Parser/asdl.py Wed Mar 1 23:49:05 2006 @@ -156,6 +156,8 @@ if id.value != "attributes": raise ASDLSyntaxError(id.lineno, msg="expected attributes, found %s" % id) + if attributes: + attributes.reverse() return Sum(sum, attributes) def p_product(self, (_0, fields, _1)): Modified: python/trunk/Parser/node.c ============================================================================== --- python/trunk/Parser/node.c (original) +++ python/trunk/Parser/node.c Wed Mar 1 23:49:05 2006 @@ -76,7 +76,7 @@ int -PyNode_AddChild(register node *n1, int type, char *str, int lineno) +PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offset) { const int nch = n1->n_nchildren; int current_capacity; @@ -103,6 +103,7 @@ n->n_type = type; n->n_str = str; n->n_lineno = lineno; + n->n_col_offset = col_offset; n->n_nchildren = 0; n->n_child = NULL; return 0; Modified: python/trunk/Parser/parser.c ============================================================================== --- python/trunk/Parser/parser.c (original) +++ python/trunk/Parser/parser.c Wed Mar 1 23:49:05 2006 @@ -105,11 +105,11 @@ /* PARSER STACK OPERATIONS */ static int -shift(register stack *s, int type, char *str, int newstate, int lineno) +shift(register stack *s, int type, char *str, int newstate, int lineno, int col_offset) { int err; assert(!s_empty(s)); - err = PyNode_AddChild(s->s_top->s_parent, type, str, lineno); + err = PyNode_AddChild(s->s_top->s_parent, type, str, lineno, col_offset); if (err) return err; s->s_top->s_state = newstate; @@ -117,13 +117,13 @@ } static int -push(register stack *s, int type, dfa *d, int newstate, int lineno) +push(register stack *s, int type, dfa *d, int newstate, int lineno, int col_offset) { int err; register node *n; n = s->s_top->s_parent; assert(!s_empty(s)); - err = PyNode_AddChild(n, type, (char *)NULL, lineno); + err = PyNode_AddChild(n, type, (char *)NULL, lineno, col_offset); if (err) return err; s->s_top->s_state = newstate; @@ -213,7 +213,7 @@ int PyParser_AddToken(register parser_state *ps, register int type, char *str, - int lineno, int *expected_ret) + int lineno, int col_offset, int *expected_ret) { register int ilabel; int err; @@ -245,7 +245,7 @@ dfa *d1 = PyGrammar_FindDFA( ps->p_grammar, nt); if ((err = push(&ps->p_stack, nt, d1, - arrow, lineno)) > 0) { + arrow, lineno, col_offset)) > 0) { D(printf(" MemError: push\n")); return err; } @@ -255,7 +255,7 @@ /* Shift the token */ if ((err = shift(&ps->p_stack, type, str, - x, lineno)) > 0) { + x, lineno, col_offset)) > 0) { D(printf(" MemError: shift.\n")); return err; } Modified: python/trunk/Parser/parser.h ============================================================================== --- python/trunk/Parser/parser.h (original) +++ python/trunk/Parser/parser.h Wed Mar 1 23:49:05 2006 @@ -32,7 +32,7 @@ parser_state *PyParser_New(grammar *g, int start); void PyParser_Delete(parser_state *ps); -int PyParser_AddToken(parser_state *ps, int type, char *str, int lineno, +int PyParser_AddToken(parser_state *ps, int type, char *str, int lineno, int col_offset, int *expected_ret); void PyGrammar_AddAccelerators(grammar *g); Modified: python/trunk/Parser/parsetok.c ============================================================================== --- python/trunk/Parser/parsetok.c (original) +++ python/trunk/Parser/parsetok.c Wed Mar 1 23:49:05 2006 @@ -130,6 +130,7 @@ int type; size_t len; char *str; + int col_offset; type = PyTokenizer_Get(tok, &a, &b); if (type == ERRORTOKEN) { @@ -185,9 +186,13 @@ len == 4 && str[0] == 'w' && strcmp(str, "with") == 0) handling_with = 1; #endif - + if (a >= tok->line_start) + col_offset = a - tok->line_start; + else + col_offset = -1; + if ((err_ret->error = - PyParser_AddToken(ps, (int)type, str, tok->lineno, + PyParser_AddToken(ps, (int)type, str, tok->lineno, col_offset, &(err_ret->expected))) != E_OK) { if (err_ret->error != E_DONE) PyObject_FREE(str); Modified: python/trunk/Parser/tokenizer.c ============================================================================== --- python/trunk/Parser/tokenizer.c (original) +++ python/trunk/Parser/tokenizer.c Wed Mar 1 23:49:05 2006 @@ -764,6 +764,7 @@ } if (tok->start == NULL) tok->buf = tok->cur; + tok->line_start = tok->cur; tok->lineno++; tok->inp = end; return Py_CHARMASK(*tok->cur++); @@ -798,6 +799,7 @@ } tok->buf = buf; tok->cur = tok->buf + oldlen; + tok->line_start = tok->cur; strcpy(tok->buf + oldlen, new); PyMem_FREE(new); tok->inp = tok->buf + newlen; @@ -809,7 +811,9 @@ if (tok->buf != NULL) PyMem_DEL(tok->buf); tok->buf = new; + tok->line_start = tok->buf; tok->cur = tok->buf; + tok->line_start = tok->buf; tok->inp = strchr(tok->buf, '\0'); tok->end = tok->inp + 1; } @@ -877,6 +881,7 @@ done = tok->inp[-1] == '\n'; } tok->cur = tok->buf + cur; + tok->line_start = tok->cur; /* replace "\r\n" with "\n" */ /* For Mac we leave the \r, giving a syntax error */ pt = tok->inp - 2; Modified: python/trunk/Parser/tokenizer.h ============================================================================== --- python/trunk/Parser/tokenizer.h (original) +++ python/trunk/Parser/tokenizer.h Wed Mar 1 23:49:05 2006 @@ -45,6 +45,7 @@ int read_coding_spec; /* whether 'coding:...' has been read */ char *encoding; int cont_line; /* whether we are in a continuation line. */ + const char* line_start; /* pointer to start of current line */ #ifndef PGEN PyObject *decoding_readline; /* codecs.open(...).readline */ PyObject *decoding_buffer; Modified: python/trunk/Python/Python-ast.c ============================================================================== --- python/trunk/Python/Python-ast.c (original) +++ python/trunk/Python/Python-ast.c Wed Mar 1 23:49:05 2006 @@ -25,6 +25,7 @@ static PyTypeObject *stmt_type; static char *stmt_attributes[] = { "lineno", + "col_offset", }; static PyObject* ast2obj_stmt(void*); static PyTypeObject *FunctionDef_type; @@ -142,6 +143,7 @@ static PyTypeObject *expr_type; static char *expr_attributes[] = { "lineno", + "col_offset", }; static PyObject* ast2obj_expr(void*); static PyTypeObject *BoolOp_type; @@ -450,7 +452,7 @@ if (!Suite_type) return 0; stmt_type = make_type("stmt", AST_type, NULL, 0); if (!stmt_type) return 0; - if (!add_attributes(stmt_type, stmt_attributes, 1)) return 0; + if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, 4); if (!FunctionDef_type) return 0; @@ -502,7 +504,7 @@ if (!Continue_type) return 0; expr_type = make_type("expr", AST_type, NULL, 0); if (!expr_type) return 0; - if (!add_attributes(expr_type, expr_attributes, 1)) return 0; + if (!add_attributes(expr_type, expr_attributes, 2)) return 0; BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); if (!BoolOp_type) return 0; BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); @@ -783,7 +785,7 @@ stmt_ty FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * - decorators, int lineno, PyArena *arena) + decorators, int lineno, int col_offset, PyArena *arena) { stmt_ty p; if (!name) { @@ -807,12 +809,13 @@ p->v.FunctionDef.body = body; p->v.FunctionDef.decorators = decorators; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, - PyArena *arena) +ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int + col_offset, PyArena *arena) { stmt_ty p; if (!name) { @@ -830,11 +833,12 @@ p->v.ClassDef.bases = bases; p->v.ClassDef.body = body; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Return(expr_ty value, int lineno, PyArena *arena) +Return(expr_ty value, int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -845,11 +849,12 @@ p->kind = Return_kind; p->v.Return.value = value; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Delete(asdl_seq * targets, int lineno, PyArena *arena) +Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -860,11 +865,13 @@ p->kind = Delete_kind; p->v.Delete.targets = targets; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Assign(asdl_seq * targets, expr_ty value, int lineno, PyArena *arena) +Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena + *arena) { stmt_ty p; if (!value) { @@ -881,12 +888,13 @@ p->v.Assign.targets = targets; p->v.Assign.value = value; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, PyArena - *arena) +AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int + col_offset, PyArena *arena) { stmt_ty p; if (!target) { @@ -914,11 +922,13 @@ p->v.AugAssign.op = op; p->v.AugAssign.value = value; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, PyArena *arena) +Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset, + PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -931,12 +941,13 @@ p->v.Print.values = values; p->v.Print.nl = nl; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int - lineno, PyArena *arena) + lineno, int col_offset, PyArena *arena) { stmt_ty p; if (!target) { @@ -960,12 +971,13 @@ p->v.For.body = body; p->v.For.orelse = orelse; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena - *arena) +While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int + col_offset, PyArena *arena) { stmt_ty p; if (!test) { @@ -983,11 +995,13 @@ p->v.While.body = body; p->v.While.orelse = orelse; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, PyArena *arena) +If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int + col_offset, PyArena *arena) { stmt_ty p; if (!test) { @@ -1005,12 +1019,13 @@ p->v.If.body = body; p->v.If.orelse = orelse; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno, - PyArena *arena) + int col_offset, PyArena *arena) { stmt_ty p; if (!context_expr) { @@ -1028,11 +1043,13 @@ p->v.With.optional_vars = optional_vars; p->v.With.body = body; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, PyArena *arena) +Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset, + PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1045,12 +1062,13 @@ p->v.Raise.inst = inst; p->v.Raise.tback = tback; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno, - PyArena *arena) + int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1063,11 +1081,13 @@ p->v.TryExcept.handlers = handlers; p->v.TryExcept.orelse = orelse; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, PyArena *arena) +TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset, + PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1079,11 +1099,12 @@ p->v.TryFinally.body = body; p->v.TryFinally.finalbody = finalbody; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Assert(expr_ty test, expr_ty msg, int lineno, PyArena *arena) +Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) { stmt_ty p; if (!test) { @@ -1100,11 +1121,12 @@ p->v.Assert.test = test; p->v.Assert.msg = msg; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Import(asdl_seq * names, int lineno, PyArena *arena) +Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1115,12 +1137,13 @@ p->kind = Import_kind; p->v.Import.names = names; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -ImportFrom(identifier module, asdl_seq * names, int level, int lineno, PyArena - *arena) +ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int + col_offset, PyArena *arena) { stmt_ty p; if (!module) { @@ -1138,11 +1161,13 @@ p->v.ImportFrom.names = names; p->v.ImportFrom.level = level; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, PyArena *arena) +Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset, + PyArena *arena) { stmt_ty p; if (!body) { @@ -1160,11 +1185,12 @@ p->v.Exec.globals = globals; p->v.Exec.locals = locals; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Global(asdl_seq * names, int lineno, PyArena *arena) +Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1175,11 +1201,12 @@ p->kind = Global_kind; p->v.Global.names = names; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Expr(expr_ty value, int lineno, PyArena *arena) +Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) { stmt_ty p; if (!value) { @@ -1195,11 +1222,12 @@ p->kind = Expr_kind; p->v.Expr.value = value; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Pass(int lineno, PyArena *arena) +Pass(int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1209,11 +1237,12 @@ } p->kind = Pass_kind; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Break(int lineno, PyArena *arena) +Break(int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1223,11 +1252,12 @@ } p->kind = Break_kind; p->lineno = lineno; + p->col_offset = col_offset; return p; } stmt_ty -Continue(int lineno, PyArena *arena) +Continue(int lineno, int col_offset, PyArena *arena) { stmt_ty p; p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1237,11 +1267,13 @@ } p->kind = Continue_kind; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -BoolOp(boolop_ty op, asdl_seq * values, int lineno, PyArena *arena) +BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena + *arena) { expr_ty p; if (!op) { @@ -1258,11 +1290,13 @@ p->v.BoolOp.op = op; p->v.BoolOp.values = values; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, PyArena *arena) +BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, + PyArena *arena) { expr_ty p; if (!left) { @@ -1290,11 +1324,13 @@ p->v.BinOp.op = op; p->v.BinOp.right = right; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -UnaryOp(unaryop_ty op, expr_ty operand, int lineno, PyArena *arena) +UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena + *arena) { expr_ty p; if (!op) { @@ -1316,11 +1352,13 @@ p->v.UnaryOp.op = op; p->v.UnaryOp.operand = operand; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Lambda(arguments_ty args, expr_ty body, int lineno, PyArena *arena) +Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena + *arena) { expr_ty p; if (!args) { @@ -1342,11 +1380,13 @@ p->v.Lambda.args = args; p->v.Lambda.body = body; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, PyArena *arena) +IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, + PyArena *arena) { expr_ty p; if (!test) { @@ -1374,11 +1414,13 @@ p->v.IfExp.body = body; p->v.IfExp.orelse = orelse; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Dict(asdl_seq * keys, asdl_seq * values, int lineno, PyArena *arena) +Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena + *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1390,11 +1432,13 @@ p->v.Dict.keys = keys; p->v.Dict.values = values; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -ListComp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena) +ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, + PyArena *arena) { expr_ty p; if (!elt) { @@ -1411,11 +1455,13 @@ p->v.ListComp.elt = elt; p->v.ListComp.generators = generators; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, PyArena *arena) +GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, + PyArena *arena) { expr_ty p; if (!elt) { @@ -1432,11 +1478,12 @@ p->v.GeneratorExp.elt = elt; p->v.GeneratorExp.generators = generators; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Yield(expr_ty value, int lineno, PyArena *arena) +Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) { expr_ty p; p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1447,12 +1494,13 @@ p->kind = Yield_kind; p->v.Yield.value = value; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno, - PyArena *arena) +Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators, int lineno, int + col_offset, PyArena *arena) { expr_ty p; if (!left) { @@ -1470,12 +1518,13 @@ p->v.Compare.ops = ops; p->v.Compare.comparators = comparators; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs, - expr_ty kwargs, int lineno, PyArena *arena) + expr_ty kwargs, int lineno, int col_offset, PyArena *arena) { expr_ty p; if (!func) { @@ -1495,11 +1544,12 @@ p->v.Call.starargs = starargs; p->v.Call.kwargs = kwargs; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Repr(expr_ty value, int lineno, PyArena *arena) +Repr(expr_ty value, int lineno, int col_offset, PyArena *arena) { expr_ty p; if (!value) { @@ -1515,11 +1565,12 @@ p->kind = Repr_kind; p->v.Repr.value = value; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Num(object n, int lineno, PyArena *arena) +Num(object n, int lineno, int col_offset, PyArena *arena) { expr_ty p; if (!n) { @@ -1535,11 +1586,12 @@ p->kind = Num_kind; p->v.Num.n = n; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Str(string s, int lineno, PyArena *arena) +Str(string s, int lineno, int col_offset, PyArena *arena) { expr_ty p; if (!s) { @@ -1555,12 +1607,13 @@ p->kind = Str_kind; p->v.Str.s = s; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, - PyArena *arena) +Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int + col_offset, PyArena *arena) { expr_ty p; if (!value) { @@ -1588,12 +1641,13 @@ p->v.Attribute.attr = attr; p->v.Attribute.ctx = ctx; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, - PyArena *arena) +Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int + col_offset, PyArena *arena) { expr_ty p; if (!value) { @@ -1621,11 +1675,13 @@ p->v.Subscript.slice = slice; p->v.Subscript.ctx = ctx; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Name(identifier id, expr_context_ty ctx, int lineno, PyArena *arena) +Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena + *arena) { expr_ty p; if (!id) { @@ -1647,11 +1703,13 @@ p->v.Name.id = id; p->v.Name.ctx = ctx; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -List(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena) +List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena + *arena) { expr_ty p; if (!ctx) { @@ -1668,11 +1726,13 @@ p->v.List.elts = elts; p->v.List.ctx = ctx; p->lineno = lineno; + p->col_offset = col_offset; return p; } expr_ty -Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, PyArena *arena) +Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena + *arena) { expr_ty p; if (!ctx) { @@ -1689,6 +1749,7 @@ p->v.Tuple.elts = elts; p->v.Tuple.ctx = ctx; p->lineno = lineno; + p->col_offset = col_offset; return p; } @@ -2264,6 +2325,9 @@ value = ast2obj_int(o->lineno); if (!value) goto failed; PyObject_SetAttrString(result, "lineno", value); + value = ast2obj_int(o->col_offset); + if (!value) goto failed; + PyObject_SetAttrString(result, "col_offset", value); return result; failed: Py_XDECREF(value); @@ -2580,6 +2644,9 @@ value = ast2obj_int(o->lineno); if (!value) goto failed; PyObject_SetAttrString(result, "lineno", value); + value = ast2obj_int(o->col_offset); + if (!value) goto failed; + PyObject_SetAttrString(result, "col_offset", value); return result; failed: Py_XDECREF(value); Modified: python/trunk/Python/ast.c ============================================================================== --- python/trunk/Python/ast.c (original) +++ python/trunk/Python/ast.c Wed Mar 1 23:49:05 2006 @@ -243,7 +243,7 @@ stmts = asdl_seq_new(1, arena); if (!stmts) goto error; - asdl_seq_SET(stmts, 0, Pass(n->n_lineno, arena)); + asdl_seq_SET(stmts, 0, Pass(n->n_lineno, n->n_col_offset, arena)); return Interactive(stmts, arena); } else { @@ -564,7 +564,7 @@ ast_error(child, "assignment to None"); return NULL; } - arg = Name(NEW_IDENTIFIER(child), Store, LINENO(child), + arg = Name(NEW_IDENTIFIER(child), Store, LINENO(child), child->n_col_offset, c->c_arena); } else { @@ -573,7 +573,7 @@ asdl_seq_SET(args, i, arg); } - result = Tuple(args, Store, LINENO(n), c->c_arena); + result = Tuple(args, Store, LINENO(n), n->n_col_offset, c->c_arena); if (!set_context(result, Store, n)) return NULL; return result; @@ -651,7 +651,7 @@ goto error; } name = Name(NEW_IDENTIFIER(CHILD(ch, 0)), - Param, LINENO(ch), c->c_arena); + Param, LINENO(ch), ch->n_col_offset, c->c_arena); if (!name) goto error; asdl_seq_SET(args, k++, name); @@ -696,14 +696,18 @@ { expr_ty e; identifier id; + int lineno, col_offset; int i; REQ(n, dotted_name); - + + lineno = LINENO(n); + col_offset = n->n_col_offset; + id = NEW_IDENTIFIER(CHILD(n, 0)); if (!id) return NULL; - e = Name(id, Load, LINENO(n), c->c_arena); + e = Name(id, Load, lineno, col_offset, c->c_arena); if (!e) return NULL; @@ -711,7 +715,7 @@ id = NEW_IDENTIFIER(CHILD(n, i)); if (!id) return NULL; - e = Attribute(e, id, Load, LINENO(CHILD(n, i)), c->c_arena); + e = Attribute(e, id, Load, lineno, col_offset, c->c_arena); if (!e) return NULL; } @@ -739,7 +743,7 @@ name_expr = NULL; } else if (NCH(n) == 5) { /* Call with no arguments */ - d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n), c->c_arena); + d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); if (!d) return NULL; name_expr = NULL; @@ -811,7 +815,7 @@ if (!body) return NULL; - return FunctionDef(name, args, body, decorator_seq, LINENO(n), c->c_arena); + return FunctionDef(name, args, body, decorator_seq, LINENO(n), n->n_col_offset, c->c_arena); } static expr_ty @@ -838,7 +842,7 @@ return NULL; } - return Lambda(args, expression, LINENO(n), c->c_arena); + return Lambda(args, expression, LINENO(n), n->n_col_offset, c->c_arena); } static expr_ty @@ -857,7 +861,7 @@ orelse = ast_for_expr(c, CHILD(n, 4)); if (!orelse) return NULL; - return IfExp(expression, body, orelse, LINENO(n), c->c_arena); + return IfExp(expression, body, orelse, LINENO(n), n->n_col_offset, c->c_arena); } /* Count the number of 'for' loop in a list comprehension. @@ -968,7 +972,7 @@ lc = comprehension(asdl_seq_GET(t, 0), expression, NULL, c->c_arena); else - lc = comprehension(Tuple(t, Store, LINENO(ch), c->c_arena), + lc = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset, c->c_arena), expression, NULL, c->c_arena); if (!lc) return NULL; @@ -1003,7 +1007,7 @@ asdl_seq_SET(listcomps, i, lc); } - return ListComp(elt, listcomps, LINENO(n), c->c_arena); + return ListComp(elt, listcomps, LINENO(n), n->n_col_offset, c->c_arena); } /* @@ -1113,7 +1117,7 @@ ge = comprehension(asdl_seq_GET(t, 0), expression, NULL, c->c_arena); else - ge = comprehension(Tuple(t, Store, LINENO(ch), c->c_arena), + ge = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset, c->c_arena), expression, NULL, c->c_arena); if (!ge) @@ -1152,7 +1156,7 @@ asdl_seq_SET(genexps, i, ge); } - return GeneratorExp(elt, genexps, LINENO(n), c->c_arena); + return GeneratorExp(elt, genexps, LINENO(n), n->n_col_offset, c->c_arena); } static expr_ty @@ -1167,14 +1171,14 @@ case NAME: /* All names start in Load context, but may later be changed. */ - return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), c->c_arena); + return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, c->c_arena); case STRING: { PyObject *str = parsestrplus(c, n); if (!str) return NULL; PyArena_AddPyObject(c->c_arena, str); - return Str(str, LINENO(n), c->c_arena); + return Str(str, LINENO(n), n->n_col_offset, c->c_arena); } case NUMBER: { PyObject *pynum = parsenumber(STR(ch)); @@ -1182,13 +1186,13 @@ return NULL; PyArena_AddPyObject(c->c_arena, pynum); - return Num(pynum, LINENO(n), c->c_arena); + return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena); } case LPAR: /* some parenthesized expressions */ ch = CHILD(n, 1); if (TYPE(ch) == RPAR) - return Tuple(NULL, Load, LINENO(n), c->c_arena); + return Tuple(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena); if (TYPE(ch) == yield_expr) return ast_for_expr(c, ch); @@ -1201,7 +1205,7 @@ ch = CHILD(n, 1); if (TYPE(ch) == RSQB) - return List(NULL, Load, LINENO(n), c->c_arena); + return List(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena); REQ(ch, listmaker); if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) { @@ -1209,7 +1213,7 @@ if (!elts) return NULL; - return List(elts, Load, LINENO(n), c->c_arena); + return List(elts, Load, LINENO(n), n->n_col_offset, c->c_arena); } else return ast_for_listcomp(c, ch); @@ -1243,14 +1247,14 @@ asdl_seq_SET(values, i / 4, expression); } - return Dict(keys, values, LINENO(n), c->c_arena); + return Dict(keys, values, LINENO(n), n->n_col_offset, c->c_arena); } case BACKQUOTE: { /* repr */ expr_ty expression = ast_for_testlist(c, CHILD(n, 1)); if (!expression) return NULL; - return Repr(expression, LINENO(n), c->c_arena); + return Repr(expression, LINENO(n), n->n_col_offset, c->c_arena); } default: PyErr_Format(PyExc_SystemError, "unhandled atom %d", TYPE(ch)); @@ -1353,7 +1357,7 @@ if (!operator) return NULL; - result = BinOp(expr1, operator, expr2, LINENO(n), c->c_arena); + result = BinOp(expr1, operator, expr2, LINENO(n), n->n_col_offset, c->c_arena); if (!result) return NULL; @@ -1371,7 +1375,7 @@ return NULL; tmp_result = BinOp(result, operator, tmp, - LINENO(next_oper), c->c_arena); + LINENO(next_oper), next_oper->n_col_offset, c->c_arena); if (!tmp) return NULL; result = tmp_result; @@ -1389,13 +1393,13 @@ REQ(n, trailer); if (TYPE(CHILD(n, 0)) == LPAR) { if (NCH(n) == 2) - return Call(left_expr, NULL, NULL, NULL, NULL, LINENO(n), c->c_arena); + return Call(left_expr, NULL, NULL, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); else return ast_for_call(c, CHILD(n, 1), left_expr); } else if (TYPE(CHILD(n, 0)) == DOT ) { return Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load, - LINENO(n), c->c_arena); + LINENO(n), n->n_col_offset, c->c_arena); } else { REQ(CHILD(n, 0), LSQB); @@ -1405,7 +1409,7 @@ slice_ty slc = ast_for_slice(c, CHILD(n, 0)); if (!slc) return NULL; - return Subscript(left_expr, slc, Load, LINENO(n), c->c_arena); + return Subscript(left_expr, slc, Load, LINENO(n), n->n_col_offset, c->c_arena); } else { /* The grammar is ambiguous here. The ambiguity is resolved @@ -1430,7 +1434,7 @@ } if (!simple) { return Subscript(left_expr, ExtSlice(slices, c->c_arena), - Load, LINENO(n), c->c_arena); + Load, LINENO(n), n->n_col_offset, c->c_arena); } /* extract Index values and put them in a Tuple */ elts = asdl_seq_new(asdl_seq_LEN(slices), c->c_arena); @@ -1439,11 +1443,11 @@ assert(slc->kind == Index_kind && slc->v.Index.value); asdl_seq_SET(elts, j, slc->v.Index.value); } - e = Tuple(elts, Load, LINENO(n), c->c_arena); + e = Tuple(elts, Load, LINENO(n), n->n_col_offset, c->c_arena); if (!e) return NULL; return Subscript(left_expr, Index(e, c->c_arena), - Load, LINENO(n), c->c_arena); + Load, LINENO(n), n->n_col_offset, c->c_arena); } } } @@ -1468,13 +1472,15 @@ tmp = ast_for_trailer(c, ch, e); if (!tmp) return NULL; + tmp->lineno = e->lineno; + tmp->col_offset = e->col_offset; e = tmp; } if (TYPE(CHILD(n, NCH(n) - 1)) == factor) { expr_ty f = ast_for_expr(c, CHILD(n, NCH(n) - 1)); if (!f) return NULL; - tmp = BinOp(e, Pow, f, LINENO(n), c->c_arena); + tmp = BinOp(e, Pow, f, LINENO(n), n->n_col_offset, c->c_arena); if (!tmp) return NULL; e = tmp; @@ -1542,9 +1548,9 @@ asdl_seq_SET(seq, i / 2, e); } if (!strcmp(STR(CHILD(n, 1)), "and")) - return BoolOp(And, seq, LINENO(n), c->c_arena); + return BoolOp(And, seq, LINENO(n), n->n_col_offset, c->c_arena); assert(!strcmp(STR(CHILD(n, 1)), "or")); - return BoolOp(Or, seq, LINENO(n), c->c_arena); + return BoolOp(Or, seq, LINENO(n), n->n_col_offset, c->c_arena); case not_test: if (NCH(n) == 1) { n = CHILD(n, 0); @@ -1555,7 +1561,7 @@ if (!expression) return NULL; - return UnaryOp(Not, expression, LINENO(n), c->c_arena); + return UnaryOp(Not, expression, LINENO(n), n->n_col_offset, c->c_arena); } case comparison: if (NCH(n) == 1) { @@ -1594,7 +1600,7 @@ return NULL; } - return Compare(expression, ops, cmps, LINENO(n), c->c_arena); + return Compare(expression, ops, cmps, LINENO(n), n->n_col_offset, c->c_arena); } break; @@ -1620,7 +1626,7 @@ if (!exp) return NULL; } - return Yield(exp, LINENO(n), c->c_arena); + return Yield(exp, LINENO(n), n->n_col_offset, c->c_arena); } case factor: { expr_ty expression; @@ -1636,11 +1642,11 @@ switch (TYPE(CHILD(n, 0))) { case PLUS: - return UnaryOp(UAdd, expression, LINENO(n), c->c_arena); + return UnaryOp(UAdd, expression, LINENO(n), n->n_col_offset, c->c_arena); case MINUS: - return UnaryOp(USub, expression, LINENO(n), c->c_arena); + return UnaryOp(USub, expression, LINENO(n), n->n_col_offset, c->c_arena); case TILDE: - return UnaryOp(Invert, expression, LINENO(n), c->c_arena); + return UnaryOp(Invert, expression, LINENO(n), n->n_col_offset, c->c_arena); } PyErr_Format(PyExc_SystemError, "unhandled factor: %d", TYPE(CHILD(n, 0))); @@ -1761,7 +1767,7 @@ } } - return Call(func, args, keywords, vararg, kwarg, LINENO(n), c->c_arena); + return Call(func, args, keywords, vararg, kwarg, func->lineno, func->col_offset, c->c_arena); } static expr_ty @@ -1787,7 +1793,7 @@ asdl_seq *tmp = seq_for_testlist(c, n); if (!tmp) return NULL; - return Tuple(tmp, Load, LINENO(n), c->c_arena); + return Tuple(tmp, Load, LINENO(n), n->n_col_offset, c->c_arena); } } @@ -1841,7 +1847,7 @@ if (!e) return NULL; - return Expr(e, LINENO(n), c->c_arena); + return Expr(e, LINENO(n), n->n_col_offset, c->c_arena); } else if (TYPE(CHILD(n, 1)) == augassign) { expr_ty expr1, expr2; @@ -1851,7 +1857,7 @@ if (TYPE(ch) == testlist) expr1 = ast_for_testlist(c, ch); else - expr1 = Yield(ast_for_expr(c, CHILD(ch, 0)), LINENO(ch), + expr1 = Yield(ast_for_expr(c, CHILD(ch, 0)), LINENO(ch), n->n_col_offset, c->c_arena); if (!expr1) @@ -1883,7 +1889,7 @@ if (TYPE(ch) == testlist) expr2 = ast_for_testlist(c, ch); else - expr2 = Yield(ast_for_expr(c, ch), LINENO(ch), c->c_arena); + expr2 = Yield(ast_for_expr(c, ch), LINENO(ch), ch->n_col_offset, c->c_arena); if (!expr2) return NULL; @@ -1891,7 +1897,7 @@ if (!operator) return NULL; - return AugAssign(expr1, operator, expr2, LINENO(n), c->c_arena); + return AugAssign(expr1, operator, expr2, LINENO(n), n->n_col_offset, c->c_arena); } else { int i; @@ -1929,7 +1935,7 @@ expression = ast_for_expr(c, value); if (!expression) return NULL; - return Assign(targets, expression, LINENO(n), c->c_arena); + return Assign(targets, expression, LINENO(n), n->n_col_offset, c->c_arena); } } @@ -1961,7 +1967,7 @@ asdl_seq_SET(seq, j, expression); } nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true; - return Print(dest, seq, nl, LINENO(n), c->c_arena); + return Print(dest, seq, nl, LINENO(n), n->n_col_offset, c->c_arena); } static asdl_seq * @@ -1998,7 +2004,7 @@ expr_list = ast_for_exprlist(c, CHILD(n, 1), Del); if (!expr_list) return NULL; - return Delete(expr_list, LINENO(n), c->c_arena); + return Delete(expr_list, LINENO(n), n->n_col_offset, c->c_arena); } static stmt_ty @@ -2020,32 +2026,32 @@ ch = CHILD(n, 0); switch (TYPE(ch)) { case break_stmt: - return Break(LINENO(n), c->c_arena); + return Break(LINENO(n), n->n_col_offset, c->c_arena); case continue_stmt: - return Continue(LINENO(n), c->c_arena); + return Continue(LINENO(n), n->n_col_offset, c->c_arena); case yield_stmt: { /* will reduce to yield_expr */ expr_ty exp = ast_for_expr(c, CHILD(ch, 0)); if (!exp) return NULL; - return Expr(exp, LINENO(n), c->c_arena); + return Expr(exp, LINENO(n), n->n_col_offset, c->c_arena); } case return_stmt: if (NCH(ch) == 1) - return Return(NULL, LINENO(n), c->c_arena); + return Return(NULL, LINENO(n), n->n_col_offset, c->c_arena); else { expr_ty expression = ast_for_testlist(c, CHILD(ch, 1)); if (!expression) return NULL; - return Return(expression, LINENO(n), c->c_arena); + return Return(expression, LINENO(n), n->n_col_offset, c->c_arena); } case raise_stmt: if (NCH(ch) == 1) - return Raise(NULL, NULL, NULL, LINENO(n), c->c_arena); + return Raise(NULL, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); else if (NCH(ch) == 2) { expr_ty expression = ast_for_expr(c, CHILD(ch, 1)); if (!expression) return NULL; - return Raise(expression, NULL, NULL, LINENO(n), c->c_arena); + return Raise(expression, NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena); } else if (NCH(ch) == 4) { expr_ty expr1, expr2; @@ -2057,7 +2063,7 @@ if (!expr2) return NULL; - return Raise(expr1, expr2, NULL, LINENO(n), c->c_arena); + return Raise(expr1, expr2, NULL, LINENO(n), n->n_col_offset, c->c_arena); } else if (NCH(ch) == 6) { expr_ty expr1, expr2, expr3; @@ -2072,7 +2078,7 @@ if (!expr3) return NULL; - return Raise(expr1, expr2, expr3, LINENO(n), c->c_arena); + return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset, c->c_arena); } default: PyErr_Format(PyExc_SystemError, @@ -2167,10 +2173,14 @@ import_from: 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' | import_as_names) */ + int lineno; + int col_offset; int i; asdl_seq *aliases; REQ(n, import_stmt); + lineno = LINENO(n); + col_offset = n->n_col_offset; n = CHILD(n, 0); if (TYPE(n) == import_name) { n = CHILD(n, 1); @@ -2184,11 +2194,10 @@ return NULL; asdl_seq_SET(aliases, i / 2, import_alias); } - return Import(aliases, LINENO(n), c->c_arena); + return Import(aliases, lineno, col_offset, c->c_arena); } else if (TYPE(n) == import_from) { int n_children; - int lineno = LINENO(n); int idx, ndots = 0; alias_ty mod = NULL; identifier modname; @@ -2259,7 +2268,7 @@ modname = mod->name; else modname = new_identifier("", c->c_arena); - return ImportFrom(modname, aliases, ndots, lineno, + return ImportFrom(modname, aliases, ndots, lineno, col_offset, c->c_arena); } PyErr_Format(PyExc_SystemError, @@ -2286,7 +2295,7 @@ return NULL; asdl_seq_SET(s, i / 2, name); } - return Global(s, LINENO(n), c->c_arena); + return Global(s, LINENO(n), n->n_col_offset, c->c_arena); } static stmt_ty @@ -2317,7 +2326,7 @@ return NULL; } - return Exec(expr1, globals, locals, LINENO(n), c->c_arena); + return Exec(expr1, globals, locals, LINENO(n), n->n_col_offset, c->c_arena); } static stmt_ty @@ -2329,7 +2338,7 @@ expr_ty expression = ast_for_expr(c, CHILD(n, 1)); if (!expression) return NULL; - return Assert(expression, NULL, LINENO(n), c->c_arena); + return Assert(expression, NULL, LINENO(n), n->n_col_offset, c->c_arena); } else if (NCH(n) == 4) { expr_ty expr1, expr2; @@ -2341,7 +2350,7 @@ if (!expr2) return NULL; - return Assert(expr1, expr2, LINENO(n), c->c_arena); + return Assert(expr1, expr2, LINENO(n), n->n_col_offset, c->c_arena); } PyErr_Format(PyExc_SystemError, "improper number of parts to 'assert' statement: %d", @@ -2436,7 +2445,7 @@ if (!suite_seq) return NULL; - return If(expression, suite_seq, NULL, LINENO(n), c->c_arena); + return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, c->c_arena); } s = STR(CHILD(n, 4)); @@ -2458,7 +2467,7 @@ if (!seq2) return NULL; - return If(expression, seq1, seq2, LINENO(n), c->c_arena); + return If(expression, seq1, seq2, LINENO(n), n->n_col_offset, c->c_arena); } else if (s[2] == 'i') { int i, n_elif, has_else = 0; @@ -2491,7 +2500,7 @@ return NULL; asdl_seq_SET(orelse, 0, If(expression, seq1, seq2, - LINENO(CHILD(n, NCH(n) - 6)), + LINENO(CHILD(n, NCH(n) - 6)), CHILD(n, NCH(n) - 6)->n_col_offset, c->c_arena)); /* the just-created orelse handled the last elif */ n_elif--; @@ -2513,12 +2522,12 @@ asdl_seq_SET(new, 0, If(expression, suite_seq, orelse, - LINENO(CHILD(n, off)), c->c_arena)); + LINENO(CHILD(n, off)), CHILD(n, off)->n_col_offset, c->c_arena)); orelse = new; } return If(ast_for_expr(c, CHILD(n, 1)), ast_for_suite(c, CHILD(n, 3)), - orelse, LINENO(n), c->c_arena); + orelse, LINENO(n), n->n_col_offset, c->c_arena); } PyErr_Format(PyExc_SystemError, @@ -2542,7 +2551,7 @@ suite_seq = ast_for_suite(c, CHILD(n, 3)); if (!suite_seq) return NULL; - return While(expression, suite_seq, NULL, LINENO(n), c->c_arena); + return While(expression, suite_seq, NULL, LINENO(n), n->n_col_offset, c->c_arena); } else if (NCH(n) == 7) { expr_ty expression; @@ -2558,7 +2567,7 @@ if (!seq2) return NULL; - return While(expression, seq1, seq2, LINENO(n), c->c_arena); + return While(expression, seq1, seq2, LINENO(n), n->n_col_offset, c->c_arena); } PyErr_Format(PyExc_SystemError, @@ -2588,7 +2597,7 @@ if (asdl_seq_LEN(_target) == 1) target = asdl_seq_GET(_target, 0); else - target = Tuple(_target, Store, LINENO(n), c->c_arena); + target = Tuple(_target, Store, LINENO(n), n->n_col_offset, c->c_arena); expression = ast_for_testlist(c, CHILD(n, 3)); if (!expression) @@ -2597,7 +2606,7 @@ if (!suite_seq) return NULL; - return For(target, expression, suite_seq, seq, LINENO(n), c->c_arena); + return For(target, expression, suite_seq, seq, LINENO(n), n->n_col_offset, c->c_arena); } static excepthandler_ty @@ -2711,7 +2720,7 @@ asdl_seq_SET(handlers, i, e); } - except_st = TryExcept(body, handlers, orelse, LINENO(n), c->c_arena); + except_st = TryExcept(body, handlers, orelse, LINENO(n), n->n_col_offset, c->c_arena); if (!finally) return except_st; @@ -2725,7 +2734,7 @@ /* must be a try ... finally (except clauses are in body, if any exist) */ assert(finally != NULL); - return TryFinally(body, finally, LINENO(n), c->c_arena); + return TryFinally(body, finally, LINENO(n), n->n_col_offset, c->c_arena); } static expr_ty @@ -2765,7 +2774,8 @@ if (!suite_seq) { return NULL; } - return With(context_expr, optional_vars, suite_seq, LINENO(n), c->c_arena); + return With(context_expr, optional_vars, suite_seq, LINENO(n), + n->n_col_offset, c->c_arena); } static stmt_ty @@ -2785,7 +2795,7 @@ s = ast_for_suite(c, CHILD(n, 3)); if (!s) return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n), + return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n), n->n_col_offset, c->c_arena); } /* check for empty base list */ @@ -2793,7 +2803,7 @@ s = ast_for_suite(c, CHILD(n,5)); if (!s) return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n), + return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n), n->n_col_offset, c->c_arena); } @@ -2805,7 +2815,7 @@ s = ast_for_suite(c, CHILD(n, 6)); if (!s) return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, LINENO(n), + return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, LINENO(n), n->n_col_offset, c->c_arena); } @@ -2835,7 +2845,7 @@ case del_stmt: return ast_for_del_stmt(c, n); case pass_stmt: - return Pass(LINENO(n), c->c_arena); + return Pass(LINENO(n), n->n_col_offset, c->c_arena); case flow_stmt: return ast_for_flow_stmt(c, n); case import_stmt: Modified: python/trunk/Python/compile.c ============================================================================== --- python/trunk/Python/compile.c (original) +++ python/trunk/Python/compile.c Wed Mar 1 23:49:05 2006 @@ -3635,7 +3635,7 @@ switch (e->kind) { case Attribute_kind: auge = Attribute(e->v.Attribute.value, e->v.Attribute.attr, - AugLoad, e->lineno, c->c_arena); + AugLoad, e->lineno, e->col_offset, c->c_arena); if (auge == NULL) return 0; VISIT(c, expr, auge); @@ -3646,7 +3646,7 @@ break; case Subscript_kind: auge = Subscript(e->v.Subscript.value, e->v.Subscript.slice, - AugLoad, e->lineno, c->c_arena); + AugLoad, e->lineno, e->col_offset, c->c_arena); if (auge == NULL) return 0; VISIT(c, expr, auge); From python-checkins at python.org Wed Mar 1 23:54:38 2006 From: python-checkins at python.org (thomas.wouters) Date: Wed, 1 Mar 2006 23:54:38 +0100 (CET) Subject: [Python-checkins] r42754 - python/trunk/Modules/gdbmmodule.c Message-ID: <20060301225438.25F401E4002@bag.python.org> Author: thomas.wouters Date: Wed Mar 1 23:54:36 2006 New Revision: 42754 Modified: python/trunk/Modules/gdbmmodule.c Log: Fix gcc (4.0.x) warning about use of uninitialized variable. Modified: python/trunk/Modules/gdbmmodule.c ============================================================================== --- python/trunk/Modules/gdbmmodule.c (original) +++ python/trunk/Modules/gdbmmodule.c Wed Mar 1 23:54:36 2006 @@ -97,6 +97,7 @@ datum key,okey; int size; okey.dsize=0; + okey.dptr=NULL; size = 0; for (key=gdbm_firstkey(dp->di_dbm); key.dptr; From python-checkins at python.org Wed Mar 1 23:57:24 2006 From: python-checkins at python.org (tim.peters) Date: Wed, 1 Mar 2006 23:57:24 +0100 (CET) Subject: [Python-checkins] r42755 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301225724.41B3C1E4002@bag.python.org> Author: tim.peters Date: Wed Mar 1 23:57:23 2006 New Revision: 42755 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Fixed a logic error in doubly-linked list fiddling. Resolved an overlooked XXX. Code fiddling to reduce the deepest nesting by a level. This is all I want to do, except to fix the new Py_ADDRESS_IN_RANGE endcase error. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Wed Mar 1 23:57:23 2006 @@ -747,7 +747,6 @@ /* This moves the arena *towards* the head of the list but it is already at the head of the list: do nothing */ - /* XXX what did that mean? */ --usable_arenas->nfreepools; if (usable_arenas->nfreepools == 0) { /* Unlink the arena: it's completely @@ -907,10 +906,20 @@ ao->freepools = pool; nf = ++ao->nfreepools; + /* All the rest is arena management. We just freed + * a pool, and there are 4 cases for arena mgmt: + * 1. If all the pools are free, return the arena to + * the system free(). + * 2. If this is the only free pool in the arena, + * add the arena back to the `usable_arenas` list. + * 3. If the "next" arena has a smaller count of + * of free pulls, we have to "push this arena right" + * to restore that `usable_arenas` is sorted in + * order of nfreepools. + * 4. Else there's nothing more to do. + */ if (nf == ao->ntotalpools) { - /* This arena is completely deallocated. - * Unlink it from the partially allocated - * arenas. + /* Case 1. First unlink ao from usable_arenas. */ assert(ao->prevarena == NULL || ao->prevarena->address != 0); @@ -930,14 +939,12 @@ ao->prevarena->nextarena = ao->nextarena; } - /* Fix the pointer in the nextarena. */ if (ao->nextarena != NULL) { assert(ao->nextarena->prevarena == ao); ao->nextarena->prevarena = ao->prevarena; } - /* Record that this arena_object slot is * available to be reused. */ @@ -946,23 +953,28 @@ /* Free the entire arena. */ free((void *)ao->address); - ao->address = 0; + ao->address = 0; /* mark unassociated */ --narenas_currently_allocated; + + UNLOCK(); + return; } - else if (nf == 1) { - /* If this arena was completely allocated, - * go link it to the head of the partially - * allocated list. + + if (nf == 1) { + /* Case 2. Put ao at the head of + * usable_arenas. Note that because + * ao->nfreepools was 0 before, ao isn't + * currently on the usable_arenas list. */ ao->nextarena = usable_arenas; ao->prevarena = NULL; + if (usable_arenas) + usable_arenas->prevarena = ao; usable_arenas = ao; - - /* Fix the pointer in the nextarena. */ - if (ao->nextarena != NULL) - ao->nextarena->prevarena = ao; - assert(usable_arenas->address != 0); + + UNLOCK(); + return; } /* If this arena is now out of order, we need to keep * the list sorted. The list is kept sorted so that @@ -971,57 +983,58 @@ * a few un-scientific tests, it seems like this * approach allowed a lot more memory to be freed. */ - else if (ao->nextarena != NULL && - nf > ao->nextarena->nfreepools) { - /* We have to move the arena towards the end - * of the list. - */ - struct arena_object** lastPointer; - if (ao->prevarena != NULL) - lastPointer = - &ao->prevarena->nextarena; - else - lastPointer = &usable_arenas; - assert(*lastPointer == ao); - - /* Step one: unlink the arena from the list. */ - *lastPointer = ao->nextarena; - ao->nextarena->prevarena = ao->prevarena; - - /* Step two: Locate the new insertion point by - * iterating over the list, using our nextarena - * pointer. - */ - while (ao->nextarena != NULL && - nf > ao->nextarena->nfreepools) { - ao->prevarena = ao->nextarena; - ao->nextarena = - ao->nextarena->nextarena; - } - - /* Step three: insert the arena at this point. */ - assert(ao->nextarena == NULL || - ao->prevarena == - ao->nextarena->prevarena); - assert(ao->prevarena->nextarena == - ao->nextarena); - - ao->prevarena->nextarena = ao; - if (ao->nextarena != NULL) { - ao->nextarena->prevarena = ao; - } + if (ao->nextarena == NULL || + nf <= ao->nextarena->nfreepools) { + /* Case 4. Nothing to do. */ + UNLOCK(); + return; + } - /* Verify that the swaps worked. */ - assert(ao->nextarena == NULL || - nf <= ao->nextarena->nfreepools); - assert(ao->prevarena == NULL || - nf > ao->prevarena->nfreepools); - assert(ao->nextarena == NULL || - ao->nextarena->prevarena == ao); - assert((usable_arenas == ao && - ao->prevarena == NULL) || - ao->prevarena->nextarena == ao); + /* Case 3: We have to move the arena towards the end + * of the list, because it has more free pools than + * the arena to its right. + * First unlink ao from usable_arenas. + */ + if (ao->prevarena != NULL) { + /* ao isn't at the head of the list */ + assert(ao->prevarena->nextarena == ao); + ao->prevarena->nextarena = ao->nextarena; } + else { + /* ao is at the head of the list */ + assert(usable_arenas == ao); + usable_arenas = ao->nextarena; + } + ao->nextarena->prevarena = ao->prevarena; + + /* Locate the new insertion point by iterating over + * the list, using our nextarena pointer. + */ + while (ao->nextarena != NULL && + nf > ao->nextarena->nfreepools) { + ao->prevarena = ao->nextarena; + ao->nextarena = ao->nextarena->nextarena; + } + + /* Insert ao at this point. */ + assert(ao->nextarena == NULL || + ao->prevarena == ao->nextarena->prevarena); + assert(ao->prevarena->nextarena == ao->nextarena); + + ao->prevarena->nextarena = ao; + if (ao->nextarena != NULL) + ao->nextarena->prevarena = ao; + + /* Verify that the swaps worked. */ + assert(ao->nextarena == NULL || + nf <= ao->nextarena->nfreepools); + assert(ao->prevarena == NULL || + nf > ao->prevarena->nfreepools); + assert(ao->nextarena == NULL || + ao->nextarena->prevarena == ao); + assert((usable_arenas == ao && + ao->prevarena == NULL) || + ao->prevarena->nextarena == ao); UNLOCK(); return; From python-checkins at python.org Thu Mar 2 00:02:59 2006 From: python-checkins at python.org (tim.peters) Date: Thu, 2 Mar 2006 00:02:59 +0100 (CET) Subject: [Python-checkins] r42756 - python/trunk/Lib/test/test_ast.py Message-ID: <20060301230259.5931A1E4009@bag.python.org> Author: tim.peters Date: Thu Mar 2 00:02:57 2006 New Revision: 42756 Modified: python/trunk/Lib/test/test_ast.py Log: Whitespace normalization. Modified: python/trunk/Lib/test/test_ast.py ============================================================================== --- python/trunk/Lib/test/test_ast.py (original) +++ python/trunk/Lib/test/test_ast.py Thu Mar 2 00:02:57 2006 @@ -128,7 +128,7 @@ raise SystemExit def test_order(ast_node, parent_pos): - + if not isinstance(ast_node, _ast.AST) or ast_node._fields == None: return if isinstance(ast_node, (_ast.expr, _ast.stmt)): From python-checkins at python.org Thu Mar 2 00:03:19 2006 From: python-checkins at python.org (tim.peters) Date: Thu, 2 Mar 2006 00:03:19 +0100 (CET) Subject: [Python-checkins] r42757 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301230319.5DBD81E4009@bag.python.org> Author: tim.peters Date: Thu Mar 2 00:03:17 2006 New Revision: 42757 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Typo repair. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Thu Mar 2 00:03:17 2006 @@ -913,7 +913,7 @@ * 2. If this is the only free pool in the arena, * add the arena back to the `usable_arenas` list. * 3. If the "next" arena has a smaller count of - * of free pulls, we have to "push this arena right" + * of free pools, we have to "push this arena right" * to restore that `usable_arenas` is sorted in * order of nfreepools. * 4. Else there's nothing more to do. From python-checkins at python.org Thu Mar 2 00:10:05 2006 From: python-checkins at python.org (thomas.wouters) Date: Thu, 2 Mar 2006 00:10:05 +0100 (CET) Subject: [Python-checkins] r42758 - python/trunk/Modules/binascii.c Message-ID: <20060301231005.AA5911E4002@bag.python.org> Author: thomas.wouters Date: Thu Mar 2 00:10:05 2006 New Revision: 42758 Modified: python/trunk/Modules/binascii.c Log: Use Py_ssize_t for arithmetic on Py_ssize_t's, instead of unsigned ints. Modified: python/trunk/Modules/binascii.c ============================================================================== --- python/trunk/Modules/binascii.c (original) +++ python/trunk/Modules/binascii.c Thu Mar 2 00:10:05 2006 @@ -1028,7 +1028,7 @@ static PyObject* binascii_a2b_qp(PyObject *self, PyObject *args, PyObject *kwargs) { - unsigned int in, out; + Py_ssize_t in, out; char ch; unsigned char *data, *odata; Py_ssize_t datalen = 0; @@ -1129,7 +1129,7 @@ static PyObject* binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs) { - unsigned int in, out; + Py_ssize_t in, out; unsigned char *data, *odata; Py_ssize_t datalen = 0, odatalen = 0; PyObject *rv; From python-checkins at python.org Thu Mar 2 00:10:50 2006 From: python-checkins at python.org (martin.v.loewis) Date: Thu, 2 Mar 2006 00:10:50 +0100 (CET) Subject: [Python-checkins] r42759 - python/trunk/Modules/cStringIO.c Message-ID: <20060301231050.256D71E4002@bag.python.org> Author: martin.v.loewis Date: Thu Mar 2 00:10:49 2006 New Revision: 42759 Modified: python/trunk/Modules/cStringIO.c Log: Remove UNLESS. Modified: python/trunk/Modules/cStringIO.c ============================================================================== --- python/trunk/Modules/cStringIO.c (original) +++ python/trunk/Modules/cStringIO.c Thu Mar 2 00:10:49 2006 @@ -33,9 +33,6 @@ "\n" "cStringIO.c,v 1.29 1999/06/15 14:10:27 jim Exp\n"); -#define UNLESS(E) if (!(E)) - - /* Declaration for file-like objects that manage data as strings The IOobject type should be though of as a common base type for @@ -80,7 +77,7 @@ static int IO__opencheck(IOobject *self) { - UNLESS (self->buf) { + if (!self->buf) { PyErr_SetString(PyExc_ValueError, "I/O operation on closed file"); return 0; @@ -107,7 +104,7 @@ static PyObject * IO_flush(IOobject *self, PyObject *unused) { - UNLESS (IO__opencheck(self)) return NULL; + if (!IO__opencheck(self)) return NULL; Py_INCREF(Py_None); return Py_None; @@ -121,7 +118,7 @@ static PyObject * IO_cgetval(PyObject *self) { - UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; + if (!IO__opencheck(IOOOBJECT(self))) return NULL; return PyString_FromStringAndSize(((IOobject*)self)->buf, ((IOobject*)self)->pos); } @@ -131,8 +128,8 @@ PyObject *use_pos=Py_None; Py_ssize_t s; - UNLESS (IO__opencheck(self)) return NULL; - UNLESS (PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL; + if (!IO__opencheck(self)) return NULL; + if (!PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL; if (PyObject_IsTrue(use_pos)) { s=self->pos; @@ -158,7 +155,7 @@ IO_cread(PyObject *self, char **output, Py_ssize_t n) { Py_ssize_t l; - UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; + if (!IO__opencheck(IOOOBJECT(self))) return -1; l = ((IOobject*)self)->string_size - ((IOobject*)self)->pos; if (n < 0 || n > l) { n = l; @@ -175,7 +172,7 @@ Py_ssize_t n = -1; char *output = NULL; - UNLESS (PyArg_ParseTuple(args, "|n:read", &n)) return NULL; + if (!PyArg_ParseTuple(args, "|n:read", &n)) return NULL; if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL; @@ -189,7 +186,7 @@ char *n, *s; Py_ssize_t l; - UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; + if (!IO__opencheck(IOOOBJECT(self))) return -1; for (n = ((IOobject*)self)->buf + ((IOobject*)self)->pos, s = ((IOobject*)self)->buf + ((IOobject*)self)->string_size; @@ -209,7 +206,7 @@ char *output; if (args) - UNLESS (PyArg_ParseTuple(args, "|i:readline", &m)) return NULL; + if (!PyArg_ParseTuple(args, "|i:readline", &m)) return NULL; if( (n=IO_creadline((PyObject*)self,&output)) < 0) return NULL; if (m >= 0 && m < n) { @@ -229,7 +226,7 @@ PyObject *result, *line; int hint = 0, length = 0; - UNLESS (PyArg_ParseTuple(args, "|i:readlines", &hint)) return NULL; + if (!PyArg_ParseTuple(args, "|i:readlines", &hint)) return NULL; result = PyList_New(0); if (!result) @@ -264,7 +261,7 @@ static PyObject * IO_reset(IOobject *self, PyObject *unused) { - UNLESS (IO__opencheck(self)) return NULL; + if (!IO__opencheck(self)) return NULL; self->pos = 0; @@ -277,7 +274,7 @@ static PyObject * IO_tell(IOobject *self, PyObject *unused) { - UNLESS (IO__opencheck(self)) return NULL; + if (!IO__opencheck(self)) return NULL; return PyInt_FromSsize_t(self->pos); } @@ -289,8 +286,8 @@ IO_truncate(IOobject *self, PyObject *args) { Py_ssize_t pos = -1; - UNLESS (IO__opencheck(self)) return NULL; - UNLESS (PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL; + if (!IO__opencheck(self)) return NULL; + if (!PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL; if (pos < 0) pos = self->pos; if (self->string_size > pos) self->string_size = pos; @@ -329,8 +326,8 @@ Py_ssize_t position; int mode = 0; - UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; - UNLESS (PyArg_ParseTuple(args, "n|i:seek", &position, &mode)) + if (!IO__opencheck(IOOOBJECT(self))) return NULL; + if (!PyArg_ParseTuple(args, "n|i:seek", &position, &mode)) return NULL; if (mode == 2) { @@ -343,8 +340,8 @@ if (position > self->buf_size) { self->buf_size*=2; if (self->buf_size <= position) self->buf_size=position+1; - UNLESS (self->buf = (char*) - realloc(self->buf,self->buf_size)) { + self->buf = (char*) realloc(self->buf,self->buf_size); + if (!self->buf) { self->buf_size=self->pos=0; return PyErr_NoMemory(); } @@ -369,7 +366,7 @@ Py_ssize_t newl; Oobject *oself; - UNLESS (IO__opencheck(IOOOBJECT(self))) return -1; + if (!IO__opencheck(IOOOBJECT(self))) return -1; oself = (Oobject *)self; newl = oself->pos+l; @@ -379,8 +376,8 @@ assert(newl + 1 < INT_MAX); oself->buf_size = (int)(newl+1); } - UNLESS (oself->buf = - (char*)realloc(oself->buf, oself->buf_size)) { + oself->buf = (char*)realloc(oself->buf, oself->buf_size); + if (!oself->buf) { PyErr_SetString(PyExc_MemoryError,"out of memory"); oself->buf_size = oself->pos = 0; return -1; @@ -404,7 +401,7 @@ char *c; int l; - UNLESS (PyArg_ParseTuple(args, "t#:write", &c, &l)) return NULL; + if (!PyArg_ParseTuple(args, "t#:write", &c, &l)) return NULL; if (O_cwrite((PyObject*)self,c,l) < 0) return NULL; @@ -543,7 +540,8 @@ self->string_size = 0; self->softspace = 0; - UNLESS (self->buf = (char *)malloc(size)) { + self->buf = (char *)malloc(size); + if (!self->buf) { PyErr_SetString(PyExc_MemoryError,"out of memory"); self->buf_size = 0; return NULL; @@ -573,8 +571,8 @@ Py_ssize_t position; int mode = 0; - UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL; - UNLESS (PyArg_ParseTuple(args, "n|i:seek", &position, &mode)) + if (!IO__opencheck(IOOOBJECT(self))) return NULL; + if (!PyArg_ParseTuple(args, "n|i:seek", &position, &mode)) return NULL; if (mode == 2) position += self->string_size; @@ -662,7 +660,8 @@ s->ob_type->tp_name); return NULL; } - UNLESS (self = PyObject_New(Iobject, &Itype)) return NULL; + self = PyObject_New(Iobject, &Itype); + if (!self) return NULL; Py_INCREF(s); self->buf=buf; self->string_size=size; From python-checkins at python.org Thu Mar 2 00:12:22 2006 From: python-checkins at python.org (tim.peters) Date: Thu, 2 Mar 2006 00:12:22 +0100 (CET) Subject: [Python-checkins] r42760 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060301231222.9562F1E4009@bag.python.org> Author: tim.peters Date: Thu Mar 2 00:12:22 2006 New Revision: 42760 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Typo repair. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Thu Mar 2 00:12:22 2006 @@ -912,10 +912,10 @@ * the system free(). * 2. If this is the only free pool in the arena, * add the arena back to the `usable_arenas` list. - * 3. If the "next" arena has a smaller count of - * of free pools, we have to "push this arena right" - * to restore that `usable_arenas` is sorted in - * order of nfreepools. + * 3. If the "next" arena has a smaller count of free + * pools, we have to "push this arena right" to + * restore that `usable_arenas` is sorted in order + * of nfreepools. * 4. Else there's nothing more to do. */ if (nf == ao->ntotalpools) { From python-checkins at python.org Thu Mar 2 00:24:35 2006 From: python-checkins at python.org (martin.v.loewis) Date: Thu, 2 Mar 2006 00:24:35 +0100 (CET) Subject: [Python-checkins] r42761 - python/trunk/Lib/test/test_compiler.py Message-ID: <20060301232435.AF5C21E4002@bag.python.org> Author: martin.v.loewis Date: Thu Mar 2 00:24:34 2006 New Revision: 42761 Modified: python/trunk/Lib/test/test_compiler.py Log: Reformat the exception message by going through a list. Modified: python/trunk/Lib/test/test_compiler.py ============================================================================== --- python/trunk/Lib/test/test_compiler.py (original) +++ python/trunk/Lib/test/test_compiler.py Thu Mar 2 00:24:34 2006 @@ -35,7 +35,9 @@ try: compiler.compile(buf, basename, "exec") except Exception, e: - e.args[0] += "[in file %s]" % basename + args = list(e.args) + args[0] += "[in file %s]" % basename + e.args = tuple(args) raise def testNewClassSyntax(self): From python-checkins at python.org Thu Mar 2 00:44:49 2006 From: python-checkins at python.org (brett.cannon) Date: Thu, 2 Mar 2006 00:44:49 +0100 (CET) Subject: [Python-checkins] r42762 - peps/trunk/pep-0352.txt Message-ID: <20060301234449.C18751E4002@bag.python.org> Author: brett.cannon Date: Thu Mar 2 00:44:47 2006 New Revision: 42762 Modified: peps/trunk/pep-0352.txt Log: Rework pseduo-code to better match implementation. Only affected __str__ and __unicode__. Had to be done this way for backwards-compatibility issues. Modified: peps/trunk/pep-0352.txt ============================================================================== --- peps/trunk/pep-0352.txt (original) +++ peps/trunk/pep-0352.txt Thu Mar 2 00:44:47 2006 @@ -59,8 +59,12 @@ """Superclass representing the base of the exception hierarchy. - Provides a 'message' attribute that contains any argument - passed in during instantiation. + Provides a 'message' attribute that contains any single argument + passed in during instantiation. If more than one argument is passed, it + is set to the empty string. It is meant to represent any message + (usually some text) that should be printed out with the traceback. + Unfortunatley, for backwards-compatibility, the 'args' attribute + (discussed below) is used for printing out to tracebacks. The 'args' attribute and __getitem__ method are provided for backwards-compatibility and will be deprecated at some point. @@ -68,28 +72,41 @@ """ def __init__(self, *args): - """Set 'message' and 'args' attribute""" + """Set 'message' and 'args' attribute. + + 'args' will eventually be deprecated. But it is still used when + printing out tracebacks for backwards-compatibility. Once 'args' is + removed, though, 'message' will be used instead. + + """ self.args = args self.message = args[0] if args else '' def __str__(self): - """Return the str of 'message'""" - return str(self.message + """Return the str of args[0] or args, depending on length. + + Once 'args' has been removed, 'message' will be used exclusively for + the str representation for exceptions. + + """ + return str(self.args[0] if len(self.args) <= 1 else self.args) def __unicode__(self): - """Return the unicode of 'message'""" - return unicode(self.message + """Return the unicode of args[0] or args, depending on length. + + Once 'args' has been removed, 'message' will be used exclusively for + the unicode representation of exceptions. + + """ + return unicode(self.args[0] if len(self.args) <= 1 else self.args) def __repr__(self): - if not self.args: - argss = "()" - else: - argss = repr(self.args) - return self.__class__.__name__ + argss + func_args = repr(self.args) if self.args else "()" + return self.__class__.__name__ + func_args def __getitem__(self, index): """Index into arguments passed in during instantiation. From python-checkins at python.org Thu Mar 2 00:49:14 2006 From: python-checkins at python.org (thomas.wouters) Date: Thu, 2 Mar 2006 00:49:14 +0100 (CET) Subject: [Python-checkins] r42763 - python/trunk/Python/marshal.c Message-ID: <20060301234914.AB6101E4002@bag.python.org> Author: thomas.wouters Date: Thu Mar 2 00:49:13 2006 New Revision: 42763 Modified: python/trunk/Python/marshal.c Log: Make Py_ssize_t clean. Modified: python/trunk/Python/marshal.c ============================================================================== --- python/trunk/Python/marshal.c (original) +++ python/trunk/Python/marshal.c Thu Mar 2 00:49:13 2006 @@ -4,6 +4,8 @@ a true persistent storage facility would be much harder, since it would have to take circular links and sharing into account. */ +#define PY_SSIZE_T_CLEAN + #include "Python.h" #include "longintrepr.h" #include "code.h" @@ -1088,7 +1090,7 @@ { RFILE rf; char *s; - int n; + Py_ssize_t n; PyObject* result; if (!PyArg_ParseTuple(args, "s#:loads", &s, &n)) return NULL; From python-checkins at python.org Thu Mar 2 00:51:20 2006 From: python-checkins at python.org (brett.cannon) Date: Thu, 2 Mar 2006 00:51:20 +0100 (CET) Subject: [Python-checkins] r42764 - peps/trunk/pep-0352.txt Message-ID: <20060301235120.DE7441E4002@bag.python.org> Author: brett.cannon Date: Thu Mar 2 00:51:20 2006 New Revision: 42764 Modified: peps/trunk/pep-0352.txt Log: Fix a typo. Modified: peps/trunk/pep-0352.txt ============================================================================== --- peps/trunk/pep-0352.txt (original) +++ peps/trunk/pep-0352.txt Thu Mar 2 00:51:20 2006 @@ -63,7 +63,7 @@ passed in during instantiation. If more than one argument is passed, it is set to the empty string. It is meant to represent any message (usually some text) that should be printed out with the traceback. - Unfortunatley, for backwards-compatibility, the 'args' attribute + Unfortunately, for backwards-compatibility, the 'args' attribute (discussed below) is used for printing out to tracebacks. The 'args' attribute and __getitem__ method are provided for From python-checkins at python.org Thu Mar 2 01:21:11 2006 From: python-checkins at python.org (thomas.wouters) Date: Thu, 2 Mar 2006 01:21:11 +0100 (CET) Subject: [Python-checkins] r42765 - python/trunk/Modules/fcntlmodule.c Message-ID: <20060302002111.AB0251E403C@bag.python.org> Author: thomas.wouters Date: Thu Mar 2 01:21:10 2006 New Revision: 42765 Modified: python/trunk/Modules/fcntlmodule.c Log: Make Py_ssize_t-clean Modified: python/trunk/Modules/fcntlmodule.c ============================================================================== --- python/trunk/Modules/fcntlmodule.c (original) +++ python/trunk/Modules/fcntlmodule.c Thu Mar 2 01:21:10 2006 @@ -1,6 +1,8 @@ /* fcntl module */ +#define PY_SSIZE_T_CLEAN + #include "Python.h" #ifdef HAVE_SYS_FILE_H @@ -35,7 +37,7 @@ int arg; int ret; char *str; - int len; + Py_ssize_t len; char buf[1024]; if (PyArg_ParseTuple(args, "O&is#:fcntl", @@ -98,7 +100,7 @@ int arg; int ret; char *str; - int len; + Py_ssize_t len; int mutate_arg = 1; char buf[1024]; From mwh at python.net Thu Mar 2 01:24:09 2006 From: mwh at python.net (Michael Hudson) Date: Thu, 02 Mar 2006 00:24:09 +0000 Subject: [Python-checkins] r42759 - python/trunk/Modules/cStringIO.c In-Reply-To: <20060301231050.256D71E4002@bag.python.org> (martin v. loewis's message of "Thu, 2 Mar 2006 00:10:50 +0100 (CET)") References: <20060301231050.256D71E4002@bag.python.org> Message-ID: <2mpsl566dy.fsf@starship.python.net> "martin.v.loewis" writes: > Author: martin.v.loewis > Date: Thu Mar 2 00:10:49 2006 > New Revision: 42759 > > Modified: > python/trunk/Modules/cStringIO.c > Log: > Remove UNLESS. Hoo-ray! Cheers, mwh -- I've even been known to get Marmite *near* my mouth -- but never actually in it yet. Vegamite is right out. UnicodeError: ASCII unpalatable error: vegamite found, ham expected -- Tim Peters, comp.lang.python From python-checkins at python.org Thu Mar 2 01:31:27 2006 From: python-checkins at python.org (martin.v.loewis) Date: Thu, 2 Mar 2006 01:31:27 +0100 (CET) Subject: [Python-checkins] r42766 - in python/trunk: Parser/asdl_c.py Python/Python-ast.c Message-ID: <20060302003127.B14EB1E4002@bag.python.org> Author: martin.v.loewis Date: Thu Mar 2 01:31:27 2006 New Revision: 42766 Modified: python/trunk/Parser/asdl_c.py python/trunk/Python/Python-ast.c Log: Fix memory leak on attributes. Modified: python/trunk/Parser/asdl_c.py ============================================================================== --- python/trunk/Parser/asdl_c.py (original) +++ python/trunk/Parser/asdl_c.py Thu Mar 2 01:31:27 2006 @@ -607,7 +607,9 @@ for a in sum.attributes: self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1) self.emit("if (!value) goto failed;", 1) - self.emit('PyObject_SetAttrString(result, "%s", value);' % a.name, 1) + self.emit('if (PyObject_SetAttrString(result, "%s", value) < 0)' % a.name, 1) + self.emit('goto failed;', 2) + self.emit('Py_DECREF(value);', 1) self.func_end() def simpleSum(self, sum, name): Modified: python/trunk/Python/Python-ast.c ============================================================================== --- python/trunk/Python/Python-ast.c (original) +++ python/trunk/Python/Python-ast.c Thu Mar 2 01:31:27 2006 @@ -2324,10 +2324,14 @@ } value = ast2obj_int(o->lineno); if (!value) goto failed; - PyObject_SetAttrString(result, "lineno", value); + if (PyObject_SetAttrString(result, "lineno", value) < 0) + goto failed; + Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - PyObject_SetAttrString(result, "col_offset", value); + if (PyObject_SetAttrString(result, "col_offset", value) < 0) + goto failed; + Py_DECREF(value); return result; failed: Py_XDECREF(value); @@ -2643,10 +2647,14 @@ } value = ast2obj_int(o->lineno); if (!value) goto failed; - PyObject_SetAttrString(result, "lineno", value); + if (PyObject_SetAttrString(result, "lineno", value) < 0) + goto failed; + Py_DECREF(value); value = ast2obj_int(o->col_offset); if (!value) goto failed; - PyObject_SetAttrString(result, "col_offset", value); + if (PyObject_SetAttrString(result, "col_offset", value) < 0) + goto failed; + Py_DECREF(value); return result; failed: Py_XDECREF(value); @@ -3023,7 +3031,7 @@ if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return; - if (PyModule_AddStringConstant(m, "__version__", "42649") < 0) + if (PyModule_AddStringConstant(m, "__version__", "42753") < 0) return; if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) From python-checkins at python.org Thu Mar 2 01:36:20 2006 From: python-checkins at python.org (brett.cannon) Date: Thu, 2 Mar 2006 01:36:20 +0100 (CET) Subject: [Python-checkins] r42767 - peps/trunk/pep-0352.txt Message-ID: <20060302003620.D61AA1E4002@bag.python.org> Author: brett.cannon Date: Thu Mar 2 01:36:20 2006 New Revision: 42767 Modified: peps/trunk/pep-0352.txt Log: Shift pseudo-code to Transition Plan section and provide a pseudo-code implementation of what BaseException will look like in Python 3.0 . Modified: peps/trunk/pep-0352.txt ============================================================================== --- peps/trunk/pep-0352.txt (original) +++ peps/trunk/pep-0352.txt Thu Mar 2 01:36:20 2006 @@ -2,7 +2,8 @@ Title: Required Superclass for Exceptions Version: $Revision$ Last-Modified: $Date$ -Author: Brett Cannon , Guido van Rossum +Author: Brett Cannon + Guido van Rossum Status: Final Type: Standards Track Content-Type: text/x-rst @@ -53,70 +54,36 @@ This PEP proposes introducing a new exception named BaseException that is a new-style class and has a single attribute, ``message`` (that -will cause the deprecation of the existing ``args`` attribute):: +will cause the deprecation of the existing ``args`` attribute) Below +is the code as the exception will work in Python 3.0 (how it will +work in Python 2.x is covered in the `Transition Plan`_ section):: class BaseException(object): """Superclass representing the base of the exception hierarchy. - Provides a 'message' attribute that contains any single argument - passed in during instantiation. If more than one argument is passed, it - is set to the empty string. It is meant to represent any message - (usually some text) that should be printed out with the traceback. - Unfortunately, for backwards-compatibility, the 'args' attribute - (discussed below) is used for printing out to tracebacks. - - The 'args' attribute and __getitem__ method are provided for - backwards-compatibility and will be deprecated at some point. + Provides a 'message' attribute that contains either the single + argument to the constructor or the empty string. This attribute + is used in both the string and unicode representation for the + exception. This is so that it provides the extra details in the + traceback. """ - def __init__(self, *args): - """Set 'message' and 'args' attribute. - - 'args' will eventually be deprecated. But it is still used when - printing out tracebacks for backwards-compatibility. Once 'args' is - removed, though, 'message' will be used instead. - - """ - self.args = args - self.message = args[0] if args else '' + def __init__(self, message=''): + """Set the 'message' attribute'""" + self.message = message def __str__(self): - """Return the str of args[0] or args, depending on length. - - Once 'args' has been removed, 'message' will be used exclusively for - the str representation for exceptions. - - """ - return str(self.args[0] - if len(self.args) <= 1 - else self.args) + """Return the str of 'message'""" + return str(self.message) def __unicode__(self): - """Return the unicode of args[0] or args, depending on length. - - Once 'args' has been removed, 'message' will be used exclusively for - the unicode representation of exceptions. - - """ - return unicode(self.args[0] - if len(self.args) <= 1 - else self.args) + """Return the unicode of 'message'""" + return unicode(self.message) def __repr__(self): - func_args = repr(self.args) if self.args else "()" - return self.__class__.__name__ + func_args - - def __getitem__(self, index): - """Index into arguments passed in during instantiation. - - Provided for backwards-compatibility and will be - deprecated. - - """ - return self.args[index] - + return "%s(%s)" % (self.__class__.__name__, repr(self.message)) The ``message`` attribute will contain either the first argument passed in at instantiation of the object or the empty string if no @@ -212,6 +179,72 @@ deprecation and the raising of a DeprecationWarning for the version specifically listed. +Here is BaseException as implemented in the 2.x series:: + + class BaseException(object): + + """Superclass representing the base of the exception hierarchy. + + Provides a 'message' attribute that contains any single argument + passed in during instantiation. If more than one argument is + passed, it is set to the empty string. It is meant to represent + any message (usually some text) that should be printed out with + the traceback. Unfortunately, for backwards-compatibility, the + 'args' attribute (discussed below) is used for printing out to + tracebacks. + + The 'args' attribute and __getitem__ method are provided for + backwards-compatibility and will be deprecated at some point. + + """ + + def __init__(self, *args): + """Set 'message' and 'args' attribute. + + 'args' will eventually be deprecated. But it is still used + when printing out tracebacks for backwards-compatibility. + Once 'args' is removed, though, 'message' will be used instead. + + """ + self.args = args + self.message = args[0] if args else '' + + def __str__(self): + """Return the str of args[0] or args, depending on length. + + Once 'args' has been removed, 'message' will be used + exclusively for the str representation for exceptions. + + """ + return str(self.args[0] + if len(self.args) <= 1 + else self.args) + + def __unicode__(self): + """Return the unicode of args[0] or args, depending on length. + + Once 'args' has been removed, 'message' will be used + exclusively for the unicode representation of exceptions. + + """ + return unicode(self.args[0] + if len(self.args) <= 1 + else self.args) + + def __repr__(self): + func_args = repr(self.args) if self.args else "()" + return self.__class__.__name__ + func_args + + def __getitem__(self, index): + """Index into arguments passed in during instantiation. + + Provided for backwards-compatibility and will be + deprecated. + + """ + return self.args[index] + + Deprecation of features in Python 2.9 is optional. This is because it is not known at this time if Python 2.9 (which is slated to be the last version in the 2.x series) will actively deprecate features that From dynkin at gmail.com Thu Mar 2 04:29:41 2006 From: dynkin at gmail.com (George Yoshida) Date: Thu, 2 Mar 2006 12:29:41 +0900 Subject: [Python-checkins] r42748 - in python/trunk: Doc/api/exceptions.tex Doc/lib/libexcs.tex Doc/tut/tut.tex Python/exceptions.c In-Reply-To: <20060301221051.30A3D1E4014@bag.python.org> References: <20060301221051.30A3D1E4014@bag.python.org> Message-ID: <2f188ee80603011929y446a0851i9569ed9fe13b2117@mail.gmail.com> On 3/2/06, brett.cannon wrote: > Author: brett.cannon > Date: Wed Mar 1 23:10:49 2006 > New Revision: 42748 > > Modified: > python/trunk/Doc/api/exceptions.tex > python/trunk/Doc/lib/libexcs.tex > python/trunk/Doc/tut/tut.tex > python/trunk/Python/exceptions.c > Log: > Document PEP 352 changes. Also added GeneratorExit. > Hmm, your commit triggers a latex compile error. -- geprge Index: Doc/lib/libexcs.tex =================================================================== --- Doc/lib/libexcs.tex (revision 42767) +++ Doc/lib/libexcs.tex (working copy) @@ -82,6 +82,7 @@ eventually be deprecated and thus its use is discouraged. \versionchanged[Changed to inherit from \exception{BaseException}]{2.5} \versionadded{2.5} +\end{excdesc} \begin{excdesc}{Exception} All built-in, non-system-exiting exceptions are derived @@ -168,11 +169,12 @@ \file{pyconfig.h} file. \end{excdesc} -\begin{excdesv}{GeneratorExit} +\begin{excdesc}{GeneratorExit} Raise when a generator's \method{close()} method is called. It directly inherits from \exception{Exception} instead of \exception{StandardError} since it is technically not an error. \versionadded{2.5} +\end{excdesc} \begin{excdesc}{IOError} % XXXJH xrefs here -------------- next part -------------- A non-text attachment was scrubbed... Name: doc.diff Type: application/octet-stream Size: 854 bytes Desc: not available Url : http://mail.python.org/pipermail/python-checkins/attachments/20060302/7e8051d1/attachment-0001.obj From python-checkins at python.org Thu Mar 2 04:46:56 2006 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 2 Mar 2006 04:46:56 +0100 (CET) Subject: [Python-checkins] r42768 - peps/trunk/pep-0008.txt Message-ID: <20060302034656.17C851E4002@bag.python.org> Author: guido.van.rossum Date: Thu Mar 2 04:46:55 2006 New Revision: 42768 Modified: peps/trunk/pep-0008.txt Log: /pubic/public/. Thanks Jennings Jared! Modified: peps/trunk/pep-0008.txt ============================================================================== --- peps/trunk/pep-0008.txt (original) +++ peps/trunk/pep-0008.txt Thu Mar 2 04:46:55 2006 @@ -552,7 +552,7 @@ Public attributes are those that you expect unrelated clients of your class to use, with your commitment to avoid backward incompatible changes. Non-public attributes are those that are not intended to be - used by third parties; you make no guarantees that non-pubic attributes + used by third parties; you make no guarantees that non-public attributes won't change or even be removed. We don't use the term "private" here, since no attribute is really From python-checkins at python.org Thu Mar 2 04:52:07 2006 From: python-checkins at python.org (brett.cannon) Date: Thu, 2 Mar 2006 04:52:07 +0100 (CET) Subject: [Python-checkins] r42769 - python/trunk/Doc/lib/libexcs.tex Message-ID: <20060302035207.DFDE31E4002@bag.python.org> Author: brett.cannon Date: Thu Mar 2 04:52:06 2006 New Revision: 42769 Modified: python/trunk/Doc/lib/libexcs.tex Log: Fix latex typos as spotted by George Yoshida. Modified: python/trunk/Doc/lib/libexcs.tex ============================================================================== --- python/trunk/Doc/lib/libexcs.tex (original) +++ python/trunk/Doc/lib/libexcs.tex Thu Mar 2 04:52:06 2006 @@ -82,6 +82,7 @@ eventually be deprecated and thus its use is discouraged. \versionchanged[Changed to inherit from \exception{BaseException}]{2.5} \versionadded{2.5} +\end{excdesc} \begin{excdesc}{Exception} All built-in, non-system-exiting exceptions are derived @@ -168,11 +169,12 @@ \file{pyconfig.h} file. \end{excdesc} -\begin{excdesv}{GeneratorExit} +\begin{excdesc}{GeneratorExit} Raise when a generator's \method{close()} method is called. It directly inherits from \exception{Exception} instead of \exception{StandardError} since it is technically not an error. \versionadded{2.5} +\end{excdesc} \begin{excdesc}{IOError} % XXXJH xrefs here From brett at python.org Thu Mar 2 04:52:44 2006 From: brett at python.org (Brett Cannon) Date: Wed, 1 Mar 2006 19:52:44 -0800 Subject: [Python-checkins] r42748 - in python/trunk: Doc/api/exceptions.tex Doc/lib/libexcs.tex Doc/tut/tut.tex Python/exceptions.c In-Reply-To: <2f188ee80603011929y446a0851i9569ed9fe13b2117@mail.gmail.com> References: <20060301221051.30A3D1E4014@bag.python.org> <2f188ee80603011929y446a0851i9569ed9fe13b2117@mail.gmail.com> Message-ID: On 3/1/06, George Yoshida wrote: > On 3/2/06, brett.cannon wrote: > > Author: brett.cannon > > Date: Wed Mar 1 23:10:49 2006 > > New Revision: 42748 > > > > Modified: > > python/trunk/Doc/api/exceptions.tex > > python/trunk/Doc/lib/libexcs.tex > > python/trunk/Doc/tut/tut.tex > > python/trunk/Python/exceptions.c > > Log: > > Document PEP 352 changes. Also added GeneratorExit. > > > > Hmm, your commit triggers a latex compile error. > Fixed in rev. 42769. Thanks, George. -Brett From guido at python.org Thu Mar 2 04:54:04 2006 From: guido at python.org (Guido van Rossum) Date: Wed, 1 Mar 2006 21:54:04 -0600 Subject: [Python-checkins] r42748 - in python/trunk: Doc/api/exceptions.tex Doc/lib/libexcs.tex Doc/tut/tut.tex Python/exceptions.c In-Reply-To: <2f188ee80603011929y446a0851i9569ed9fe13b2117@mail.gmail.com> References: <20060301221051.30A3D1E4014@bag.python.org> <2f188ee80603011929y446a0851i9569ed9fe13b2117@mail.gmail.com> Message-ID: > On 3/2/06, brett.cannon wrote: > > Author: brett.cannon > > Date: Wed Mar 1 23:10:49 2006 > > New Revision: 42748 On 3/1/06, George Yoshida wrote: > Hmm, your commit triggers a latex compile error. Thanks -- now fixed! -- --Guido van Rossum (home page: http://www.python.org/~guido/) From python-checkins at python.org Thu Mar 2 05:03:51 2006 From: python-checkins at python.org (neal.norwitz) Date: Thu, 2 Mar 2006 05:03:51 +0100 (CET) Subject: [Python-checkins] r42770 - python/trunk/Misc/NEWS Message-ID: <20060302040351.461581E400E@bag.python.org> Author: neal.norwitz Date: Thu Mar 2 05:03:44 2006 New Revision: 42770 Modified: python/trunk/Misc/NEWS Log: Remove duplicate entry Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Thu Mar 2 05:03:44 2006 @@ -430,9 +430,6 @@ - Bug #1413790: zipfile now sanitizes absolute archive names that are not allowed by the specs. -- Bug #1413790: zipfile now sanitizes absolute archive names that are - not allowed by the specs. - - Patch #1215184: FileInput now can be given an opening hook which can be used to control how files are opened. From python-checkins at python.org Thu Mar 2 05:06:28 2006 From: python-checkins at python.org (neal.norwitz) Date: Thu, 2 Mar 2006 05:06:28 +0100 (CET) Subject: [Python-checkins] r42771 - python/trunk/Python/compile.c Message-ID: <20060302040628.C4D681E4002@bag.python.org> Author: neal.norwitz Date: Thu Mar 2 05:06:10 2006 New Revision: 42771 Modified: python/trunk/Python/compile.c Log: Update known issues to reflect reality Modified: python/trunk/Python/compile.c ============================================================================== --- python/trunk/Python/compile.c (original) +++ python/trunk/Python/compile.c Thu Mar 2 05:06:10 2006 @@ -35,14 +35,11 @@ /* ISSUES: - character encodings aren't handled - - ref leaks in interpreter when press return on empty line - opcode_stack_effect() function should be reviewed since stack depth bugs could be really hard to find later. Dead code is being generated (i.e. after unconditional jumps). + XXX(nnorwitz): not sure this is still true */ #define DEFAULT_BLOCK_SIZE 16 From neal at metaslash.com Thu Mar 2 05:09:12 2006 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 1 Mar 2006 23:09:12 -0500 Subject: [Python-checkins] Python Regression Test Failures refleak (4) Message-ID: <20060302040912.GA11253@python.psfb.org> test_ast leaked [107, 107, 107] references test_cfgparser leaked [0, -54, 0] references test_cmd_line leaked [15, 0, 15] references test_compiler leaked [204, 67, 146] references test_future leaked [3, 3, 3] references test_generators leaked [255, 255, 255] references test_pep352 leaked [1, 1, 1] references test_sys leaked [1, 1, 1] references test_threadedtempfile leaked [3, 4, 0] references test_threading leaked [1, 0, 0] references test_threading_local leaked [42, 42, 34] references test_urllib2 leaked [80, -130, 70] references From neal at metaslash.com Thu Mar 2 05:09:12 2006 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 1 Mar 2006 23:09:12 -0500 Subject: [Python-checkins] Python Regression Test Failures refleak (4) Message-ID: <20060302040912.GA11256@python.psfb.org> test_ast leaked [107, 107, 107] references test_cfgparser leaked [0, -54, 0] references test_cmd_line leaked [15, 0, 15] references test_compiler leaked [204, 67, 146] references test_future leaked [3, 3, 3] references test_generators leaked [255, 255, 255] references test_pep352 leaked [1, 1, 1] references test_sys leaked [1, 1, 1] references test_threadedtempfile leaked [3, 4, 0] references test_threading leaked [1, 0, 0] references test_threading_local leaked [42, 42, 34] references test_urllib2 leaked [80, -130, 70] references From neal at metaslash.com Thu Mar 2 05:09:12 2006 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 1 Mar 2006 23:09:12 -0500 Subject: [Python-checkins] Python Regression Test Failures refleak (4) Message-ID: <20060302040912.GA11254@python.psfb.org> test_ast leaked [107, 107, 107] references test_cfgparser leaked [0, -54, 0] references test_cmd_line leaked [15, 0, 15] references test_compiler leaked [204, 67, 146] references test_future leaked [3, 3, 3] references test_generators leaked [255, 255, 255] references test_pep352 leaked [1, 1, 1] references test_sys leaked [1, 1, 1] references test_threadedtempfile leaked [3, 4, 0] references test_threading leaked [1, 0, 0] references test_threading_local leaked [42, 42, 34] references test_urllib2 leaked [80, -130, 70] references From neal at metaslash.com Thu Mar 2 05:09:12 2006 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 1 Mar 2006 23:09:12 -0500 Subject: [Python-checkins] Python Regression Test Failures refleak (4) Message-ID: <20060302040912.GA11252@python.psfb.org> test_ast leaked [107, 107, 107] references test_cfgparser leaked [0, -54, 0] references test_cmd_line leaked [15, 0, 15] references test_compiler leaked [204, 67, 146] references test_future leaked [3, 3, 3] references test_generators leaked [255, 255, 255] references test_pep352 leaked [1, 1, 1] references test_sys leaked [1, 1, 1] references test_threadedtempfile leaked [3, 4, 0] references test_threading leaked [1, 0, 0] references test_threading_local leaked [42, 42, 34] references test_urllib2 leaked [80, -130, 70] references From python-checkins at python.org Thu Mar 2 05:24:09 2006 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 2 Mar 2006 05:24:09 +0100 (CET) Subject: [Python-checkins] r42772 - in python/trunk/Lib: compiler/transformer.py test/test_compiler.py Message-ID: <20060302042409.A2AB91E400F@bag.python.org> Author: guido.van.rossum Date: Thu Mar 2 05:24:01 2006 New Revision: 42772 Modified: python/trunk/Lib/compiler/transformer.py python/trunk/Lib/test/test_compiler.py Log: Fix failure of test_compiler.py when compiling test_contextlib.py. The culprit was an expression-less yield -- the first apparently in the standard library. I added a unit test for this. Also removed the hack to force compilation of test_with.py. Modified: python/trunk/Lib/compiler/transformer.py ============================================================================== --- python/trunk/Lib/compiler/transformer.py (original) +++ python/trunk/Lib/compiler/transformer.py Thu Mar 2 05:24:01 2006 @@ -408,11 +408,11 @@ return Discard(expr, lineno=expr.lineno) def yield_expr(self, nodelist): - if len(nodelist)>1: - value = nodelist[1] + if len(nodelist) > 1: + value = self.com_node(nodelist[1]) else: value = Const(None) - return Yield(self.com_node(value), lineno=nodelist[0][2]) + return Yield(value, lineno=nodelist[0][2]) def raise_stmt(self, nodelist): # raise: [test [',' test [',' test]]] Modified: python/trunk/Lib/test/test_compiler.py ============================================================================== --- python/trunk/Lib/test/test_compiler.py (original) +++ python/trunk/Lib/test/test_compiler.py Thu Mar 2 05:24:01 2006 @@ -20,7 +20,7 @@ for basename in os.listdir(dir): if not basename.endswith(".py"): continue - if not TEST_ALL and random() < 0.98 and basename != "test_with.py": + if not TEST_ALL and random() < 0.98: continue path = os.path.join(dir, basename) if test.test_support.verbose: @@ -43,6 +43,9 @@ def testNewClassSyntax(self): compiler.compile("class foo():pass\n\n","","exec") + def testYieldExpr(self): + compiler.compile("def g(): yield\n\n", "", "exec") + def testLineNo(self): # Test that all nodes except Module have a correct lineno attribute. filename = __file__ From python-checkins at python.org Thu Mar 2 05:31:57 2006 From: python-checkins at python.org (brett.cannon) Date: Thu, 2 Mar 2006 05:31:57 +0100 (CET) Subject: [Python-checkins] r42773 - python/trunk/Python/exceptions.c Message-ID: <20060302043157.5E7B91E4002@bag.python.org> Author: brett.cannon Date: Thu Mar 2 05:31:55 2006 New Revision: 42773 Modified: python/trunk/Python/exceptions.c Log: Add a missing Py_DECREF to BaseException__unicode__ . Modified: python/trunk/Python/exceptions.c ============================================================================== --- python/trunk/Python/exceptions.c (original) +++ python/trunk/Python/exceptions.c Thu Mar 2 05:31:55 2006 @@ -285,16 +285,22 @@ } else if (args_len == 1) { PyObject *temp = PySequence_GetItem(args, 0); + PyObject *unicode_obj; + if (!temp) { Py_DECREF(args); return NULL; } Py_DECREF(args); - return PyObject_Unicode(temp); + unicode_obj = PyObject_Unicode(temp); + Py_DECREF(temp); + return unicode_obj; } else { + PyObject *unicode_obj = PyObject_Unicode(args); + Py_DECREF(args); - return PyObject_Unicode(args); + return unicode_obj; } } #endif /* Py_USING_UNICODE */ From neal at metaslash.com Thu Mar 2 05:46:31 2006 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 1 Mar 2006 23:46:31 -0500 Subject: [Python-checkins] Python Regression Test Failures all (1) Message-ID: <20060302044631.GA22293@python.psfb.org> /home/neal/python/trunk/Lib/random.py:44: RuntimeWarning: Python C API version mismatch for module math: This Python has API version 1013, module math has version 1012. from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil /home/neal/python/trunk/Lib/random.py:47: RuntimeWarning: Python C API version mismatch for module binascii: This Python has API version 1013, module binascii has version 1012. from binascii import hexlify as _hexlify /home/neal/python/trunk/Lib/random.py:68: RuntimeWarning: Python C API version mismatch for module _random: This Python has API version 1013, module _random has version 1012. import _random ./Lib/test/regrtest.py:113: RuntimeWarning: Python C API version mismatch for module cStringIO: This Python has API version 1013, module cStringIO has version 1012. import cStringIO /home/neal/python/trunk/Lib/unittest.py:51: RuntimeWarning: Python C API version mismatch for module time: This Python has API version 1013, module time has version 1012. import time test_grammar test_opcodes test_operations test_builtin /home/neal/python/trunk/Lib/test/test_builtin.py:5: RuntimeWarning: Python C API version mismatch for module operator: This Python has API version 1013, module operator has version 1012. from operator import neg /home/neal/python/trunk/Lib/locale.py:28: RuntimeWarning: Python C API version mismatch for module _locale: This Python has API version 1013, module _locale has version 1012. from _locale import * /home/neal/python/trunk/Lib/string.py:527: RuntimeWarning: Python C API version mismatch for module strop: This Python has API version 1013, module strop has version 1012. from strop import maketrans, lowercase, uppercase, whitespace test test_builti/home/neal/python/trunk/Lib/test/test_exceptions.py:179: RuntimeWarning: Python C API version mismatch for module _testcapi: This Python has API version 1013, module _testcapi has version 1012. import _testcapi test_types test_MimeWriter /home/neal/python/trunk/Lib/tempfile.py:40: RuntimeWarning: Python C API version mismatch for module fcntl: This Python has API version 1013, module fcntl has version 1012. import fcntl as _fcntl test_StringIO test___all__ /home/neal/python/trunk/Lib/test/test___all__.py:41: RuntimeWarning: Python C API version mismatch for module _socket: This Python has API version 1013, module _socket has version 1012. import _socket /home/neal/python/trunk/Lib/soc/home/neal/python/trunk/Lib/test/test___all__.py:41: RuntimeWarning: Python C API version mismatch for module _socket: This Python has API version 1013,/home/neal/python/trunk/Lib/CGIHTTPServer.py:31: RuntimeWarning: Python C API version mismatch for module select: This Python has API version 1013, module select has version 1012. import select /home/neal/python/trunk/Lib/Cookie.py:216: RuntimeWarning: Python C API version mismatch for module cPickle: This Python has API version 1013, module cPickle has version 1012. from cPickle import dumps, loads /home/neal/python/trunk/Lib/Queue.py:4: RuntimeWarning: Python C API version mismatch for module collections: This Python has API version 1013, module collections has version 1012. from collections import deque /home/neal/python/trunk/Lib/aifc.py:137: RuntimeWarning: Python C API version mismatch for module struct: This Python has API version 1013, module struct has version 1012. import struct /home/neal/python/trunk/Lib/calendar.py:8: RuntimeWarning: Python C API version mismatch for module datetime: This Python has API version 1013, module datetime has version 1012. import datetime /home/neal/python/trunk/Lib/csv.py:7: RuntimeWarning: Python C API version mismatch for module _csv: This Python has API version 1013, module _csv has version 1012. from _csv import Error, __version__, writer, reader, register_diale/home//home/neal/python/trunk/Lib/weakref.py:14: RuntimeWarning: Python C API version mismatch for module _weakref: This Python has API version 1013, module _weakref has version 1012. from _weakref import ( /home/neal/python/trunk/Lib/heapq.py:132: RuntimeWarning: Python C API version mismatch for module itertools: This Python has API version 1013, module itertools has version 1012. from itertools import islice, repeat, count, imap, iz/home/neal/python/trunk/Lib/heapq.py:132: RuntimeWarning: Python C API version mismatch for module itertools: This Python has API version 1013, module itertools has version 1012. from itertools import islice, repeat, count, imap, izip, tee /home/neal/python/trunk/Lib/bisect.py:82: RuntimeWarning: Python C API version mismatch for module _bisect: This Python has API version 1013, module _bisect has version 1012. from _bisect import bisect_right, bisect_left, insort_left, insort_right, insort, bisect /home/neal/python/tru/home/neal/python/trunk/Lib/getpass.py:106: RuntimeWarning: Python C API version mismatch for module termios: This Python has API version 1013, module termios has version 1012. import termios /home/neal/python/trunk/Lib/gzip.py:9: RuntimeWarning: Python C API version mismatch for module zlib: This Python has API version 1013, module zlib has version 1012. import zlib /home/neal/python/trunk/Lib/profile.py:116: RuntimeWarning: Python C API version mismatch for module resource: This Python has API version 1013, module resource has version 1012. import resource /home/neal/python/trunk/Lib/reconvert/home/neal/python/trunk/Lib/profile.py:116: RuntimeWarning: Python C API version mismatch for module resource: This Python has API version 1013, module resource has version 1012. import resource /home/neal/python/trunk/Lib/reconvert.py:67: RuntimeWarning: Python C API version mismatch for module regex: This Python has API version 1013, module regex has version 1012. import regex /home/neal/python/trunk/Lib/rlcompleter.py:42: RuntimeWarning: Python C API version mismatch for module readline: This Python has API version 1013, modutest___future__ test__locale test_aepack test_aepack skipped -- No module named aepack test_al test_al skipped -- No module named al test_anydbm /home/neal/python/trunk/Lib/anydbm.py:54: RuntimeWarning: Python C API version mismatch for module gdbm: This Python has API version 1013, module gdbm has version 1012. _mod = __import__(_name) /home/neal/python/trunk/Litest_anydbm /home/neal/python/trunk/Lib/anydbm.py:54: RuntimeWarning: Python C API version mismatch for module gdbm: This Python has API version 1013, module gdbm has vtest test_anydbm failed -- errors occurred in test.test_anydbm.AnyDBMTestCase test_applesingle test_applesingle skipped -- No module named macostools test_array /home/neal/python/trunk/Lib/test/test_array.py:9: RuntimeWarning: Python test test_anydbm failed -- errors occurred in test.test_anydbm.AnyDBMTestCase test_applesingle test_applesingle skipped -- No module namedtest_ast test_asynchat test_atexit test_audioop /home/neal/python/trunk/Lib/test/test_audioop.py:2: RuntimeWarning: Python C API version mismatch for module audioop: This Python has API version 1013, module audioop has version 1012. import audioop test_augassign test_base64 test_bastion test_binascii test_binhex test_binop test_bisect test_bool test_bsddb test_bsddb185 test_bsddb185 skipped -- No module named bsddb185 test_bsddb3 Exception in thread reader 4: Traceback (most recent call last): File "/home/neal/python/trunk/Lib/threading.py", line 473, in __bootstrap self.run() File "/home/neal/python/trunk/Lib/threading.py", line 453, in run self.__target(*self.__args, **self.__kwargs) File "/home/neal/python/trunk/Lib/bsddb/test/test_thread.py", line 275, in readerThread rec = dbutils.DeadlockWrap(c.next, max_retries=10) File "/home/neal/python/trunk/Lib/bsddb/dbutils.py", line 62, in DeadlockWrap return function(*_args, **_kwargs) DBLockDeadlockError: (-30996, 'DB_LOCK_DEADLOCK: Locker killed to resolve a deadlock') Exception in thread writer 0: Traceback (most recent call last): File "/home/neal/python/trunk/Lib/threading.py", line 473, in __bootstrap self.run() File "/home/neal/python/trunk/Lib/threading.py", line 453, in run self.__target(*self.__args, **self.__kwargs) File "/home/neal/python/trunk/Lib/bsddb/test/test_thread.py", line 254, in writerThread self.assertEqual(data, self.makeData(key)) File "/home/neal/python/trunk/Lib/unittest.py", line 334, in failUnlessEqual (msg or '%r != %r' % (first, second)) AssertionError: None != '0003-0003-0003-0003-0003' Exception in thread writer 1: Traceback (most recent call last): File "/home/neal/python/trunk/Lib/threading.py", line 473, in __bootstrap self.run() File "/home/neal/python/trunk/Lib/threading.py", line 453, in run self.__target(*self.__args, **self.__kwargs) File "/home/neal/python/trunk/Lib/bsddb/test/test_thread.py", line 254, in writerThread self.assertEqual(data, self.makeData(key)) File "/home/neal/python/trunk/Lib/unittest.py", line 334, in failUnlessEqual (msg or '%r != %r' % (first, second)) AssertionError: None != '1000-1000-1000-1000-1000' Exception in thread writer 2: Traceback (most recent call Exception in thread writer 1: Traceback (most recent call last): File "/home/neal/python/trunk/Lib/threading.py", line 473, in __bootstrap self.run() File "/home/neal/python/trunk/Lib/threading.py", line 453, in run self.__target(*self.__args, **self.__kwargs) File "/home/neal/python/trunk/Lib/bsddb/test/test_thread.py", line 372, in writerThread self.doWrite(d, name, x, min(stop, x+step)) File "/home/neal/python/trunk/Lib/bsddb/test/test_thread.py", line 360, in doWrite txn.abort() DBRunRecoverytest test_bsddb3 failed -- errors occurred; run in verbose mode for details test_bufio test_bz2 /home/neal/python/trunk/Lib/test/test_bz2.py:11: RuntimeWarning: Python C API version mismatch for module bz2: This Python has API version 1013, module bz2 has version 1012. import bz2 test_cProfile /home/neal/python/trunk/Lib/cProfile.py:9: RuntimeWarning: Python C API version mismatch for module _lsprof: This Python has API version 1013, module _lsprof has version 1012. import _lsprof test_calendar test_call test_capi test_cd test_cd skipped -- No module named cd test_cfgparser test_cgi test_charmapcodec test_cl test_cl skipped -- No module named cl test_class test_cmath /home/neal/python/trunk/Lib/test/test_cmath.py:5: RuntimeWarning: Python C API version mismatch for module cmath: This Python has API version 1013, module cmath has version 1012. import cmath, math test_cmd_line test_code test_codeccallbacks /home/neal/python/trunk/Lib/test/test_codeccallbacks.py:2: RuntimeWarning: Python C API version mismatch for module unicodedata: This Python has API version 1013, module unicodedata has version 1012. import sys, codecs, htmlentitydefs, unicodedata test_codecencodings_cn /home/neal/python/trunk/Lib/encodings/gb2312.py:8: RuntimeWarning: Python C API version mismatch for module _codecs_cn: This Python has API version 1013, module _codecs_cn has version 1012. import _codecs_cn, codecs /home/neal/python/trunk/Lib/encodings/gb2312.py:10: RuntimeWarning: Python C API version mismatch for module _multibytecodec: This Python has API version 1013, module _multibytecodec has version 1012. codec = _codecs_cn.getcodec('gb2312') test_codecencodings_hk /home/neal/python/trunk/Lib/encodings/big5hkscs.py:8: RuntimeWarning: Python C API version mismatch for module _codecs_hk: This Python has API version 1013, module _codecs_hk has version 1012. import _codecs_hk, codecs /home/neal/python/trunk/Lib/encodings/big5hkscs.py:10: RuntimeWarning: Python C API version mismatch for module _codecs_tw: This Python has API version 1013, module _codecs_tw has version 1012. codec = _codecs_hk.getcodec('big5hkscs') test_codecencodings_jp /home/neal/python/trunk/Lib/encodings/cp932.py:8: RuntimeWarning: Python C API version mismatch for module _codecs_jp: This Python has API version 1013, module _codecs_jp has version 1012. import _codecs_jp, codecs test_codecencodings_kr /home/neal/python/trunk/Lib/encodings/cp949.py:8: RuntimeWarning: Python C API version mismatch for module _codecs_kr: This Python has API version 1013, module _codecs_kr has version 1012. import _codecs_kr, codecs test_codecencodings_tw test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_codecs /home/neal/python/trunk/Lib/encodings/iso2022_jp.py:8: RuntimeWarning: Python C API version mismatch for module _codecs_iso2022: This Python has API version 1013, module _codecs_iso2022 has version 1012. import _codecs_iso2022, codecs test_codeop test_coding test_coercion test_colorsys test_commands test_compare test_compile test_compiler test test_compiler failed -- Traceback (most recent call last): File "/home/neal/python/trunk/Lib/test/test_compiler.py", line 35, in testCompileLibrary compiler.compile(buf, basename, "exec") File "/home/neal/python/trunk/Lib/compiler/pycodegen.py", line 63, in compile gen.compile() File "/home/neal/python/trunk/Lib/compiler/pycodegen.py", line 110, in compile tree = self._get_tree() File "/home/neal/python/trunk/Lib/compiler/pycodegen.py", line 76, in _get_tree tree = parse(self.source, self.mode) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 52, in parse return Transformer().parsesuite(buf) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 129, in parsesuite return self.transform(parser.suite(text)) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 125, in transform return self.compile_node(tree) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 158, in compile_node return self.file_input(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 189, in file_input self.com_append_stmt(stmts, node) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1059, in com_append_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 296, in classdef code = self.com_node(nodelist[-1]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 779, in com_node return self._dispatch[node[0]](node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 553, in suite self.com_append_stmt(stmts, node) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1059, in com_append_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 260, in funcdef code = self.com_node(nodelist[-1]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 779, in com_node return self._dispatch[node[0]](node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 553, in suite self.com_append_stmt(stmts, node) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1059, in com_append_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 260, in funcdef code = self.com_node(nodelist[-1]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 779, in com_node return self._dispatch[node[0]](node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 553, in suite self.com_append_stmt(stmts, node) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1059, in com_append_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 316, in simple_stmt self.com_append_stmt(stmts, nodelist[i]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1059, in com_append_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 306, in stmt return self.com_stmt(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 1052, in com_stmt result = self.lookup_node(node)(node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 407, in yield_stmt expr = self.com_node(nodelist[0]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 779, in com_node return self._dispatch[node[0]](node[1:]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 415, in yield_expr return Yield(self.com_node(value), lineno=nodelist[0][2]) File "/home/neal/python/trunk/Lib/compiler/transformer.py", line 779, in com_node return self._dispatch[node[0]](node[1:]) AttributeError: Const instance has no attribute '__getitem__' test_complex test_contains test_contextlib test_cookie test_cookielib /home/neal/python/trunk/Lib/hashlib.py:73: RuntimeWarning: Python C API version mismatch for module _hashlib: This Python has API version 1013, module _hashlib has version 1012. import _hashlib /home/neal/python/trunk/Lib/hashlib.py:34: RuntimeWarning: Python C API version mismatch for module _sha256: This Python has API version 1013, module _sha256 has version 1012. import _sha256 /home/neal/python/trunk/Lib/hashlib.py:41: RuntimeWarning: Python C API version mismatch for module _sha512: This Python has API version 1013, module _sha512 has version 1012. import _sha512 test_copy test_copy_reg test_cpickle test_crypt /home/neal/python/trunk/Lib/test/test_crypt.py:7: RuntimeWarning: Python C API version mismatch for module crypt: This Python has API version 1013, module crypt has version 1012. import crypt test_csv test_datetime test_dbm test_decimal test_decorators test_defaultdict test_deque test_descr test_descrtut test_dict test_difflib test_dircache test_dis test_distutils test_dl /home/neal/python/trunk/Lib/test/test_dl.py:6: RuntimeWarning: Python C API version mismatch for module dl: This Python has API version 1013, module dl has version 1012. import dl test_doctest test_doctest2 test_dumbdbm test_dummy_thread test_dummy_threading test_email test_email_codecs test_enumerate test_eof test_errno test_exception_variations test_extcall test_fcntl test_file test_filecmp test_fileinput test_float test_fnmatch test_fork1 test_format test_fpformat test_frozen test_funcattrs test_functional /home/neal/python/trunk/Lib/test/test_functional.py:1: RuntimeWarning: Python C API version mismatch for module functional: This Python has API version 1013, module functional has version 1012. import functional test_future test_gc test_gdbm test_generators test_genexps test_getargs test_getargs2 test_getopt test_gettext test_gl test_gl skipped -- No module named gl test_glob test_global test_grp test_gzip test_hash test_hashlib test_hashlib_speed test_hashlib_speed skipped -- not a unit test (stand alone benchmark) test_heapq test_hexoct test_hmac test_hotshot /home/neal/python/trunk/Lib/hotshot/__init__.py:3: RuntimeWarning: Python C API version mismatch for module _hotshot: This Python has API version 1013, module _hotshot has version 1012. import _hotshot test_htmllib test_htmlparser test_httplib test_imageop /home/neal/python/trunk/Lib/test/test_imageop.py:10: RuntimeWarning: Python C API version mismatch for module imageop: This Python has API version 1013, module imageop has version 1012. import imageop, uu, os /home/neal/python/trunk/Lib/test/test_imageop.py:129: RuntimeWarning: Python C API version mismatch for module rgbimg: This Python has API version 1013, module rgbimg has version 1012. import rgbimg test_imaplib test_imgfile test_imgfile skipped -- No module named imgfile test_imp test_import test_importhooks test_inspect test_ioctl test_ioctl skipped -- Unable to open /dev/tty test_isinstance test_iter test_iterlen test_itertools test_largefile test_list test_locale test_logging test_long test_long_future test_longexp test_macfs test_macfs skipped -- No module named macfs test_macostools test_macostools skipped -- No module named macostools test_macpath test_mailbox test_marshal test_math test_md5 test_mhlib test_mimetools test_mimetypes test_minidom /home/neal/python/trunk/Lib/xmlcore/parsers/expat.py:4: RuntimeWarning: Python C API version mismatch for module pyexpat: This Python has API version 1013, module pyexpat has version 1012. from pyexpat import * test_mmap /home/neal/python/trunk/Lib/test/test_mmap.py:2: RuntimeWarning: Python C API version mismatch for module mmap: This Python has API version 1013, module mmap has version 1012. import mmap test_module test_multibytecodec test_multibytecodec_support test_multifile test_mutants test_netrc test_new test_nis /home/neal/python/trunk/Lib/test/test_nis.py:2: RuntimeWarning: Python C API version mismatch for module nis: This Python has API version 1013, module nis has version 1012. import nis test_nis skipped -- Local domain name not set test_normalization test_ntpath test_openpty test_operator test_optparse test_os test_parser test_peepholer test_pep247 test_pep263 test_pep277 test_pep277 skipped -- test works only on NT+ test_pep292 test_pep352 test_pickle test_pickletools test_pkg test_pkgimport test_platform test_plistlib test_plistlib skipped -- No module named plistlib test_poll test_popen [9159 refs] [9159 refs] [9159 refs] test_popen2 test_posix test_posixpath test_pow test_pprint test_profile test_profilehooks test_pty test_pwd test_pyclbr test_pyexpat test_queue test_quopri /home/neal/python/trunk/Lib/quopri.py:15: RuntimeWarning: Python C API version mismatch for module binascii: This Python has API version 1013, module binascii has version 1012. from binascii import a2b_qp, b2a_qp [9447 refs] /home/neal/python/trunk/Lib/quopri.py:15: RuntimeWarning: Python C API version mismatch for module binascii: This Python has API version 1013, module binascii has version 1012. from binascii import a2b_qp, b2a_qp [9447 refs] test_random test_re test_regex test_repr test_resource test_rfc822 test_rgbimg test_richcmp test_robotparser test_sax test_scope test_scriptpackages test_scriptpackages skipped -- No module named aetools test_select test_set test_sets test_sgmllib test_sha test_shelve test_shlex test_shutil test_signal test_site test_slice test_socket test_socket_ssl test_socketserver test_softspace test_sort test_str test_strftime test_string test_stringprep test_strop test_strptime test_struct test_structseq test_subprocess [9154 refs] [9156 refs] [9154 refs] [9154 refs] [9154 refs] [9154 refs] [9154 refs] [9155 refs] [9155 refs] [9154 refs] [9155 refs] [9154 refs] -c:1: RuntimeWarning: Python C API version mismatch for module time: This Python has API version 1013, module time has version 1012. [9464 refs] [9155 refs] [9155 refs] [9155 refs] [9155 refs] [9155 refs] [9155 refs] [9155 refs] this bit of output is from a test of stdout in a different process ... [9155 refs] [9154 refs] -c:1: RuntimeWarning: Python C API version mismatch for module time: This Python has API version 1013, module time has version 1012. [9464 refs] test_sunaudiodev test_sunaudiodev skipped -- No module named sunaudiodev test_sundry /home/neal/python/trunk/Lib/curses/__init__.py:15: RuntimeWarning: Python C API version mismatch for module _curses: This Python has API version 1013, module _curses has version 1012. from _curses import * test_symtable test_syntax test_sys [9154 refs] [9154 refs] test_tarfile test_tcl test_tcl skipped -- No module named _tkinter test_tempfile [9156 refs] test_textwrap test_thread test_threaded_import test_threadedtempfile test_threading test_threading_local test_threadsignals test_time test_timeout test_timing /home/neal/python/trunk/Lib/test/test_timing.py:2: RuntimeWarning: Python C API version mismatch for module timing: This Python has API version 1013, module timing has version 1012. import timing test_tokenize test_trace test_traceback test_transformer test_tuple test_ucn test_unary test_unicode test_unicode_file test_unicode_file skipped -- No Unicode filesystem semantics on this platform. test_unicodedata test_unittest test_univnewlines test_unpack test_urllib test_urllib2 test_urllib2net test_urllibnet test_urlparse test_userdict test_userlist test_userstring test_uu test_warnings test_wave test_weakref test_whichdb test_winreg test_winreg skipped -- No module named _winreg test_winsound test_winsound skipped -- No module named winsound test_with test_xdrlib test_xml_etree test_xml_etree_c /home/neal/python/trunk/Lib/xmlcore/etree/cElementTree.py:3: RuntimeWarning: Python C API version mismatch for module _elementtree: This Python has API version 1013, module _elementtree has version 1012. from _elementtree import * test_xmllib test_xmlrpc test_xpickle test_xrange test_zipfile test_zipimport test_zlib 281 tests OK. 3 tests failed: test_anydbm test_bsddb3 test_compiler 21 tests skipped: test_aepack test_al test_applesingle test_bsddb185 test_cd test_cl test_gl test_hashlib_speed test_imgfile test_ioctl test_macfs test_macostools test_nis test_pep277 test_plistlib test_scriptpackages test_sunaudiodev test_tcl test_unicode_file test_winreg test_winsound 1 skip unexpected on linux2: test_ioctl [363040 refs] From python-checkins at python.org Thu Mar 2 05:48:28 2006 From: python-checkins at python.org (thomas.wouters) Date: Thu, 2 Mar 2006 05:48:28 +0100 (CET) Subject: [Python-checkins] r42774 - python/trunk/Modules/_hashopenssl.c Message-ID: <20060302044828.224521E4002@bag.python.org> Author: thomas.wouters Date: Thu Mar 2 05:48:27 2006 New Revision: 42774 Modified: python/trunk/Modules/_hashopenssl.c Log: Py_SAFE_DOWNCAST isn't quite doing the right thing for going from Py_ssize_t to an unsigned int (and back again) on 64-bit machines, even though the actual value of the Py_ssize_t variable is way below 31 bits. I suspect compiler-error. Modified: python/trunk/Modules/_hashopenssl.c ============================================================================== --- python/trunk/Modules/_hashopenssl.c (original) +++ python/trunk/Modules/_hashopenssl.c Thu Mar 2 05:48:27 2006 @@ -173,8 +173,7 @@ if (!PyArg_ParseTuple(args, "s#:update", &cp, &len)) return NULL; - EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, - unsigned int)); + EVP_DigestUpdate(&self->ctx, cp, (unsigned int)len); Py_INCREF(Py_None); return Py_None; @@ -265,8 +264,7 @@ Py_INCREF(self->name); if (cp && len) - EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, - unsigned int)); + EVP_DigestUpdate(&self->ctx, cp, (unsigned int)len); return 0; } @@ -393,8 +391,7 @@ digest = EVP_get_digestbyname(name); - return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, - unsigned int)); + return EVPnew(name_obj, digest, NULL, cp, (unsigned int)len); } /* @@ -419,7 +416,7 @@ CONST_ ## NAME ## _name_obj, \ NULL, \ CONST_new_ ## NAME ## _ctx_p, \ - cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \ + cp, (unsigned int)len); \ } /* a PyMethodDef structure for the constructor */ From nnorwitz at gmail.com Thu Mar 2 05:50:21 2006 From: nnorwitz at gmail.com (Neal Norwitz) Date: Wed, 1 Mar 2006 20:50:21 -0800 Subject: [Python-checkins] r42743 - python/trunk/Modules/_hashopenssl.c In-Reply-To: <20060301215009.5E5CE1E4002@bag.python.org> References: <20060301215009.5E5CE1E4002@bag.python.org> Message-ID: This change causes failures on my amd64: http://www.python.org/dev/buildbot/all/amd64%20gentoo%20trunk/builds/199/step-test/0 n -- On 3/1/06, thomas.wouters wrote: > Author: thomas.wouters > Date: Wed Mar 1 22:50:07 2006 > New Revision: 42743 > > Modified: > python/trunk/Modules/_hashopenssl.c > Log: > > Make Py_ssize_t-clean. > > > > Modified: python/trunk/Modules/_hashopenssl.c > ============================================================================== > --- python/trunk/Modules/_hashopenssl.c (original) > +++ python/trunk/Modules/_hashopenssl.c Wed Mar 1 22:50:07 2006 > @@ -11,6 +11,8 @@ > * > */ > > +#define PY_SSIZE_T_CLEAN > + > #include "Python.h" > #include "structmember.h" > > @@ -166,12 +168,13 @@ > EVP_update(EVPobject *self, PyObject *args) > { > unsigned char *cp; > - int len; > + Py_ssize_t len; > > if (!PyArg_ParseTuple(args, "s#:update", &cp, &len)) > return NULL; > > - EVP_DigestUpdate(&self->ctx, cp, len); > + EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, > + unsigned int)); > > Py_INCREF(Py_None); > return Py_None; > @@ -238,7 +241,7 @@ > PyObject *name_obj = NULL; > char *nameStr; > unsigned char *cp = NULL; > - unsigned int len; > + Py_ssize_t len; > const EVP_MD *digest; > > if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s#:HASH", kwlist, > @@ -262,7 +265,8 @@ > Py_INCREF(self->name); > > if (cp && len) > - EVP_DigestUpdate(&self->ctx, cp, len); > + EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, > + unsigned int)); > > return 0; > } > @@ -375,7 +379,7 @@ > char *name; > const EVP_MD *digest; > unsigned char *cp = NULL; > - unsigned int len; > + Py_ssize_t len; > > if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O|s#:new", kwlist, > &name_obj, &cp, &len)) { > @@ -389,7 +393,8 @@ > > digest = EVP_get_digestbyname(name); > > - return EVPnew(name_obj, digest, NULL, cp, len); > + return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, > + unsigned int)); > } > > /* > @@ -404,7 +409,7 @@ > EVP_new_ ## NAME (PyObject *self, PyObject *args) \ > { \ > unsigned char *cp = NULL; \ > - unsigned int len; \ > + Py_ssize_t len; \ > \ > if (!PyArg_ParseTuple(args, "|s#:" #NAME , &cp, &len)) { \ > return NULL; \ > @@ -414,7 +419,7 @@ > CONST_ ## NAME ## _name_obj, \ > NULL, \ > CONST_new_ ## NAME ## _ctx_p, \ > - cp, len); \ > + cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \ > } > > /* a PyMethodDef structure for the constructor */ > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > From python-checkins at python.org Thu Mar 2 06:05:19 2006 From: python-checkins at python.org (thomas.wouters) Date: Thu, 2 Mar 2006 06:05:19 +0100 (CET) Subject: [Python-checkins] r42775 - python/trunk/Modules/_hashopenssl.c Message-ID: <20060302050519.39AF01E401C@bag.python.org> Author: thomas.wouters Date: Thu Mar 2 06:05:17 2006 New Revision: 42775 Modified: python/trunk/Modules/_hashopenssl.c Log: Properly fix Py_SAFE_DOWNCAST-triggerd bugs. Modified: python/trunk/Modules/_hashopenssl.c ============================================================================== --- python/trunk/Modules/_hashopenssl.c (original) +++ python/trunk/Modules/_hashopenssl.c Thu Mar 2 06:05:17 2006 @@ -173,7 +173,8 @@ if (!PyArg_ParseTuple(args, "s#:update", &cp, &len)) return NULL; - EVP_DigestUpdate(&self->ctx, cp, (unsigned int)len); + EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, + unsigned int)); Py_INCREF(Py_None); return Py_None; @@ -240,7 +241,7 @@ PyObject *name_obj = NULL; char *nameStr; unsigned char *cp = NULL; - Py_ssize_t len; + Py_ssize_t len = 0; const EVP_MD *digest; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s#:HASH", kwlist, @@ -264,7 +265,8 @@ Py_INCREF(self->name); if (cp && len) - EVP_DigestUpdate(&self->ctx, cp, (unsigned int)len); + EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, + unsigned int)); return 0; } @@ -377,7 +379,7 @@ char *name; const EVP_MD *digest; unsigned char *cp = NULL; - Py_ssize_t len; + Py_ssize_t len = 0; if (!PyArg_ParseTupleAndKeywords(args, kwdict, "O|s#:new", kwlist, &name_obj, &cp, &len)) { @@ -391,7 +393,8 @@ digest = EVP_get_digestbyname(name); - return EVPnew(name_obj, digest, NULL, cp, (unsigned int)len); + return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, + unsigned int)); } /* @@ -406,7 +409,7 @@ EVP_new_ ## NAME (PyObject *self, PyObject *args) \ { \ unsigned char *cp = NULL; \ - Py_ssize_t len; \ + Py_ssize_t len = 0; \ \ if (!PyArg_ParseTuple(args, "|s#:" #NAME , &cp, &len)) { \ return NULL; \ @@ -416,7 +419,7 @@ CONST_ ## NAME ## _name_obj, \ NULL, \ CONST_new_ ## NAME ## _ctx_p, \ - cp, (unsigned int)len); \ + cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \ } /* a PyMethodDef structure for the constructor */ From python-checkins at python.org Thu Mar 2 08:41:13 2006 From: python-checkins at python.org (tim.peters) Date: Thu, 2 Mar 2006 08:41:13 +0100 (CET) Subject: [Python-checkins] r42776 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060302074113.700091E401A@bag.python.org> Author: tim.peters Date: Thu Mar 2 08:41:12 2006 New Revision: 42776 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Repaired the new insecurity in Py_ADDRESS_IN_RANGE. Explained more about what that macro does and why. This "is done" now, except (I hope) for eventually merging to the trunk. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Thu Mar 2 08:41:12 2006 @@ -470,10 +470,14 @@ /* Number of slots currently allocated in the `arenas` vector. */ static uint maxarenas = 0; -/* The head of the singly-linked list of available arena objects. */ +/* The head of the singly-linked, NULL-terminated list of available + * arena_objects. + */ static struct arena_object* available_arenas = NULL; -/* The head of the doubly-linked list of arenas with pools available. */ +/* The head of the doubly-linked, NULL-terminated at each end, list of + * arena_objects associated with arenas that have pools available. + */ static struct arena_object* usable_arenas = NULL; /* How many arena_objects do we initially allocate? @@ -494,8 +498,8 @@ /* Allocate a new arena. If we run out of memory, return NULL. Else * allocate a new arena, and return the address of an arena_object - * descriptor describing the new arena. It's expected that the caller will - * set `usable_arenas` to the return value. + * describing the new arena. It's expected that the caller will set + * `usable_arenas` to the return value. */ static struct arena_object* new_arena(void) @@ -600,25 +604,59 @@ * 0 <= P-B < ARENA_SIZE * By using unsigned arithmetic, the "0 <=" half of the test can be skipped. * - * XXX This is broken. The arena-management patch sets B to 0 when an - * XXX arena_object isn't associated with storage obmalloc controls. - * XXX But if P is "small enough" (< ARENA_SIZE), P is not an address - * XXX controlled by obmalloc, and arenas[POOL_ADDR(P)->arenaindex] doesn't - * XXX correspond to an allocated arena, - * XXX (uptr)(P) - arenas[(POOL)->arenaindex].address will equal - * XXX (uptr)P - 0 = (uptr)P, and Py_ADDRESS_IN_RANGE will falsely claim - * XXX that P _is_ controlled by obmalloc (P < ARENA_SIZE by case assumption). - * XXX This is a disaster ... complicate+slow the macro to verify that - * XXX .address != 0 too? - * * Obscure: A PyMem "free memory" function can call the pymalloc free or - * realloc before the first arena has been allocated. arenas is still + * realloc before the first arena has been allocated. `arenas` is still * NULL in that case. We're relying on that maxarenas is also 0 in that case, * so that (POOL)->arenaindex < maxarenas must be false, saving us from * trying to index into a NULL arenas. + * + * Details: given P and POOL, the arena_object corresponding to P is + * AO = arenas[(POOL)->arenaindex]. Suppose obmalloc controls P. Then + * (barring wild stores, etc), POOL is the correct address of P's pool, + * AO.address is the correct base address of the pool's arena, and P must be + * within ARENA_SIZE of AO.address. Therefore Py_ADDRESS_IN_RANGE correctly + * reports that obmalloc controls P. + * + * Now suppose obmalloc does not control P (e.g., P was obtained via a + * direct call to the system malloc() or free()). (POOL)->arenaindex may + * be anything in this case -- it may even be uninitialized trash. If the + * trash arenaindex is >= maxarenas, the macro correctly concludes at once + * that obmalloc doesn't control P. + * + * Else arenaindex is < maxarena, and AO is read up. If AO corresponds + * to an unassociated arena, AO.address is 0 and the macro correctly + * concludes that obmalloc doesn't control P. Note: This clause was added + * in Python 2.5. Before 2.5, arenas were never free()'ed, and an + * arenaindex < maxarena always corresponded to a currently-allocated + * arena. Why this matters is explained later. + * + * Else AO corresponds to an allocated arena, with base address AO.address. + * AO.address can't be 0 in this case, since no allocated memory can start + * at address 0 (NULL). Since it is an allocated arena, obmalloc controls + * all the memory in slice AO.address:AO.address+ARENA_SIZE. By case + * assumption, P is not controlled by obmalloc, so it doesn't lie in that + * slice, so the macro again correctly reports that P is not controlled by + * obmalloc. + * + * Why the test for AO.address != 0 is necessary: suppose some address P + * has integer value < ARENA_SIZE, P is not controlled by obmalloc, and + * the trash arenaindex corresponding to P's POOL gives an AO for a currently + * unassociated arena. Then AO.address is 0, and P - AO.address = P - 0 = + * P < ARENA_SIZE. Without the AO.address != 0 check, the macro would + * _incorrectly_ conclude that obmalloc does control P. While that's very + * unlikely, it's not impossible, and it would be a disaster if it occurred. + * + * Note that the logic is excruciating, and reading up possibly uninitialized + * memory when P is not controlled by obmalloc (to get at (POOL)->arenaindex) + * creates problems for some memory debuggers. The overwhelming advantage is + * that this test determines whether an arbitrary address is controlled by + * obmalloc in a small constant time, independent of the number of arenas + * obmalloc controls. Since this test is needed at every entry point, it's + * extremely desirable that it be this fast. */ -#define Py_ADDRESS_IN_RANGE(P, POOL) \ +#define Py_ADDRESS_IN_RANGE(P, POOL) \ ((POOL)->arenaindex < maxarenas && \ + arenas[(POOL)->arenaindex].address != 0 && \ (uptr)(P) - arenas[(POOL)->arenaindex].address < (uptr)ARENA_SIZE) @@ -1673,12 +1711,15 @@ #endif /* PYMALLOC_DEBUG */ #ifdef Py_USING_MEMORY_DEBUGGER -/* Make this function last so gcc won't inline it - since the definition is after the reference. */ +/* Make this function last so gcc won't inline it since the definition is + * after the reference. + */ int Py_ADDRESS_IN_RANGE(void *P, poolp pool) { - return ((pool->arenaindex) < maxarenas && - (uptr)(P) - arenas[pool->arenaindex].address < (uptr)ARENA_SIZE); + const uptr address = arenas[pool->arenaindex].address; + return pool->arenaindex < maxarenas && + address != 0 && + (uptr)P - address < (uptr)ARENA_SIZE; } #endif From python-checkins at python.org Thu Mar 2 08:51:46 2006 From: python-checkins at python.org (neal.norwitz) Date: Thu, 2 Mar 2006 08:51:46 +0100 (CET) Subject: [Python-checkins] r42777 - python/trunk/Misc/build.sh Message-ID: <20060302075146.D95071E4002@bag.python.org> Author: neal.norwitz Date: Thu Mar 2 08:51:44 2006 New Revision: 42777 Modified: python/trunk/Misc/build.sh Log: Spell threading write, not thraeading Modified: python/trunk/Misc/build.sh ============================================================================== --- python/trunk/Misc/build.sh (original) +++ python/trunk/Misc/build.sh Thu Mar 2 08:51:44 2006 @@ -59,7 +59,7 @@ # test_generators really leaks. Since test_generators probably won't # be fixed real soon, disable warning about it for now. # The entire leak report will be mailed if any test not in this list leaks. -LEAKY_TESTS="test_(capi|cfgparser|charmapcodec|cmd_line|compiler|filecmp|generators|threaded_import|threadedtempfile|threading|thraeading_local|urllib2)" +LEAKY_TESTS="test_(capi|cfgparser|charmapcodec|cmd_line|compiler|filecmp|generators|threaded_import|threadedtempfile|threading|threading_local|urllib2)" # Change this flag to "yes" for old releases to just update/build the docs. BUILD_DISABLED="no" From python-checkins at python.org Thu Mar 2 08:54:30 2006 From: python-checkins at python.org (neal.norwitz) Date: Thu, 2 Mar 2006 08:54:30 +0100 (CET) Subject: [Python-checkins] r42778 - python/trunk/Python/ceval.c Message-ID: <20060302075430.33F971E4002@bag.python.org> Author: neal.norwitz Date: Thu Mar 2 08:54:28 2006 New Revision: 42778 Modified: python/trunk/Python/ceval.c Log: Use Py_ssize_t since we are working with list size below Modified: python/trunk/Python/ceval.c ============================================================================== --- python/trunk/Python/ceval.c (original) +++ python/trunk/Python/ceval.c Thu Mar 2 08:54:28 2006 @@ -1174,7 +1174,7 @@ v = TOP(); if (PyList_CheckExact(v) && PyInt_CheckExact(w)) { /* INLINE: list[int] */ - long i = PyInt_AsLong(w); + Py_ssize_t i = PyInt_AsSsize_t(w); if (i < 0) i += PyList_GET_SIZE(v); if (i >= 0 && i < PyList_GET_SIZE(v)) { From python-checkins at python.org Thu Mar 2 08:59:44 2006 From: python-checkins at python.org (tim.peters) Date: Thu, 2 Mar 2006 08:59:44 +0100 (CET) Subject: [Python-checkins] r42779 - python/branches/tim-obmalloc/Objects/obmalloc.c Message-ID: <20060302075944.D45B81E4002@bag.python.org> Author: tim.peters Date: Thu Mar 2 08:59:42 2006 New Revision: 42779 Modified: python/branches/tim-obmalloc/Objects/obmalloc.c Log: Oops! I "over-optimized" the new spelling of the Py_ADDRESS_IN_RANGE() _function_. Repaired. Modified: python/branches/tim-obmalloc/Objects/obmalloc.c ============================================================================== --- python/branches/tim-obmalloc/Objects/obmalloc.c (original) +++ python/branches/tim-obmalloc/Objects/obmalloc.c Thu Mar 2 08:59:42 2006 @@ -1717,9 +1717,8 @@ int Py_ADDRESS_IN_RANGE(void *P, poolp pool) { - const uptr address = arenas[pool->arenaindex].address; return pool->arenaindex < maxarenas && - address != 0 && - (uptr)P - address < (uptr)ARENA_SIZE; + arenas[pool->arenaindex].address != 0 && + (uptr)P - arenas[pool->arenaindex].address < (uptr)ARENA_SIZE; } #endif From python-checkins at python.org Thu Mar 2 09:08:44 2006 From: python-checkins at python.org (neal.norwitz) Date: Thu, 2 Mar 2006 09:08:44 +0100 (CET) Subject: [Python-checkins] r42780 - python/trunk/Python/compile.c Message-ID: <20060302080844.1B4A31E4002@bag.python.org> Author: neal.norwitz Date: Thu Mar 2 09:08:42 2006 New Revision: 42780 Modified: python/trunk/Python/compile.c Log: Fix refleak if from __future__ import was not first Modified: python/trunk/Python/compile.c ============================================================================== --- python/trunk/Python/compile.c (original) +++ python/trunk/Python/compile.c Thu Mar 2 09:08:42 2006 @@ -2529,6 +2529,7 @@ if (s->lineno > c->c_future->ff_lineno) { if (!strcmp(PyString_AS_STRING(s->v.ImportFrom.module), "__future__")) { + Py_DECREF(level); Py_DECREF(names); return compiler_error(c, "from __future__ imports must occur " From neal at metaslash.com Thu Mar 2 10:54:42 2006 From: neal at metaslash.com (Neal Norwitz) Date: Thu, 2 Mar 2006 04:54:42 -0500 Subject: [Python-checkins] Python Regression Test Failures refleak (2) Message-ID: <20060302095442.GA20026@python.psfb.org> test_cmd_line leaked [0, 15, 0] references test_compiler leaked [131, 48, 252] references test_generators leaked [255, 255, 255] references test_quopri leaked [17, 0, 0] references test_sys leaked [1, 1, 1] references test_threadedtempfile leaked [1, 1, 0] references test_threading_local leaked [42, 34, 42] references test_urllib2 leaked [80, -130, 70] references From python-checkins at python.org Thu Mar 2 17:45:10 2006 From: python-checkins at python.org (sean.reifschneider) Date: Thu, 2 Mar 2006 17:45:10 +0100 (CET) Subject: [Python-checkins] r42781 - peps/trunk/pep2pyramid.py Message-ID: <20060302164510.7D2591E4028@bag.python.org> Author: sean.reifschneider Date: Thu Mar 2 17:45:09 2006 New Revision: 42781 Added: peps/trunk/pep2pyramid.py (contents, props changed) Log: Kludged version. Added: peps/trunk/pep2pyramid.py ============================================================================== --- (empty file) +++ peps/trunk/pep2pyramid.py Thu Mar 2 17:45:09 2006 @@ -0,0 +1,624 @@ +#!/usr/bin/env python +"""Convert PEPs to (X)HTML - courtesy of /F + +Usage: %(PROGRAM)s [options] [ ...] + +Options: + +-u, --user + python.org username + +-b, --browse + After generating the HTML, direct your web browser to view it + (using the Python webbrowser module). If both -i and -b are + given, this will browse the on-line HTML; otherwise it will + browse the local HTML. If no pep arguments are given, this + will browse PEP 0. + +-i, --install + After generating the HTML, install it and the plaintext source file + (.txt) on python.org. In that case the user's name is used in the scp + and ssh commands, unless "-u username" is given (in which case, it is + used instead). Without -i, -u is ignored. + +-l, --local + Same as -i/--install, except install on the local machine. Use this + when logged in to the python.org machine (dinsdale). + +-q, --quiet + Turn off verbose messages. + +-h, --help + Print this help message and exit. + +The optional arguments ``peps`` are either pep numbers or .txt files. +""" + +import sys +import os +import re +import cgi +import glob +import getopt +import errno +import random +import time + +REQUIRES = {'python': '2.2', + 'docutils': '0.2.7'} +PROGRAM = sys.argv[0] +RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html' +PEPURL = 'pep-%04d.html' +PEPCVSURL = ('http://svn.python.org/view/peps/trunk/pep-%04d.txt') +PEPDIRRUL = 'http://www.python.org/peps/' + + +HOST = "dinsdale.python.org" # host for update +HDIR = "/data/ftp.python.org/pub/www.python.org/peps" # target host directory +LOCALVARS = "Local Variables:" + +COMMENT = """""" + +# The generated HTML doesn't validate -- you cannot use
and

inside +#
 tags.  But if I change that, the result doesn't look very nice...
+DTD = ('')
+
+fixpat = re.compile("((https?|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt)?)|"
+                    "(RFC[- ]?(?P\d+))|"
+                    "(PEP\s+(?P\d+))|"
+                    ".")
+
+EMPTYSTRING = ''
+SPACE = ' '
+COMMASPACE = ', '
+
+
+
+def usage(code, msg=''):
+    """Print usage message and exit.  Uses stderr if code != 0."""
+    if code == 0:
+        out = sys.stdout
+    else:
+        out = sys.stderr
+    print >> out, __doc__ % globals()
+    if msg:
+        print >> out, msg
+    sys.exit(code)
+
+
+
+def fixanchor(current, match):
+    text = match.group(0)
+    link = None
+    if (text.startswith('http:') or text.startswith('https:')
+        or text.startswith('ftp:')):
+        # Strip off trailing punctuation.  Pattern taken from faqwiz.
+        ltext = list(text)
+        while ltext:
+            c = ltext.pop()
+            if c not in '();:,.?\'"<>':
+                ltext.append(c)
+                break
+        link = EMPTYSTRING.join(ltext)
+    elif text.startswith('pep-') and text <> current:
+        link = os.path.splitext(text)[0] + ".html"
+    elif text.startswith('PEP'):
+        pepnum = int(match.group('pepnum'))
+        link = PEPURL % pepnum
+    elif text.startswith('RFC'):
+        rfcnum = int(match.group('rfcnum'))
+        link = RFCURL % rfcnum
+    if link:
+        return '%s' % (cgi.escape(link), cgi.escape(text))
+    return cgi.escape(match.group(0)) # really slow, but it works...
+
+
+
+NON_MASKED_EMAILS = [
+    'peps at python.org',
+    'python-list at python.org',
+    'python-dev at python.org',
+    ]
+
+def fixemail(address, pepno):
+    if address.lower() in NON_MASKED_EMAILS:
+        # return hyperlinked version of email address
+        return linkemail(address, pepno)
+    else:
+        # return masked version of email address
+        parts = address.split('@', 1)
+        return '%s at %s' % (parts[0], parts[1])
+
+
+def linkemail(address, pepno):
+    parts = address.split('@', 1)
+    return (''
+            '%s at %s'
+            % (parts[0], parts[1], pepno, parts[0], parts[1]))
+
+
+def fixfile(inpath, input_lines, outfile):
+    m = re.search(r'pep-(\d+)\.', inpath)
+    if not m:
+        print "Ugh, can't find PEP number in name"
+        sys.exit(1)
+    pepIn = m.group(1)
+    destDir = '/home/jafo/cvs/beta.python.org/build/data/doc/peps/'
+    destDir = os.path.join(destDir, 'pep-%s' % pepIn)
+
+    if not os.path.exists(destDir):
+        os.mkdir(destDir)
+
+        fp = open(os.path.join(destDir, 'content.html'), 'w')
+        fp.write('\n')
+        fp.write('
' + print >> outfile, '

%s

' % line.strip() + need_pre = 1 + elif not line.strip() and need_pre: + continue + else: + # PEP 0 has some special treatment + if basename == 'pep-0000.txt': + parts = line.split() + if len(parts) > 1 and re.match(r'\s*\d{1,4}', parts[1]): + # This is a PEP summary line, which we need to hyperlink + url = PEPURL % int(parts[1]) + if need_pre: + print >> outfile, '
'
+                        need_pre = 0
+                    print >> outfile, re.sub(
+                        parts[1],
+                        '%s' % (int(parts[1]),
+                            parts[1]), line, 1),
+                    continue
+                elif parts and '@' in parts[-1]:
+                    # This is a pep email address line, so filter it.
+                    url = fixemail(parts[-1], pep)
+                    if need_pre:
+                        print >> outfile, '
'
+                        need_pre = 0
+                    print >> outfile, re.sub(
+                        parts[-1], url, line, 1),
+                    continue
+            line = fixpat.sub(lambda x, c=inpath: fixanchor(c, x), line)
+            if need_pre:
+                print >> outfile, '
'
+                need_pre = 0
+            outfile.write(line)
+
+
+docutils_settings = None
+"""Runtime settings object used by Docutils.  Can be set by the client
+application when this module is imported."""
+
+def fix_rst_pep(inpath, input_lines, outfile):
+    m = re.search(r'pep-(\d+)\.', inpath)
+    if not m:
+        print "Ugh, can't find PEP number in name"
+        sys.exit(1)
+    pepIn = m.group(1)
+    destDir = '/home/jafo/cvs/beta.python.org/build/data/doc/peps/'
+    destDir = os.path.join(destDir, 'pep-%s' % pepIn)
+
+    if not os.path.exists(destDir):
+        os.mkdir(destDir)
+
+        fp = open(os.path.join(destDir, 'content.html'), 'w')
+        fp.write('\n')
+        fp.write('
 
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/mimelib.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/mimelib.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/mimelib.html Sun Mar 5 20:54:07 2006 @@ -45,7 +45,7 @@

Barry Warsaw

Release 4.0
-February 17, 2006

+March 5, 2006

@@ -122,7 +122,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Added: sandbox/trunk/emailpkg/4_0/docs/mimelib.pdf ============================================================================== Binary file. No diff available. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.charset.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.charset.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.charset.html Sun Mar 5 20:54:07 2006 @@ -67,7 +67,7 @@

- +
class Charset(class Charset( [input_charset])
Map character sets to their email properties. @@ -103,7 +103,7 @@ Charset instances have the following data attributes:

-

input_charset
+
input_charset
The initial character set specified. Common aliases are converted to their official email names (e.g. latin_1 is converted to @@ -111,7 +111,7 @@

-

header_encoding
+
header_encoding
If the character set must be encoded before it can be used in an email header, this attribute will be set to Charset.QP (for @@ -121,7 +121,7 @@

-

body_encoding
+
body_encoding
Same as header_encoding, but describes the encoding for the mail message's body, which indeed may be different than the header @@ -130,7 +130,7 @@

-

output_charset
+
output_charset
Some character sets must be converted before they can be used in email headers or bodies. If the input_charset is one of @@ -139,7 +139,7 @@

-

input_codec
+
input_codec
The name of the Python codec used to convert the input_charset to Unicode. If no conversion codec is necessary, this attribute will be @@ -147,7 +147,7 @@

-

output_codec
+
output_codec
The name of the Python codec used to convert Unicode to the output_charset. If no conversion codec is necessary, this @@ -159,7 +159,7 @@

- +
get_body_encoding(get_body_encoding( )
Return the content transfer encoding used for body encoding. @@ -180,7 +180,7 @@

- +
convert(convert( s)
Convert the string s from the input_codec to the @@ -189,7 +189,7 @@

- +
to_splittable(to_splittable( s)
Convert a possibly multibyte string to a safely splittable format. @@ -211,7 +211,7 @@

- +
from_splittable(from_splittable( ustr[, to_output])
Convert a splittable string back into an encoded string. ustr @@ -235,7 +235,7 @@

- +
get_output_charset(get_output_charset( )
Return the output character set. @@ -247,7 +247,7 @@

- +
encoded_header_len(encoded_header_len( )
Return the length of the encoded header string, properly calculating @@ -256,7 +256,7 @@

- +
header_encode(header_encode( s[, convert])
Header-encode the string s. @@ -276,7 +276,7 @@

- +
body_encode(body_encode( s[, convert])
Body-encode the string s. @@ -299,7 +299,7 @@

- +
__str__(__str__( )
Returns input_charset as a string coerced to lower case. @@ -308,7 +308,7 @@

- +
__eq__(__eq__( other)
This method allows you to compare two Charset instances for equality. @@ -316,7 +316,7 @@

- +
__ne__(__ne__( other)
This method allows you to compare two Charset instances for inequality. @@ -329,7 +329,7 @@

- +
add_charset(add_charset( charset[, header_enc[, body_enc[, output_charset]]])
@@ -368,7 +368,7 @@

- +
add_alias(add_alias( alias, canonical)
Add a character set alias. alias is the alias name, @@ -382,7 +382,7 @@

- +
add_codec(add_codec( charset, codecname)
Add a codec that map characters in the given character set to and from @@ -429,7 +429,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.encoders.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.encoders.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.encoders.html Sun Mar 5 20:54:07 2006 @@ -71,20 +71,20 @@

- +
encode_quopri(encode_quopri( msg)
Encodes the payload into quoted-printable form and sets the Content-Transfer-Encoding: header to quoted-printable2. + HREF="#foot2098">2. This is a good encoding to use when most of your payload is normal printable data, but contains a few unprintable characters.

- +
encode_base64(encode_base64( msg)
Encodes the payload into base64 form and sets the @@ -97,7 +97,7 @@

- +
encode_7or8bit(encode_7or8bit( msg)
This doesn't actually modify the message's payload, but it does set @@ -107,7 +107,7 @@

- +
encode_noop(encode_noop( msg)
This does nothing; it doesn't even set the @@ -117,7 +117,7 @@



Footnotes

-
...quoted-printable...quoted-printable2
Note that encoding with encode_quopri() also encodes all tabs and space characters in @@ -157,7 +157,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.errors.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.errors.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.errors.html Sun Mar 5 20:54:07 2006 @@ -57,7 +57,7 @@

- +
exception MessageError(exception MessageError( )
This is the base class for all exceptions that the email @@ -67,7 +67,7 @@

- +
exception MessageParseError(exception MessageParseError( )
This is the base class for exceptions thrown by the Parser @@ -76,10 +76,10 @@

- +
exception HeaderParseError(exception HeaderParseError( )
-Raised under some error conditions when parsing the RFC 2822 headers of a message, this class is derived from MessageParseError. It can be raised from the Parser.parse() or @@ -87,9 +87,9 @@

Situations where it can be raised include finding an envelope -header after the first RFC 2822 header of the message, finding a -continuation line before the first RFC 2822 header is found, or finding a line in the headers which is neither a header or a continuation line. @@ -97,10 +97,10 @@

- +
exception BoundaryError(exception BoundaryError( )
-Raised under some error conditions when parsing the RFC 2822 headers of a message, this class is derived from MessageParseError. It can be raised from the Parser.parse() or @@ -114,7 +114,7 @@

- +
exception MultipartConversionError(exception MultipartConversionError( )
Raised when a payload is added to a Message object using @@ -216,7 +216,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.generator.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.generator.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.generator.html Sun Mar 5 20:54:07 2006 @@ -102,7 +102,7 @@ maxheaderlen (in characters, with tabs expanded to 8 spaces), the header will be split as defined in the email.header.Header class. Set to zero to disable header wrapping. The default is 78, as -recommended (but not required) by RFC 2822.
@@ -121,7 +121,7 @@

Optional unixfrom is a flag that forces the printing of the -envelope header delimiter before the first RFC 2822 header of the root message object. If the root object has no envelope header, a standard one is crafted. By default, this is set to False to @@ -278,7 +278,7 @@


-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.header.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.header.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.header.html Sun Mar 5 20:54:07 2006 @@ -52,12 +52,12 @@

-RFC 2822 is the base standard that describes the format of email -messages. It derives from the older RFC 822 standard which came into widespread use at a time when most email was composed of ASCII -characters only. RFC 2822 is a specification written assuming email contains only 7-bit ASCII characters. @@ -67,12 +67,12 @@ be used in email messages. The base standard still requires email messages to be transferred using only 7-bit ASCII characters, so a slew of RFCs have been written describing how to encode email -containing non-ASCII characters into RFC 2822-compliant format. -These RFCs include RFC 2045, RFC 2046, RFC 2047, and RFC 2045, RFC 2046, RFC 2047, and RFC 2231. The email package supports these standards in its email.header and email.charset modules. @@ -101,7 +101,7 @@ non-ASCII character? We did this by creating a Header instance and passing in the character set that the byte string was encoded in. When the subsequent Message instance was -flattened, the Subject: field was properly Subject: field was properly RFC 2047 encoded. MIME-aware mail readers would show this header using the embedded ISO-8859-1 character. @@ -115,7 +115,7 @@

- +
class Header(class Header( [s[, charset[, maxlinelen[, header_name[, continuation_ws[, errors]]]]]])
@@ -149,7 +149,7 @@ taken into account for the first line of a long, split header.

-Optional continuation_ws must be continuation_ws must be RFC 2822-compliant folding whitespace, and is usually either a space or a hard tab character. This character will be prepended to continuation lines. @@ -161,7 +161,7 @@

- +
append(append( s[, charset[, errors]])
Append the string s to the MIME header. @@ -183,8 +183,8 @@

If s is a Unicode string, then charset is a hint specifying the character set of the characters in the string. In this -case, when producing an RFC 2822-compliant header using RFC 2822-compliant header using RFC 2047 rules, the Unicode string will be encoded using the following charsets in order: us-ascii, the charset hint, utf-8. The @@ -197,16 +197,16 @@

- +
encode(encode( [splitchars])
Encode a message header into an RFC-compliant format, possibly wrapping long lines and encapsulating non-ASCII parts in base64 or quoted-printable encodings. Optional splitchars is a string containing characters to split long ASCII lines on, in rough support -of RFC 2822's highest level syntactic breaks. This doesn't -affect RFC 2047 encoded lines.
@@ -216,7 +216,7 @@

- +
__str__(__str__( )
A synonym for Header.encode(). Useful for @@ -225,7 +225,7 @@

- +
__unicode__(__unicode__( )
A helper for the built-in unicode() function. Returns the @@ -234,7 +234,7 @@

- +
__eq__(__eq__( other)
This method allows you to compare two Header instances for equality. @@ -242,7 +242,7 @@

- +
__ne__(__ne__( other)
This method allows you to compare two Header instances for inequality. @@ -254,7 +254,7 @@

- +
decode_header(decode_header( header)
Decode a message header value without converting the character set. @@ -280,7 +280,7 @@

- +
make_header(make_header( decoded_seq[, maxlinelen[, header_name[, continuation_ws]]])
@@ -333,7 +333,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.html Sun Mar 5 20:54:07 2006 @@ -60,22 +60,22 @@

The email package is a library for managing email messages, -including MIME and other RFC 2822-based message documents. It subsumes most of the functionality in several older standard modules such as rfc822, mimetools, multifile, and other non-standard packages such as mimecntl. It is specifically not designed to do any -sending of email messages to SMTP (RFC 2821), NNTP, or other servers; those are functions of modules such as smtplib and nntplib. The email package attempts to be as RFC-compliant as possible, -supporting in addition to RFC 2822, such MIME-related RFCs as -RFC 2045, RFC 2046, RFC 2047, and RFC 2045, RFC 2046, RFC 2047, and RFC 2231.

@@ -188,7 +188,7 @@


-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.iterators.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.iterators.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.iterators.html Sun Mar 5 20:54:07 2006 @@ -59,7 +59,7 @@

- +
body_line_iterator(body_line_iterator( msg[, decode])
This iterates over all the payloads in all the subparts of msg, @@ -75,7 +75,7 @@

- +
typed_subpart_iterator(typed_subpart_iterator( msg[, maintype[, subtype]])
@@ -100,7 +100,7 @@

- +
_structure(_structure( msg[, fp[, level]])
Prints an indented representation of the content types of the @@ -167,7 +167,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.message.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.message.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.message.html Sun Mar 5 20:54:07 2006 @@ -60,7 +60,7 @@

Conceptually, a Message object consists of headers and -payloads. Headers are payloads. Headers are RFC 2822 style field names and values where the field name and value are separated by a colon. The colon is not part of either the field name or the field value. @@ -260,7 +260,7 @@

The following methods implement a mapping-like interface for accessing -the message's RFC 2822 headers. Note that there are some semantic differences between these methods and a normal mapping (i.e. dictionary) interface. For example, in a dictionary there are @@ -467,17 +467,17 @@ lower case of the form maintype/subtype. If there was no Content-Type: header in the message the default type as given by get_default_type() will be returned. Since -according to RFC 2045, messages always have a default type, get_content_type() will always return a value.

-RFC 2045 defines a message's default type to be text/plain unless it appears inside a multipart/digest container, in which case it would be message/rfc822. If the Content-Type: header -has an invalid type specification, RFC 2045 mandates that the default type be text/plain. @@ -592,7 +592,7 @@

Parameter keys are always compared case insensitively. The return value can either be a string, or a 3-tuple if the parameter was -RFC 2231 encoded. When it's a 3-tuple, the elements of the value are of the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and LANGUAGE can be None, in which case you should consider @@ -601,7 +601,7 @@

If your application doesn't care whether the parameter was encoded as in -RFC 2231, you can collapse the parameter value by calling email.Utils.collapse_rfc2231_value(), passing in the return value from get_param(). This will return a suitably decoded Unicode string @@ -639,7 +639,7 @@ parameter already exists in the header, its value will be replaced with value. If the Content-Type: header as not yet been defined for this message, it will be set to text/plain -and the new parameter value will be appended as per RFC 2045.

@@ -650,7 +650,7 @@

If optional charset is specified, the parameter will be encoded -according to RFC 2231. Optional language specifies the RFC 2231 language, defaulting to the empty string. Both charset and language should be strings. @@ -919,7 +919,7 @@


-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.mime.text.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.mime.text.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.mime.text.html Sun Mar 5 20:54:07 2006 @@ -154,7 +154,38 @@

- + +
class MIMEAudio(class MIMEApplication(_data[, _subtype[, + _encoder[, **_params]]])
+
+Module: email.mime.application + +

+A subclass of MIMENonMultipart, the MIMEApplication class is +used to represent MIME message objects of major type application. +_data is a string containing the raw byte data. Optional _subtype +specifies the MIME subtype and defaults to octet-stream. + +

+Optional _encoder is a callable (i.e. function) which will +perform the actual encoding of the data for transport. This +callable takes one argument, which is the MIMEApplication instance. +It should use get_payload() and set_payload() to +change the payload to encoded form. It should also add any +Content-Transfer-Encoding: or other headers to the message +object as necessary. The default encoding is base64. See the +email.encoders module for a list of the built-in encoders. + +

+_params are passed straight through to the base class constructor. + +New in version 2.5. + +

+ +

+

+
class MIMEAudio( _audiodata[, _subtype[, _encoder[, **_params]]])
@@ -187,7 +218,7 @@

- +
class MIMEImage(class MIMEImage( _imagedata[, _subtype[, _encoder[, **_params]]])
@@ -221,7 +252,7 @@

- +
class MIMEMessage(class MIMEMessage( _msg[, _subtype])
Module: email.mime.message @@ -240,7 +271,7 @@

- +
class MIMEText(class MIMEText( _text[, _subtype[, _charset]])
Module: email.mime.text @@ -297,7 +328,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.parser.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.parser.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.parser.html Sun Mar 5 20:54:07 2006 @@ -146,7 +146,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.utils.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/module-email.utils.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.utils.html Sun Mar 5 20:54:07 2006 @@ -57,7 +57,7 @@

- +
quote(quote( str)
Return a new string with backslashes in str replaced by two @@ -66,7 +66,7 @@

- +
unquote(unquote( str)
Return a new string which is an unquoted version of str. @@ -77,7 +77,7 @@

- +
parseaddr(parseaddr( address)
Parse address - which should be the value of some address-containing @@ -89,7 +89,7 @@

- +
formataddr(formataddr( pair)
The inverse of parseaddr(), this takes a 2-tuple of the form @@ -100,7 +100,7 @@

- +
getaddresses(getaddresses( fieldvalues)
This method returns a list of 2-tuples of the form returned by @@ -122,14 +122,14 @@

- +
parsedate(parsedate( date)
-Attempts to parse a date according to the rules in RFC 2822. however, some mailers don't follow that format as specified, so parsedate() tries to guess correctly in such cases. -date is a string containing an date is a string containing an RFC 2822 date, such as "Mon, 20 Nov 1995 19:12:08 -0500". If it succeeds in parsing the date, parsedate() returns a 9-tuple that can be passed @@ -140,7 +140,7 @@

- +
parsedate_tz(parsedate_tz( date)
Performs the same function as parsedate(), but returns @@ -148,7 +148,7 @@ that can be passed directly to time.mktime(), and the tenth is the offset of the date's timezone from UTC (which is the official term for Greenwich Mean Time)3. If the input + HREF="#foot2387">3. If the input string has no timezone, the last element of the tuple returned is None. Note that fields 6, 7, and 8 of the result tuple are not usable. @@ -156,7 +156,7 @@

- +
mktime_tz(mktime_tz( tuple)
Turn a 10-tuple as returned by parsedate_tz() into a UTC @@ -170,10 +170,10 @@

- +
formatdate(formatdate( [timeval[, localtime][, usegmt]])
-Returns a date string as per RFC 2822, e.g.:

@@ -204,10 +204,10 @@

- +
make_msgid(make_msgid( [idstring])
-Returns a string suitable for an RFC 2822-compliant Message-ID: header. Optional idstring if given, is a string used to strengthen the uniqueness of the message id. @@ -215,19 +215,19 @@

- +
decode_rfc2231(decode_rfc2231( s)
-Decode the string s according to s according to RFC 2231.

- +
encode_rfc2231(encode_rfc2231( s[, charset[, language]])
-Encode the string s according to s according to RFC 2231. Optional charset and language, if given is the character set name and language name to use. If neither is given, s is returned @@ -237,18 +237,18 @@

- +
collapse_rfc2231_value(collapse_rfc2231_value( value[, errors[, fallback_charset]])
-When a header parameter is encoded in RFC 2231 format, Message.get_param() may return a 3-tuple containing the character set, language, and value. collapse_rfc2231_value() turns this into a unicode string. Optional errors is passed to the errors argument of the built-in unicode() function; it defaults to replace. Optional fallback_charset specifies the character set -to use if the one in the RFC 2231 header is not known by Python; it defaults to us-ascii. @@ -260,10 +260,10 @@

- +
decode_params(decode_params( params)
-Decode parameters list according to RFC 2231. params is a sequence of 2-tuples containing elements of the form (content-type, string-value). @@ -291,12 +291,12 @@



Footnotes

-
... Time)... Time)3
Note that the sign of the timezone offset is the opposite of the sign of the time.timezone variable for the same timezone; the latter variable follows the -POSIX standard while this module follows RFC 2822.
@@ -333,7 +333,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/node1.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/node1.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node1.html Sun Mar 5 20:54:07 2006 @@ -117,7 +117,7 @@
-Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/node16.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/node16.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node16.html Sun Mar 5 20:54:07 2006 @@ -70,7 +70,7 @@

    -
  • All modules have been renamed according to All modules have been renamed according to PEP 8 standards. For example, the version 3 module email.Message was renamed to email.message in version 4. @@ -262,7 +262,7 @@
    -Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/node17.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/node17.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node17.html Sun Mar 5 20:54:07 2006 @@ -191,7 +191,7 @@ a Message instance containing separate Message subparts for each header block in the delivery status notification4. + HREF="#foot2697">4.

    The Generator class has no differences in its public @@ -251,11 +251,11 @@



    Footnotes

    -
    ... +
    ... notification4
    Delivery Status Notifications (DSN) are defined -in RFC 1894.
    @@ -292,7 +292,7 @@
    -Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/node18.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/node18.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node18.html Sun Mar 5 20:54:07 2006 @@ -136,7 +136,7 @@ Here's an example of how to send the entire contents of a directory as an email message: 5 + HREF="#foot2688">5

    #!/usr/bin/env python
    @@ -337,7 +337,7 @@
     



    Footnotes

    -
    ... message:... message:5
    Thanks to Matthew Dixon Cowles for the original inspiration and examples. @@ -376,7 +376,7 @@

    -Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/node5.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/node5.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node5.html Sun Mar 5 20:54:07 2006 @@ -143,7 +143,7 @@
    -Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/node6.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/node6.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node6.html Sun Mar 5 20:54:07 2006 @@ -105,7 +105,7 @@ on file-like objects.

    -The text contained in fp must be formatted as a block of fp must be formatted as a block of RFC 2822 style headers and header continuation lines, optionally preceded by a envelope header. The header block is terminated either by the @@ -227,7 +227,7 @@


    -Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/docs/node7.html ============================================================================== --- sandbox/trunk/emailpkg/4.0/docs/node7.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node7.html Sun Mar 5 20:54:07 2006 @@ -125,7 +125,7 @@
    -Release 4.0, documentation updated on February 17, 2006. +Release 4.0, documentation updated on March 5, 2006. Modified: sandbox/trunk/emailpkg/4_0/manual/Makefile ============================================================================== --- sandbox/trunk/emailpkg/4.0/manual/Makefile (original) +++ sandbox/trunk/emailpkg/4_0/manual/Makefile Sun Mar 5 20:54:07 2006 @@ -1,2 +1,2 @@ all: - mkhowto --html --pdf --dir ../doc mimelib.tex + mkhowto --html --pdf --dir ../docs mimelib.tex From python-checkins at python.org Sun Mar 5 21:27:58 2006 From: python-checkins at python.org (barry.warsaw) Date: Sun, 5 Mar 2006 21:27:58 +0100 (CET) Subject: [Python-checkins] r42856 - in sandbox/trunk/emailpkg/4_0: docs/email-pkg-history.html docs/index.html docs/mimelib.html docs/mimelib.pdf docs/module-email.encoders.html docs/module-email.errors.html docs/module-email.generator.html docs/module-email.header.html docs/module-email.html docs/module-email.iterators.html docs/module-email.message.html docs/module-email.mime.text.html docs/module-email.parser.html docs/module-email.utils.html docs/node1.html docs/node17.html docs/node18.html docs/node6.html email/__init__.py manual/Makefile manual/email.tex manual/emailmimebase.tex manual/mimelib.tex Message-ID: <20060305202758.9F5561E4007@bag.python.org> Author: barry.warsaw Date: Sun Mar 5 21:27:55 2006 New Revision: 42856 Added: sandbox/trunk/emailpkg/4_0/docs/email-pkg-history.html Modified: sandbox/trunk/emailpkg/4_0/docs/index.html sandbox/trunk/emailpkg/4_0/docs/mimelib.html sandbox/trunk/emailpkg/4_0/docs/mimelib.pdf sandbox/trunk/emailpkg/4_0/docs/module-email.encoders.html sandbox/trunk/emailpkg/4_0/docs/module-email.errors.html sandbox/trunk/emailpkg/4_0/docs/module-email.generator.html sandbox/trunk/emailpkg/4_0/docs/module-email.header.html sandbox/trunk/emailpkg/4_0/docs/module-email.html sandbox/trunk/emailpkg/4_0/docs/module-email.iterators.html sandbox/trunk/emailpkg/4_0/docs/module-email.message.html sandbox/trunk/emailpkg/4_0/docs/module-email.mime.text.html sandbox/trunk/emailpkg/4_0/docs/module-email.parser.html sandbox/trunk/emailpkg/4_0/docs/module-email.utils.html sandbox/trunk/emailpkg/4_0/docs/node1.html sandbox/trunk/emailpkg/4_0/docs/node17.html sandbox/trunk/emailpkg/4_0/docs/node18.html sandbox/trunk/emailpkg/4_0/docs/node6.html sandbox/trunk/emailpkg/4_0/email/__init__.py sandbox/trunk/emailpkg/4_0/manual/Makefile sandbox/trunk/emailpkg/4_0/manual/email.tex sandbox/trunk/emailpkg/4_0/manual/emailmimebase.tex sandbox/trunk/emailpkg/4_0/manual/mimelib.tex Log: Updated documentation. Bump to 4.0a2 and ready for upload and release. Added: sandbox/trunk/emailpkg/4_0/docs/email-pkg-history.html ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/4_0/docs/email-pkg-history.html Sun Mar 5 21:27:55 2006 @@ -0,0 +1,294 @@ + + + + + + + + + + + + +2.11 Package History + + + + + +

    +
    +2.11 Package History +

    + +

    +This table describes the release history of the email package, corresponding +to the version of Python that the package was released with. For purposes of +this document, when you see a note about change or added versions, these refer +to the Python version the change was made it, not the email package +version. This table also describes the Python compatibility of each version +of the package. + +

    +

    + + + + + + + + + + + + + + + + + + + + +
    email versiondistributed withcompatible with
    1.xPython 2.2.0 to Python 2.2.1no longer supported
    2.5Python 2.2.2+ and Python 2.3Python 2.1 to 2.5
    3.0Python 2.4Python 2.3 to 2.5
    4.0Python 2.5Python 2.3 to 2.5
    + +

    +Here are the major differences between email verson 4 and version 3: + +

    + +

      +
    • All modules have been renamed according to PEP 8 standards. For + example, the version 3 module email.Message was renamed to + email.message in version 4. + +

      +

    • +
    • A new subpackage email.mime was added and all the version 3 + email.MIME* modules were renamed and situated into the + email.mime subpackage. For example, the version 3 module + email.MIMEText was renamed to email.mime.text. + +

      +Note that the version 3 names will continue to work until Python + 2.6. + +

      +

    • +
    • The email.mime.application module was added, which contains the + MIMEApplication class. + +

      +

    • +
    • Methods that were deprecated in version 3 have been removed. These + include Generator.__call__(), Message.get_type(), + Message.get_main_type(), Message.get_subtype(). +
    • +
    + +

    +Here are the major differences between email version 3 and version 2: + +

    + +

      +
    • The FeedParser class was introduced, and the Parser + class was implemented in terms of the FeedParser. All parsing + therefore is non-strict, and parsing will make a best effort never to + raise an exception. Problems found while parsing messages are stored in + the message's defect attribute. + +

      +

    • +
    • All aspects of the API which raised DeprecationWarnings in + version 2 have been removed. These include the _encoder argument + to the MIMEText constructor, the Message.add_payload() + method, the Utils.dump_address_pair() function, and the + functions Utils.decode() and Utils.encode(). + +

      +

    • +
    • New DeprecationWarnings have been added to: + Generator.__call__(), Message.get_type(), + Message.get_main_type(), Message.get_subtype(), and + the strict argument to the Parser class. These are + expected to be removed in future versions. + +

      +

    • +
    • Support for Pythons earlier than 2.3 has been removed. +
    • +
    + +

    +Here are the differences between email version 2 and version 1: + +

    + +

      +
    • The email.Header and email.Charset modules + have been added. + +

      +

    • +
    • The pickle format for Message instances has changed. + Since this was never (and still isn't) formally defined, this + isn't considered a backward incompatibility. However if your + application pickles and unpickles Message instances, be + aware that in email version 2, Message + instances now have private variables _charset and + _default_type. + +

      +

    • +
    • Several methods in the Message class have been + deprecated, or their signatures changed. Also, many new methods + have been added. See the documentation for the Message + class for details. The changes should be completely backward + compatible. + +

      +

    • +
    • The object structure has changed in the face of + message/rfc822 content types. In email + version 1, such a type would be represented by a scalar payload, + i.e. the container message's is_multipart() returned + false, get_payload() was not a list object, but a single + Message instance. + +

      +This structure was inconsistent with the rest of the package, so + the object representation for message/rfc822 content + types was changed. In email version 2, the container + does return True from is_multipart(), and + get_payload() returns a list containing a single + Message item. + +

      +Note that this is one place that backward compatibility could + not be completely maintained. However, if you're already + testing the return type of get_payload(), you should be + fine. You just need to make sure your code doesn't do a + set_payload() with a Message instance on a + container with a content type of message/rfc822. + +

      +

    • +
    • The Parser constructor's strict argument was + added, and its parse() and parsestr() methods + grew a headersonly argument. The strict flag was + also added to functions email.message_from_file() + and email.message_from_string(). + +

      +

    • +
    • Generator.__call__() is deprecated; use + Generator.flatten() instead. The Generator + class has also grown the clone() method. + +

      +

    • +
    • The DecodedGenerator class in the + email.Generator module was added. + +

      +

    • +
    • The intermediate base classes MIMENonMultipart and + MIMEMultipart have been added, and interposed in the + class hierarchy for most of the other MIME-related derived + classes. + +

      +

    • +
    • The _encoder argument to the MIMEText constructor + has been deprecated. Encoding now happens implicitly based + on the _charset argument. + +

      +

    • +
    • The following functions in the email.Utils module have + been deprecated: dump_address_pairs(), + decode(), and encode(). The following + functions have been added to the module: + make_msgid(), decode_rfc2231(), + encode_rfc2231(), and decode_params(). + +

      +

    • +
    • The non-public function email.Iterators._structure() + was added. +
    • +
    + +

    + +

    + + + + Modified: sandbox/trunk/emailpkg/4_0/docs/index.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/index.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/index.html Sun Mar 5 21:27:55 2006 @@ -87,7 +87,7 @@
  • 2.8 Exception and Defect classes
  • 2.9 Miscellaneous utilities
  • 2.10 Iterators -
  • 2.11 Package History +
  • 2.11 Package History
  • 2.12 Differences from mimelib
  • 2.13 Examples
Modified: sandbox/trunk/emailpkg/4_0/docs/mimelib.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/mimelib.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/mimelib.html Sun Mar 5 21:27:55 2006 @@ -87,7 +87,7 @@
  • 2.8 Exception and Defect classes
  • 2.9 Miscellaneous utilities
  • 2.10 Iterators -
  • 2.11 Package History +
  • 2.11 Package History
  • 2.12 Differences from mimelib
  • 2.13 Examples Modified: sandbox/trunk/emailpkg/4_0/docs/mimelib.pdf ============================================================================== Binary files. No diff available. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.encoders.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.encoders.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.encoders.html Sun Mar 5 21:27:55 2006 @@ -77,7 +77,7 @@ Encodes the payload into quoted-printable form and sets the Content-Transfer-Encoding: header to quoted-printable2. + HREF="#foot2099">2. This is a good encoding to use when most of your payload is normal printable data, but contains a few unprintable characters.
  • @@ -117,7 +117,7 @@



    Footnotes

    -
    ...quoted-printable...quoted-printable2
    Note that encoding with encode_quopri() also encodes all tabs and space characters in Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.errors.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.errors.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.errors.html Sun Mar 5 21:27:55 2006 @@ -79,7 +79,7 @@ exception HeaderParseError( )
    -Raised under some error conditions when parsing the RFC 2822 headers of a message, this class is derived from MessageParseError. It can be raised from the Parser.parse() or @@ -87,9 +87,9 @@

    Situations where it can be raised include finding an envelope -header after the first RFC 2822 header of the message, finding a -continuation line before the first RFC 2822 header is found, or finding a line in the headers which is neither a header or a continuation line. @@ -100,7 +100,7 @@ exception BoundaryError( )

    -Raised under some error conditions when parsing the RFC 2822 headers of a message, this class is derived from MessageParseError. It can be raised from the Parser.parse() or Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.generator.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.generator.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.generator.html Sun Mar 5 21:27:55 2006 @@ -102,7 +102,7 @@ maxheaderlen (in characters, with tabs expanded to 8 spaces), the header will be split as defined in the email.header.Header class. Set to zero to disable header wrapping. The default is 78, as -recommended (but not required) by RFC 2822.
    @@ -121,7 +121,7 @@

    Optional unixfrom is a flag that forces the printing of the -envelope header delimiter before the first RFC 2822 header of the root message object. If the root object has no envelope header, a standard one is crafted. By default, this is set to False to Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.header.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.header.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.header.html Sun Mar 5 21:27:55 2006 @@ -52,12 +52,12 @@

    -RFC 2822 is the base standard that describes the format of email -messages. It derives from the older RFC 822 standard which came into widespread use at a time when most email was composed of ASCII -characters only. RFC 2822 is a specification written assuming email contains only 7-bit ASCII characters. @@ -67,12 +67,12 @@ be used in email messages. The base standard still requires email messages to be transferred using only 7-bit ASCII characters, so a slew of RFCs have been written describing how to encode email -containing non-ASCII characters into RFC 2822-compliant format. -These RFCs include RFC 2045, RFC 2046, RFC 2047, and RFC 2045, RFC 2046, RFC 2047, and RFC 2231. The email package supports these standards in its email.header and email.charset modules. @@ -101,7 +101,7 @@ non-ASCII character? We did this by creating a Header instance and passing in the character set that the byte string was encoded in. When the subsequent Message instance was -flattened, the Subject: field was properly Subject: field was properly RFC 2047 encoded. MIME-aware mail readers would show this header using the embedded ISO-8859-1 character. @@ -149,7 +149,7 @@ taken into account for the first line of a long, split header.

    -Optional continuation_ws must be continuation_ws must be RFC 2822-compliant folding whitespace, and is usually either a space or a hard tab character. This character will be prepended to continuation lines. @@ -183,8 +183,8 @@

    If s is a Unicode string, then charset is a hint specifying the character set of the characters in the string. In this -case, when producing an RFC 2822-compliant header using RFC 2822-compliant header using RFC 2047 rules, the Unicode string will be encoded using the following charsets in order: us-ascii, the charset hint, utf-8. The @@ -204,9 +204,9 @@ wrapping long lines and encapsulating non-ASCII parts in base64 or quoted-printable encodings. Optional splitchars is a string containing characters to split long ASCII lines on, in rough support -of RFC 2822's highest level syntactic breaks. This doesn't -affect RFC 2047 encoded lines.

    Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.html Sun Mar 5 21:27:55 2006 @@ -60,22 +60,22 @@

    The email package is a library for managing email messages, -including MIME and other RFC 2822-based message documents. It subsumes most of the functionality in several older standard modules such as rfc822, mimetools, multifile, and other non-standard packages such as mimecntl. It is specifically not designed to do any -sending of email messages to SMTP (RFC 2821), NNTP, or other servers; those are functions of modules such as smtplib and nntplib. The email package attempts to be as RFC-compliant as possible, -supporting in addition to RFC 2822, such MIME-related RFCs as -RFC 2045, RFC 2046, RFC 2047, and RFC 2045, RFC 2046, RFC 2047, and RFC 2231.

    @@ -149,7 +149,7 @@

  • 2.8 Exception and Defect classes
  • 2.9 Miscellaneous utilities
  • 2.10 Iterators -
  • 2.11 Package History +
  • 2.11 Package History
  • 2.12 Differences from mimelib
  • 2.13 Examples Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.iterators.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.iterators.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.iterators.html Sun Mar 5 21:27:55 2006 @@ -5,10 +5,10 @@ - + - + 2.10 Iterators @@ -24,7 +24,7 @@ href="module-email.html">Up One Level email Package Reference Up: 2 email Next: - +
    @@ -147,7 +147,7 @@ href="module-email.html">Up One Level email Package Reference Up: 2 email Next: - +
    Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.message.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.message.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.message.html Sun Mar 5 21:27:55 2006 @@ -60,7 +60,7 @@

    Conceptually, a Message object consists of headers and -payloads. Headers are payloads. Headers are RFC 2822 style field names and values where the field name and value are separated by a colon. The colon is not part of either the field name or the field value. @@ -260,7 +260,7 @@

    The following methods implement a mapping-like interface for accessing -the message's RFC 2822 headers. Note that there are some semantic differences between these methods and a normal mapping (i.e. dictionary) interface. For example, in a dictionary there are @@ -467,17 +467,17 @@ lower case of the form maintype/subtype. If there was no Content-Type: header in the message the default type as given by get_default_type() will be returned. Since -according to RFC 2045, messages always have a default type, get_content_type() will always return a value.

    -RFC 2045 defines a message's default type to be text/plain unless it appears inside a multipart/digest container, in which case it would be message/rfc822. If the Content-Type: header -has an invalid type specification, RFC 2045 mandates that the default type be text/plain. @@ -592,7 +592,7 @@

    Parameter keys are always compared case insensitively. The return value can either be a string, or a 3-tuple if the parameter was -RFC 2231 encoded. When it's a 3-tuple, the elements of the value are of the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and LANGUAGE can be None, in which case you should consider @@ -601,7 +601,7 @@

    If your application doesn't care whether the parameter was encoded as in -RFC 2231, you can collapse the parameter value by calling email.Utils.collapse_rfc2231_value(), passing in the return value from get_param(). This will return a suitably decoded Unicode string @@ -639,7 +639,7 @@ parameter already exists in the header, its value will be replaced with value. If the Content-Type: header as not yet been defined for this message, it will be set to text/plain -and the new parameter value will be appended as per RFC 2045.

    @@ -650,7 +650,7 @@

    If optional charset is specified, the parameter will be encoded -according to RFC 2231. Optional language specifies the RFC 2231 language, defaulting to the empty string. Both charset and language should be strings. Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.mime.text.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.mime.text.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.mime.text.html Sun Mar 5 21:27:55 2006 @@ -121,7 +121,7 @@ [subtype[, boundary[, _subparts[, _params]]]])

    -Module: email.mmime.multipart +Module: email.mime.multipart

    A subclass of MIMEBase, this is an intermediate base class for Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.parser.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.parser.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.parser.html Sun Mar 5 21:27:55 2006 @@ -79,7 +79,7 @@ an email message from a socket). The FeedParser can consume and parse the message incrementally, and only returns the root object when you close the parser1. + HREF="#foot977">1.

    Note that the parser can be extended in limited ways, and of course @@ -91,7 +91,7 @@



    Footnotes

    -
    ... +
    ... parser1
    As of email package version 3.0, introduced in Modified: sandbox/trunk/emailpkg/4_0/docs/module-email.utils.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/module-email.utils.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/module-email.utils.html Sun Mar 5 21:27:55 2006 @@ -125,11 +125,11 @@ parsedate( date)
    -Attempts to parse a date according to the rules in RFC 2822. however, some mailers don't follow that format as specified, so parsedate() tries to guess correctly in such cases. -date is a string containing an date is a string containing an RFC 2822 date, such as "Mon, 20 Nov 1995 19:12:08 -0500". If it succeeds in parsing the date, parsedate() returns a 9-tuple that can be passed @@ -148,7 +148,7 @@ that can be passed directly to time.mktime(), and the tenth is the offset of the date's timezone from UTC (which is the official term for Greenwich Mean Time)3. If the input + HREF="#foot2388">3. If the input string has no timezone, the last element of the tuple returned is None. Note that fields 6, 7, and 8 of the result tuple are not usable. @@ -173,7 +173,7 @@ formatdate( [timeval[, localtime][, usegmt]])
    -Returns a date string as per RFC 2822, e.g.:

    @@ -207,7 +207,7 @@ make_msgid( [idstring])

    -Returns a string suitable for an RFC 2822-compliant Message-ID: header. Optional idstring if given, is a string used to strengthen the uniqueness of the message id. @@ -218,7 +218,7 @@ decode_rfc2231( s)
    -Decode the string s according to s according to RFC 2231.
    @@ -227,7 +227,7 @@ encode_rfc2231( s[, charset[, language]])
    -Encode the string s according to s according to RFC 2231. Optional charset and language, if given is the character set name and language name to use. If neither is given, s is returned @@ -241,14 +241,14 @@ value[, errors[, fallback_charset]])
    -When a header parameter is encoded in RFC 2231 format, Message.get_param() may return a 3-tuple containing the character set, language, and value. collapse_rfc2231_value() turns this into a unicode string. Optional errors is passed to the errors argument of the built-in unicode() function; it defaults to replace. Optional fallback_charset specifies the character set -to use if the one in the RFC 2231 header is not known by Python; it defaults to us-ascii. @@ -263,7 +263,7 @@ decode_params( params)
    -Decode parameters list according to RFC 2231. params is a sequence of 2-tuples containing elements of the form (content-type, string-value). @@ -291,12 +291,12 @@



    Footnotes

    -
    ... Time)... Time)3
    Note that the sign of the timezone offset is the opposite of the sign of the time.timezone variable for the same timezone; the latter variable follows the -POSIX standard while this module follows RFC 2822.
    Modified: sandbox/trunk/emailpkg/4_0/docs/node1.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/node1.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node1.html Sun Mar 5 21:27:55 2006 @@ -71,7 +71,8 @@
    • Deprecation and ``version added'' notes are relative to the - Python version a feature was added or deprecated. + Python version a feature was added or deprecated. See + the package history in section 2.11 for details.

    • Modified: sandbox/trunk/emailpkg/4_0/docs/node17.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/node17.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node17.html Sun Mar 5 21:27:55 2006 @@ -6,7 +6,7 @@ - + @@ -18,7 +18,7 @@
      Previous: - + Up: 2 email Next: @@ -191,7 +191,7 @@ a Message instance containing separate Message subparts for each header block in the delivery status notification4. + HREF="#foot2719">4.

      The Generator class has no differences in its public @@ -251,11 +251,11 @@



      Footnotes

      -
      ... +
      ... notification4
      Delivery Status Notifications (DSN) are defined -in RFC 1894.
      @@ -266,7 +266,7 @@
      Previous: - + Up: 2 email Next: Modified: sandbox/trunk/emailpkg/4_0/docs/node18.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/node18.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node18.html Sun Mar 5 21:27:55 2006 @@ -136,7 +136,7 @@ Here's an example of how to send the entire contents of a directory as an email message: 5 + HREF="#foot2708">5

      #!/usr/bin/env python
      @@ -337,7 +337,7 @@
       



      Footnotes

      -
      ... message:... message:5
      Thanks to Matthew Dixon Cowles for the original inspiration and examples. Modified: sandbox/trunk/emailpkg/4_0/docs/node6.html ============================================================================== --- sandbox/trunk/emailpkg/4_0/docs/node6.html (original) +++ sandbox/trunk/emailpkg/4_0/docs/node6.html Sun Mar 5 21:27:55 2006 @@ -105,7 +105,7 @@ on file-like objects.

      -The text contained in fp must be formatted as a block of fp must be formatted as a block of RFC 2822 style headers and header continuation lines, optionally preceded by a envelope header. The header block is terminated either by the Modified: sandbox/trunk/emailpkg/4_0/email/__init__.py ============================================================================== --- sandbox/trunk/emailpkg/4_0/email/__init__.py (original) +++ sandbox/trunk/emailpkg/4_0/email/__init__.py Sun Mar 5 21:27:55 2006 @@ -4,7 +4,7 @@ """A package for parsing, handling, and generating email messages.""" -__version__ = '4.0a1' +__version__ = '4.0a2' __all__ = [ # Old names Modified: sandbox/trunk/emailpkg/4_0/manual/Makefile ============================================================================== --- sandbox/trunk/emailpkg/4_0/manual/Makefile (original) +++ sandbox/trunk/emailpkg/4_0/manual/Makefile Sun Mar 5 21:27:55 2006 @@ -1,2 +1,3 @@ all: mkhowto --html --pdf --dir ../docs mimelib.tex + mv -f mimelib.pdf ../docs Modified: sandbox/trunk/emailpkg/4_0/manual/email.tex ============================================================================== --- sandbox/trunk/emailpkg/4_0/manual/email.tex (original) +++ sandbox/trunk/emailpkg/4_0/manual/email.tex Sun Mar 5 21:27:55 2006 @@ -89,18 +89,21 @@ \subsection{Iterators} \input{emailiter} -\subsection{Package History} +\subsection{Package History\label{email-pkg-history}} -Version 1 of the \module{email} package was bundled with Python -releases up to Python 2.2.1. Version 2 was developed for the Python -2.3 release, and backported to Python 2.2.2. It was also available as -a separate distutils-based package, and is compatible back to Python 2.1. - -\module{email} version 3.0 was released with Python 2.4 and as a separate -distutils-based package. It is compatible back to Python 2.3. - -\module{email} version 4.0 was released with Python 2.5 and as a separate -distutils-based package. It is also compatible back to Python 2.3. +This table describes the release history of the email package, corresponding +to the version of Python that the package was released with. For purposes of +this document, when you see a note about change or added versions, these refer +to the Python version the change was made it, \emph{not} the email package +version. This table also describes the Python compatibility of each version +of the package. + +\begin{tableiii}{l|l|l}{constant}{email version}{distributed with}{compatible with} +\lineiii{1.x}{Python 2.2.0 to Python 2.2.1}{\emph{no longer supported}} +\lineiii{2.5}{Python 2.2.2+ and Python 2.3}{Python 2.1 to 2.5} +\lineiii{3.0}{Python 2.4}{Python 2.3 to 2.5} +\lineiii{4.0}{Python 2.5}{Python 2.3 to 2.5} +\end{tableiii} Here are the major differences between \module{email} verson 4 and version 3: @@ -117,6 +120,9 @@ \emph{Note that the version 3 names will continue to work until Python 2.6}. +\item The \module{email.mime.application} module was added, which contains the + \class{MIMEApplication} class. + \item Methods that were deprecated in version 3 have been removed. These include \method{Generator.__call__()}, \method{Message.get_type()}, \method{Message.get_main_type()}, \method{Message.get_subtype()}. Modified: sandbox/trunk/emailpkg/4_0/manual/emailmimebase.tex ============================================================================== --- sandbox/trunk/emailpkg/4_0/manual/emailmimebase.tex (original) +++ sandbox/trunk/emailpkg/4_0/manual/emailmimebase.tex Sun Mar 5 21:27:55 2006 @@ -57,7 +57,7 @@ \begin{classdesc}{MIMEMultipart}{\optional{subtype\optional{, boundary\optional{, _subparts\optional{, _params}}}}} -Module: \module{email.mmime.multipart} +Module: \module{email.mime.multipart} A subclass of \class{MIMEBase}, this is an intermediate base class for MIME messages that are \mimetype{multipart}. Optional \var{_subtype} Modified: sandbox/trunk/emailpkg/4_0/manual/mimelib.tex ============================================================================== --- sandbox/trunk/emailpkg/4_0/manual/mimelib.tex (original) +++ sandbox/trunk/emailpkg/4_0/manual/mimelib.tex Sun Mar 5 21:27:55 2006 @@ -51,7 +51,8 @@ \begin{itemize} \item Deprecation and ``version added'' notes are relative to the - Python version a feature was added or deprecated. + Python version a feature was added or deprecated. See + the package history in section \ref{email-pkg-history} for details. \item If you're reading this documentation as part of the standalone \module{email} package, some of the internal links to From python-checkins at python.org Sun Mar 5 21:49:55 2006 From: python-checkins at python.org (barry.warsaw) Date: Sun, 5 Mar 2006 21:49:55 +0100 (CET) Subject: [Python-checkins] r42857 - sandbox/trunk/emailpkg/4_0/MANIFEST Message-ID: <20060305204955.73CF91E4007@bag.python.org> Author: barry.warsaw Date: Sun Mar 5 21:49:53 2006 New Revision: 42857 Modified: sandbox/trunk/emailpkg/4_0/MANIFEST Log: Updated Modified: sandbox/trunk/emailpkg/4_0/MANIFEST ============================================================================== --- sandbox/trunk/emailpkg/4_0/MANIFEST (original) +++ sandbox/trunk/emailpkg/4_0/MANIFEST Sun Mar 5 21:49:53 2006 @@ -1,6 +1,6 @@ setup.py testall.py -README +README.txt email/__init__.py email/_parseaddr.py email/base64mime.py @@ -83,12 +83,14 @@ docs/contents.png docs/email-dir.txt docs/email-mime.txt +docs/email-pkg-history.html docs/email-simple.txt docs/email-unpack.txt docs/index.html docs/index.png docs/mimelib.css docs/mimelib.html +docs/mimelib.pdf docs/module-email.charset.html docs/module-email.encoders.html docs/module-email.errors.html @@ -112,3 +114,20 @@ docs/previous.png docs/pyfav.png docs/up.png +manual/Makefile +manual/email-dir.py +manual/email-mime.py +manual/email-simple.py +manual/email-unpack.py +manual/email.tex +manual/emailcharsets.tex +manual/emailencoders.tex +manual/emailexc.tex +manual/emailgenerator.tex +manual/emailheaders.tex +manual/emailiter.tex +manual/emailmessage.tex +manual/emailmimebase.tex +manual/emailparser.tex +manual/emailutil.tex +manual/mimelib.tex From neal at metaslash.com Sun Mar 5 22:54:09 2006 From: neal at metaslash.com (Neal Norwitz) Date: Sun, 5 Mar 2006 16:54:09 -0500 Subject: [Python-checkins] Python Regression Test Failures refleak (1) Message-ID: <20060305215409.GA7545@python.psfb.org> test_cmd_line leaked [0, 15, 0] references test_compiler leaked [80, 73, 185] references test_generators leaked [255, 255, 255] references test_socket leaked [0, 0, 197] references test_threadedtempfile leaked [4, 2, 3] references test_threading leaked [1, 0, 0] references test_threading_local leaked [27, 27, 27] references test_urllib2 leaked [80, -130, 70] references From python-checkins at python.org Mon Mar 6 01:23:07 2006 From: python-checkins at python.org (barry.warsaw) Date: Mon, 6 Mar 2006 01:23:07 +0100 (CET) Subject: [Python-checkins] r42858 - in sandbox/trunk/emailpkg: 2.5 2_5 3.0 3_0 Message-ID: <20060306002307.6BA581E4007@bag.python.org> Author: barry.warsaw Date: Mon Mar 6 01:23:06 2006 New Revision: 42858 Added: sandbox/trunk/emailpkg/2_5/ - copied from r42857, sandbox/trunk/emailpkg/2.5/ sandbox/trunk/emailpkg/3_0/ - copied from r42857, sandbox/trunk/emailpkg/3.0/ Removed: sandbox/trunk/emailpkg/2.5/ sandbox/trunk/emailpkg/3.0/ Log: Moved 2.5 to 2_5 and 3.0 to 3_0. From python-checkins at python.org Mon Mar 6 01:55:27 2006 From: python-checkins at python.org (barry.warsaw) Date: Mon, 6 Mar 2006 01:55:27 +0100 (CET) Subject: [Python-checkins] r42859 - python/branches/release24-maint/Lib/email/test/test_email_codecs.py Message-ID: <20060306005527.6D2021E4007@bag.python.org> Author: barry.warsaw Date: Mon Mar 6 01:55:25 2006 New Revision: 42859 Modified: python/branches/release24-maint/Lib/email/test/test_email_codecs.py Log: Skip codecs tests on Python 2.3. Modified: python/branches/release24-maint/Lib/email/test/test_email_codecs.py ============================================================================== --- python/branches/release24-maint/Lib/email/test/test_email_codecs.py (original) +++ python/branches/release24-maint/Lib/email/test/test_email_codecs.py Mon Mar 6 01:55:25 2006 @@ -10,6 +10,13 @@ from email.Header import Header, decode_header from email.Message import Message +# We're compatible with Python 2.3, but it doesn't have the built-in Asian +# codecs, so we have to skip all these tests. +try: + unicode('foo', 'euc-jp') +except LookupError: + raise TestSkipped + class TestEmailAsianCodecs(TestEmailBase): From python-checkins at python.org Mon Mar 6 02:06:11 2006 From: python-checkins at python.org (barry.warsaw) Date: Mon, 6 Mar 2006 02:06:11 +0100 (CET) Subject: [Python-checkins] r42860 - in sandbox/trunk/emailpkg/3_0: MANIFEST NEWS README README.txt docs docs/about.html docs/blank.png docs/contents.png docs/email-dir.txt docs/email-mime.txt docs/email-simple.txt docs/email-unpack.txt docs/index.dat docs/index.html docs/index.png docs/internals.pl docs/intlabels.pl docs/labels.pl docs/mimelib.css docs/mimelib.html docs/mimelib.pdf docs/module-email.Charset.html docs/module-email.Encoders.html docs/module-email.Errors.html docs/module-email.Generator.html docs/module-email.Header.html docs/module-email.Iterators.html docs/module-email.Message.html docs/module-email.Parser.html docs/module-email.Utils.html docs/module-email.html docs/modules.png docs/next.png docs/node1.html docs/node10.html docs/node11.html docs/node18.html docs/node19.html docs/node20.html docs/node4.html docs/node6.html docs/node7.html docs/node8.html docs/previous.png docs/pyfav.png docs/up.png Message-ID: <20060306010611.5E2081E4007@bag.python.org> Author: barry.warsaw Date: Mon Mar 6 02:05:58 2006 New Revision: 42860 Added: sandbox/trunk/emailpkg/3_0/README.txt - copied, changed from r42858, sandbox/trunk/emailpkg/3_0/README sandbox/trunk/emailpkg/3_0/docs/ sandbox/trunk/emailpkg/3_0/docs/about.html sandbox/trunk/emailpkg/3_0/docs/blank.png (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/contents.png (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/email-dir.txt sandbox/trunk/emailpkg/3_0/docs/email-mime.txt sandbox/trunk/emailpkg/3_0/docs/email-simple.txt sandbox/trunk/emailpkg/3_0/docs/email-unpack.txt sandbox/trunk/emailpkg/3_0/docs/index.dat sandbox/trunk/emailpkg/3_0/docs/index.html sandbox/trunk/emailpkg/3_0/docs/index.png (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/internals.pl sandbox/trunk/emailpkg/3_0/docs/intlabels.pl sandbox/trunk/emailpkg/3_0/docs/labels.pl sandbox/trunk/emailpkg/3_0/docs/mimelib.css sandbox/trunk/emailpkg/3_0/docs/mimelib.html sandbox/trunk/emailpkg/3_0/docs/mimelib.pdf (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/module-email.Charset.html sandbox/trunk/emailpkg/3_0/docs/module-email.Encoders.html sandbox/trunk/emailpkg/3_0/docs/module-email.Errors.html sandbox/trunk/emailpkg/3_0/docs/module-email.Generator.html sandbox/trunk/emailpkg/3_0/docs/module-email.Header.html sandbox/trunk/emailpkg/3_0/docs/module-email.Iterators.html sandbox/trunk/emailpkg/3_0/docs/module-email.Message.html sandbox/trunk/emailpkg/3_0/docs/module-email.Parser.html sandbox/trunk/emailpkg/3_0/docs/module-email.Utils.html sandbox/trunk/emailpkg/3_0/docs/module-email.html sandbox/trunk/emailpkg/3_0/docs/modules.png (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/next.png (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/node1.html sandbox/trunk/emailpkg/3_0/docs/node10.html sandbox/trunk/emailpkg/3_0/docs/node11.html sandbox/trunk/emailpkg/3_0/docs/node18.html sandbox/trunk/emailpkg/3_0/docs/node19.html sandbox/trunk/emailpkg/3_0/docs/node20.html sandbox/trunk/emailpkg/3_0/docs/node4.html sandbox/trunk/emailpkg/3_0/docs/node6.html sandbox/trunk/emailpkg/3_0/docs/node7.html sandbox/trunk/emailpkg/3_0/docs/node8.html sandbox/trunk/emailpkg/3_0/docs/previous.png (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/pyfav.png (contents, props changed) sandbox/trunk/emailpkg/3_0/docs/up.png (contents, props changed) Removed: sandbox/trunk/emailpkg/3_0/NEWS sandbox/trunk/emailpkg/3_0/README Modified: sandbox/trunk/emailpkg/3_0/MANIFEST Log: Add docs, remove NEWS, move README to README.txt. Modified: sandbox/trunk/emailpkg/3_0/MANIFEST ============================================================================== --- sandbox/trunk/emailpkg/3_0/MANIFEST (original) +++ sandbox/trunk/emailpkg/3_0/MANIFEST Mon Mar 6 02:05:58 2006 @@ -1,7 +1,6 @@ setup.py testall.py -NEWS -README +README.txt LICENSE.txt email/_compat21.py email/_compat22.py @@ -83,10 +82,15 @@ docs/email-mime.txt docs/email-simple.txt docs/email-unpack.txt +docs/index.dat docs/index.html docs/index.png +docs/internals.pl +docs/intlabels.pl +docs/labels.pl docs/mimelib.css docs/mimelib.html +docs/mimelib.pdf docs/module-email.Charset.html docs/module-email.Encoders.html docs/module-email.Errors.html @@ -110,4 +114,5 @@ docs/node7.html docs/node8.html docs/previous.png +docs/pyfav.png docs/up.png Deleted: /sandbox/trunk/emailpkg/3_0/NEWS ============================================================================== --- /sandbox/trunk/emailpkg/3_0/NEWS Mon Mar 6 02:05:58 2006 +++ (empty file) @@ -1,594 +0,0 @@ -Copyright (C) 2001-2004 Python Software Foundation - -Here is a history of user visible changes to this software. - -2.5.5 (13-May-2004) -2.5.4 -2.5.3 -2.5.2 - - Lots of bug fixes. - -2.5.1 (30-Mar-2003) - - Bug fixes and improved compatibility for Python 2.2.0. - -2.5 (21-Mar-2003) - - A few other minor bug fixes. - -2.5b1 (11-Mar-2003) - - - Message.get_payload() now recognizes various uuencoded - Content-Transfer-Encodings (e.g. x-uuencode). - - When passing decode=True to Message.get_payload() and a - low-level decoding error occurs, the payload is returned as-is - instead of raising an exception. - - - Header.__init__() and Header.append() now accept an optional - argument `errors' which is passed through to the unicode() and - ustr.encode() calls. You can use this to prevent conversion - errors by e.g. passing 'replace' or 'ignore'. - - RFC 2822 specifies that long headers should be split at the - "highest level syntactic break" possible. This can only really - be determined by the application, and the current API doesn't - support arbitrary break points. As a compromise, - Header.encode() grew a `splitchars' argument which provides some - control over splitting at higher level syntactic breaks. - - Header.decode_header() now transforms binascii.Errors into - email.Errors.HeaderParseErrors when bogus base64 data appears in - the header. - - The header splitting and folding algorithms were completely - reimplemented, especially when dealing with ASCII headers. - - We now preserve spaces between encoded and non-encode parts in - RFC 2047 headers when converting the header to Unicode. While - the RFC is technically ambiguous on this point, this is the - behavior most people expect. - - - email.Iterators.body_line_iterator() now takes an optional - decode argument, which is passed through to Message.get_payload(). - - - The MIMEText constructor used to append a newline to the _text - argument if it didn't already end in a newline. Now it doesn't. - This could theoretically break code so it should be considered - experimental for 2.5 beta 1. But it's the right fix, so we'll - keep it unless there are howls of derision. - - - The quopriMIME.header_encode() maxlinelen argument now accepts - None, which inhibits line breaking. - - - Support for Korean charsets was added to Charset.py. Also the - Charset class grew a __repr__() method. - - - Various and sundry bug fixes, improved RFC conformance, and - improved lax parsing. - -2.4.3 (14-Oct-2002) -2.4.2 (10-Oct-2002) -2.4.1 (07-Oct-2002) - - Last minute patches for the Python 2.2.2 backport. This includes - case insensitivity of character set names, patches for Windows, - and some fixes for non-splitting of unspecified 8bit header data. - -2.4 (01-Oct-2002) - - - Updated all the documentation. - - - Clarification to the semantics of Header.__init__() and - Header.append() when it gets byte strings and Unicode strings as - its first argument. When a byte string is used, the charset - must be the encoding of the string, such that unicode(s,charset) - succeeds. When a Unicode string is used, the charset is a hint, - and the first of the following to succeed is used: us-ascii, the - charset hint, utf-8. - - - A new header encoding flag has been added to the Charset - module. SHORTEST (which cannot be used for body encodings) - returns the string either quoted-printable or base64 encoding, - whichever is shortest in terms of characters. This is a good - heuristic for providing the most human readable value possible. - The utf-8 charset uses SHORTEST encoding by default now. - - - Message.get_content_charset() is a new method that returns the - charset parameter on the Content-Type header, unquoted and RFC - 2231 decoded if necessary. - - - "import email" no longer imports some sub-modules by side-effect. - - - Fixed some problems related to RFC 2231 encoding of boundary and - charset parameters on Content-Type headers. Document that - get_param() and get_params() may return values that are strings - or 3-tuples. - - - The signature of the non-public function _structure() has - changed. - -2.3.1 (13-Sep-2002) - - - Minor update to the distutils package. A file was missing in - the email-2.3.tar.gz file. - -2.3 (10-Sep-2002) - - - Added support for RFC 2231 encoding. Patch by Oleg Broytmann - (previous patch was for RFC 2231 decoding only). - - - New method Message.replace_header() which replaces the first - occurrence of a header with a new value, preserving header order - and header name case. Patch by Skip Montanaro. - - - RFC 2045, section 5.2 states that if the Content-Type: header is - invalid, it defaults to text/plain. Implement simple checks for - this in get_content_type(), get_content_maintype(), and - get_content_subtype(). These will no longer raise ValueErrors. - - - In non-strict parsing, if no start boundary can be found for a - multipart message, the entire body of the message is set as the - payload. Strict parsing such a message will still raise a - BoundaryError. - -2.2 (23-Jul-2002) - - - Better support for default content types has been added. - Specifically: - - o The following methods have been silently deprecated. At some - future release they may be unsilently deprecated: - Message.get_type(), Message.get_main_type(), - Message.get_subtype(). - - o The following methods have been added as a consistent way of - getting a message's content type: Message.get_content_type(), - Message.get_content_maintype(), Message.get_content_subtype(). - - Note that none of these methods take a `failobj' argument - because messages always have a default content type. Usually - this type is text/plain, but for messages inside a - multipart/digest container, it's message/rfc822. - - Also note that .get_content_maintype() and - .get_content_subtype() can raise ValueError exceptions if the - default content type doesn't include exactly one slash. - - - The Parser constructor's `strict' flag is exposed to - email.message_from_file() and email.message_from_string(). - Also, non-strict parsing is now the default, since that seems to - be the most useful behavior. - - - email.Header.Header.append() now allows the charset argument to - be a string, naming a character set. It will convert these to a - Charset instance automatically. - - - The test procedure has changed. See the README for details. - Also, a new torture test has been added. - - - The non-public function email.Iterators._structure() can now - take an output file object (which must be suitable for print>>). - -2.1 (09-Jul-2002) - - - Support for RFC 2231 by Oleg Broytmann was added. - - - Fixed some representational, parsing, and generation bugs with - multipart/digest and message/rfc822 messages. Now we guarantee - that the structure of such messages is something like: - - multipart/digest - message/rfc822 - text/plain (or whatever the subpart's type is) - message/rfc822 - text/plain (ditto) - - The encapsulating message/rfc822 object is a multipart of - exactly length 1. - - To preserve idempotency, the concept of a "default type" is - added to Message objects. For most messages the default type is - text/plain, except for messages at the first level inside a - multipart/digest which are message/rfc822. This default type is - not described in the Content-Type: header of the container. - - Message objects thus have new methods get_default_type() and - set_default_type(), the latter of which takes a string argument - that must be either 'text/plain' or 'message/rfc822'. - - (Some changes were also made to the non-public interface for the - Generator class.) - - - The Header class now knows how to split long non-RFC 2047 - encoded headers (i.e. us-ascii charset) in the RFC 2822 - recommended way. Splits are attempted at the "highest-level - syntactic breaks" which we define as on parameter semicolons, - followed by folding whitespace. No errors are raised if long - headers still exceed the maximum RFC 2822 header length of 998 - characters after splitting. - - - Other Header class API changes: - o All __init__() arguments have default values now. Also, a - new argument continuation_ws has been added (defaults to a - single ASCII space). - o Rich comparison __eq__ and __ne__ operators are defined - o __unicode__() for Python 2.2 by Mikhail Zabaluev - o guess_maxlinelen() method has been removed - o encode_chunks() is no longer public - - - The email.Header module has grown a function make_header() which - takes the output of decode_header() and returns a Header - instance. - - - A non-public function email.Iterators._structure() has been - added for debugging purposes. - - - MIMEMultipart.__init__() doesn't attach the subparts of the - tuple is empty (i.e. there are no subparts). Fixed a bug - related to passing in explicit boundary. - - - Anthony Baxter's patches for non-strict parsing have been added - to the Parser class. There are currently no test cases for - non-strict parsing yet. Other Parser class API changes: - o Parser.__init__() grew a strict argument, defaulting to - true for backwards compatibility. - o parse() and parsestr() both grew a headersonly argument - which tells them to stop parsing once the header block is - parsed. The file pointer is left at the start of the body. - - - For RFC 2231 support, added the following functions to the - email.Utils module: decode_rfc2231(), encode_rfc2231(), - decode_params(). - -2.0.5 (02-Jun-2002) - - - Two new class/modules MIMEMultipart and MIMENonMultipart have - been added. The former is useful as a concrete class for - creating multipart/* parts. The latter is mostly useful as a - base class for other MIME non-multipart subparts. For example, - the MIMEAudio, MIMEImage, and MIMEText clases now derive from - MIMENonMultipart. Note also that MIMENonMultipart.attach() - raises a MultipartConversionError. - - - The message structure for message/rfc822 subparts has been - changed to be more consistent. Now message/rfc822 payloads are - defined as a list containing exactly one element, the - sub-Message object. - - - The callable interface to the Generator class is now silently - deprecated in favor of the Generator.flatten() method. - __call__() can be 2-3 times slower than the equivalent normal - method. - -2.0.4 (21-May-2002) - - - Fixed a bug in email.Utils.getaddresses(). - -2.0.3 (19-May-2002) - - - Fixed some limitations that caused the Parser to not work with - CRLF style line-endings. The parser should now be able to parse - any email message with consistent line endings of \r, \n, \r\n. - - - Fixed a bug related to the semantics of the Header class - constructor. If neither maxlinelen or header_name is given, the - maximum line length is 76 by default. If maxlinelen is given, - it is always honored. If maxlinelen is not given, but - header_name is given, then a suitable default line length is - calculated. - - - Implemented a simpler testing framework. Now you just need to - run "python test.py" in the source directory. - - - Merged with the standard Python cvs tree, with compatibility - modules for working in Python 2.1 and Python 2.2. - -2.0.2 (26-Apr-2002) - - - Fix a Python 2.1.3 incompatibility in Iterators.py, - body_line_iterator(). - -2.0.1 (10-Apr-2002) - - - Minor bug fixes in the test suite. - - - One minor API change: in Header.append(), the charset is - optional, and used to default to the empty Charset(). It now - defaults to the charset given in the Header constructor. - -2.0 (08-Apr-2002) - - - Message.add_payload() is now deprecated. Instead use - Message.attach() and Message.set_payload(). The former always - ensures that the message's payload is a list object, while the - latter is used only for scalar payloads (i.e. a string or a - single Message object in the case of message/rfc822 types). - - - email.Utils.formataddr(): New function which is the inverse of - .parseaddr(); i.e. it glues a realname and an email address - together. This replaces email.Utils.dump_address_pair() which - is deprecated. - - - class Charset now has a __str__() method, and implements rich - comparison operators for comparison to lower case charset - names. - - - encode_7or8bit(): If there is no payload, set the - Content-Transfer-Encoding: value to 7bit. - - - Fixes for bugs in generating multipart messages that had exactly - zero or one subparts. - -1.2 (18-Mar-2002) - - - In the MIMEText class's constructor, the _encoder argument is - deprecated. You will get a DeprecationWarning if you try to use - it. This is because there is a fundamental conflict between - _encoder and the fact that _charset is passed to the underlying - set_payload() method. _encoder really makes no sense any more. - - - When Message.set_type() is used to set the Content-Type: header, - the MIME-Version: header is always set (overriding any existing - MIME-Version: header). - - - More liberal acceptance of parameter formatting, e.g. this is - now accepted: Content-Type: multipart/mixed; boundary = "FOO" - I.e. spaces around the = sign. - - - Bug fix in Generator related to splitting long lines in a - multiline header. - - - In class Charset, __str__() method added, as were __eq__() and - __ne__(). - - - Charset.get_body_encoding() may now return a function as well as - a string character set name. The function takes a single - argument, which is a Message instance, and may change the - Content-Transfer-Encoding: header (or do any other manipulations - on the message). - - - Charset.from_splittable() added argument to_output which is used - to specify whether the input_codec or the output_codec is used - for the conversion (by default, the output codec is used). - -1.1 (unreleased) - - - No changes since 0.97. Only the version number has changed. - -0.97 (unreleased) - - - Message.set_charset() can now take a string naming a character - set in addition to a Charset instance. In the former case, a - Charset is instantiated by passing the string to its - constructor. - - - The MIMEText constructor now passes the _charset argument to the - underlying set_charset() method. This makes things consistent - at the cost of a minor semantic change: the resulting instance - will have a Content-Transfer-Encoding: header where previously - it did not. - - - A fix for a crash when quopriMIME.encode() tried to encode a - multiline string containing a blank line. - - - New module Header.py which provides a higher level interface for - encoded email headers, such as Subject:, From:, and To:. This - module provides an abstraction for composing such headers out of - charset encoded parts, and for decoding such headers. It - properly splits lines on character boundaries even for multibyte - character sets. - - - New RFC compliant base64 and quoted-printable modules, called - base64MIME.py and quopriMIME.py. These are intended to replace - the Python standard base64.py and quopri.py modules, but are - geared toward their use conformant to the various MIME email - standards. - - - The Message class is much more character set aware and RFC - compliant: - - + set_payload() now takes a new optional charset argument - + New methods set_charset(), get_charset(), set_param(), - del_param(), set_type() - + Header parameter quoting is more RFC compliant - + get_param() and get_params() now take a new optional unquote - argument - - - The Charset module now knows about utf-8, gb2132, and big5 - codecs, the latter two of which are available independently of - Python (see the comments in this module for downloading Chinese, - Japanese, and Korean codecs). - - New Charset methods get_body_encoding(), get_output_charset(), - encoded_header_len(), header_encode(), and body_encode(). - - - The Generator now handles encoding the body, if the message - object has a character set. - - - The Utils module has new functions fix_eols() and make_msgid(). - It also includes a workaround for bugs in parseaddr() when used - with Python versions before 2.2. - - - A fix for a Parser bug when parsing multipart/* parts that - contain only a single subpart. - -0.96 (19-Nov-2001) - - - A fix for email.Utils.formatdate() for "uneven" timezones like - Australia/Adelaide and America/St_Johns. - -0.95 (09-Nov-2001) - - - A new implementation of email.Utils.formatdate() which makes it - more RFC 2822 compliant. - -0.94 (25-Oct-2001) - - - A fix for SF bug #472560, extra newlines returned by get_param() - when the separating semi-colon shows up on a continuation line - (legal, but weird). - -0.93 (17-Oct-2001) - - - Fix for SF bug #471918, generator splitting long headers - produces dupliaction. Bug report and fix contributed by Matthew - Cowles. - - - If a line could not be split on semicolons in order to produce - shorter lines, an attempt is made to split the header on folding - white space. One deficiency still: it won't try to split on - both semis and folding whitespace. Oh well. - -0.92 (14-Oct-2001) - - - Iterators.typed_subpart_iterator() should use a 'text/plain' - failobj in its get_main_type() call. - - - Added class Parser.HeaderParser which just parses headers and - leaves the message as a string payload; it does not recursively - parse the body. - -0.91 (09-Oct-2001) - - - Added the MIMEAudio class/module for audio/* MIME types. - Contributed by Anthony Baxter. - - - Fixed a bug in Message.get_all() where failobj was never - returned if no matching fields were found. - -0.90 (01-Oct-2001) - - - mimelib has been integrated with Python 2.2. A compatibility - package called email 0.90 is being made available here. It is - significantly different in API from the mimelib package. See - the README for details. mimelib as a separate package is no - longer being supported. - -0.6 (17-Sep-2001) - - - Last minute bug fixes. - -0.5 (17-Sep-2001) - - - New methods in the top-level mimelib package namespace: - + messageFromString() to create an object tree from a string. - + messageFromFile() to create an object tree from an open file. - - - New methods in the address.py module: - + encode() for encoding to RFC 2047 headers - + decode() for decoding from RFC 2047 headers - - - New methods in the Message class: - + asString() to get a flat text representation of the object - tree. - + __str__() same as asString() but includes the Unix-From - envelope header in the output. - + __contains__() for use with the `in' operator. - + attach() is a synonym for add_payload() - + getcharsets() - + getfilename() - + getboundary() - + setboundary() - + getdecodedpayload() - + getpayloadastext() - + getbodyastext() - - - Message.preamble and Message.epilogue default to None (they used - to not exist by default). - - - Changes to the Generator class: - + New optional argument `maxheaderlen' for __init__() controls - the maximum length in characters of any header line. - + write() isn't the entry point for doing the text generation - any more. This lets us make this method compatible with - file-like objects. Use __call__() semantics instead. - + Calling a Generator instance creates the plain text - message. This is the same as the old write() interface - except that the optional `unixfrom' argument now defaults to - 0. - + There is a new, undocumented semi-private interface for - extending the MIME types Generator can handle. UTSL. - - - New Encoders.py module contains some useful encoders for Image - and Text instances. - - - Text.__init__() has a new _encoder optional argument, which has - the same semantics as _encoder for Image.__init__(). - - - StringableMixin.py module has been removed, and its - functionality merged back into the Message class. - - - MessageParseError doesn't contain line numbers any more. - - - Lots of bug fixes; lots more unit tests. - -0.4 (09-Jul-2001) - - - New module/class called RFC822 which represents message/rfc822 - MIME types. This takes a single Message instance. - - - Message.getmaintype() and Message.getsubtype() will now return - failobj when the Content-Type: header doesn't have enough - information. - -0.3 (20-Apr-2001) - - - In the Image class, the _encoding argument has been changed to - _encoder. Also ImageTypeError is removed; if Image.__init__() - can't guess the image's minor type, a TypeError is raised - instead. - - - Message.getparam() and Message.getparams() have grown a new - optional argument `header'. - - - MsgReader class has grown a new method readlines() for - compatibility with Python 2.1's xreadline module. - - - The ReprMixin module and class have been renamed to - StringableMixin - - - New exception MultipartConversionError can be raised by - Message.add_payload() - - - Bug fixes - - - mimelib has been moved to SourceForge. See - http://mimelib.sourceforge.net - -0.2 (14-Feb-2001) - - - Generator constructor has a new optional argument `mangle_from_' - which is a flag. If true, the generated flat text has From_ - lines mangled in the body of messages by prepending a `>' in - front of the line. This assures that such lines are not - mistaken for Unix mailbox separators. - - - Added a new class ReprMixin for adding convenience methods - get_text() and __str__() to Message subclasses. - - - RFC 1341 (MIME) calls the blob between the closing boundary and - the end of the message, the `epilogue'. Change `postamble' to - `epilogue' in Message and Generator classes. - - - Much better conformance to RFC 1341 in the Generator. - - - Added __all__ support for "from mimelib import *" - - - Added LICENSE file, currently BSD-ish. The copyright will - eventually be transferred to the Python Software Foundation when - it is activated. - - - Bug fixes. - -0.1 (24-Jan-2001) - - Initial beta release. - - - -Local Variables: -mode: indented-text -indent-tabs-mode: nil -End: Deleted: /sandbox/trunk/emailpkg/3_0/README ============================================================================== --- /sandbox/trunk/emailpkg/3_0/README Mon Mar 6 02:05:58 2006 +++ (empty file) @@ -1,95 +0,0 @@ -email -- a mail and MIME handling package -Copyright (C) 2001-2004 Python Software Foundation - - -Introduction - - The email package is a library for managing email messages, including MIME - and other RFC 2822-based message documents. It is intended to replace - most of the functionality in several older standard modules such as - rfc822, mimetools, multifile, mimify, and MIMEWriter, and other - non-standard packages such as mimecntl. It is compliant with most of the - email related RFCs such as 2045-2047 (the MIME RFCs) and 2231. - - This version is identical to the package available in Python 2.4. It is - being made available as a standalone distutils package for use in older - Python releases. A minimum of Python 2.3 is required. Because the email - package is part of Python, it is covered by the PSF license for Python, as - described in the LICENSE.txt file. - - -Testing - - To test the email package, run the standard unit test suite from the - directory that you unpacked the source in (i.e. the directory containing - the setup.py file and this README file): - - % python testall.py - - You should see a couple of lines of dots followed by the number of tests - ran and the time the tests took. The test should end with an "OK". If - so, you're good to go. Note that the exact number of tests depends on - such things as whether you have the Japanese codecs installed or not. - - -Documentation and Examples - - The documentation can be found in the docs directory: - - docs/index.html - - If you're looking for examples, you might want to check out some - of the tests. There are a few examples in the documentation as - well. - - -Installing - - To install simply execute the following at your shell prompt: - - % python setup.py install - - If you're using Python 2.4, you've already got the latest version. - - -Acknowledgements - - A big thanks goes to Ben Gertzfield who implemented the bulk of the - multibyte support in version 1.1, as well as the RFC compliant base64 and - quoted-printable modules. - - Many thanks to these other fine folks for providing code contributions or - examples, suggestions, bug reports, feedback, encouragement, etc. - - Anthony Baxter - Martin Bless - Oleg Broytmann - Matthew Dixon Cowles - Jeff Dairiki - Quinn Dunkan - David Given - Phil Hunt - Sheila King - Martin Koch - Jason Mastaler - Andrew McNamara - Skip Montanaro - Guido van Rossum - Thomas Wouters - - Apologies to anybody I've left out (let me know!). - - -Contact Information - - The email-sig is the mailing list and community of users and developers of - the package and related Python email technologies. For more information: - - http://www.python.org/sigs/email-sig - - - -Local Variables: -mode: indented-text -indent-tabs-mode: nil -End: Copied: sandbox/trunk/emailpkg/3_0/README.txt (from r42858, sandbox/trunk/emailpkg/3_0/README) ============================================================================== --- sandbox/trunk/emailpkg/3_0/README (original) +++ sandbox/trunk/emailpkg/3_0/README.txt Mon Mar 6 02:05:58 2006 @@ -1,5 +1,5 @@ email -- a mail and MIME handling package -Copyright (C) 2001-2004 Python Software Foundation +Copyright (C) 2001-2006 Python Software Foundation Introduction Added: sandbox/trunk/emailpkg/3_0/docs/about.html ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/about.html Mon Mar 6 02:05:58 2006 @@ -0,0 +1,108 @@ + + + + + + + + + + +About this document ... + + +

      + + +

      +About this document ... +

      + email Package Reference, +March 5, 2006, Release 3.0 +

      This document was generated using the + LaTeX2HTML translator. +

      + +

      + LaTeX2HTML is Copyright © + 1993, 1994, 1995, 1996, 1997, Nikos + Drakos, Computer Based Learning Unit, University of + Leeds, and Copyright © 1997, 1998, Ross + Moore, Mathematics Department, Macquarie University, + Sydney. +

      + +

      The application of + LaTeX2HTML to the Python + documentation has been heavily tailored by Fred L. Drake, + Jr. Original navigation icons were contributed by Christopher + Petrilli. +

      + + + + + + Added: sandbox/trunk/emailpkg/3_0/docs/blank.png ============================================================================== Binary file. No diff available. Added: sandbox/trunk/emailpkg/3_0/docs/contents.png ============================================================================== Binary file. No diff available. Added: sandbox/trunk/emailpkg/3_0/docs/email-dir.txt ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/email-dir.txt Mon Mar 6 02:05:58 2006 @@ -0,0 +1,124 @@ +#!/usr/bin/env python + +"""Send the contents of a directory as a MIME message. + +Usage: dirmail [options] from to [to ...]* + +Options: + -h / --help + Print this message and exit. + + -d directory + --directory=directory + Mail the contents of the specified directory, otherwise use the + current directory. Only the regular files in the directory are sent, + and we don't recurse to subdirectories. + +`from' is the email address of the sender of the message. + +`to' is the email address of the recipient of the message, and multiple +recipients may be given. + +The email is sent by forwarding to your local SMTP server, which then does the +normal delivery process. Your local machine must be running an SMTP server. +""" + +import sys +import os +import getopt +import smtplib +# For guessing MIME type based on file name extension +import mimetypes + +from email import Encoders +from email.Message import Message +from email.MIMEAudio import MIMEAudio +from email.MIMEBase import MIMEBase +from email.MIMEMultipart import MIMEMultipart +from email.MIMEImage import MIMEImage +from email.MIMEText import MIMEText + +COMMASPACE = ', ' + + +def usage(code, msg=''): + print >> sys.stderr, __doc__ + if msg: + print >> sys.stderr, msg + sys.exit(code) + + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], 'hd:', ['help', 'directory=']) + except getopt.error, msg: + usage(1, msg) + + dir = os.curdir + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + elif opt in ('-d', '--directory'): + dir = arg + + if len(args) < 2: + usage(1) + + sender = args[0] + recips = args[1:] + + # Create the enclosing (outer) message + outer = MIMEMultipart() + outer['Subject'] = 'Contents of directory %s' % os.path.abspath(dir) + outer['To'] = COMMASPACE.join(recips) + outer['From'] = sender + outer.preamble = 'You will not see this in a MIME-aware mail reader.\n' + # To guarantee the message ends with a newline + outer.epilogue = '' + + for filename in os.listdir(dir): + path = os.path.join(dir, filename) + if not os.path.isfile(path): + continue + # Guess the content type based on the file's extension. Encoding + # will be ignored, although we should check for simple things like + # gzip'd or compressed files. + ctype, encoding = mimetypes.guess_type(path) + if ctype is None or encoding is not None: + # No guess could be made, or the file is encoded (compressed), so + # use a generic bag-of-bits type. + ctype = 'application/octet-stream' + maintype, subtype = ctype.split('/', 1) + if maintype == 'text': + fp = open(path) + # Note: we should handle calculating the charset + msg = MIMEText(fp.read(), _subtype=subtype) + fp.close() + elif maintype == 'image': + fp = open(path, 'rb') + msg = MIMEImage(fp.read(), _subtype=subtype) + fp.close() + elif maintype == 'audio': + fp = open(path, 'rb') + msg = MIMEAudio(fp.read(), _subtype=subtype) + fp.close() + else: + fp = open(path, 'rb') + msg = MIMEBase(maintype, subtype) + msg.set_payload(fp.read()) + fp.close() + # Encode the payload using Base64 + Encoders.encode_base64(msg) + # Set the filename parameter + msg.add_header('Content-Disposition', 'attachment', filename=filename) + outer.attach(msg) + + # Now send the message + s = smtplib.SMTP() + s.connect() + s.sendmail(sender, recips, outer.as_string()) + s.close() + + +if __name__ == '__main__': + main() Added: sandbox/trunk/emailpkg/3_0/docs/email-mime.txt ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/email-mime.txt Mon Mar 6 02:05:58 2006 @@ -0,0 +1,34 @@ +# Import smtplib for the actual sending function +import smtplib + +# Here are the email package modules we'll need +from email.MIMEImage import MIMEImage +from email.MIMEMultipart import MIMEMultipart + +COMMASPACE = ', ' + +# Create the container (outer) email message. +msg = MIMEMultipart() +msg['Subject'] = 'Our family reunion' +# me == the sender's email address +# family = the list of all recipients' email addresses +msg['From'] = me +msg['To'] = COMMASPACE.join(family) +msg.preamble = 'Our family reunion' +# Guarantees the message ends in a newline +msg.epilogue = '' + +# Assume we know that the image files are all in PNG format +for file in pngfiles: + # Open the files in binary mode. Let the MIMEImage class automatically + # guess the specific image type. + fp = open(file, 'rb') + img = MIMEImage(fp.read()) + fp.close() + msg.attach(img) + +# Send the email via our own SMTP server. +s = smtplib.SMTP() +s.connect() +s.sendmail(me, family, msg.as_string()) +s.close() Added: sandbox/trunk/emailpkg/3_0/docs/email-simple.txt ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/email-simple.txt Mon Mar 6 02:05:58 2006 @@ -0,0 +1,25 @@ +# Import smtplib for the actual sending function +import smtplib + +# Import the email modules we'll need +from email.MIMEText import MIMEText + +# Open a plain text file for reading. For this example, assume that +# the text file contains only ASCII characters. +fp = open(textfile, 'rb') +# Create a text/plain message +msg = MIMEText(fp.read()) +fp.close() + +# me == the sender's email address +# you == the recipient's email address +msg['Subject'] = 'The contents of %s' % textfile +msg['From'] = me +msg['To'] = you + +# Send the message via our own SMTP server, but don't include the +# envelope header. +s = smtplib.SMTP() +s.connect() +s.sendmail(me, [you], msg.as_string()) +s.close() Added: sandbox/trunk/emailpkg/3_0/docs/email-unpack.txt ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/email-unpack.txt Mon Mar 6 02:05:58 2006 @@ -0,0 +1,83 @@ +#!/usr/bin/env python + +"""Unpack a MIME message into a directory of files. + +Usage: unpackmail [options] msgfile + +Options: + -h / --help + Print this message and exit. + + -d directory + --directory=directory + Unpack the MIME message into the named directory, which will be + created if it doesn't already exist. + +msgfile is the path to the file containing the MIME message. +""" + +import sys +import os +import getopt +import errno +import mimetypes +import email + + +def usage(code, msg=''): + print >> sys.stderr, __doc__ + if msg: + print >> sys.stderr, msg + sys.exit(code) + + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], 'hd:', ['help', 'directory=']) + except getopt.error, msg: + usage(1, msg) + + dir = os.curdir + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + elif opt in ('-d', '--directory'): + dir = arg + + try: + msgfile = args[0] + except IndexError: + usage(1) + + try: + os.mkdir(dir) + except OSError, e: + # Ignore directory exists error + if e.errno <> errno.EEXIST: raise + + fp = open(msgfile) + msg = email.message_from_file(fp) + fp.close() + + counter = 1 + for part in msg.walk(): + # multipart/* are just containers + if part.get_content_maintype() == 'multipart': + continue + # Applications should really sanitize the given filename so that an + # email message can't be used to overwrite important files + filename = part.get_filename() + if not filename: + ext = mimetypes.guess_extension(part.get_type()) + if not ext: + # Use a generic bag-of-bits extension + ext = '.bin' + filename = 'part-%03d%s' % (counter, ext) + counter += 1 + fp = open(os.path.join(dir, filename), 'wb') + fp.write(part.get_payload(decode=1)) + fp.close() + + +if __name__ == '__main__': + main() Added: sandbox/trunk/emailpkg/3_0/docs/index.dat ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/index.dat Mon Mar 6 02:05:58 2006 @@ -0,0 +1,133 @@ +email (standard module)###DEF0000003005 +email.Message (standard module)###DEF0000003021 +Message (class in email.Message)###0000003022 +as_string() (Message method)###0000003023 +__str__() (Message method)###0000003024 +is_multipart() (Message method)###0000003025 +set_unixfrom() (Message method)###0000003026 +get_unixfrom() (Message method)###0000003027 +attach() (Message method)###0000003028 +get_payload() (Message method)###0000003029 +set_payload() (Message method)###0000003030 +set_charset() (Message method)###0000003031 +get_charset() (Message method)###0000003032 +__len__() (Message method)###0000003033 +__contains__() (Message method)###0000003034 +__getitem__() (Message method)###0000003035 +__setitem__() (Message method)###0000003036 +__delitem__() (Message method)###0000003037 +has_key() (Message method)###0000003038 +keys() (Message method)###0000003039 +values() (Message method)###0000003040 +items() (Message method)###0000003041 +get() (Message method)###0000003042 +get_all() (Message method)###0000003043 +add_header() (Message method)###0000003044 +replace_header() (Message method)###0000003045 +get_content_type() (Message method)###0000003046 +get_content_maintype() (Message method)###0000003047 +get_content_subtype() (Message method)###0000003048 +get_default_type() (Message method)###0000003049 +set_default_type() (Message method)###0000003050 +get_params() (Message method)###0000003051 +get_param() (Message method)###0000003052 +set_param() (Message method)###0000003053 +del_param() (Message method)###0000003054 +set_type() (Message method)###0000003055 +get_filename() (Message method)###0000003056 +get_boundary() (Message method)###0000003057 +set_boundary() (Message method)###0000003058 +get_content_charset() (Message method)###0000003059 +get_charsets() (Message method)###0000003060 +walk() (Message method)###0000003061 +preamble (in module email.Message)###0000003062 +epilogue (in module email.Message)###0000003063 +defects (in module email.Message)###0000003064 +get_type() (Message method)###0000003084 +get_main_type() (Message method)###0000003085 +get_subtype() (Message method)###0000003086 +email.Parser (standard module)###DEF0000003088 +FeedParser (class in email.Parser)###0000003093 +feed() (FeedParser method)###0000003094 +close() (FeedParser method)###0000003095 +Parser (class in email.Parser)###0000003097 +parse() (Parser method)###0000003098 +parsestr() (Parser method)###0000003099 +message_from_string() (in module email.Parser)###0000003100 +message_from_file() (in module email.Parser)###0000003101 +email.Generator (standard module)###DEF0000003106 +Generator (class in email.Generator)###0000003107 +flatten() (Generator method)###0000003108 +clone() (Generator method)###0000003109 +write() (Generator method)###0000003110 +DecodedGenerator (class in email.Generator)###0000003111 +__call__() (Generator method)###0000003117 +MIMEBase (class in email.Generator)###0000003119 +MIMENonMultipart (class in email.Generator)###0000003120 +MIMEMultipart (class in email.Generator)###0000003121 +MIMEAudio (class in email.Generator)###0000003122 +MIMEImage (class in email.Generator)###0000003123 +MIMEMessage (class in email.Generator)###0000003124 +MIMEText (class in email.Generator)###0000003125 +email.Header (standard module)###DEF0000003127 +Header (class in email.Header)###0000003128 +append() (Header method)###0000003129 +encode() (Header method)###0000003130 +__str__() (Header method)###0000003131 +__unicode__() (Header method)###0000003132 +__eq__() (Header method)###0000003133 +__ne__() (Header method)###0000003134 +decode_header() (in module email.Header)###0000003135 +make_header() (in module email.Header)###0000003136 +email.Charset (standard module)###DEF0000003166 +Charset (class in email.Charset)###0000003167 +input_charset (in module email.Charset)###0000003168 +header_encoding (in module email.Charset)###0000003169 +body_encoding (in module email.Charset)###0000003170 +output_charset (in module email.Charset)###0000003171 +input_codec (in module email.Charset)###0000003172 +output_codec (in module email.Charset)###0000003173 +get_body_encoding() (Charset method)###0000003174 +convert() (Charset method)###0000003175 +to_splittable() (Charset method)###0000003176 +from_splittable() (Charset method)###0000003177 +get_output_charset() (Charset method)###0000003178 +encoded_header_len() (Charset method)###0000003179 +header_encode() (Charset method)###0000003180 +body_encode() (Charset method)###0000003181 +__str__() (Charset method)###0000003182 +__eq__() (Charset method)###0000003183 +__ne__() (Header method)###0000003184 +add_charset() (in module email.Charset)###0000003185 +add_alias() (in module email.Charset)###0000003186 +add_codec() (in module email.Charset)###0000003187 +email.Encoders (standard module)###DEF0000003189 +encode_quopri() (in module email.Encoders)###0000003190 +encode_base64() (in module email.Encoders)###0000003193 +encode_7or8bit() (in module email.Encoders)###0000003194 +encode_noop() (in module email.Encoders)###0000003195 +email.Errors (standard module)###DEF0000003198 +MessageError (exception in email.Errors)###0000003199 +MessageParseError (exception in email.Errors)###0000003200 +HeaderParseError (exception in email.Errors)###0000003201 +BoundaryError (exception in email.Errors)###0000003202 +MultipartConversionError (exception in email.Errors)###0000003203 +email.Utils (standard module)###DEF0000003213 +quote() (in module email.Utils)###0000003214 +unquote() (in module email.Utils)###0000003215 +parseaddr() (in module email.Utils)###0000003216 +formataddr() (in module email.Utils)###0000003217 +getaddresses() (in module email.Utils)###0000003218 +parsedate() (in module email.Utils)###0000003219 +parsedate_tz() (in module email.Utils)###0000003220 +mktime_tz() (in module email.Utils)###0000003225 +formatdate() (in module email.Utils)###0000003226 +make_msgid() (in module email.Utils)###0000003227 +decode_rfc2231() (in module email.Utils)###0000003228 +encode_rfc2231() (in module email.Utils)###0000003229 +collapse_rfc2231_value() (in module email.Utils)###0000003230 +decode_params() (in module email.Utils)###0000003231 +email.Iterators (standard module)###DEF0000003252 +body_line_iterator() (in module email.Iterators)###0000003253 +typed_subpart_iterator() (in module email.Iterators)###0000003254 +_structure() (in module email.Iterators)###0000003255 Added: sandbox/trunk/emailpkg/3_0/docs/index.html ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/index.html Mon Mar 6 02:05:58 2006 @@ -0,0 +1,136 @@ + + + + + + + + + +email Package Reference + + + + + +

      + +

      +
      +

      email Package Reference

      +

      Barry Warsaw

      +

      +

      Release 3.0
      +March 5, 2006

      +

      +
      +
      + +

      + +

      Abstract:

      +
      + The email package provides classes and utilities to create, + parse, generate, and modify email messages, conforming to all the + relevant email and MIME related RFCs. +
      +

      + +

      + +



      + + + + + + + Added: sandbox/trunk/emailpkg/3_0/docs/index.png ============================================================================== Binary file. No diff available. Added: sandbox/trunk/emailpkg/3_0/docs/internals.pl ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/internals.pl Mon Mar 6 02:05:58 2006 @@ -0,0 +1,50 @@ +# LaTeX2HTML 2002-2-1 (1.71) +# Associate internals original text with physical files. + + +$key = q/module-email.Utils/; +$ref_files{$key} = "$dir".q|node16.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Parser/; +$ref_files{$key} = "$dir".q|node5.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Errors/; +$ref_files{$key} = "$dir".q|node15.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Generator/; +$ref_files{$key} = "$dir".q|node9.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Header/; +$ref_files{$key} = "$dir".q|node12.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Encoders/; +$ref_files{$key} = "$dir".q|node14.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Iterators/; +$ref_files{$key} = "$dir".q|node17.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email/; +$ref_files{$key} = "$dir".q|node2.html|; +$noresave{$key} = "$nosave"; + +$key = q/about/; +$ref_files{$key} = "$dir".q|node21.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Charset/; +$ref_files{$key} = "$dir".q|node13.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Message/; +$ref_files{$key} = "$dir".q|node3.html|; +$noresave{$key} = "$nosave"; + +1; + Added: sandbox/trunk/emailpkg/3_0/docs/intlabels.pl ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/intlabels.pl Mon Mar 6 02:05:58 2006 @@ -0,0 +1,136 @@ +%internal_labels = (); +1; # hack in case there are no entries + +$internal_labels{"l2h-1"} = "/node2.html"; +$internal_labels{"l2h-2"} = "/node3.html"; +$internal_labels{"l2h-3"} = "/node3.html"; +$internal_labels{"l2h-4"} = "/node3.html"; +$internal_labels{"l2h-5"} = "/node3.html"; +$internal_labels{"l2h-6"} = "/node3.html"; +$internal_labels{"l2h-7"} = "/node3.html"; +$internal_labels{"l2h-8"} = "/node3.html"; +$internal_labels{"l2h-9"} = "/node3.html"; +$internal_labels{"l2h-10"} = "/node3.html"; +$internal_labels{"l2h-11"} = "/node3.html"; +$internal_labels{"l2h-12"} = "/node3.html"; +$internal_labels{"l2h-13"} = "/node3.html"; +$internal_labels{"l2h-14"} = "/node3.html"; +$internal_labels{"l2h-15"} = "/node3.html"; +$internal_labels{"l2h-16"} = "/node3.html"; +$internal_labels{"l2h-17"} = "/node3.html"; +$internal_labels{"l2h-18"} = "/node3.html"; +$internal_labels{"l2h-19"} = "/node3.html"; +$internal_labels{"l2h-20"} = "/node3.html"; +$internal_labels{"l2h-21"} = "/node3.html"; +$internal_labels{"l2h-22"} = "/node3.html"; +$internal_labels{"l2h-23"} = "/node3.html"; +$internal_labels{"l2h-24"} = "/node3.html"; +$internal_labels{"l2h-25"} = "/node3.html"; +$internal_labels{"l2h-26"} = "/node3.html"; +$internal_labels{"l2h-27"} = "/node3.html"; +$internal_labels{"l2h-28"} = "/node3.html"; +$internal_labels{"l2h-29"} = "/node3.html"; +$internal_labels{"l2h-30"} = "/node3.html"; +$internal_labels{"l2h-31"} = "/node3.html"; +$internal_labels{"l2h-32"} = "/node3.html"; +$internal_labels{"l2h-33"} = "/node3.html"; +$internal_labels{"l2h-34"} = "/node3.html"; +$internal_labels{"l2h-35"} = "/node3.html"; +$internal_labels{"l2h-36"} = "/node3.html"; +$internal_labels{"l2h-37"} = "/node3.html"; +$internal_labels{"l2h-38"} = "/node3.html"; +$internal_labels{"l2h-39"} = "/node3.html"; +$internal_labels{"l2h-40"} = "/node3.html"; +$internal_labels{"l2h-41"} = "/node3.html"; +$internal_labels{"l2h-42"} = "/node3.html"; +$internal_labels{"l2h-43"} = "/node3.html"; +$internal_labels{"l2h-44"} = "/node3.html"; +$internal_labels{"l2h-45"} = "/node3.html"; +$internal_labels{"l2h-46"} = "/node4.html"; +$internal_labels{"l2h-47"} = "/node4.html"; +$internal_labels{"l2h-48"} = "/node4.html"; +$internal_labels{"l2h-49"} = "/node5.html"; +$internal_labels{"l2h-50"} = "/node6.html"; +$internal_labels{"l2h-51"} = "/node6.html"; +$internal_labels{"l2h-52"} = "/node6.html"; +$internal_labels{"l2h-53"} = "/node7.html"; +$internal_labels{"l2h-54"} = "/node7.html"; +$internal_labels{"l2h-55"} = "/node7.html"; +$internal_labels{"l2h-56"} = "/node7.html"; +$internal_labels{"l2h-57"} = "/node7.html"; +$internal_labels{"l2h-58"} = "/node9.html"; +$internal_labels{"l2h-59"} = "/node9.html"; +$internal_labels{"l2h-60"} = "/node9.html"; +$internal_labels{"l2h-61"} = "/node9.html"; +$internal_labels{"l2h-62"} = "/node9.html"; +$internal_labels{"l2h-63"} = "/node9.html"; +$internal_labels{"l2h-64"} = "/node10.html"; +$internal_labels{"l2h-65"} = "/node11.html"; +$internal_labels{"l2h-66"} = "/node11.html"; +$internal_labels{"l2h-67"} = "/node11.html"; +$internal_labels{"l2h-68"} = "/node11.html"; +$internal_labels{"l2h-69"} = "/node11.html"; +$internal_labels{"l2h-70"} = "/node11.html"; +$internal_labels{"l2h-71"} = "/node11.html"; +$internal_labels{"l2h-72"} = "/node12.html"; +$internal_labels{"l2h-73"} = "/node12.html"; +$internal_labels{"l2h-74"} = "/node12.html"; +$internal_labels{"l2h-75"} = "/node12.html"; +$internal_labels{"l2h-76"} = "/node12.html"; +$internal_labels{"l2h-77"} = "/node12.html"; +$internal_labels{"l2h-78"} = "/node12.html"; +$internal_labels{"l2h-79"} = "/node12.html"; +$internal_labels{"l2h-80"} = "/node12.html"; +$internal_labels{"l2h-81"} = "/node12.html"; +$internal_labels{"l2h-82"} = "/node13.html"; +$internal_labels{"l2h-83"} = "/node13.html"; +$internal_labels{"l2h-84"} = "/node13.html"; +$internal_labels{"l2h-85"} = "/node13.html"; +$internal_labels{"l2h-86"} = "/node13.html"; +$internal_labels{"l2h-87"} = "/node13.html"; +$internal_labels{"l2h-88"} = "/node13.html"; +$internal_labels{"l2h-89"} = "/node13.html"; +$internal_labels{"l2h-90"} = "/node13.html"; +$internal_labels{"l2h-91"} = "/node13.html"; +$internal_labels{"l2h-92"} = "/node13.html"; +$internal_labels{"l2h-93"} = "/node13.html"; +$internal_labels{"l2h-94"} = "/node13.html"; +$internal_labels{"l2h-95"} = "/node13.html"; +$internal_labels{"l2h-96"} = "/node13.html"; +$internal_labels{"l2h-97"} = "/node13.html"; +$internal_labels{"l2h-98"} = "/node13.html"; +$internal_labels{"l2h-99"} = "/node13.html"; +$internal_labels{"l2h-100"} = "/node13.html"; +$internal_labels{"l2h-101"} = "/node13.html"; +$internal_labels{"l2h-102"} = "/node13.html"; +$internal_labels{"l2h-103"} = "/node13.html"; +$internal_labels{"l2h-104"} = "/node14.html"; +$internal_labels{"l2h-105"} = "/node14.html"; +$internal_labels{"l2h-106"} = "/node14.html"; +$internal_labels{"l2h-107"} = "/node14.html"; +$internal_labels{"l2h-108"} = "/node14.html"; +$internal_labels{"l2h-109"} = "/node15.html"; +$internal_labels{"l2h-110"} = "/node15.html"; +$internal_labels{"l2h-111"} = "/node15.html"; +$internal_labels{"l2h-112"} = "/node15.html"; +$internal_labels{"l2h-113"} = "/node15.html"; +$internal_labels{"l2h-114"} = "/node15.html"; +$internal_labels{"l2h-115"} = "/node16.html"; +$internal_labels{"l2h-116"} = "/node16.html"; +$internal_labels{"l2h-117"} = "/node16.html"; +$internal_labels{"l2h-118"} = "/node16.html"; +$internal_labels{"l2h-119"} = "/node16.html"; +$internal_labels{"l2h-120"} = "/node16.html"; +$internal_labels{"l2h-121"} = "/node16.html"; +$internal_labels{"l2h-122"} = "/node16.html"; +$internal_labels{"l2h-123"} = "/node16.html"; +$internal_labels{"l2h-124"} = "/node16.html"; +$internal_labels{"l2h-125"} = "/node16.html"; +$internal_labels{"l2h-126"} = "/node16.html"; +$internal_labels{"l2h-127"} = "/node16.html"; +$internal_labels{"l2h-128"} = "/node16.html"; +$internal_labels{"l2h-129"} = "/node16.html"; +$internal_labels{"l2h-130"} = "/node17.html"; +$internal_labels{"l2h-131"} = "/node17.html"; +$internal_labels{"l2h-132"} = "/node17.html"; +$internal_labels{"l2h-133"} = "/node17.html"; Added: sandbox/trunk/emailpkg/3_0/docs/labels.pl ============================================================================== --- (empty file) +++ sandbox/trunk/emailpkg/3_0/docs/labels.pl Mon Mar 6 02:05:58 2006 @@ -0,0 +1,97 @@ +# LaTeX2HTML 2002-2-1 (1.71) +# Associate labels original text with physical files. + + +$key = q/module-email.Utils/; +$external_labels{$key} = "$URL/" . q|node16.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Parser/; +$external_labels{$key} = "$URL/" . q|node5.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Errors/; +$external_labels{$key} = "$URL/" . q|node15.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Generator/; +$external_labels{$key} = "$URL/" . q|node9.html|; +$noresave{$key} = "$nosave"; + +$key = q/module-email.Header/; +$external_labels{$key} = "$URL/" . q|node12.