Commit Graph

1696 Commits

Author SHA1 Message Date
Martin v. Löwis 314fc79ce8 Patch #542659: Eliminate duplicate check for NULL of freevars/cellvars. 2002-04-14 09:53:49 +00:00
Tim Peters 0e871188e8 _PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Added code to call this when PYMALLOC_DEBUG is enabled, and envar
PYTHONMALLOCSTATS is set, whenever a new arena is obtained and once
late in the Python shutdown process.
2002-04-13 08:29:14 +00:00
Tim Peters 2bbdba3c00 Removed more hair in support of future-generator stmts. 2002-04-12 01:20:10 +00:00
Jack Jansen 8ab04b4d65 Got rid of ifdefs for long-obsolete GUSI versions. 2002-04-11 20:46:23 +00:00
Guido van Rossum 50ee94fd41 is_builtin() is not a Boolean -- it can return -1, 0, 1. [SF #541652] 2002-04-09 18:00:58 +00:00
Marc-André Lemburg 95de5c1631 Move Unicode finalization further down in the chain.
Fixes bug #525620.
2002-04-08 08:19:36 +00:00
Guido van Rossum b8bff3f4a9 Return bools from functions named is_<whatever>(). 2002-04-07 06:34:38 +00:00
Guido van Rossum 55474766f0 Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Bugfix candidate.
2002-04-04 16:22:30 +00:00
Guido van Rossum 77f6a65eb0 Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285.  Everything described in the PEP is here, and there is even
some documentation.  I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison.  I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.

Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.
2002-04-03 22:41:51 +00:00
Neal Norwitz 7829335763 Get rid of another use of PyArg_Parse() 2002-04-01 01:41:20 +00:00
Neal Norwitz 031829d3ef Use symbolic METH_VARARGS instead of 1 for ml_flags 2002-03-31 14:37:44 +00:00
Tim Peters 1f7df3595a Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols. 2002-03-29 03:29:08 +00:00
Neil Schemenauer 835840560b Call PyObject_GC_UnTrack before putting an object on the list of trash. 2002-03-29 03:07:29 +00:00
Skip Montanaro 995895f023 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex 2002-03-28 20:57:51 +00:00
Guido van Rossum cfbf1a33c1 Fix an issue that was reported in but unrelated to the main problem of
SF bug 535905 (Evil Trashcan and GC interaction).

The SETLOCAL() macro should not DECREF the local variable in-place and
then store the new value; it should copy the old value to a temporary
value, then store the new value, and then DECREF the temporary value.
This is because it is possible that during the DECREF the frame is
accessed by other code (e.g. a __del__ method or gc.collect()) and the
variable would be pointing to already-freed memory.

BUGFIX CANDIDATE!
2002-03-28 20:17:52 +00:00
Fred Drake 7bf9715a8b Introduce two new flag bits that can be set in a PyMethodDef method
descriptor, as used for the tp_methods slot of a type.  These new flag
bits are both optional, and mutually exclusive.  Most methods will not
use either.  These flags are used to create special method types which
exist in the same namespace as normal methods without having to use
tedious construction code to insert the new special method objects in
the type's tp_dict after PyType_Ready() has been called.

If METH_CLASS is specified, the method will represent a class method
like that returned by the classmethod() built-in.

If METH_STATIC is specified, the method will represent a static method
like that returned by the staticmethod() built-in.

These flags may not be used in the PyMethodDef table for modules since
these special method types are not meaningful in that case; a
ValueError will be raised if these flags are found in that context.
2002-03-28 05:33:33 +00:00
Neal Norwitz 0c766a0bb6 Change sys_exit to use METH_VARARGS.
sys.exit() now requires 0-1 arguments.  Previously 2+ arguments were allowed.
2002-03-27 13:03:09 +00:00
Tim Peters fdba55fe8e I've been waiting 8 years for KSR to re-emerge from bankruptcy. If they
ever do, they can damn well #define _POSIX_THREADS their own damn selves.
2002-03-25 06:49:10 +00:00
Tim Peters 8e5fd53be0 SF bug 480215: softspace confused in nested print
This fixes the symptom, but PRINT_ITEM has no way to know what (if
anything) PyFile_WriteObject() writes unless the object being printed
is a string.  When the object isn't a string, this fix retains the
guess that softspace should be set after PyFile_WriteObject().
We might want to say that it's the job of filelike-object write methods
to leave the file's softspace in the correct state.  That would probably
be better -- but everyone relies on PRINT_ITEM to guess for them now.
2002-03-24 19:25:00 +00:00
Neil Schemenauer 0f2103fb16 Fix wording of sys.exit docstring. Close SF bug 534113. 2002-03-23 20:46:35 +00:00
Neil Schemenauer c24ea08644 Disable the parser hacks that enabled the "yield" keyword using a future
statement.
2002-03-22 23:53:36 +00:00
Neil Schemenauer 08de92a267 Re-enable GC of generator objects. 2002-03-18 20:45:09 +00:00
Martin v. Löwis 42ab61eeab Document that _POSIX_SEMAPHORES is predefined. 2002-03-17 17:19:00 +00:00
Martin v. Löwis cc89866b65 Patch #525532: Add support for POSIX semaphores. 2002-03-17 09:53:51 +00:00
Martin v. Löwis 7d1cd6947d Patch #504224: add plan9 threads include to thread.c. 2002-03-09 12:10:54 +00:00
Martin v. Löwis 3484a18af1 Patch #494045: patches errno and stat to cope on plan9. 2002-03-09 12:07:51 +00:00
Tim Peters d50e544b9f Docstring for filter(): Someone on the Tutor list reasonably complained
that it didn't tell enough of the truth.
Bugfix candidate (I guess -- it helps and it's harmless).
2002-03-09 00:06:26 +00:00
Martin v. Löwis cfeb3b6ab8 Patch #50002: Display line information for bad \x escapes:
- recognize "SyntaxError"s by the print_file_and_line attribute.
- add the syntaxerror attributes to all exceptions in compile.c.
Fixes #221791
2002-03-03 21:30:27 +00:00
Neal Norwitz 290d31e2fc SF #506611, fix sys.setprofile(), sys.settrace() core dumps
when no arguments are passed
2002-03-03 15:12:58 +00:00
Tim Peters e64ef931d6 SF patch 522961: Leak in Python/thread_nt.h, from Gerald S. Williams.
A file-static "threads" dict mapped thread IDs to Windows handles, but
was never referenced, and entries never got removed.  This gets rid of
the YAGNI-dict entirely.
Bugfix candidate.
2002-02-28 21:34:34 +00:00
Michael W. Hudson 494cdb6d78 Add 2002 to PSF copyrights.
Doc/README is odd; it assigns some copyright to the PSF in 2000, when
I didn't think it existed...
2002-02-27 13:29:46 +00:00
Andrew MacIntyre d940054ad4 OS/2 EMX port changes (Python part of patch #450267):
Python/
    dynload_shlib.c  // EMX port emulates dlopen() etc. for DL extensions
    import.c         // changes to support 8.3 DLL name limit (VACPP+EMX)
                     //  and case sensitive import semantics
    importdl.h
    thread_os2.h
2002-02-26 11:41:34 +00:00
Neil Schemenauer 6354386d65 Move some opcodes to top of big eval_frame switch statement. Skip
things_to_do block for a few common opcodes that don't do any real
work.  Closes SF patch #512256.
2002-02-17 19:10:14 +00:00
Tim Peters 373f8d81ff LOAD_FAST: rearrange branches to favor the expected case, and get
rid of a redundant NULL-pointer check in the expected case.
2002-02-12 04:31:21 +00:00
Jack Jansen 58e7a68dea Removed a spurious }. (How did it get there in the first place??) 2002-02-11 16:21:00 +00:00
Marc-André Lemburg bd3be8f0ca Fix to the UTF-8 encoder: it failed on 0-length input strings.
Fix for the UTF-8 decoder: it will now accept isolated surrogates
(previously it raised an exception which causes round-trips to
fail).

Added new tests for UTF-8 round-trip safety (we rely on UTF-8 for
marshalling Unicode objects, so we better make sure it works for
all Unicode code points, including isolated surrogates).

Bumped the PYC magic in a non-standard way -- please review. This
was needed because the old PYC format used illegal UTF-8 sequences
for isolated high surrogates which now raise an exception.
2002-02-07 11:33:49 +00:00
Jack Jansen a762f4ca18 Got rid of an extra level of {} and funny formatting that was still
there because of the NeXT history.
2002-02-01 22:24:56 +00:00
Jack Jansen d4c76bf65a A new dynload_next, which actually only works on OSX but isn't renamed yet.
By default every module is imported in its own namespace, but this can
be changed by defining USE_DYLD_GLOBAL_NAMESPACE. In a future version this
define will be replaced by a runtime setting, but that needs a bit more
thought.

This code is largely based on code and feedback from Steven Majewski,
Marcel Prastawa, Manoj Plakal and other on pythonmac-sig.
2002-02-01 16:01:05 +00:00
Neal Norwitz 150d09d360 Fix missing space between words. Bugfix candidate. 2002-01-29 00:56:37 +00:00
Neal Norwitz 2a47c0fa23 Fix spelling mistakes. Bugfix candidates. 2002-01-29 00:53:41 +00:00
Martin v. Löwis fb0da9d770 Test for error status of shl_findsym. Fixes #505417. 2.2.1 candiate. 2002-01-26 20:03:48 +00:00
Michael W. Hudson ff06671acf Fix for
[ #496154 ] Typos in dynload_beos.c

as suggested in the report.  A little embarassing; 2.2.1 candidate for sure.
2002-01-23 15:51:12 +00:00
Fred Drake 7bb1c9a11d Remove the unused & broken PyThread_*_sema() functions and related constants.
This closes SF patch #504215.
2002-01-19 22:02:55 +00:00
Guido van Rossum 340cbe74b9 A tentative fix for SF bug #503837 (Roeland Rengelink):
type.__module__ problems (again?)

This simply initializes the __module__ local in a class statement from
the __name__ global.  I'm not 100% sure that this is the correct fix,
although it usually does the right thing.  The problem is that if the
class statement executes in a custom namespace, the __name__ global
may be taken from __builtins__, in which case it would have the value
__builtin__, or it may not exist at all (if the custom namespace also
has a custom __builtins__), in which case the class statement will
fail.

Nevertheless, unless someone finds a better solution, this is a 2.2.1
bugfix too.
2002-01-15 21:06:07 +00:00
Jack Jansen 7668957508 Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
on a function pointer formal argument called "destructor", which is typedeffed
as a different function pointer type in object.h.
2002-01-15 20:36:14 +00:00
Martin v. Löwis cdc4451222 Include <unistd.h> in Python.h. Fixes #500924. 2002-01-12 11:05:12 +00:00
Marc-André Lemburg 3e3eacb5fc Fixed "u#" parser marker to pass through Unicode objects as-is without
going through the buffer interface API.

Added tests for this to the _testcapi module and updated docs.
2002-01-09 16:21:27 +00:00
Martin v. Löwis 7198a525f3 Patch #494783: Rename cmp_op enumerators. 2002-01-01 19:59:11 +00:00
Martin v. Löwis a6e975801e Patch #497098: build support for GNU/Hurd. 2002-01-01 18:41:33 +00:00
Tim Peters 54b11918be SF bug #496549 -Qnew and in-place division "/=".
eval_frame():  Under -Qnew, INPLACE_DIVIDE wasn't getting handed off to
INPLACE_TRUE_DIVIDE (like BINARY_DIVIDE was getting handed off to
BINARY_TRUE_DIVIDE).

Bugfix candidate.
2001-12-25 18:49:11 +00:00
Barry Warsaw b2dd86defe PyOS_vsnprintf(): Change PyMem_Malloc() call to PyMem_MALLOC() macro,
(ditto for PyMem_Free() -> PyMem_FREE()) to fix and close SF bug
#495875 on systems that HAVE_SNPRINTF=0.

Check in on both release-22 branch and trunk.
2001-12-21 16:32:15 +00:00
Tim Peters b6d14daa1c SF bug #494668: PUSH() should assert-fail on overflow.
eval_frame():  Added asserts to the top of the eval loop, to verify
that the eval stack pointer is in bounds, plus some comments.
2001-12-19 04:11:07 +00:00
Martin v. Löwis 8d3ce5a6b3 Patch #494384: Disable more Unicode API if Unicode is not used. 2001-12-18 22:36:40 +00:00
Tim Peters b519638d1e _PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
to Guido for the revelation).
2001-12-16 19:44:20 +00:00
Tim Peters cb479e78e0 _PyEval_SliceIndex(): Repaired the comments, and added XXX comments
about its dubious treatment of NULL (also opened a bug report on that,
but don't want to risk changing it this late in the 2.2 game).
2001-12-16 19:11:44 +00:00
Jeremy Hylton 733c8935f9 Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Based on the patch from Danny Yoo.  The fix is in exec_statement() in
ceval.c.

There are also changes to introduce use of PyCode_GetNumFree() in
several places.
2001-12-13 19:51:56 +00:00
Jeremy Hylton 2990640d8a Add a comment explaining the st_symbols cache. 2001-12-10 00:53:18 +00:00
Tim Peters 0f2d4b84a6 PySymtableEntry_New(): I'm not sure what this routine is doing, but it
was obviously leaking an int object when whatever the heck it's looking for
was found.  Repaired that.  This accounts for why entering function and
class definitions at an interactive prompt leaked a reference to the
integer 1 each time.
Bugfix candidate.
2001-12-08 23:40:38 +00:00
Jeremy Hylton 0702858d73 Missing DECREFs when exception is raised in sys.excepthook.
Bug fix candidate for 2.1 branch.

(I imagine the other recent leak patches are bug fix candidates, too,
but I forgot to mark mine as such.)
2001-12-07 15:35:35 +00:00
Jack Jansen e3d7622fb3 Don't fail on importing things with undefined references. Unfortunately we
still fail on importing modules that link with libraries that fail
their initialization code (such as windowing libraries when we don't have
access to the window server) and that is what I really wanted to fix.
2001-12-06 22:58:56 +00:00
Guido van Rossum 35974fbf31 Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Had nothing to do with rich comparisons -- some stack cleanup code was
lost as a result of merging in Neil Schemenauer's generators patch.
Reinserted the stack cleanup code, skipping it when yielding.
2001-12-06 21:28:18 +00:00
Guido van Rossum 2556f2e1e2 Fix a typo (probably caused by autocompletion <blush>) that caused a
leak when a class defined a __metaclass__.  This fixes the problem
reported on python-dev by Ping; I dunno if it's the same as SF bug
#489669 (since that mentions Unicode).
2001-12-06 14:09:56 +00:00
Tim Peters 3caca2326e SF bug #488514: -Qnew needs work
Big Hammer to implement -Qnew as PEP 238 says it should work (a global
option affecting all instances of "/").

pydebug.h, main.c, pythonrun.c:  define a private _Py_QnewFlag flag, true
iff -Qnew is passed on the command line.  This should go away (as the
comments say) when true division becomes The Rule.  This is
deliberately not exposed to runtime inspection or modification:  it's
a one-way one-shot switch to pretend you're using Python 3.

ceval.c:  when _Py_QnewFlag is set, treat BINARY_DIVIDE as
BINARY_TRUE_DIVIDE.

test_{descr, generators, zipfile}.py:  fiddle so these pass under
-Qnew too.  This was just a matter of s!/!//! in test_generators and
test_zipfile.  test_descr was trickier, as testbinop() is passed
assumptions that "/" is the same as calling a "__div__" method; put
a temporary hack there to call "__truediv__" instead when the method
name is "__div__" and 1/2 evaluates to 0.5.

Three standard tests still fail under -Qnew (on Windows; somebody
please try the Linux tests with -Qnew too!  Linux runs a whole bunch
of tests Windows doesn't):
    test_augassign
    test_class
    test_coercion
I can't stay awake longer to stare at this (be my guest).  Offhand
cures weren't obvious, nor was it even obvious that cures are possible
without major hackery.

Question:  when -Qnew is in effect, should calls to __div__ magically
change into calls to __truediv__?  See "major hackery" at tail end of
last paragraph <wink>.
2001-12-06 06:23:26 +00:00
Guido van Rossum 6b70599450 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
There's now a new structmember code, T_OBJECT_EX, which is used for
all __slot__ variables (except __weakref__, which has special behavior
anyway).  This new code raises AttributeError when the variable is
NULL rather than converting NULL to None.
2001-12-04 16:23:42 +00:00
Jeremy Hylton 86424e333f SF bug #488687 reported by Neal Norwitz
The error for assignment to __debug__ used ste->ste_opt_lineno instead
of n->n_lineno.  The latter was at best incorrect; often the slot was
uninitialized.  Two fixes here: Use the correct lineno for the error.
Initialize ste_opt_lineno in PySymtable_New(); while there are no
current cases where it is referenced unless it has already been
assigned to, there is no harm in initializing it.
2001-12-04 02:41:46 +00:00
Tim Peters 22a51efc1c More sprintf -> PyOS_snprintf. 2001-12-04 01:11:32 +00:00
Guido van Rossum 354797ccad Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
and assign_slice() weren't properly DECREF'ing the temporary slice
object they created.  (Shame on me. :-)
2001-12-03 19:45:06 +00:00
Guido van Rossum bb8f59a371 unpack_iterable(): Add a missing DECREF in an error case. Reported by
Armin Rigo (SF bug #488477).  Added a testcase to test_unpack_iter()
in test_iter.py.
2001-12-03 19:33:25 +00:00
Tim Peters faad5ad590 mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, to
use wrappers on all platforms, to make this as consistent as possible x-
platform (in particular, make sure there's at least one \0 byte in
the output buffer).  Also document more of the truth about what these do.

getargs.c, seterror():  Three computations of remaining buffer size were
backwards, thus telling PyOS_snprintf the buffer is larger than it
actually is.  This matters a lot now that PyOS_snprintf ensures there's a
trailing \0 byte (because it didn't get the truth about the buffer size,
it was storing \0 beyond the true end of the buffer).

sysmodule.c, mywrite():  Simplify, now that PyOS_vsnprintf guarantees to
produce a \0 byte.
2001-12-03 00:43:33 +00:00
Tim Peters 080d5b3f0b mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
ends.  Also, when there is trouble, ensure the buffer has a traiing
0 byte.
2001-12-02 08:29:16 +00:00
Guido van Rossum 64be0b4aa5 When the number of bytes written to the malloc'ed buffer is larger
than the argument string size, copy as many bytes as will fit
(including a terminating '\0'), rather than not copying anything.
This to make it satisfy the C99 spec.
2001-12-01 16:00:10 +00:00
Tim Peters cffed4bc21 SF bug 486278 SystemError: Python/getargs.c:1086: bad.
vgetargskeywords():  Now that this routine is checking for bad input
(rather than dump core in some cases), some bad calls are raising errors
that previously "worked".  This patch makes the error strings more
revealing, and changes the exceptions from SystemError to RuntimeError
(under the theory that SystemError is more of a "can't happen!" assert-
like thing, and so inappropriate for bad arguments to a public C API
function).
2001-11-29 03:26:37 +00:00
Jeremy Hylton b048b26db0 Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Also change all the helper functions to pass along the size of the
msgbuf and use PyOS_snprintf() when writing into the buffer.
2001-11-28 22:14:37 +00:00
Tim Peters 75cdad5584 More sprintf -> PyOS_snprintf. 2001-11-28 22:07:30 +00:00
Jeremy Hylton f16e05e7ec Use PyOS_snprintf() at some cost even though it was correct before.
seterror() uses a char array and a pointer to the current position in
that array.  Use snprintf() and compute the amount of space left in
the buffer based on the current pointer position.
2001-11-28 21:46:59 +00:00
Jeremy Hylton 5d3d134d56 Use PyOS_vsnprintf() and check its return value.
If it returns -1 (which indicates overflow on old Linux platforms and
perhaps on Windows) or size greater than buffer, write a message
indicating that the previous message was truncated.
2001-11-28 21:44:53 +00:00
Barry Warsaw 4b4ab20f2c ste_repr(): Conversion of sprintf() to PyOS_snprintf() for buffer
overrun avoidance.
2001-11-28 21:36:28 +00:00
Barry Warsaw 857bf52d56 aix_loaderror(): Conversion of sprintf() to PyOS_snprintf() for buffer
overrun avoidance.
2001-11-28 21:35:49 +00:00
Barry Warsaw 8f6d868bbb code_repr(), com_addop_varname(), com_list_comprehension(),
com_arglist(), symtable_check_unoptimized(), symtable_params(),
symtable_global(), symtable_list_comprehension():

    Conversion of sprintf() to PyOS_snprintf() for buffer overrun
    avoidance.
2001-11-28 21:10:39 +00:00
Jeremy Hylton 518ab1c02a Use PyOS_snprintf instead of sprintf. 2001-11-28 20:42:20 +00:00
Jeremy Hylton ef58b31991 Use PyOS_snprintf instead of sprintf.
Also replace a switch statement with one case and a default to an
if/else.
2001-11-28 20:37:25 +00:00
Jeremy Hylton 23ae987401 Use PyOS_snprintf when possible. 2001-11-28 20:29:22 +00:00
Jeremy Hylton 05bd787c6c Use PyOS_snprintf instead of sprintf.
Just being sure.  The old code looks like it was safe, but there's no
harm in double-checking.
2001-11-28 20:24:33 +00:00
Marc-André Lemburg d4c0a9c59b Fixes for possible buffer overflows in sprintf() usages. 2001-11-28 11:47:00 +00:00
Tim Peters b13680bf03 SF bug #483469: crash on unbounded recursion in __del__.
PyEval_EvalCodeEx():  increment tstate->recursion_depth around the
decref of the frame, because the C stack for this call is still in
use and the decref can lead to __del__ methods getting called.

While this gives tstate->recursion_depth a value proportional to the
depth of the C stack (instead of a small constant no matter how
deeply __del__s recurse), it's not enough to stop the reported crash
when using the default recursion limit on Windows.

Bugfix candidate.
2001-11-27 23:29:29 +00:00
Tim Peters 6d20b43a4e SF bug 485175: buffer overflow in traceback.c.
Bugfix candidate.
tb_displayline():  the sprintf format was choking off the file name, but
used plain %s for the function name (which can be arbitrarily long).
Limit both to 500 chars max.
2001-11-27 20:30:42 +00:00
Marc-André Lemburg 0c4d8d05a8 Fix for bug #480188: printing unicode objects 2001-11-20 15:17:25 +00:00
Tim Peters 36515e28ed Since the MAGIC number scheme is going to break on January 1st, document
what it is more carefully and point out some of the subtleties.
2001-11-18 04:06:29 +00:00
Barry Warsaw afeb2a4d89 PyOS_getsig(), PyOS_setsig(): The minimal amount of work to avoid the
uninitialized memory reads reported in bug #478001.

Note that this doesn't address the following larger issues:

- Error conditions are not documented for PyOS_*sig() in the C API.

- Nothing that actually calls PyOS_*sig() in the core interpreter and
  extension modules actually /checks/ the return value of the call.

Fixing those is left as an exercise for a later day.
2001-11-13 23:08:26 +00:00
Jeremy Hylton 9f64caaf00 Use PyObject_CheckReadBuffer(). 2001-11-09 22:02:48 +00:00
Martin v. Löwis 107b7daf5a Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571. 2001-11-09 20:59:39 +00:00
Jeremy Hylton 778e265462 Fix SF buf #480096: Assign to __debug__ still allowed
Easy enough to catch assignment in the compiler.  The perverse user
can still change the value of __debug__, but that may be the least he
can do.
2001-11-09 19:50:08 +00:00
Fred Drake 03459a5cd7 Fix memory leak. This is part of SF patch #478006. 2001-11-09 16:00:41 +00:00
Marc-André Lemburg 4962fc8fed Backing out the fast path for interned string compares again as requested. 2001-11-08 08:34:43 +00:00
Marc-André Lemburg c52d713b7a Add fast-path for comparing interned (true) string objects.
This patch boosts performance for comparing identical string object
by some 20% on my machine while not causing any noticable slow-down
for other operations (according to tests done with pybench).
2001-11-07 14:54:49 +00:00
Jack Jansen 537a69fe66 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me. 2001-11-05 14:39:22 +00:00
Tim Peters 603c6831d0 SF patch 473749 compile under OS/2 VA C++, from Michael Muller.
Changes enabling Python to compile under OS/2 Visual Age C++.
2001-11-05 02:45:59 +00:00
Tim Peters 8c5e41559c Part of SF bug #478003 possible memory leaks in err handling.
PyNode_CompileSymtable:  if symtable_init() fails, free the memory
allocated for the PyFutureFeatures struct.
2001-11-04 19:26:58 +00:00
Jack Jansen 666b1e7e2f Link the core with CoreServices, not with Carbon, and don't use any Carbon
routines. As of 10.1 using Carbon will crash Python if no window server is
available (ssh connection, console mode, MacOSX Server). This fixes bug
#466907.

A result of this mod is that the default 8bit encoding on OSX is now ASCII,
for the time being. Also, the extension modules that need the Carbon
framework now explicitly include it in setup.py.
2001-10-31 12:11:48 +00:00
Tim Peters a6ca4f40d0 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Muller.
2001-10-31 03:50:45 +00:00
Jack Jansen 550fdae2f5 On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism. 2001-10-30 13:08:39 +00:00
Tim Peters a427a2b8d0 Rename "dictionary" (type and constructor) to "dict". 2001-10-29 22:25:45 +00:00
Tim Peters c2f011201a vgetargskeywords()
+ Squash another potential buffer overrun.
+ Simplify the keyword-arg loop by decrementing the count of keywords
  remaining instead of incrementing Yet Another Variable; also break
  out early if the number of keyword args remaining hits 0.

Since I hit the function's closing curly brace with this patch, that's
enough of this for now <wink>.
2001-10-27 07:25:06 +00:00
Tim Peters b639d49798 vgetargskeywords: Now that it's clear that nkwlist must equal max, and
we're ensuring that's true during the format parse, get rid of nkwlist.
2001-10-27 07:00:56 +00:00
Tim Peters dc5eff9170 vgetargskeywords: Prevent another potential sprintf buffer overrun. 2001-10-27 06:53:00 +00:00
Tim Peters 62d48e1735 vgetargskeywords: Verify kwlist has the required length while parsing
the format, instead of waiting until after we can overindex it by
mistake.
2001-10-27 06:42:16 +00:00
Tim Peters 0af4916ad4 vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
this routine will report an error now when it didn't before, but, if so,
it's a legitimate error that should never have been suppressed.
2001-10-27 06:14:32 +00:00
Tim Peters 077f574db1 vgetargskeywords: The keywords arg is a dict (if non-NULL), so use the
dict API everywhere on it instead of sometimes using the slower mapping
API.
2001-10-27 05:50:39 +00:00
Tim Peters 61dde63e3b vgetargskeywords: Removed one of the mysterious PyErr_Clear() calls.
The "need" for this was probably removed by an earlier patch that stopped
the loop right before it from passing NULL to a dict lookup routine.
I still haven't convinced myself that the next loop is correct, so am
leaving the next mysterious PyErr_Clear() call in for now.
2001-10-27 05:30:17 +00:00
Tim Peters b054be41c0 vgetargskeywords:
+ Generally test nkeywords against 0 instead of keywords against NULL
  (saves a little work if an empty keywords dict is passed, and is
  conceptually more on-target regardless).
+ When a call erroneously specifies a keyword argument both by position
  and by keyword name:
    - It was easy to provoke this routine into an internal buffer overrun
      by using a long argument name.  Now uses PyErr_format instead (which
      computes a safe buffer size).
    - Improved the error msg.
2001-10-27 05:07:41 +00:00
Tim Peters b0872fc8a6 vgetargskeywords:
+ Got rid of now-redundant dict typecheck.
+ Renamed nkwds to nkwlist.  Now all the "counting" vrbls have names
  related to the things they're counting in an obvious way.
2001-10-27 04:45:34 +00:00
Tim Peters 6fb2635f25 vgetargskeywords:
+ Renamed argslen to nargs.
+ Renamed kwlen to nkeywords.  This one was especially confusing because
  kwlen wasn't the length of the kwlist argument, but of the keywords
  argument.
2001-10-27 04:38:11 +00:00
Tim Peters 28bf7a9770 vgetargskeywords:
+ Removed now-redundant tuple typecheck.
+ Renamed "tplen" local to "argslen" (it's the length of the "args"
  argument; I suppose "tp" was for "Tim Peters should rename me
  someday <wink>).
2001-10-27 04:33:41 +00:00
Tim Peters f8cd3e8621 PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
introduced this bug just a little while ago, when *adding* internal error
checks).

vgetargskeywords:  Rewrote the section that crawls over the format string.
+ Added block comment so it won't take the next person 15 minutes to
  reverse-engineer what it's doing.
+ Lined up the "else" clauses.
+ Rearranged the ifs in decreasing order of likelihood (for speed).
2001-10-27 04:26:57 +00:00
Tim Peters 45772cde7e PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
and raise an error if they're insane.
vgetargskeywords:  the same, except that since this is an internal routine,
just assert that the arguments are sane.
2001-10-27 03:58:40 +00:00
Tim Peters a9f4739a1b tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed
the kwlist vector whenever there was a mix of positional and keyword
arguments, and the number of positional arguments exceeded the length
of the kwlist vector.  If there was just one more positional arg than
keyword, the kwlist-terminating NULL got passed to PyMapping_HasKeyString,
which set an internal error that vgetargskeywords() then squashed (but
it's impossible to say whether it knew it was masking an error).  If
more than one more positional argument, it went on to pass random trash
to PyMapping_HasKeyString, which is why the example at the start
happened to kill the process.

Pure bugfix candidate.
2001-10-27 00:46:09 +00:00
Tim Peters f4331c1c38 vgetargskeywords(): remove test that can't succeed. Not a bugfix, just
removing useless obfuscation.
2001-10-27 00:17:34 +00:00
Fred Drake 9cd0efcee9 Use PyDict_Copy() and PyDict_Update() instead of using PyObject_CallMethod()
to call the corresponding methods.  This is not a performance improvement
since the times are still swamped by disk I/O, but cleans up the code just
a little.
2001-10-25 21:38:59 +00:00
Fred Drake a768882b00 Convert getrefcount() to METH_O, and sys_excepthook() to use
PyArg_UnpackTuple().
2001-10-24 20:47:48 +00:00
Guido van Rossum e2ae77b8b8 SF patch #474590 -- RISC OS support 2001-10-24 20:42:55 +00:00
Fred Drake e4616e6752 PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fulton, based on code Jim supplied.
2001-10-23 21:09:29 +00:00
Fred Drake 563dfc2f73 Style conformance: function name begins a new line *consistently*.
Make convertbuffer() static like the prototype says.  Not used elsewhere.
2001-10-23 14:41:08 +00:00
Jeremy Hylton fd14d8e187 Make traceback objects collectable.
This should eliminate the traceback returned by sys.exc_info() as a
common source of memory leaks.
2001-10-22 22:17:41 +00:00
Tim Peters d7c3652aa7 Removed two pointless and obfuscating macros. 2001-10-22 19:34:09 +00:00
Guido van Rossum b8cf3e64be SF patch #470393 (Jim Ahlstrom): Add missing marshal function
In Include/, marshal.h declares both
    PyMarshal_ReadLongFromFile()
    and PyMarshal_ReadShortFromFile(),
    but the second is missing from marshal.c.

[Shouldn't the return type be declared as 'short' instead of 'int'?
But 'int' is what was in marshal.h all those years...  --Guido]
2001-10-19 01:46:21 +00:00
Martin v. Löwis 8a57f00081 Move dlfcn.h block out of NetBSD block, assuming that NetBSD before
199712 didn't have dlfcn.h, or that it wouldn't conflict with the other
stuff defined.
2001-10-18 21:24:04 +00:00
Tim Peters 6e6a63f01c SF Patch (but with no patch) 472555 Remove trailing common in enumeration.
Some AIX compiler didn't like the trailing comma at the end of the
why_code enum decl.
2001-10-18 20:49:35 +00:00
Tim Peters 84a0657ee9 Squash compiler wng about signed/unsigned mismatch. 2001-10-18 18:57:31 +00:00
Guido van Rossum 8f4d3316de First part of SF patch #416704: More robust freeze, by Toby Dickenson.
This fixes the behavior reported by SF bug #404545, where a file
x.y.py could be imported by the statement "import x.y" when there's a
frozen package x (I believe even if x.y also exists as a frozen
module).
2001-10-18 18:54:11 +00:00
Guido van Rossum 4114a4afec Fix the frozen bytecode for __hello__ (betcha didn't know that existed
:-).

Add a test that prevents the __hello__ bytecode from going stale
unnoticed again.

The test also tests the loophole noted in SF bug #404545.  This test
will fail right now; I'll check in the fix in a minute.
2001-10-18 18:49:37 +00:00
Jeremy Hylton 961dfe0d85 Fix for SF bug [ #471928 ] global made w/nested list comprehensions
The symbol table pass didn't have an explicit case for the list_iter
node which is used only for a nested list comprehension.  As a result,
the target of the list comprehension was treated as a use instead of
an assignment.  Fix is to add a case to symtable_node() to handle
list_iter.

Also, rework and document a couple of the subtler implementation
issues in the symbol table pass.  The symtable_node() switch statement
depends on falling through the last several cases, in order to handle
some of the more complicated nodes like atom.  Add a comment
explaining the behavior before the first fall through case.  Add a
comment /* fall through */ at the end of case so that it is explicitly
marked as such.

Move the for_stmt case out of the fall through logic, which simplifies
both for_stmt and default.  (The default used the local variable start
to skip the first three nodes of a for_stmt when it fell through.)

Rename the flag argument to symtable_assign() to def_flag and add a
comment explaining its use:

   The third argument to symatble_assign() is a flag to be passed to
   symtable_add_def() if it is eventually called.  The flag is useful
   to specify the particular type of assignment that should be
   recorded, e.g. an assignment caused by import.
2001-10-18 16:15:10 +00:00
Martin v. Löwis 0eb1ed556b Patch to bug #472202: Correctly recognize NetBSD before 199712. 2001-10-18 11:45:19 +00:00
Jeremy Hylton 14368158c2 For debug build, check that the stack pointer never exceeds the stack size. 2001-10-17 13:29:30 +00:00
Jeremy Hylton 93a569d634 Fix computation of stack depth for classdef and closures.
Also minor tweaks to internal routines.
Use PyCF_MASK instead of explicit list of flags.

For the MAKE_CLOSURE opcode, the number of items popped off the stack
depends on both the oparg and the number of free variables for the
code object.  Fix the code so it accounts for the free variables.

In com_classdef(), record an extra pop to account for the STORE call
after the BUILD_CLASS.

Get rid of some commented out debugging code in com_push() and
com_pop().

Factor string resize logic into helper routine com_check_size().

In com_addbyte(), remove redudant if statement after assert.  (They
test the same condition.)

In several routines, use string macros instead of string functions.
2001-10-17 13:22:22 +00:00
Guido van Rossum 2c40adb1e4 Fix a bug in the previous checkin. The wrong bootstrap function was
passed to _beginthread().
2001-10-16 21:50:04 +00:00
Guido van Rossum d892357bf7 SF patch #471852 (anonymous) notes that getattr(obj, name, default)
masks any exception, not just AttributeError.  Fix this.
2001-10-16 21:31:32 +00:00
Guido van Rossum 3c28863e08 Partial patch from SF #452266, by Jason Petrone.
This changes Pythread_start_thread() to return the thread ID, or -1
for an error.  (It's technically an incompatible API change, but I
doubt anyone calls it.)
2001-10-16 21:13:49 +00:00
Guido van Rossum ae9e7960d3 SF patch #471839: Bug when extensions import extensions (Shane Hathaway)
When an extension imports another extension in its
    initXXX() function, the variable _Py_PackageContext is
    prematurely reset to NULL. If the outer extension then
    calls Py_InitModule(), the extension is installed in
    sys.modules without its package name. The
    manifestation of this bug is a "SystemError:
    _PyImport_FixupExtension: module <package>.<extension>
    not loaded".

    To fix this, importdl.c just needs to retain the old
    value of _Py_PackageContext and restore it after the
    initXXX() method is called. The attached patch does this.

    This patch applies to Python 2.1.1 and the current CVS.
2001-10-16 20:07:34 +00:00
Jeremy Hylton 26633f4c00 Put descr name in "bad memberdescr type" error message. 2001-10-16 16:51:56 +00:00
Skip Montanaro f118cb1d6f make getarray static - it's only called from ceval.c and is not an
extern-able name.
2001-10-15 20:51:38 +00:00
Guido van Rossum 1c917072ca Very subtle syntax change: in a list comprehension, the testlist in
"for <var> in <testlist> may no longer be a single test followed by
a comma.  This solves SF bug #431886.  Note that if the testlist
contains more than one test, a trailing comma is still allowed, for
maximum backward compatibility; but this example is not:

    [(x, y) for x in range(10), for y in range(10)]
                              ^

The fix involved creating a new nonterminal 'testlist_safe' whose
definition doesn't allow the trailing comma if there's only one test:

    testlist_safe: test [(',' test)+ [',']]
2001-10-15 15:44:05 +00:00
Martin v. Löwis 69c0ff3836 Do not define _POSIX_THREADS if unistd.h defines it.
Check for pthread_sigmask before using it. Fixes remaining problem in #470781.
2001-10-15 14:34:42 +00:00
Fred Drake de26cfc1e1 Suppress a bunch of "value computed is not used" warnings when building in
debug mode (--with-pydebug).
2001-10-13 06:11:28 +00:00
Guido van Rossum 9abaf4d3b7 SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
This patch changes to logic to:

   if env.var. set and non-empty:
       if env.var. is an integer:
           set flag to that integer
   if flag is zero: # [actually, <= 0 --GvR]
       set flag to 1

   Under this patch, anyone currently using
   PYTHONVERBOSE=yes will get the same output as before.

   PYTHONVERBNOSE=2 will generate more verbosity than
   before.

   The only unusual case that the following three are
   still all equivalent:
   PYTHONVERBOSE=yespleas
   PYTHONVERBOSE=1
   PYTHONVERBOSE=0
2001-10-12 22:17:56 +00:00
Guido van Rossum 80230998b9 Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
This patch updates Python/thread_pthread.h to mask all
   signals for any thread created. This will keep all
   signals masked for any thread that isn't the initial
   thread. For Solaris and Linux, the two platforms I was
   able to test it on, it solves bug #465673 (pthreads
   need signal protection) and probably will solve bug
   #219772 (Interactive InterPreter+ Thread -> core dump
   at exit).

   I'd be great if this could get some testing on other
   platforms, especially HP-UX pre 11.00 and post 11.00,
   as I had to make some guesses for the DCE thread case.
   AIX is also a concern as I saw some mention of using
   sigthreadmask() as a pthread_sigmask() equivalent, but
   this patch doesn't use sigthreadmask(). I don't have
   access to AIX.
2001-10-12 21:49:17 +00:00
Jeremy Hylton 4819e97a48 Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
convertbuffer() uses the buffer interface's getreadbuffer(), but 't'
should use getcharbuffer().
2001-10-11 14:40:37 +00:00
Jeremy Hylton 0407aeae01 One more place where PyString_AsString() was used after a
PyString_Check() had already succeeded.
2001-10-10 02:51:57 +00:00
Jeremy Hylton a4c8cd7b2c Use AS_STRING() following the check and avoid an extra call. 2001-10-10 02:51:08 +00:00
Guido van Rossum 03290ecbf1 Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
not other sequences (then we'd have to except strings, and we'd still
be susceptible to recursive attacks).
2001-10-07 20:54:12 +00:00
Fred Drake bb9fa21cfe weakref.ReferenceError becomes a built-in exception now that weak ref objects
are moving into the core; with these changes, it will be possible for the
exception to be raised without the weakref module ever being imported.
2001-10-05 21:50:08 +00:00