Commit Graph

840 Commits

Author SHA1 Message Date
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 4a1f39a26b Undo half of the previous change :-(
Setting interp->builtins to the __builtin__ module instead of to its
dictionary had the unfortunate side effect of always running in
restricted execution mode :-(

I will check in a different way of setting __main__.__builtins__ to
the __builtin__ module later.

Also, there was a typo -- a comment was unfinished, and as a result
some finalizations were not being executed.

In Bart Simpson style,

I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
I Will Not Check In Untested Changes.
1997-11-04 19:36:18 +00:00
Guido van Rossum 25c649fdf2 Get rid of another reference to _PyImport_Inittab (now a static array)
that should be PyImport_Inittab (a new pointer initialized to point to
the array).
1997-11-04 17:04:34 +00:00
Guido van Rossum 22348dc0e1 The warning about thread still having a frame now only happens in
verbose mode.
1997-11-03 22:08:36 +00:00
Guido van Rossum 3a44e1b9fb Two independent changes (alas):
- The interp->builtins variable (and hence, __main__.__builtins__) is
once again initialized to the built-in *module* instead of its
dictionary.

- The finalization order is once again changed.  Signals are finalized
relatively early, because (1) it DECREF's the signal handlers, and if
a signal handler happens to be a bound method, deleting it could cause
problems when there's no current thread around, and (2) we don't want
to risk executing signal handlers during finalization.
1997-11-03 21:58:47 +00:00
Guido van Rossum 197346fafe New policy for package imports: only a directory containing
__init__.py (or __init__.pyc/.pyo, whichever applies) is considered a
package.  All other subdirectories are left alone.  Should make Konrad
Hinsen happy!
1997-10-31 18:38:52 +00:00
Guido van Rossum 771c6c8f7a Instead of using _PyImport_Inittab[] directly, use the new "official"
pointer *PyImport_Inittab which is initialized to _PyImport_Inittab.
1997-10-31 18:37:24 +00:00
Guido van Rossum e85da651dd Some patches to Lee Busby's fpectl mods that accidentally didn't make it
into 1.5a4.
1997-10-20 23:50:01 +00:00
Guido van Rossum ed1100f3b6 Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it. 1997-10-20 23:24:07 +00:00
Guido van Rossum 3b31cd2fe7 Shared libraries didn't quite work under AIX because of the change in
status of the GNU readline interface.  Here's a patch, by Vladimir
Marangozov.
1997-10-10 17:40:00 +00:00
Guido van Rossum 9a61dc90e2 Moved mac-specific speedup to a different place (Jack) 1997-10-08 15:25:08 +00:00
Guido van Rossum ac1fc95c3c Fixed for WITHOUT_COMPLEX compilation (Jack) 1997-10-08 15:23:55 +00:00
Guido van Rossum 2ac650f385 New version of PyErr_NewException() that is compatible with -X option. 1997-10-03 19:50:55 +00:00
Guido van Rossum 999e5e921e Initialize Py_UseClassExceptionsFlag to 1. 1997-10-03 19:46:02 +00:00
Guido van Rossum a7f2e813c9 Remove unreachable "return 1" at end of ensure_fromlist(). 1997-10-03 15:33:32 +00:00
Guido van Rossum aa9606f45a Fix small omission: with all the new code, sys.exit(None) would print
"None"; this should be equivalent to sys.exit(0).
1997-10-03 13:53:28 +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 b4102bf5f8 Fix a bug in this code that made it do the wrong thing when an option
was a single '-'.  Thanks to Andrew Kuchling.
1997-09-30 22:00:13 +00:00
Barry Warsaw 3a74993118 PyErr_NormalizeException(): If the exception's type is a class and the
instance's class is a subclass of this, then use the instance's class
as the exception type.
1997-09-30 15:00:18 +00:00
Guido van Rossum 6c1e5f2033 Get DLL version from a variable. 1997-09-29 23:34:23 +00:00
Guido van Rossum ee81af8977 Release interpreter lock around readline call in [raw_]input(). 1997-09-26 21:47:43 +00:00
Barry Warsaw 963b871e86 Py_Initialize(): move the call to _PyImport_FixupExtension() to after
the phase 2 init of the __builtin__ module, so that multiple
interpreters will get the right exceptions.
1997-09-18 16:42:02 +00:00
Barry Warsaw b01a7fa5f8 initerrors(): Eliminate circular reference which was causing a small
but annoying memory leak.  This was introduced when PyExc_Exception
was added; the loop above populating the PyExc_StandardError exception
tuple started at index 1 in bltin_exc, but PyExc_Exception was added
at index 0, so PyExc_StandardError was getting inserted in itself!
How else can a tuple include itself?!

Change the loop to start at index 2.

This was a *fun* one! :-)
1997-09-18 03:44:38 +00:00
Barry Warsaw 412cdc2284 [Py_Exc]NumberError => [Py_Exc]ArithmeticError 1997-09-16 21:51:14 +00:00
Barry Warsaw 2f5f6a2595 PyErr_Print(): When printing a class exception, try to dig out the
__module__ string and if found, print <module>.<class>, unless
<module> == "exceptions".
1997-09-16 21:42:03 +00:00
Guido van Rossum 7617e05a9b New API PyErr_NewException(name, base, dict) to create simple new exceptions. 1997-09-16 18:43:50 +00:00
Guido van Rossum 0474832d9c Introduce PyExc_Exception as the conceptual root class for all exceptions. 1997-09-16 18:43:15 +00:00
Guido van Rossum 0207e6de38 Added docstrings. Not for the obsolete functions though. 1997-09-09 22:04:42 +00:00
Guido van Rossum c172f26861 Deleted find_module_in_package and find_module_in_directory -- they
aren't needed and it was a mistake to add them.
1997-09-09 20:54:35 +00:00
Guido van Rossum a86f77d4dd Crrected a flow control error that caused the wrong error message when
load-module() didn't find a built-in or frozen module.  Also got rid
of is_frozen(), which duplicated the functionality of
find_frozen()!=NULL.
1997-09-09 18:53:47 +00:00
Guido van Rossum 9905ef9669 Added support for __all__, which should be a list of modules to be
imported when the user says "from package import *".
1997-09-08 16:07:11 +00:00
Guido van Rossum 0c81945808 Bugfix: import A.B from inside package was busted by mark_miss optimization. 1997-09-07 06:16:57 +00:00
Guido van Rossum f5f5fdbdd0 Significant speedup -- when a submodule imports a global module, add a
dummy entry to sys.modules, marking the absence of a submodule by the
same name.

Thus, if module foo.bar executes the statement "import time",
sys.modules['foo.time'] will be set to None, once the absence of a
module foo.time is confirmed (by looking for it in foo's path).

The next time when foo.bar (or any other submodule of foo) executes
"import time", no I/O is necessary to determine that there is no
module foo.time.

(Justification: It may seem strange to pollute sys.modules.  However,
since we're doing the lookup anyway it's definitely the fastest
solution.  This is the same convention that 'ni' uses and I haven't
heard any complaints.)
1997-09-06 20:29:52 +00:00
Guido van Rossum 222ef56bbf Fix reload() for package submodules. 1997-09-06 19:41:09 +00:00
Guido van Rossum 17fc85f2f5 Phase two of package import. "import a.b.c" and all variants now do the
right thing.

Still to do:

- Make reload() of a submodule work.

- Performance tweaks -- currently, a submodule that tries to import a
global module *always* searches the package directory first, even if
the global module was already imported.  Not sure how to solve this
one; probably need to record misses per package.

- Documentation!
1997-09-06 18:52:03 +00:00
Guido van Rossum d6bf45bcf6 Fixed some details of printing the str() of an exception. This fixes
a core dump when __str__() returns a non-string, and plugs a memory
leak as well: the result of PyObject_Str() was never DECREFed.
1997-09-05 19:11:53 +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
Guido van Rossum dcc0c13f74 Two independent changes (oops):
- Changed semantics for initialized flag (again); forget the ref
counting, forget the fatal errors -- redundant calls to
Py_Initialize() or Py_Finalize() calls are simply ignored.

- Automatically import site.py on initialization, unless a flag is set
not to do this by main().
1997-08-29 22:32:42 +00:00
Barry Warsaw 757af0e7bb Removed obsolete exception PyExc_AccessError.
Added PyErr_MemoryErrorInst to hold the pre-instantiated instance when
using class based exceptions.

Simplified the creation of all built-in exceptions, both class based
and string based.  Actually, for class based exceptions, the string
ones are still created just in case there's a problem creating the
class based ones (so you still get *some* exception handling!).  Now
the init and fini functions run through a list of structure elements,
creating the strings (and optionally classes) for every entry.

initerrors(): the new base class exceptions StandardError,
LookupError, and NumberError are initialized when using string
exceptions, to tuples containing the list of derived string
exceptions.  This GvR trick enables forward compatibility!  One bit of
nastiness is that the C code has to know the inheritance tree embodied
in exceptions.py.

Added the two phase init and fini functions.
1997-08-29 22:13:51 +00:00
Barry Warsaw 035574d755 Added Py_UseClassExceptionsFlag, the variable containing the state of
the -X command line option.

Py_Initialize(): Handle the two phase initialization of the built-in
module.

Py_Finalize(): Handle the two phase finalization of the built-in
module.

parse_syntax_error(): New function which parses syntax errors that
PyErr_Print() will catch.  This correctly parses such errors
regardless of whether PyExc_SyntaxError is an old-style string
exception or new-fangled class exception.

PyErr_Print(): Many changes:

    1. Normalize the exception.

    2. Handle SystemExit exceptions which might be class based.  Digs
       the exit code out of the "code" attribute.  String based
       SystemExit is handled the same as before.

    3. Handle SyntaxError exceptions which might be class based.  Digs
       the various information bits out of the instance's attributes
       (see parse_syntax_error() for details).  String based
       SyntaxError still works too.

    4. Don't write the `:' after the exception if the exception is
       class based and has an empty string str() value.
1997-08-29 22:07:17 +00:00
Barry Warsaw 2d8adff10a PyErr_NoMemory(): If the pre-instantiated memory exception is non-null
(PyExc_MemoryErrorInst) raise this instead of PyExc_MemoryError.  This
only happens when exception classes are enabled (e.g. when Python is
started with -X).
1997-08-29 21:54:35 +00:00
Guido van Rossum beef8aa719 Cprrect stuoid tyops -- was comparing variabes with themselves because
of co/cp mixup.
1997-08-29 17:12:43 +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 36b8f945e7 PyErr_Print(): Use PyErr_GivenExceptionMatches() instead of pointer
compares to test for SystemExit and SyntaxError.
1997-08-26 18:09:48 +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
Barry Warsaw c0dc92af7d Three new C API functions:
- int PyErr_GivenExceptionMatches(obj1, obj2)

  Returns 1 if obj1 and obj2 are the same object, or if obj1 is an
  instance of type obj2, or of a class derived from obj2

- int PyErr_ExceptionMatches(obj)

  Higher level wrapper around PyErr_GivenExceptionMatches() which uses
  PyErr_Occurred() as obj1.  This will be the more commonly called
  function.

- void PyErr_NormalizeException(typeptr, valptr, tbptr)

  Normalizes exceptions, and places the normalized values in the
  arguments.  If type is not a class, this does nothing.  If type is a
  class, then it makes sure that value is an instance of the class by:

  1. if instance is of the type, or a class derived from type, it does
     nothing.

  2. otherwise it instantiates the class, using the value as an
     argument.  If value is None, it uses an empty arg tuple, and if
     the value is a tuple, it uses just that.
1997-08-22 21:22:58 +00:00
Barry Warsaw cde8b1ba0c Two new built-in functions: issubclass() and isinstance(). Both take
classes as their second arguments.  The former takes a class as the
first argument and returns true iff first is second, or is a subclass
of second.

The latter takes any object as the first argument and returns true iff
first is an instance of the second, or any subclass of second.

Also, change all occurances of pointer compares against
PyExc_IndexError with PyErr_ExceptionMatches() calls.
1997-08-22 21:14:38 +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 e3c0d5eb34 Added new Py_IsInitalized() API function to test the 'initialized' flag. 1997-08-22 04:20:13 +00:00
Guido van Rossum 5f896a4de0 Added missing newline to warning msg 1997-08-21 02:28:19 +00:00
Guido van Rossum aa61505fd2 Use a counter instead of a Boolean to check for initialized; n calls
to Py_Initialize will be undone by n calls to Py_Uninitialize.
1997-08-20 22:40:18 +00:00
Guido van Rossum 54dec59b56 set sharedlib extensions properly for NeXT (Ted Horst) 1997-08-16 14:38:09 +00:00
Guido van Rossum 7c14103d77 Keep gcc -Wall happy 1997-08-15 02:52:08 +00:00
Guido van Rossum 49b1226781 Use _beginthread() and _endthread() in favor of CreateThread() and
ExitThread().  As discussed in c.l.p, this takes care of
initialization and finalization of thread-local storage allocated by
the C runtime system.  Not sure whether non-MS compilers grok this
though (but who cares :-).
1997-08-14 20:12:58 +00:00
Guido van Rossum d47a0a86b4 Added Jim Fulton's PyImport_Import(), which calls whatever
__import__() hook is currently installed.
1997-08-14 20:11:26 +00:00
Guido van Rossum 741689d5f3 Use string interning and caching to get speedups on the mac (Jack). 1997-08-12 14:53:39 +00:00
Guido van Rossum e5b4026881 Use strerror on the mac if using MSL (Jack). 1997-08-12 14:51:52 +00:00
Guido van Rossum 622f73f188 Remove unised variable 1997-08-07 19:22:48 +00:00
Guido van Rossum cc283f56a7 Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
functions.
1997-08-05 02:22:03 +00:00
Guido van Rossum 085d269f1d New rules for deleting modules. Rather than having an elaborate
scheme based on object's types, have a simple two-phase scheme based
on object's *names*:

	/* To make the execution order of destructors for global
	   objects a bit more predictable, we first zap all objects
	   whose name starts with a single underscore, before we clear
	   the entire dictionary.  We zap them by replacing them with
	   None, rather than deleting them from the dictionary, to
	   avoid rehashing the dictionary (to some extent). */
1997-08-05 02:20:51 +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 40b33c648a Removed fatal errors from Py_Initmodule4() (and thus from
Py_Initmodule(), which is a macro wrapper around it).

The return value is now a NULL pointer if the initialization failed.
This may make old modules fail with a SEGFAULT, since they don't
expect this kind of failure.  That's OK, since (a) it "never" happens,
and (b) they would fail with a fatal error otherwise, anyway.

Tons of extension modules should now check the return value of
Py_Initmodule*() -- that's on my TODO list.
1997-08-02 03:07:46 +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 6fc06e770f Plugged a leak. (The same as the one plugged in compile.c -- forgot
to free lnotab).
1997-07-26 23:30:18 +00:00
Guido van Rossum 275558cb9f Plug a leak in code_dealloc() (and reordered the deallocs to match the
order of the variables in the declarations).

Also removed an entry in the TODO list that's done.
1997-07-25 20:13:49 +00:00
Guido van Rossum ef3d02ebb9 Removed some variables that are used to exchange data between import.c and
importdl.c: the MAXSUFFIXSIZE macro is now defined in importdl.h, and
the modules dictionary is now passed using PyImport_GetModuleDict().

Also undefine USE_SHLIB for AIX -- in AIX 4.2 and up, dlfcn.h exists
but we don't want to use it.
1997-07-21 14:54:36 +00:00
Guido van Rossum a94145118a frozenmain.c is now also in the library,
with entry point Py_FrozenMain().
1997-07-19 21:59:47 +00:00
Guido van Rossum 019db5d73e Oops -- this contains frozen bytecode, but it was Python 1.4 bytecode! 1997-07-19 21:54:24 +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 534ac094f9 Removed a bunch of extern declarations of functions that are now
properly declared in Python.h.
1997-07-19 19:51:43 +00:00
Guido van Rossum 8fb26ede51 Make it return a _const_ char*. 1997-07-19 19:48:41 +00:00
Guido van Rossum f6ca6aa869 New build procedure. 1997-07-19 19:39:57 +00:00
Guido van Rossum 3768fb1097 Tracking changes to Py_Main():
- Got rid of inspection of some environment variables.

- Got rid of Py_GetProgramName() and related logic.

- Print the version header *after* successful initialization.
1997-07-19 19:24:41 +00:00
Guido van Rossum ad6dfda9af Moved some stuff here from main.c (part of a big restructuring - wait
for more!).

- The global flags that can be set from environment variables are now
set in Py_Initialize (except the silly Py_SuppressPrint, which no
longer exists).  This saves duplicate code in frozenmain.c and main.c.

- Py_GetProgramName() is now here; added Py_SetProgramName().  An
embedding program should no longer provide Py_GetProgramName(),
instead it should call Py_SetProgramName() *before* calling
Py_Initialize().
1997-07-19 19:17:22 +00:00
Guido van Rossum 0c88e1fd96 Remove confusing usage comments at end. 1997-07-19 00:02:22 +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 b65e85cb73 Fix problem discovered by Greg McFarlane: when an imported module
replaces its own entry in sys.module, reference count errors ensue;
even if there is no reference count problem, it would be preferable
for the import to yield the new thing in sys.modules anyway (if only
because that's what later imports will yield).  This opens the road to
an official hack to implement a __getattr__ like feature for modules:
stick an instance in sys.modules[__name__].
1997-07-10 18:00:45 +00:00
Guido van Rossum db9e20f418 Fix bug reported by Just: anonymous arguments used for tuples should
have a unique name, otherwise they get squished by locals2fast (or
fast2locals, I dunno) when the debugger is invoked before they have
been transferred to real locals.
1997-07-10 01:06:53 +00:00
Guido van Rossum 46ff1903a3 Add default case (standard conformance) to avoid piling up
system specific #ifdefs.
1997-06-02 22:25:45 +00:00
Guido van Rossum 296b4751e1 Can't return 0 from void function... 1997-05-23 00:19:20 +00:00
Guido van Rossum c8b6df9004 PyObject_Compare can raise an exception now. 1997-05-23 00:06:51 +00:00
Guido van Rossum 7e8d26d78c PyFile_WriteString now returns an error indicator instead of calling
PyErr_Clear().  Add checking of those errors.
1997-05-22 22:35:47 +00:00
Guido van Rossum 78a1ed3d70 Py_FlushLine and PyFile_WriteString now return error indicators
instead of calling PyErr_Clear().  Add checking of those errors.
1997-05-22 22:35:04 +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 64f9105fb7 DG/UX thread patches (Ross Andrus) 1997-05-22 20:41:59 +00:00
Guido van Rossum b2c8ec4b75 Set sys.executable to full path of python (from argv[0]). 1997-05-22 20:41:20 +00:00
Guido van Rossum 23c9446d9a Added a space in an error message 1997-05-22 20:21:30 +00:00
Guido van Rossum f9cba090f9 Don't use function prototypes in function definition headers. 1997-05-20 22:23:34 +00:00
Guido van Rossum 2f75b29630 Indent the #error directives so a classic K&R cpp doesn't see them. 1997-05-20 22:18:48 +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 1254d79dfa Use #ifdef in stead of #if (Jack) 1997-05-20 15:57:25 +00:00
Guido van Rossum c8fba8ee14 Add pthred-std define for Linux. 1997-05-15 12:24:53 +00:00
Guido van Rossum af5dfb4ceb One last rename glitch: import_modules -> _PyImport_Modules. 1997-05-14 17:36:12 +00:00
Guido van Rossum d6353e2c0e Support for various versions of the pthread draft. 1997-05-13 17:51:13 +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 b6a7f77c9f Oops -- missed FloatingPointError in renaming. 1997-05-09 03:03:23 +00:00
Guido van Rossum 9a0f04d4cd Get rid of obsolete support for access statement. 1997-05-09 00:58:02 +00:00
Guido van Rossum ee2373b930 Oops, missed some renamings. 1997-05-07 23:51:07 +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 666b17a280 New dir() function --
- uses abstract interface where possible
- uses __members__ and __methods__
- returns [] when an object has no info available
1997-05-06 16:36:57 +00:00
Guido van Rossum 478e718aca Keep MS compiler happy: use (int)strlen() when comparing; make sure
not to use kill().
1997-05-06 15:24:59 +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 fdf95dd525 Checkin of Jack's buffer mods.
Not really checked, but didn't fail any tests either...
1997-05-05 22:15:02 +00:00
Guido van Rossum 13454c3f9c Fix old typo PyArgs_VaParse -> PyArg_VaParse.
(Redoing the checking without merging in Jack's buffer mods.)
1997-05-05 21:57:29 +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 73237c54b4 Only use PyCode_Addr2Line to get tb_lineno when Py_OptimizeFlag is set. 1997-05-05 20:53:25 +00:00
Guido van Rossum 9218b70bdc Remove 2 out of 3 __FreeBSD__ tests.
These are no longer needed as of FreeBSD 2.0.5, according to
Thomas Gellekum <tg@ihf.rwth-aachen.de>.
1997-05-05 15:03:26 +00:00
Guido van Rossum f4806c2a85 Add detach call so threads are GC'ed. 1997-04-30 19:59:22 +00:00
Guido van Rossum bc2472db8e Avoid some potential (though unlikely) sprintf buffer overflows. 1997-04-30 19:07:54 +00:00
Guido van Rossum 15e33a4c42 Avoid sprintf buffer overflow if more than 9999 arguments. 1997-04-30 19:00:27 +00:00
Guido van Rossum d11bfdd9f5 Ugly hack for SGI IRIX 6.2. Apparently _POSIX_THREADS is defined even
when the pthread package is not installed.  configure knows better, so
#undef _POSIX_THREADS when pthread.h does not exist.
1997-04-29 21:48:34 +00:00
Guido van Rossum bb5c6f8529 Oops, forgot one: inittab. 1997-04-29 20:42:30 +00:00
Guido van Rossum 0bac33b420 Oops, forgot one: inittab. 1997-04-29 20:24:10 +00:00
Guido van Rossum 79f25d9a7b Quickly renamed the remaining files -- this directory is done. 1997-04-29 20:08:16 +00:00
Guido van Rossum 65bf9f265e Quickly renamed. 1997-04-29 18:33:38 +00:00
Guido van Rossum 373c869a6a Quickly renamed. Also removed the long comment explaining why this is
better than the old error API.
1997-04-29 18:22:47 +00:00
Guido van Rossum b209a116cf Quickly renamed. 1997-04-29 18:18:01 +00:00
Guido van Rossum 62cb0bafe2 Moved to ../Modules. 1997-04-29 15:50:32 +00:00
Guido van Rossum 58a6ac55d2 Removed cgensupport.[co] (to ../Modules). 1997-04-29 15:42:53 +00:00
Guido van Rossum c474deaaf6 Expand one level of symbolic link in sys.argv[0] before inserting its
dirname in sys.path.  This means that you can create a symbolic link
foo in /usr/local/bin pointing to /usr/yourname/src/foo/foo.py, and
then invoking foo will insert /usr/yourname/src/foo in sys.path, not
/usr/local/bin.  This makes it easier to have multifile programs
(before, the program would have to do an os.readlink(sys.argv[0])
itself and insert the resulting directory in sys.path -- Grail does
this).

Note that the expansion is only used for sys.path; sys.argv[0] is
still the original, unadorned filename (/usr/local/bin/foo in the
example).
1997-04-25 15:38:31 +00:00
Guido van Rossum 03a7466b8f OK, ready to make 'assert' a keyword (instead of '__assert__'). 1997-04-16 00:34:46 +00:00
Guido van Rossum 7844e38a98 Keep Microsoft VC happy. 1997-04-11 20:44:04 +00:00
Guido van Rossum 6bf62dad9e Keep gcc -Wall and Microsoft VC happy. 1997-04-11 20:37:35 +00:00
Guido van Rossum 1d2e240954 (Jack:) On the Mac, don't automatically enable dynamic loading. 1997-04-11 19:22:06 +00:00
Guido van Rossum 62bf108392 (Jack:) Don't define TRUE and FALSE if already defined. 1997-04-11 19:19:46 +00:00
Guido van Rossum 6976a52099 (Jack:) On the Mac, use standard strerror() if using MSL C-library. 1997-04-11 19:18:23 +00:00
Guido van Rossum 644a12b00c Tweaks to keep the Microsoft compiler quier. 1997-04-09 19:24:53 +00:00
Guido van Rossum 5f5e817e00 Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
In interactive mode, do generate code for single-string statements.
1997-04-06 03:41:40 +00:00
Guido van Rossum 2a7f58de1c Allow passing a .pyo file.
Print correct name in fatal error from PyErr_Print.
1997-04-02 05:28:38 +00:00
Guido van Rossum 228d7f3f67 Added assert statement. 1997-04-02 05:24:36 +00:00
Guido van Rossum 8ecd1ad785 Added assert grammar. 1997-04-02 05:24:08 +00:00
Guido van Rossum c6472e9ee1 1. Add string conversions to int(), long(), float(). (Not to complex()!)
2. Fix two bugs in complex():

   - Memory leak when using complex(classinstance) -- r was never
   DECREF'ed.

   - Conversion of the second argument, if not complex, was done using
   the type vector of the 1st.
1997-03-31 17:15:43 +00:00
Guido van Rossum 45b83915f8 New form of PyFPE_END_PROTECT macro. 1997-03-14 04:32:50 +00:00
Guido van Rossum 6af0c00ab6 Fix dumb bug calling parsestrplus with wrong node as argument.
Add prototypes for parsestr() and parsestrplus() (unrelated, but
seemed to make sense.)
1997-03-11 21:25:55 +00:00
Guido van Rossum 1c6a459921 Define __debug__ as 0 if -O is given, 1 otherwise. Also test for
errors in initializing the dictionary.
1997-03-11 18:43:26 +00:00
Guido van Rossum 7c53111d5b Added support for ``if __debug__:'' -- if -O is given, this form is
recognized by the code generator and code generation for the test and
the subsequent suite is suppressed.

One must write *exactly* ``if __debug__:'' or ``elif __debug__:'' --
no parentheses or operators must be present, or the optimization is
not carried through.  Whitespace doesn't matter.  Other uses of
__debug__ will find __debug__ defined as 0 or 1 in the __builtin__
module.
1997-03-11 18:42:21 +00:00
Guido van Rossum 0824f63cfc When -O is given, use ".pyo" instead of ".pyc". 1997-03-11 18:37:35 +00:00
Guido van Rossum c43b685054 Clarify error message for unexpected keyword parameter. 1997-03-10 22:58:23 +00:00
Guido van Rossum 82598051e6 Greatly renamed. Not a very thorough job -- I'm going to restructure
it anyway.
1997-03-05 00:20:32 +00:00
Guido van Rossum 8e793d925c Add global Py_OptimizeFlag. SET_LINENO is omitted again unless this is
nonzero.
1997-03-03 19:13:14 +00:00
Guido van Rossum 0ae748d3c4 Changes for Lee Busby's SIGFPE patch set.
New file pyfpe.c and exception FloatingPointError.
Surround some f.p. operations with PyFPE macro brackets.
1997-02-14 22:58:07 +00:00
Guido van Rossum 0f4bbd2f34 Keep gcc -Wall happy. 1997-02-14 21:12:56 +00:00
Guido van Rossum 2dc466169e Oops, remove an unused variable from PyErr_Format(). 1997-02-14 20:57:31 +00:00
Guido van Rossum 7433b12a5c Added new global flag variable Py_InteractiveFlag and new function
Py_FdIsInteractive().  The flag is supposed to be set by the -i
command line option.  The function is supposed to be called instead of
isatty().  This is used for Lee Busby's wish #1, to have an option
that pretends stdin is interactive even when it really isn't.
1997-02-14 19:45:36 +00:00
Guido van Rossum 1548bacb14 Added convenience function PyErr_Format(exception, formatstring, ...) -> NULL. 1997-02-14 17:09:47 +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 e8811f85ed Added intern() function. 1997-02-14 15:48:05 +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 43f1b8d6e4 Added optional interface for dynamic execution profile (to be gathered
in ceval.c).
1997-01-24 04:07:45 +00:00
Guido van Rossum b3f515af64 Get the line number from PyCode_Addr2Line instead of believing
tb_lineno.  Store it in tb_lineno for the user.
1997-01-24 04:02:55 +00:00
Guido van Rossum 99d182550b New magin number (because of linenumber table). 1997-01-24 03:44:53 +00:00
Guido van Rossum d031c89891 Marshal the line number table of code objects. 1997-01-24 03:44:17 +00:00
Guido van Rossum da4eb5c3b5 Instead of emitting SET_LINENO instructions, generate a line number
table which is incorporated in the code object.  This way, the runtime
overhead to keep track of line numbers is only incurred when an
exception has to be reported.
1997-01-24 03:43:35 +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 554fa49500 get build info from elsewhere 1997-01-20 18:34:55 +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 7eb883a18e Remove unused variable. 1997-01-18 20:04:05 +00:00
Guido van Rossum 8d75161671 Intern the string "__complex__". 1997-01-18 08:04:16 +00:00
Guido van Rossum 7b89b6a660 Intern all names and varnames in newcodeobject(), plus those string
literals that look like identifiers.  Also intern all strings used as
names during the compilation.
1997-01-18 08:02:57 +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 98a9b312e8 Marshal the new stacksize item in code objects. 1997-01-17 21:07:08 +00:00
Guido van Rossum 7af8130857 Working semaphore implementation by Sjoerd. 1997-01-17 21:06:41 +00:00
Guido van Rossum dd5db43905 New MAGIC number (code objects have one more item when marshalled). 1997-01-17 21:06:11 +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 8b993a98db Add co_stacksize field to codeobject structure, and stacksize argument
to PyCode_New() argument list.  Move MAXBLOCKS constant to conpile.h.

Added accurate calculation of the actual stack size needed by the
generated code.

Also commented out all fprintf statements (except for a new one to
diagnose stack underflow, and one in #ifdef'ed out code), and added
some new TO DO suggestions (now that the stacksize is taken of the TO
DO list).
1997-01-17 21:04:03 +00:00
Guido van Rossum 635abd24f0 Check for duplicate keyword arguments at compile time. 1997-01-06 22:56:52 +00:00
Guido van Rossum 8f49e12a0e Make builtin_module_names a tuple instead of a list. 1997-01-06 22:55:54 +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 c1547d930f Better way to handle 64-bit ints, keeping gcc -Wall happy.
Tested with AMK's help.
1996-12-10 15:39:04 +00:00
Guido van Rossum 1a2c5cbcc4 Add unistd.h to make gcc -Wall happy. 1996-12-10 15:37:36 +00:00
Guido van Rossum 067998f35e Add const to error and newstring functions 1996-12-10 15:33:34 +00:00
Guido van Rossum 80bb9655f0 Keep gcc -Wall happy. 1996-12-05 23:27:02 +00:00
Guido van Rossum ed0af8fe70 Support __complex__ method on instances, for complex() conversion.
Keep gcc -Wall happy.
1996-12-05 23:18:18 +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 3afb5959aa Some extra flags that an HPUX user wants me to add. 1996-12-05 23:15:35 +00:00
Guido van Rossum b0c168cbe8 Tentative changes to make this work better on 64-bit machines.
A plain int that doesn't fit in 32 bits will be marshalled using a new
type.  32 bits machines can't handle this and will issue a warning.
1996-12-05 23:15:02 +00:00
Guido van Rossum d266eb460e New permission notice, includes CNRI. 1996-10-25 14:44:06 +00:00
Guido van Rossum b75fba04c7 Forget about Ellipses b/w compatibility. 1996-10-16 04:18:36 +00:00
Guido van Rossum e449af7da9 Ellipses -> Ellipsis rename (the dictionary really says that it should
be Ellipsis!).
Bumped the API version because a linker-visible symbol is affected.
Old C code will still compile -- there's a b/w compat macro.
Similarly, old Python code will still run, builtin exports both
Ellipses and Ellipsis.
1996-10-11 16:25:41 +00:00
Guido van Rossum cf1474b73a Sjoerd's thread changes (including down_sema typo fix).
Note: waitflag not supported on NT.
1996-10-08 14:17:53 +00:00
Guido van Rossum 452a9833c9 Added line number to most compile-time error messages. 1996-09-17 14:32:04 +00:00
Guido van Rossum 9b38a145e2 Rationalized MS ifdefs 1996-09-11 23:12:24 +00:00
Guido van Rossum cc88341e6d Changes to setpythonpath():
Test for / as well as for SEP for MS filenames.
Drop trailing separator from sys.path[0] for MS and Unix filenames.
1996-09-10 14:44:21 +00:00
Guido van Rossum b072150d7f Stupid bug: complex(x,y) would yield x+xj 1996-09-07 15:55:27 +00:00
Guido van Rossum 57b1822459 *** empty log message *** 1996-08-29 18:10:41 +00:00
Guido van Rossum 927f6e68fb Needed more includes... 1996-08-29 18:10:30 +00:00
Guido van Rossum bae29713ec *** empty log message *** 1996-08-29 17:48:26 +00:00
Guido van Rossum 6eea32622c typo (#indef -> #undef) 1996-08-26 14:58:54 +00:00