Commit Graph

185 Commits

Author SHA1 Message Date
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Guido van Rossum 582acece2e Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
tests.
2000-06-28 22:07:35 +00:00
Guido van Rossum 20c6add7ff Trent Mick:
Change static slice_index() to extern _PyEval_SliceIndex() (with
different return value interpretation: 0 for failure, 1 for success).
2000-05-08 14:06:50 +00:00
Guido van Rossum cc229ea76f Add useless 'return 1' to prtrace() to shut up VC++. 2000-05-04 00:55:17 +00:00
Guido van Rossum b18618dab7 Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives.
For documentation read the comments in mymalloc.h and objimpl.h.

(This is not exactly what Vladimir posted to the patches list; I've
made a few changes, and Vladimir sent me a fix in private email for a
problem that only occurs in debug mode.  I'm also holding back on his
change to main.c, which seems unnecessary to me.)
2000-05-03 23:44:39 +00:00
Guido van Rossum 25826c93c4 Charles Waldman writes:
"""
Running "test_extcall" repeatedly results in memory leaks.

One of these can't be fixed (at least not easily!), it happens since
this code:

def saboteur(**kw):
    kw['x'] = locals()
d = {}
saboteur(a=1, **d)

creates a circular reference - d['x']['d']==d

The others are due to some missing decrefs in ceval.c, fixed by the
patch attached below.

Note:  I originally wrote this without the "goto", just adding the
missing decref's where needed.  But I think the goto is justified in
keeping the executable code size of ceval as small as possible.
"""

[I think the circular reference is more like kw['x']['kw'] == kw. --GvR]
2000-04-21 21:17:39 +00:00
Guido van Rossum 5db862dd0c Skip Montanaro: add string precisions to calls to PyErr_Format
to prevent possible buffer overruns.
2000-04-10 12:46:51 +00:00
Guido van Rossum 7a5b796322 Thomas Heller fixes a typo in an error message. 2000-03-31 13:52:29 +00:00
Jeremy Hylton 387b1011a1 rename args variable in CALL_FUNCTION to callargs (avoids name
override)

add missing DECREFs in error handling code of CALL_FUNCTION
2000-03-31 01:22:54 +00:00
Jeremy Hylton 074c3e62d1 Two fixes for extended call syntax:
If a non-tuple sequence is passed as the *arg, convert it to a tuple
before checking its length.
If named keyword arguments are used in combination with **kwargs, make
a copy of kwargs before inserting the new keys.
2000-03-30 23:55:31 +00:00
Barry Warsaw b2ba9d8963 eval_code2(): Oops, in the last checkin, we shouldn't check for
PyErr_Occurred(), just set x=NULL and break.  Oh, and make Jeremy stop
nagging me about the "special" indentation for this block.
2000-03-29 18:36:49 +00:00
Barry Warsaw 4961ef7086 eval_code2(): In the extended calling syntax opcodes, you must check
the return value of PySequence_Length().  If an exception occurred,
the returned length will be -1.  Make sure this doesn't get obscurred,
and that the bogus length isn't used.
2000-03-29 18:30:03 +00:00
Jeremy Hylton 7690151c7e slightly modified version of Greg Ewing's extended call syntax patch
executive summary:
Instead of typing 'apply(f, args, kwargs)' you can type 'f(*arg, **kwargs)'.
Some file-by-file details follow.

Grammar/Grammar:
    simplify varargslist, replacing '*' '*' with '**'
    add * & ** options to arglist

Include/opcode.h & Lib/dis.py:
    define three new opcodes
        CALL_FUNCTION_VAR
        CALL_FUNCTION_KW
        CALL_FUNCTION_VAR_KW

Python/ceval.c:
    extend TypeError "keyword parameter redefined" message to include
        the name of the offending keyword
    reindent CALL_FUNCTION using four spaces
    add handling of sequences and dictionaries using extend calls
    fix function import_from to use PyErr_Format
2000-03-28 23:49:17 +00:00
Andrew M. Kuchling 2194b165db Allow using long integers as slice indexes 2000-02-23 22:18:48 +00:00
Fred Drake 145c26e3d3 Remove comment that Guido agree's doesn't make sense:
PyEval_EvalCode() is *not* a "backward compatible interface", it's the
one to use!
2000-02-21 17:59:48 +00:00
Guido van Rossum a400d8a96d Fix a bug in exec_statement() noted incidentally by Tim Peters in
PR#175 -- when exec is passed a code object, it didn't sync the locals
from the dictionary back into their fast representation.

