Anthony Baxter [Thu, 13 Apr 2006 02:06:09 +0000 (02:06 +0000)]
spread the extern "C" { } magic pixie dust around. Python itself builds now
using a C++ compiler. Still lots and lots of errors in the modules built by
setup.py, and a bunch of warnings from g++ in the core.
Anthony Baxter [Thu, 13 Apr 2006 01:34:33 +0000 (01:34 +0000)]
reverting r45321: Patch #860326: traceback.format_exception_only() now
prepends the exception's module name to non-builtin exceptions, like
the interpreter itself does.
broke a number of doctests. should be discussed before checking in (see
discussion on python-dev).
bsddb.*open() methods cachesize parameter wouldn't work (raised an
internal bsddb.db exception when it was given). The set_cachesize
call needed to be moved from the DB object to the DBEnv since the env
was introduced to allow for threading.
Using None for a filename with the 'n' flag when calling bsddb.btopen
would cause an error while checking if the file None existed. error
not likely to be seen as anyone using None for a filename would likely
use the 'c' flag in the first place.
Tim Peters [Wed, 12 Apr 2006 06:44:36 +0000 (06:44 +0000)]
gen_throw(): The caller doesn't own PyArg_ParseTuple()
"O" arguments, so must not decref them. This accounts
for why running test_contextlib.test_main() in a loop
eventually tried to deallocate Py_None.
Update comments and the skip list, maybe some of these tests don't
report failures, we'll see.
Skip certain hopeless tests: compiler and logging.
compiler will likely always show varying leaks since it doesn't work
on a defined set of modules unless -u compiler is specified. But that
takes forever (we only run with -u network currently).
Anthony Baxter [Wed, 12 Apr 2006 00:43:09 +0000 (00:43 +0000)]
per Jeremy's email, remove the _WITH_CAST versions of macros. g++
still has errors from the casts of asdl_seq_GET to cmpop_ty, but
otherwise it's C++ clean.
Thomas Wouters [Wed, 12 Apr 2006 00:06:34 +0000 (00:06 +0000)]
Fix SF bug #1466641: multiple adjacent 'if's in listcomps and genexps, as in
[x for x in it if x if x], were broken for no good reason by the PEP 308
patch.
Thomas Wouters [Tue, 11 Apr 2006 23:50:33 +0000 (23:50 +0000)]
Fix int() and long() to repr() their argument when formatting the exception,
to avoid confusing situations like:
>>> int("")
ValueError: invalid literal for int():
>>> int("2\n\n2")
ValueError: invalid literal for int(): 2
2
Also report the base used, to avoid:
ValueError: invalid literal for int(): 2
They now report:
>>> int("")
ValueError: invalid literal for int() with base 10: ''
>>> int("2\n\n2")
ValueError: invalid literal for int() with base 10: '2\n\n2'
>>> int("2", 2)
ValueError: invalid literal for int() with base 2: '2'
(Reporting the base could be avoided when base is 10, which is the default,
but hrm.) Another effect of these changes is that the errormessage can be
longer; before, it was cut off at about 250 characters. Now, it can be up to
four times as long, as the unrepr'ed string is cut off at 200 characters,
instead.
No tests were added or changed, since testing for exact errormsgs is (pardon
the pun) somewhat errorprone, and I consider not testing the exact text
preferable. The actually changed code is tested frequent enough in the
test_builtin test as it is (120 runs for each of ints and longs.)
Tim Peters [Tue, 11 Apr 2006 19:12:33 +0000 (19:12 +0000)]
_Py_PrintReferenceAddresses,_Py_PrintReferences:
interpolate PY_FORMAT_SIZE_T for refcount display
instead of casting refcounts to long.
I understand that gcc on some boxes delivers
nuisance warnings about this, but if any new ones
appear because of this they'll get fixed by magic
when the others get fixed.
Anthony Baxter [Tue, 11 Apr 2006 12:01:56 +0000 (12:01 +0000)]
more low-hanging fruit to make code compile under a C++ compiler. Not
entirely happy with the two new VISIT macros in compile.c, but I
couldn't see a better approach.
As discussed on python-dev, really fix the PyMem_*/PyObject_* memory API
mismatches. At least I hope this fixes them all.
This reverts part of my change from yesterday that converted everything
in Parser/*.c to use PyObject_* API. The encoding doesn't really need
to use PyMem_*, however, it uses new_string() which must return PyMem_*
for handling the result of PyOS_Readline() which returns PyMem_* memory.
If there were 2 versions of new_string() one that returned PyMem_*
for tokens and one that return PyObject_* for encodings that could
also fix this problem. I'm not sure which version would be clearer.
This seems to fix both Guido's and Phillip's problems, so it's good enough
for now. After this change, it would be good to review Parser/*.c
for consistent use of the 2 memory APIs.
Anthony Baxter [Tue, 11 Apr 2006 07:42:36 +0000 (07:42 +0000)]
More low-hanging fruit. Still need to re-arrange some code (or find a better
solution) in the same way as listobject.c got changed. Hoping for a better
solution.
Anthony Baxter [Tue, 11 Apr 2006 06:54:30 +0000 (06:54 +0000)]
More C++-compliance. Note especially listobject.c - to get C++ to accept the
PyTypeObject structures, I had to make prototypes for the functions, and
move the structure definition ahead of the functions. I'd dearly like a better
way to do this - to change this would make for a massive set of changes to
the codebase.
There's still some warnings - this is purely to get rid of errors first.
Anthony Baxter [Tue, 11 Apr 2006 05:39:14 +0000 (05:39 +0000)]
Fix the code in Parser/ to also compile with C++. This was mostly casts for
malloc/realloc type functions, as well as renaming one variable called 'new'
in tokensizer.c. Still lots more to be done, going to be checking in one
chunk at a time or the patch will be massively huge. Still compiles ok with
gcc.
Tim Peters [Tue, 11 Apr 2006 02:59:48 +0000 (02:59 +0000)]
Try to repair what may be the last new test failure on the
"x86 OpenBSD trunk" buildbot due to changing Python so that
Python-exposed addresses are always non-negative.
test_int_pointer_arg(): This line failed now whenever the
box happened to assign an address to `ci` "with the sign
bit set":
The problem is that the ctypes addressof() inherited "all
addresses are non-negative now" from changes to
PyLong_FromVoidPtr(), but byref() did not inherit that
change and can still return a negative int.
I don't know whether, or what, the ctypes implementation wants
to do about that (possibly nothing), but in the meantime
the test fails frequently.
So, introduced a Python positive_address() function in
the test module, that takes a purported machine address and,
if negative, converts it to a non-negative value "with the
same bits". This should leave the test passing under all
versions of Python.
Belated thanks to Armin Rigo for teaching me the sick trick ;-)
for determining the # of bits in a machine pointer via abuse
of the struct module.
Tim Peters [Tue, 11 Apr 2006 01:59:34 +0000 (01:59 +0000)]
subclasspropagation(): Squash two more bogus hash(x) == id(x)
tests. Alas, because only the "x86 OpenBSD trunk" buildbot fails
these tests, and test_descr stops after the first failure, there's
no sane way for me to fix these short of fixing one and then
waiting for the buildbot to reveal the next one.
Tim Peters [Tue, 11 Apr 2006 01:44:07 +0000 (01:44 +0000)]
More words on patch #837242, since 4 or 5 tests started
failing on one of the 32-bit buildbot boxes because of it,
due to tempting but always-wrong Python code. Users
probably have code like this too (I know I did ...).
Tim Peters [Tue, 11 Apr 2006 01:21:00 +0000 (01:21 +0000)]
specials(): squash another incorrect hash(x) == id(x)
test. Add some lines that at least invoke the default
__hash__, although there's nothing to check there beyond
that they don't blow up.
Updated the warnings, linecache, inspect, traceback, site, and doctest modules
to work correctly with modules imported from zipfiles or via other PEP 302
__loader__ objects. Tests and doc updates are included.
Tim Peters [Tue, 11 Apr 2006 00:43:27 +0000 (00:43 +0000)]
Try to repair more new buildbot failures in "x86 OpenBSD trunk", due
to that id() can now return a Python long on a 32-bit box that allocates
addresses "with the sign bit set".
test_set.py test_subclass_with_custom_hash(): it's never been portably
legal for a __hash__() method to return id(self), but on 32-bit boxes
that never caused a problem before it became possible for id() to
return a Python long. Changed __hash__ here to return a Python int
regardless of platform.
test_descr.py specials():
vereq(hash(c1), id(c1))
has never been a correct test -- just removed it (hash() is always
a Python int; id() may be a Python long).
Tim Peters [Mon, 10 Apr 2006 21:38:11 +0000 (21:38 +0000)]
Fix one of the tests that fails on the "x86 OpenBSD trunk" buildbot,
due to that id() may return a long on a 32-bit box now. On a box that
assigns addresses "with the sign bit set", id() always returns a long now.
Tim Peters [Mon, 10 Apr 2006 21:34:00 +0000 (21:34 +0000)]
Fix one of the tests that fails on the "x86 OpenBSD trunk" buildbot, due
to that id() may return a long on a 32-bit box now. On a box that assigns
addresses "with the sign bit set", id() always returns a long now.
Tim Peters [Mon, 10 Apr 2006 20:25:47 +0000 (20:25 +0000)]
DecimalContextTestCase: this permanently changed the
default decimal context, causing test_tokenize to fail
if it ran after test_contextlib. Changed to restore
the decimal context in effect at the test's start.
SF Patch #1463867: Improved generator finalization to allow generators
that are suspended outside of any try/except/finally blocks to be
garbage collected even if they are part of a cycle. Generators that
suspend inside of an active try/except or try/finally block (including
those created by a ``with`` statement) are still not GC-able if they
are part of a cycle, however.
Martin v. Löwis [Mon, 10 Apr 2006 15:55:37 +0000 (15:55 +0000)]
Patch #1467770: Add Popen objects to _active only in __del__.
Introduce _child_active member to keep track on whether a child
needs to be waited for.
Backport candidate.
SF patch #1467512, fix double free with triple quoted string in standard build.
This was the result of inconsistent use of PyMem_* and PyObject_* allocators.
By changing to use PyObject_* allocator almost everywhere, this removes
the inconsistency.