Commit Graph

210 Commits

Author SHA1 Message Date
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
Guido van Rossum cd649654d7 Reverse the search order for the Don Beaudry hook so that the first
class wins.  Makes more sense.
1997-08-22 16:56:16 +00:00
Guido van Rossum f9c90c533e Renamed a local label that was accidentally grandly renamed to
'Py_Cleanup' back to 'cleanup'.
1997-08-05 02:18:01 +00:00
Guido van Rossum 25ce566661 The last of the mass checkins for separate (sub)interpreters.
Everything should now work again.

See the comments for the .h files mass checkin (e.g. pystate.h) for
more detail.
1997-08-02 03:10:38 +00:00
Guido van Rossum 55b9ab5bdb Extend the "Don Beaudry hack" with "Guido's corollary" -- if the base
class has a __class__ attribute, call that to create the new class.
This allows us to write metaclasses purely in C!
1997-07-31 03:54:02 +00:00
Guido van Rossum 9cc8a20cd2 Moved PyEval_{Acquire,Release}Thread() to within the same #ifdef
WITH_THREAD as PyEval_InitThreads().

Removed use of Py_SuppressPrintingFlag.
1997-07-19 19:55:50 +00:00
Guido van Rossum 2fca21f762 PyEval_SaveThread() and PyEval_RestoreThread() now return/take a
PyThreadState pointer instead of a (frame) PyObject pointer.  This
makes much more sense.  It is backward incompatible, but that's no
problem, because (a) the heaviest users are the Py_{BEGIN,END}_
ALLOW_THREADS macros here, which have been fixed too; (b) there are
very few direct users; (c) those who use it are there will probably
appreciate the change.

Also, added new functions PyEval_AcquireThread() and
PyEval_ReleaseThread() which allows the threads created by the thread
module as well threads created by others (!) to set/reset the current
thread, and at the same time acquire/release the interpreter lock.

Much saner.
1997-07-18 23:56:58 +00:00
Guido van Rossum c12da6980f Huge speedup by inlining some common integer operations:
int+int, int-int, int <compareop> int, and list[int].
(Unfortunately, int*int is way too much code to inline.)

Also corrected a NULL that should have been a zero.
1997-07-17 23:12:42 +00:00
Guido van Rossum c8b6df9004 PyObject_Compare can raise an exception now. 1997-05-23 00:06:51 +00:00
Guido van Rossum be27026c09 Py_FlushLine and PyFile_WriteString now return error indicators
instead of calling PyErr_Clear().  Add checking of those errors.
1997-05-22 22:26:18 +00:00
Guido van Rossum df4c308f5a Plug leak of stack frame object in exception handling code.
Also delay DECREF calls until after the structures have been updated
(for reentrancy awareness).
1997-05-20 17:06:11 +00:00
Guido van Rossum df0d00e29b Logic for enabling mac-specific signal handling fixed (Jack) 1997-05-20 15:57:49 +00:00
Guido van Rossum 5f15b96c36 (int) cast for strlen() to keep picky compilers happy. 1997-05-13 17:50:01 +00:00
Guido van Rossum b05a5c7698 Instead of importing graminit.h whenever one of the three grammar 'root'
symbols is needed, define these in Python.h with a Py_ prefix.
1997-05-07 17:46:13 +00:00
Guido van Rossum fc49073cd0 Used operators from abstract.h where possible (arithmetic operators,
get/set/del item).  This removes a pile of duplication.  There's no
abstract operator for 'not' but I removed the function call for it
anyway -- it's a little faster in-line.
1997-05-06 15:06:49 +00:00
Guido van Rossum a027efa5bf Massive changes for separate thread state management.
All per-thread globals are moved into a struct which is manipulated
separately.
1997-05-05 20:56:21 +00:00
Guido van Rossum b209a116cf Quickly renamed. 1997-04-29 18:18:01 +00:00
Guido van Rossum c43b685054 Clarify error message for unexpected keyword parameter. 1997-03-10 22:58:23 +00:00
Guido van Rossum 0d85be19e2 *Don't* kill all local variables on function exit. This will be done
by the frameobject dealloc when it is time for the locals to go.  When
there's still a traceback object referencing this stack frame, we
don't want the local variables to disappear yet.