Also took the time to remove some repetitive code there and to do the
syncing even when an exception is raised (since a partial effect
should still be synced).
2000-01-12 22:45:54 +00:00
Guido van Rossum ba98a42a0f Change the last PyErr_Format %s format to %.400s. 1999-11-15 19:29:33 +00:00
Guido van Rossum 25da5bebd8 Fix PR117. The error message is "keywords must be strings". Perhaps
not as descriptive as what Barry suggests, but this also catches the
(in my opinion important) case where some other C code besides apply()
constructs a kwdict that doesn't have the right format.  All the other
possibilities of getting it wrong (non-dict, wrong keywords etc) are
already caught so this makes sense to check here.
1999-10-26 00:12:20 +00:00
Barry Warsaw f6202635f9 call_trace(): A fix for PR#73, if an exception occurred in the
tracefunc (or profilefunc -- we're not sure which), zap the global
trace and profile funcs so that we can't get into recursive loop when
instantiating the resulting class based exception.
1999-09-08 16:26:33 +00:00
Guido van Rossum 8746082175 Patch by Tim Peters:
Introduce a new builtin exception, UnboundLocalError, raised when ceval.c
tries to retrieve or delete a local name that isn't bound to a value.
Currently raises NameError, which makes this behavior a FAQ since the same
error is raised for "missing" global names too:  when the user has a global
of the same name as the unbound local, NameError makes no sense to them.
Even in the absence of shadowing, knowing whether a bogus name is local or
global is a real aid to quick understanding.

Example:

D:\src\PCbuild>type local.py
x = 42

def f():
    print x
    x = 13
    return x

f()

D:\src\PCbuild>python local.py
Traceback (innermost last):
  File "local.py", line 8, in ?
    f()
  File "local.py", line 4, in f
    print x
UnboundLocalError: x

D:\src\PCbuild>

Note that UnboundLocalError is a subclass of NameError, for compatibility
with existing class-exception code that may be trying to catch this as a
NameError.  Unfortunately, I see no way to make this wholly compatible
with -X (see comments in bltinmodule.c):  under -X, [UnboundLocalError
is an alias for NameError --GvR].

[The ceval.c patch differs slightly from the second version that Tim
submitted; I decided not to raise UnboundLocalError for DELETE_NAME,
only for DELETE_LOCAL.  DELETE_NAME is only generated at the module
level, and since at that level a NameError is raised for referencing
an undefined name, it should also be raised for deleting one.]
1999-06-22 14:47:32 +00:00
Guido van Rossum 2571cc8bf5 Changes by Mark Hammond for Windows CE. Mostly of the form
#ifdef DONT_HAVE_header_H ... #endif around #include <header.h>.
1999-04-07 16:07:23 +00:00
Guido van Rossum eb894ebd0a Always test for an error return (usually NULL or -1) without setting
an exception.
1999-03-09 16:16:45 +00:00
Guido van Rossum 65d5b5763c Thanks to Chris Herborth, the thread primitives now have proper Py*
names in the source code (they already had those for the linker,
through some smart macros; but the source still had the old, un-Py names).
1998-12-21 19:32:43 +00:00
Guido van Rossum 885553e8d3 Use PyThreadState_GET() macro. 1998-12-21 18:33:30 +00:00
Guido van Rossum cf183acf15 Use PyInt_AS_LONG macro instead of explicit inlining. 1998-12-04 18:51:36 +00:00
Guido van Rossum 014518f66c Whoops! One the "redundant" initializations removed by Vladimir in
the previous patch wasn't -- there was a path through the code that
bypassed all initializations.  Thanks to Just for reporting the bug!
1998-11-23 21:09:51 +00:00
Guido van Rossum 50cd34888b Remove some redundant initializations -- patch by Vladimir Marangozov. 1998-11-17 17:02:51 +00:00
Guido van Rossum d076c73cc8 Changes to support other object types besides strings
as the code string of code objects, as long as they support
the (readonly) buffer interface.  By Greg Stein.
1998-10-07 19:42:25 +00:00
Guido van Rossum 49b560698b Renamed thread.h to pythread.h. 1998-10-01 20:42:43 +00:00
Guido van Rossum 2d1ad39b81 Add the type of the object to the error message about calling a non-function. 1998-08-25 18:16:54 +00:00
Guido van Rossum 5053efc2c4 In BUILD_LIST, use PyList_SET_ITEM() instead of PyList_SetItem(); and
get rid of redundant error check.
1998-08-04 15:27:50 +00:00
Guido van Rossum fa00e958fd # In case BINARY_SUBSCR, use proper PyList_GET* macros instead of inlining. 1998-07-08 15:02:37 +00:00
Guido van Rossum 7859f87fdb Marc-Andre Lemburg's patch to support instance methods with other
callable objects than regular Pythonm functions as their im_func.
1998-07-08 14:58:16 +00:00
Guido van Rossum 7e33c6e896 Moved cmp_member() to abstract.c, as PySequence_Contains() [with
swapped arguments].

Also make sure that no use of a function pointer gotten from a
tp_as_sequence or tp_as_mapping structure is made without checking it
for NULL first.
1998-05-22 00:52:29 +00:00
Guido van Rossum 234e260d5e Since PyDict_GetItem() can't raise an exception any more, there's no
need to call PyErr_Clear() when it returns NULL.
1998-05-14 02:16:20 +00:00
Guido van Rossum 2e4c899e2d DELETE_FAST should issue an exception when the local variable is undefined. 1998-05-12 20:27:36 +00:00
Guido van Rossum 730806d3d9 Make new gcc -Wall happy 1998-04-10 22:27:42 +00:00
Guido van Rossum d295f120ae Make first raise argument optional 1998-04-09 21:39:57 +00:00
Guido van Rossum 8f18320270 Last-minute fix for Jim H: don't die after del sys.stdout 1997-12-31 05:53:15 +00:00
Guido van Rossum aa06b0ede5 Plug the most annoying recursive printing problem -- reset '_' to None
before printing and set it to the printed variable *after* printing
(and only when printing is successful).
1997-12-26 22:15:57 +00:00
Guido van Rossum df9db1ea18 Give more detailed error message when the argument count isn't right. 1997-11-19 16:05:40 +00:00
Guido van Rossum dfed725e2c Fix memory leak in exec statement with code object -- the None returned
by PyEval_EvalCode() on success was never DECREF'ed.

Fix by Bernhard Herzog.
1997-11-11 16:29:38 +00:00
Guido van Rossum b74eca9349 Change PyEval_SaveThread() and PyEval_RestoreThread() to always do the
tstate swapping.  Only the acquiring and releasing of the lock is
conditional (twice, under ``#ifdef WITH_THREAD'' and inside ``if
(interpreter_lock)'').
1997-09-30 22:03:16 +00:00
Guido van Rossum aee0bad0a5 First part of package support.
This doesn't yet support "import a.b.c" or "from a.b.c import x", but
it does recognize directories.  When importing a directory, it
initializes __path__ to a list containing the directory name, and
loads the __init__ module if found.

The (internal) find_module() and load_module() functions are
restructured so that they both also handle built-in and frozen modules
and Mac resources (and directories of course).  The imp module's
find_module() and (new) load_module() also have this functionality.
Moreover, imp unconditionally defines constants for all module types,
and has two more new functions: find_module_in_package() and
find_module_in_directory().

There's also a new API function, PyImport_ImportModuleEx(), which
takes all four __import__ arguments (name, globals, locals, fromlist).
The last three may be NULL.  This is currently the same as
PyImport_ImportModule() but in the future it will be able to do
relative dotted-path imports.

Other changes:

- bltinmodule.c: in __import__, call PyImport_ImportModuleEx().

- ceval.c: always pass the fromlist to __import__, even if it is a C
function, so PyImport_ImportModuleEx() is useful.

- getmtime.c: the function has a second argument, the FILE*, on which
it applies fstat().  According to Sjoerd this is much faster.  The
first (pathname) argument is ignored, but remains for backward
compatibility (so the Mac version still works without changes).

By cleverly combining the new imp functionality, the full support for
dotted names in Python (mini.py, not checked in) is now about 7K,
lavishly commented (vs. 14K for ni plus 11K for ihooks, also lavishly
commented).

Good night!
1997-09-05 07:33:22 +00:00
Guido van Rossum d7ed683a7e Inline PyObject_CallObject (Marc-Andre Lemburg). 1997-08-30 15:02:50 +00:00
Barry Warsaw eaedc7ce32 eval_code2(), set_exc_info(): Call PyErr_NormalizeException() the
former rather than the latter, since PyErr_NormalizeException takes
PyObject** and I didn't want to change the interface for set_exc_info
(but I did want the changes propagated to eval_code2!).
1997-08-28 22:36:40 +00:00
Barry Warsaw 910105515e unpack_sequence(): In finally clause, watch out for Py_DECREF
evaluating its arguments twice.
1997-08-25 22:30:51 +00:00
Barry Warsaw e42b18f9d1 eval_code2(): collapsed the implementations of UNPACK_TUPLE and
UNPACK_LIST byte codes and added a third code path that allows
generalized sequence unpacking.  Now both syntaxes:

    a, b, c = seq
    [a, b, c] = seq

can be used to unpack any sequence with the exact right number of
items.

unpack_sequence(): out-lined implementation of generalized sequence
unpacking.  tuple and list unpacking are still inlined.
1997-08-25 22:13:04 +00:00
Barry Warsaw 4249f54b28 cmp_exception gets promoted (essentially) to the C API function
PyErr_GivenExceptionMatches().

set_exc_info(): make sure to normalize exceptions.

do_raise(): Use PyErr_NormalizeException() if type is a class.

loop_subscript(): Use PyErr_ExceptionMatches() instead of raw pointer
compare for PyExc_IndexError.
1997-08-22 21:26:19 +00:00