The beginnings of a script to help finding / operators that may need
to be change to //. The code is pretty gross so far, and I promise
I'll work on this more, but I have to go eat now! :-)
Guido van Rossum [Fri, 31 Aug 2001 17:46:35 +0000 (17:46 +0000)]
Allow for the possibility that globals['__name__'] does not exist;
substitute "<string>" for the module name in that case. This actually
occurred when running test_descr.py with -Dwarn.
Guido van Rossum [Fri, 31 Aug 2001 17:40:15 +0000 (17:40 +0000)]
Add warning mode for classic division, almost exactly as specified in
PEP 238. Changes:
- add a new flag variable Py_DivisionWarningFlag, declared in
pydebug.h, defined in object.c, set in main.c, and used in
{int,long,float,complex}object.c. When this flag is set, the
classic division operator issues a DeprecationWarning message.
- add a new API PyRun_SimpleStringFlags() to match
PyRun_SimpleString(). The main() function calls this so that
commands run with -c can also benefit from -Dnew.
- While I was at it, I changed the usage message in main() somewhat:
alphabetized the options, split it in *four* parts to fit in under
512 bytes (not that I still believe this is necessary -- doc strings
elsewhere are much longer), and perhaps most visibly, don't display
the full list of options on each command line error. Instead, the
full list is only displayed when -h is used, and otherwise a brief
reminder of -h is displayed. When -h is used, write to stdout so
that you can do `python -h | more'.
Notes:
- I don't want to use the -W option to control whether the classic
division warning is issued or not, because the machinery to decide
whether to display the warning or not is very expensive (it involves
calling into the warnings.py module). You can use -Werror to turn
the warnings into exceptions though.
- The -Dnew option doesn't select future division for all of the
program -- only for the __main__ module. I don't know if I'll ever
change this -- it would require changes to the .pyc file magic
number to do it right, and a more global notion of compiler flags.
- You can usefully combine -Dwarn and -Dnew: this gives the __main__
module new division, and warns about classic division everywhere
else.
Guido van Rossum [Thu, 30 Aug 2001 23:13:11 +0000 (23:13 +0000)]
Give 'super' a decent repr(), and readonly attributes to access the
type and obj properties. The "bogus super object" message is gone --
this will now just raise an AttributeError.
Tim Peters [Thu, 30 Aug 2001 22:05:26 +0000 (22:05 +0000)]
SF bug #456621: normpath on Win32 not collapsing c:\\..
I actually rewrote normpath quite a bit: it had no test cases, and as
soon as I starting writing some I found several cases that didn't make
sense.
Guido van Rossum [Thu, 30 Aug 2001 20:00:07 +0000 (20:00 +0000)]
Pytype_GenericAlloc(): round up size so we zap all four bytes of the
__dict__ slot for string subtypes.
subtype_dealloc(): properly use _PyObject_GetDictPtr() to get the
(potentially negative) dict offset. Don't copy things into local
variables that are used only once.
type_new(): properly calculate a negative dict offset when tp_itemsize
is nonzero. The __dict__ attribute, if present, is now a calculated
attribute rather than a structure member.
Fred Drake [Thu, 30 Aug 2001 19:15:20 +0000 (19:15 +0000)]
Revert the previous patch to test_pow.py and move the test to test_unary.py
based on a suggestion from Tim Peters; also make sure that we're really
doing exponentiation and not multiplication.
Fred Drake [Thu, 30 Aug 2001 18:53:25 +0000 (18:53 +0000)]
When re-writing a factor containing a unary negation of a literal, only
affect nodes without another operator. This was causing negated
exponentiations to drop the exponentiation. This closes SF bug #456756.
Guido van Rossum [Thu, 30 Aug 2001 16:06:23 +0000 (16:06 +0000)]
Do the int inlining only if the type is really an int, not whenever
PyInt_Check() succeeds. That returns true for subtypes of int, which
may override __add__ or __sub__.
Neil Schemenauer [Thu, 30 Aug 2001 00:05:51 +0000 (00:05 +0000)]
Make more things internal to this file. Remove
visit_finalizer_reachable since it's the same as visit_reachable.
Rename visit_reachable to visit_move. Objects can now have the GC type
flag set, reachable by tp_traverse and not be in a GC linked list. This
should make the collector more robust and easier to use by extension
module writers. Add memory management functions for container objects
(new, del, resize).
Neil Schemenauer [Wed, 29 Aug 2001 23:49:28 +0000 (23:49 +0000)]
Change the GC type flag since the API has changed. Allow types using
the old flag to still compile. Remove the PyType_BASICSIZE and
PyType_SET_BASICSIZE macros. Add PyObject_GC_New, PyObject_GC_NewVar,
PyObject_GC_Resize, PyObject_GC_Del, PyObject_GC_Track,
PyObject_GC_UnTrack. Part of SF patch #421893.
Jeremy Hylton [Wed, 29 Aug 2001 22:30:09 +0000 (22:30 +0000)]
Track the block stack more reasonably in order to handle continue in
try/except or try/finally.
Previous versions had only track SETUP_LOOP blocks and ignored the
exception part. This meant that it allowed continue inside a
try/except but generated buggy code. Now it does the right thing.
Tim Peters [Wed, 29 Aug 2001 21:37:10 +0000 (21:37 +0000)]
SF bug [#456252] Python should never stomp on [u]intptr_t.
pyport.h: typedef a new Py_intptr_t type.
DELICATE ASSUMPTION: That HAVE_UINTPTR_T implies intptr_t is
available as well as uintptr_t. If that turns out not to be
true, things must get uglier (C99 wants both, so I think it's
an assumption we're *likely* to get away with).
thread_nt.h, PyThread_start_new_thread: MS _beginthread is documented
as returning unsigned long; no idea why uintptr_t was being used.
Others: Always use Py_[u]intptr_t, never [u]intptr_t directly.
Jack Jansen [Wed, 29 Aug 2001 20:26:24 +0000 (20:26 +0000)]
Workaround by Tim Peters to skip this test if run from test.autotest,
in which case it will hang because the import lock is already held
by the main thread.
Jeremy Hylton [Wed, 29 Aug 2001 19:45:33 +0000 (19:45 +0000)]
Undo change from list to dict for handling varnames, consts, etc.
As the doc string for _lookupName() explains:
This routine uses a list instead of a dictionary, because a
dictionary can't store two different keys if the keys have the
same value but different types, e.g. 2 and 2L. The compiler
must treat these two separately, so it does an explicit type
comparison before comparing the values.
Jeremy Hylton [Wed, 29 Aug 2001 18:12:30 +0000 (18:12 +0000)]
Add support for // and //=.
Avoid if/elif/elif/else tests where the final else is supposed to
handle exactly one case instead of all other cases. When the list of
operators is extended, the catchall else treats all new operators as
the last operator in the set of tests. Instead, raise an exception if
an unexpected operator occurs.
Jeremy Hylton [Wed, 29 Aug 2001 18:08:02 +0000 (18:08 +0000)]
Revise implementations of getChildren() and getChildNodes().
Add support for floor division (// and //=)
The implementation of getChildren() and getChildNodes() is intended to
be faster, because it avoids calling flatten() on every return value.
But it's not clear that it is a lot faster, because constructing a
tuple with just the right values ends up being slow. (Too many
attribute lookups probably.)
The ast.txt file is much more complicated, with funny characters at
the ends of names (*, &, !) to indicate the types of each child node.
The astgen script is also much more complex, making me wonder if it's
still useful.
Guido van Rossum [Wed, 29 Aug 2001 15:47:06 +0000 (15:47 +0000)]
Fix super() so that it is usable for static methods (like __new__) as well.
In particular, the second argument can now be a subclass of the first
as well (normally it must be an instance though).
Jack Jansen [Wed, 29 Aug 2001 15:24:53 +0000 (15:24 +0000)]
GUSI on the Mac creates threads with a default stack size of 20KB, which is
not enough for Python. Increased the stacksize to a (somewhat arbitrary)
64KB.
Barry Warsaw [Wed, 29 Aug 2001 01:41:58 +0000 (01:41 +0000)]
On Fred's suggestion, convert sprintf() examples to use
PyString_FromFormat(). Also fixed one grammar problem, and a few
other mark-up issues. Sample code not checked.
Tim Peters [Tue, 28 Aug 2001 22:21:18 +0000 (22:21 +0000)]
pickle.py, load_int(): Match cPickle's just-repaired ability to unpickle
64-bit INTs on 32-bit boxes (where they become longs). Also exploit that
int(str) and long(str) will ignore a trailing newline (saves creating a
new string at the Python level).
pickletester.py: Simulate reading a pickle produced by a 64-bit box.