(Hmm...  Shouldn't they be copied to the f_locals dictionary?)
1997-02-14 16:32:14 +00:00
Guido van Rossum deb0c5e66c Two small changes:
- Use co->... instead of f->f_code->...; save an extra lookup of what
we already have in a local variable).

- Remove test for nlocals > 0 before setting fastlocals to
f->f_localsplus; 0 is a rare case and the assignment is safe even
then.
1997-01-27 23:42:36 +00:00
Guido van Rossum d0eb429b88 Plug a leak with calling something other than a function or method is
called with keyword arguments -- the keyword and value were leaked.
This affected for instance with a __call__() method.

Bug reported and fix supplied by Jim Fulton.
1997-01-27 21:30:09 +00:00
Guido van Rossum 950361c6ca Patches for (two forms of) optional dynamic execution profiling --
i.e., counting opcode frequencies, or (with DXPAIRS defined) opcode
pair frequencies.  Define DYNAMIC_EXECUTION_PROFILE on the command
line (for this file and for sysmodule.c) to enable.
1997-01-24 13:49:28 +00:00
Guido van Rossum 8c5df06ec7 Change the control flow for error handling in the function prelude to
jump to the "Kill locals" section at the end.  Add #ifdef macintosh
bandaid to make sure we call sigcheck() on the Mac.
1997-01-24 04:19:24 +00:00
Guido van Rossum a4240132ec Kill all local variables on function return. This closes a gigantic
leak of memory and file descriptors (thanks for Roj for reporting
that!).  Alas, the speed goes down by 5%. :-(
1997-01-21 21:18:36 +00:00
Guido van Rossum 70d44787a3 Only call sigcheck() at the ticker code if we don't have true signals.
This is safe now that both intrcheck() and signalmodule.c schedule a
sigcheck() call via Py_AddPendingCall().

This gives another 7% speedup (never run such a test twice ;-).
1997-01-21 06:15:24 +00:00
Guido van Rossum 1aa14838d2 Cleanup:
- fix bug in Py_MakePendingCalls() with threading
- fix return type of do_raise
- remove build_slice (same as PySlice_New)
- remove code inside #if 0
- remove code inside #ifdef CHECK_STACK
- remove code inside #ifdef SUPPORT_OBSOLETE_ACCESS
- comment about newimp.py should refer to ni.py
1997-01-21 05:34:20 +00:00
Guido van Rossum 768360243a Changes for frame object speedup:
- get fastlocals differently
- call newframeobject() with fewer arguments
- toss getowner(), which was unused anyway
1997-01-20 04:26:20 +00:00
Guido van Rossum 3dfd53b4c8 Add "if (x != NULL) continue;" (or similar for err==0) before the
break to most cases, as suggested by Tim Peters.  This gives another
8-10% speedup.
1997-01-18 02:46:13 +00:00
Guido van Rossum 62f7d15d0b Use the stack size from the code object and the CO_MAXBLOCKS constant
from compile.h.  Remove all eval stack overflow checks.
1997-01-17 21:05:28 +00:00
Guido van Rossum 408027ea46 Rename DEBUG macro to Py_DEBUG 1996-12-30 16:17:54 +00:00
Guido van Rossum 0aa9ee65ab Moved the raise logic out of the main interpreter loop to a separate function.
The raise logic has one additional feature: if you raise <class>,
<value> where <value> is not an instance, it will construct an
instance using <value> as argument.  If <value> is None, <class> is
instantiated without arguments.  If <value> is a tuple, it is used as
the argument list.

This feature is intended to make it easier to upgrade code from using
string exceptions to using class exceptions; without this feature,
you'd have to change every raise statement from ``raise X'' to ``raise
X()'' and from ``raise X, y'' to ``raise X(y)''.  The latter is still
the recommended form (because it has no ambiguities about the number
of arguments), but this change makes the transition less painful.
1996-12-10 18:07:35 +00:00
Guido van Rossum 150b2df682 Change the Don Beaudry hack into the Don B + Jim F hack; now, if *any*
base class is special it gets invoked.

Make gcc -Wall happy.
1996-12-05 23:17:11 +00:00
Guido van Rossum d266eb460e New permission notice, includes CNRI. 1996-10-25 14:44:06 +00:00
Guido van Rossum 6d43c5de5a Raise TypeError, not KeyError, on unknown keyword argument. 1996-08-19 22:09:16 +00:00
Guido van Rossum bf51afa049 Don't test here for negative number to float power; that belongs in
floatobject.c.
1996-08-16 20:49:17 +00:00
Guido van Rossum 0dfcf753ad Disable support for access statement 1996-08-12 22:00:53 +00:00
Guido van Rossum 3b9c6677f8 Better error message if stride used on normal sequence object 1996-07-30 18:40:29 +00:00
Guido van Rossum 8861b74445 Changes for slice and ellipses 1996-07-30 16:49:37 +00:00
Guido van Rossum 3b4da59cd6 Renamed static pow() to powerop() to avoid name conflict in some compilers. 1996-06-19 21:49:17 +00:00
Guido van Rossum 8c1e150215 Removed some done "to do" items.
Changed #ifdef DEBUG slightly.
1996-05-24 20:49:24 +00:00
Guido van Rossum 5e3e426961 removed sime redundant header includes and decls. 1996-05-23 22:49:38 +00:00
Guido van Rossum 50564e8dae changes for complex and power (**) operator 1996-01-12 01:13:16 +00:00
Guido van Rossum 72b56e831f don't return from main loop when error occurs 1995-12-10 04:57:42 +00:00
Guido van Rossum 9d78d8d2fb spell TraceBack with capital B 1995-09-18 21:29:36 +00:00
Guido van Rossum e3e61c1642 empty kw dict is ok for builtins 1995-08-04 04:14:47 +00:00
Guido van Rossum 0db1ef96ac fix bogus DECREF in finally clause 1995-07-28 23:06:00 +00:00
Guido van Rossum ff8b494cf0 changes for keyword args to built-in functions and classes 1995-07-26 18:16:42 +00:00
Guido van Rossum 681d79aaf3 keyword arguments and faster calls 1995-07-18 14:51:37 +00:00
Guido van Rossum f10570b9eb 3rd arg for raise; INCOMPLETE keyword parameter passing (currently f(kw=value) is seen as f('kw', value)) 1995-07-07 22:53:21 +00:00
Guido van Rossum 6f9e433ab3 fix dusty debugging macros 1995-03-29 16:57:48 +00:00
Guido van Rossum 684ed9891b remove unused code for tp_call 1995-03-22 10:09:02 +00:00
Guido van Rossum 8d617a60b1 various tuple related optimizations; remove unused b/w compat code from ceval.c 1995-03-09 12:12:11 +00:00
Guido van Rossum 1d339e8c35 fix bug in try-finally with class exceptions; declare different func pointers for different uses 1995-02-17 15:04:21 +00:00
Guido van Rossum 24c137432c call __import__() with 4 args instead of 1 1995-02-14 09:42:43 +00:00
Guido van Rossum 7f7f274839 use Py_CHARMASK 1995-02-10 17:01:56 +00:00
Guido van Rossum 6b6e0aafe5 DECREF result of run_string 1995-02-07 15:36:56 +00:00
Guido van Rossum a715299a14 remove unused variable 1995-01-30 12:53:21 +00:00
Guido van Rossum 8bf7c484c1 allow classes as exceptions 1995-01-26 00:41:04 +00:00
Guido van Rossum 1919ca7b28 add missing INCREF in RAISE_EXCEPTION 1995-01-20 16:55:14 +00:00
Guido van Rossum b4e7e25fe6 different init for __builtins__ 1995-01-17 16:27:25 +00:00
Guido van Rossum 94390ec2a6 use getbuiltins() everywhere, it defaults to getbuiltidict() 1995-01-12 11:37:57 +00:00
Guido van Rossum 6135a87f2b __builtins__ mods (and sys_checkinterval for ceval.c) 1995-01-09 17:53:26 +00:00
Guido van Rossum 06186519e5 Use new instancebinop interface 1995-01-07 12:40:10 +00:00
Guido van Rossum 6d023c98b0 Added 1995 to copyright message.
bltinmodule.c: fixed coerce() nightmare in ternary pow().
modsupport.c (initmodule2): pass METH_FREENAME flag to newmethodobject().
pythonrun.c: move flushline() into and around print_error().
1995-01-04 19:12:13 +00:00
Guido van Rossum 1ae940a587 Lots of changes, most minor (fatal() instead of abort(), use of
err_fetch/err_restore and so on).  But...
NOTE: import.c has been rewritten and all the DL stuff is now in the
new file importdl.c.
1995-01-02 19:04:15 +00:00
Guido van Rossum 69d9eb9f56 replace abort() calls by fatal() 1994-11-10 22:41:15 +00:00
Guido van Rossum 180d7b4d55 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
global: Py_MakePendingCalls.  Also guard against recursive calls

	* Include/classobject.h, Objects/classobject.c,
	Python/{ceval.c,bltinmodule.c}: entirely redone operator
	overloading.  The rules for class instances are now much more
	relaxed than for other built-in types
	(whose coerce must still return two objects of the same type)
1994-09-29 09:45:57 +00:00
Guido van Rossum a96720907a * Python/ceval.c (eval_code): added registry of pending functions
(to be used by functions that are called asynchronously, like
	UNIX signal handlers or Mac I/O completion routines)
1994-09-14 13:31:22 +00:00
Guido van Rossum e59214ed91 call_object: print message before abort() 1994-08-30 08:01:59 +00:00
Guido van Rossum 67a5fdbcc2 * mpzmodule.c: cast some methods to the proper type.
* traceback.c (tb_print): use sys.tracebacklimit as a maximum number of
  traceback entries to print (default 1000).
* ceval.c (printtraceback): Don't print stack trace header -- this is now
  done by tb_print().
1993-12-17 12:09:14 +00:00
Guido van Rossum c600411755 * mpzmodule.c: removed redundant mpz_print function.
* object.[ch], bltinmodule.c, fileobject.c: changed str() to call
  strobject() which calls an object's __str__ method if it has one.
  strobject() is also called by writeobject() when PRINT_RAW is passed.
* ceval.c: rationalize code for PRINT_ITEM (no change in function!)
* funcobject.c, codeobject.c: added compare and hash functionality.
  Functions with identical code objects and the same global dictionary are
  equal.  Code objects are equal when their code, constants list and names
  list are identical (i.e. the filename and code name don't count).
  (hash doesn't work yet since the constants are in a list and lists can't
  be hashed -- suppose this should really be done with a tuple now we have
  resizetuple!)
1993-11-05 10:22:19 +00:00
Guido van Rossum b73cc04e62 * ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
pythonrun.c: added static forward declarations
* pythonrun.h, ceval.h, longobject.h, node.h: removed declarations of
  static routines
1993-11-01 16:28:59 +00:00
Sjoerd Mullender 3bb8a05947 Several optimizations and speed improvements.
cstubs: Use Matrix type instead of float[4][4].
1993-10-22 12:04:32 +00:00
Guido van Rossum db3165e655 * bltinmodule.c: removed exec() built-in function.
* Grammar: add exec statement; allow testlist in expr statement.
* ceval.c, compile.c, opcode.h: support exec statement;
  avoid optimizing locals when it is used
* fileobject.{c,h}: add getfilename() internal function.
1993-10-18 17:06:59 +00:00
Guido van Rossum f1dc566328 * Makefile: added all: and default: targets.
* many files: made some functions static; removed "extern int errno;".
* frozenmain.c: fixed bugs introduced on 24 June...
* flmodule.c: remove 1.5 bw compat hacks, add new functions in 2.2a
  (and some old functions that were omitted).
* timemodule.c: added MSDOS floatsleep version .
* pgenmain.c: changed exit() to goaway() and added defn of goaway().
* intrcheck.c: add hack (to UNIX only) so interrupting 3 times
  will exit from a hanging program.  The second interrupt prints
  a message explaining this to the user.
1993-07-05 10:31:29 +00:00
Guido van Rossum 9e90a672b4 * pythonmain.c: -k option, usage message, more environment flags.
(the latter also in frozenmain.c)
* ceval.c: global 'killprint' flag raises exception when printing an
  expression statement's value (useful for finding stray output)
* timemodule.c: add asctime() and ctime().  Change julian date to
  1-based origin (as intended and documented).
* Removed unused DO_TIMES stuff from timemodule.c.  Added 'epoch' and
  'day0' globals (year where time.time() == 0 and day of the week the
  epoch started).
1993-06-24 11:10:19 +00:00