Commit Graph

1356 Commits

Author SHA1 Message Date
Martin v. Löwis 4f1cd8bdcb Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774. 2001-07-26 13:41:06 +00:00
Neil Schemenauer 7d4bb9f179 Add -E command line switch (ignore environment variables like PYTHONHOME
and PYTHONPATH).
2001-07-23 16:30:27 +00:00
Moshe Zadka 03897ea1f7 Patch number #422106 by Greg Ball, to fix segmentation
fault in sys.displayhook.

Please check this in on the 2.2a1 branch (or whatever is necessary
to get it working next release)
2001-07-23 13:32:43 +00:00
Guido van Rossum f48f11cd79 SF Patch #441791, with changes: when "import foo.bar" fails with an
exception in the execution of bar, ensure that foo.bar exists.
(Previously, while sys.modules['foo.bar'] would exist, foo.bar would
only be created upon successful execution of bar.  This is
inconvenient; some would say wrong. :-)
2001-07-23 13:27:49 +00:00
Guido van Rossum f5df46d701 Add a low-level API to access interpreters, for David Beazley.
SF patch #436376.
2001-07-19 12:19:27 +00:00
Martin v. Löwis f0473d511b Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Add dlopenflags to PyInterpreterState, and use it in dlopen calls.
2001-07-18 16:17:16 +00:00
Guido van Rossum b1a77dd248 Deleting zombies 2001-07-17 15:45:08 +00:00
Guido van Rossum e16c7aee4b jcompile(): inherit the CO_GENERATOR_ALLOWED flag from the 'base'
compiling struct.
2001-07-16 16:53:08 +00:00
Guido van Rossum a1b3a47406 PyRun_StringFlags(): forgot to pass the flags on to
PyParser_SimpleParseString().  Now calls
PyParser_SimpleParseStringFlags() with the correct flag.
2001-07-16 16:51:33 +00:00
Tim Peters fe2127d3cb Ugly. A pile of new xxxFlags() functions, to communicate to the parser
that 'yield' is a keyword.  This doesn't help test_generators at all!  I
don't know why not.  These things do work now (and didn't before this
patch):

1. "from __future__ import generators" now works in a native shell.

2. Similarly "python -i xxx.py" now has generators enabled in the
   shell if xxx.py had them enabled.

3. This program (which was my doctest proxy) works fine:

from __future__ import generators

source = """\
def f():
    yield 1
"""

exec compile(source, "", "single") in globals()
print type(f())
2001-07-16 05:37:24 +00:00
Tim Peters 51d76f1f75 future.c: insert a cosmetic space.
pythonrun.c, run_pyc_file():  repair semantic error wrt CO_GENERATOR vs
CO_GENERATOR_ALLOWED.
2001-07-16 03:11:48 +00:00
Tim Peters 5ba5866281 Part way to allowing "from __future__ import generators" to communicate
that info to code dynamically compiled *by* code compiled with generators
enabled.  Doesn't yet work because there's still no way to tell the parser
that "yield" is OK (unlike nested_scopes, the parser has its fingers in
this too).
Replaced PyEval_GetNestedScopes by a more-general
PyEval_MergeCompilerFlags.  Perhaps I should not have?  I doubted it was
*intended* to be part of the public API, so just did.
2001-07-16 02:29:45 +00:00
Guido van Rossum b09f7ed623 Preliminary support for "from __future__ import generators" to enable
the yield statement.  I figure we have to have this in before I can
release 2.2a1 on Wednesday.

Note: test_generators is currently broken, I'm counting on Tim to fix
this.
2001-07-15 21:08:29 +00:00
Neil Schemenauer f8c7c20ba5 GC for generator objects. 2001-07-12 13:27:49 +00:00
Thomas Wouters efafcea280 Re-add 'advanced' xrange features, adding DeprecationWarnings as discussed
on python-dev. The features will still vanish, however, just one release
later.
2001-07-09 12:30:54 +00:00
Guido van Rossum cfd829eefc Complete the xrange-simplification checkins: call PyRange_New() with
fewer arguments.
2001-07-05 14:44:41 +00:00
Tim Peters 0f9431fb18 SF bug #438295: [Windows] __init__.py cause strange behavior
Probable fix (the bug report doesn't have enough info to say for sure).
find_init_module():  Insist on a case-sensitive match for __init__ files.
Given __INIT__.PY instead, find_init_module() thought that was fine, but
the later attempt to do find_module("__INIT__.PY") didn't and its caller
silently suppressed the resulting ImportError.  Now find_init_module()
refuses to accept __INIT__.PY to begin with.
Bugfix candidate; specific to platforms with case-insensitive filesystems.
2001-07-05 03:47:53 +00:00
Fred Drake 9e3ad78444 This change adjusts the profiling/tracing support so that the common
path (with no profile/trace function) through eval_code2() and
eval_frame() avoids several checks.

In the common cases of calls, returns, and exception propogation,
eval_code2() and eval_frame() used to test two values in the
thread-state: the profiling function and the tracing function.  With
this change, a flag is set in the thread-state if either of these is
active, allowing a single check to suffice when both are NULL.  This
also simplifies the code needed when either function is in use but is
already active (to avoid profiling/tracing the profiler/tracer); the
flag is set to 0 when the profile/trace code is entered, allowing the
same check to suffice for "already in the tracer" for call/return/
exception events.
2001-07-03 23:39:52 +00:00
Tim Peters 08a898f85d Another "if 0:" hack, this time to complain about otherwise invisible
"return expr" instances in generators (which latter may be generators
due to otherwise invisible "yield" stmts hiding in "if 0" blocks).
This was fun the first time, but this has gotten truly ugly now.
2001-06-28 01:52:22 +00:00
Fred Drake 5755ce693d Revise the interface to the profiling and tracing support for the
Python interpreter.

This change adds two new C-level APIs:  PyEval_SetProfile() and
PyEval_SetTrace().  These can be used to install profile and trace
functions implemented in C, which can operate at much higher speeds
than Python-based functions.  The overhead for calling a C-based
profile function is a very small fraction of a percent of the overhead
involved in calling a Python-based function.

The machinery required to call a Python-based profile or trace
function been moved to sysmodule.c, where sys.setprofile() and
sys.setprofile() simply become users of the new interface.

As a side effect, SF bug #436058 is fixed; there is no longer a
_PyTrace_Init() function to declare.
2001-06-27 19:19:46 +00:00
Fredrik Lundh 8f4558583f use Py_UNICODE_WIDE instead of USE_UCS4_STORAGE and Py_UNICODE_SIZE
tests.
2001-06-27 18:59:43 +00:00
Martin v. Löwis ce9b5a55e1 Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Implement sys.maxunicode.
Explicitly wrap around upper/lower computations for wide Py_UNICODE.
When decoding large characters with UTF-8, represent expected test
results using the \U notation.
2001-06-27 06:28:56 +00:00
Guido van Rossum 236d8b7974 Cosmetic changes to MvL's change to unichr():
- the correct range for the error message is range(0x110000);

- put the 4-byte Unicode-size code inside the same else branch as the
  2-byte code, rather generating unreachable code in the 2-byte case.

- Don't hide the 'else' behine the '}'.

(I would prefer that in 4-byte mode, any value should be accepted, but
reasonable people can argue about that, so I'll put that off.)
2001-06-26 23:12:25 +00:00
Tim Peters e77f2e2798 gen_getattr: make the gi_running and gi_frame members discoverable (but
not writable -- too dangerous!) from Python code.
2001-06-26 22:24:51 +00:00
Martin v. Löwis 0ba70cc3c8 Support using UCS-4 as the Py_UNICODE type:
Add configure option --enable-unicode.
Add config.h macros Py_USING_UNICODE, PY_UNICODE_TYPE, Py_UNICODE_SIZE,
                    SIZEOF_WCHAR_T.
Define Py_UCS2.
Encode and decode large UTF-8 characters into single Py_UNICODE values
for wide Unicode types; likewise for UTF-16.
Remove test whether sizeof Py_UNICODE is two.
2001-06-26 22:22:37 +00:00
Tim Peters d8e1c9e177 Add "gi_" (generator-iterator) prefix to names of genobject members.
Makes it much easier to find references via dumb editor search (former
"frame" in particular was near-hopeless).
2001-06-26 20:58:58 +00:00
Fredrik Lundh 0dcf67e56d more unicode tweaks: make unichr(0xdddddddd) behave like u"\Udddddddd"
wrt surrogates.  (this extends the valid range from 65535 to 1114111)
2001-06-26 20:01:56 +00:00
Fredrik Lundh 5b97935604 experimental UCS-4 support: don't assume that MS_WIN32 implies
HAVE_USABLE_WCHAR_T
2001-06-26 17:46:10 +00:00
Tim Peters b6c3ceae79 SF bug #436207: "if 0: yield x" is ignored.
Not anymore <wink>.  Pure hack.  Doesn't fix any other "if 0:" glitches.
2001-06-26 03:36:28 +00:00
Tim Peters ad1a18b78e Change the semantics of "return" in generators, as discussed on the
Iterators list and Python-Dev; e.g., these all pass now:

def g1():
    try:
        return
    except:
        yield 1
assert list(g1()) == []

def g2():
    try:
        return
    finally:
        yield 1
assert list(g2()) == [1]

def g3():
    for i in range(3):
        yield None
    yield None
assert list(g3()) == [None] * 4

compile.c:  compile_funcdef and com_return_stmt:  Just van Rossum's patch
to compile the same code for "return" regardless of function type (this
goes back to the previous scheme of returning Py_None).

ceval.c:  gen_iternext:  take a return (but not a yield) of Py_None as
meaning the generator is exhausted.
2001-06-23 06:19:16 +00:00
Tim Peters 5eb4b87ae6 gen_iternext(): Don't assume that the current thread state's frame is
not NULL.  I don't think it can be NULL from Python code, but if using
generators via the C API I expect a NULL frame is possible.
2001-06-23 05:47:56 +00:00
Tim Peters 8c96369513 PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
the next free valuestack slot, not to the base (in America, stacks push
and pop at the top -- they mutate at the bottom in Australia <winK>).
eval_frame():  assert that f_stacktop isn't NULL upon entry.
frame_delloc():  avoid ordered pointer comparisons involving f_stacktop
when f_stacktop is NULL.
2001-06-23 05:26:56 +00:00
Tim Peters 95c80f8439 Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Derived from Thomas Wouters's patch on the Iterators list, but doesn't
try to read c->c_block[c->c_nblocks].
2001-06-23 02:07:08 +00:00
Tim Peters d6d010b874 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
giving up the goods.
NEEDS DOC CHANGES
2001-06-21 02:49:55 +00:00
Neil Schemenauer 2b13ce8317 Try to avoid creating reference cycles involving generators. Only keep a
reference to f_back when its really needed.  Do a little whitespace
normalization as well.  This whole file is a big war between tabs and spaces
but now is probably not the time to reindent everything.
2001-06-21 02:41:10 +00:00
Tim Peters 6302ec63fc gen_iternext(): repair subtle refcount problem.
NeilS, please check!  This came from staring at your genbug.py, but I'm
not sure it plugs all possible holes.  Without this, I caught a
frameobject refcount going negative, and it was also the cause (in debug
build) of _Py_ForgetReference's attempt to forget an object with already-
NULL _ob_prev and _ob_next pointers -- although I'm still not entirely
sure how!  Part of the difficulty is that frameobjects are stored on a
free list that gets recycled very quickly, so if there's a stray pointer
to one of them it never looks like an insane frameobject (never goes
trough the free() mangling MS debug forces, etc).
2001-06-20 06:57:32 +00:00
Neil Schemenauer 43afb24c30 Remove unused code. 2001-06-20 00:39:28 +00:00
Tim Peters 5ca576ed0a Merging the gen-branch into the main line, at Guido's direction. Yay!
Bugfix candidate in inspect.py:  it was referencing "self" outside of
a method.
2001-06-18 22:08:13 +00:00
Fred Drake d083839fb4 Instead of initializing & interning the strings passed to the profile
and trace functions lazily, which incurs extra argument pushing and checks
in the C overhead for profiling/tracing, create the strings semi-lazily
when the Python code first registers a profile or trace function.  This
simplifies the trampoline into the profile/trace functions.
2001-06-16 21:02:31 +00:00
Tim Peters 239508cd10 SF bug 433228: repr(list) woes when len(list) big
call_object:  If the object isn't callable, display its type in the error
msg rather than its repr.
Bugfix candidate.
2001-06-16 00:09:28 +00:00
Marc-André Lemburg 464fe3aa7b Temporarily disable the message to stderr. Jeremy will know what to do
about this...
2001-06-13 17:18:06 +00:00
Tim Peters 2a7f384122 SF bug 430991: wrong co_lnotab
Armin Rigo pointed out that the way the line-# table got built didn't work
for lines generating more than 255 bytes of bytecode.  Fixed as he
suggested, plus corresponding changes to pyassem.py, plus added some
long overdue docs about this subtle table to compile.c.

Bugfix candidate (line numbers may be off in tracebacks under -O).
2001-06-09 09:26:21 +00:00
Fred Drake 904aa7bb00 call_trace(): Add an additional parameter -- pointer to a PyObject*
that should be used to cache an interned version of the event
    string passed to the profile/trace function.  call_trace() will
    create interned strings and cache them in using the storage
    specified by this additional parameter, avoiding a lot of string
    object creation at runtime when using the profiling or tracing
    functions.

All call sites are modified to pass the additional parameter, and four
static PyObject* variables are allocated to cache the interned string
objects.

This closes SF patch #431257.
2001-06-08 04:33:09 +00:00
Tim Peters 024da3545b PyErr_Occurred(): Use PyThreadState_GET(), which saves a tiny function call
in release builds.  Suggested by Martin v. Loewis.

I'm half tempted to macroize PyErr_Occurred too, as the whole thing could
collapse to just
     _PyThreadState_Current->curexc_type
2001-05-30 06:09:50 +00:00
Jeremy Hylton 25916bdc11 Change cascaded if stmts to switch stmt in vgetargs1().
In the default branch, keep three ifs that are used if level == 0, the
most common case.  Note that first if here is a slight optimization
for the 'O' format.

Second part of SF patch 426072.
2001-05-29 17:46:19 +00:00
Jeremy Hylton 1cb7aa3e6e Internal refactoring of convertsimple() and friends.
Note that lots of code was re-indented.

Replace two-step of convertsimple() and convertsimple1() with
convertsimple() and helper converterr(), which is called to format
error messages when convertsimple() fails.  The old code did all the
real work in convertsimple1(), but deferred error message formatting
to conversimple().  The result was paying the price of a second
function call on every call just to format error messages in the
failure cases.

Factor out of the buffer-handling code in convertsimple() and package
it as convertbuffer().

Add two macros to ease readability of Unicode coversions,
UNICODE_DEFAULT_ENCODING() and CONV_UNICODE, an error string.

The convertsimple() routine had awful indentation problems, primarily
because there were two tabs between the case line and the body of the
case statements.  This patch reformats the entire function to have a
single tab between case line and case body, which makes the code
easier to read (and consistent with ceval).  The introduction of
converterr() exacerbated the problem and prompted this fix.

Also, eliminate non-standard whitespace after opening paren and before
closing paren in a few if statements.

(This checkin is part of SF patch 426072.)
2001-05-29 17:37:05 +00:00
Jeremy Hylton 4c9dace392 Fix bug reported by Tim Peters on python-dev:
Keyword arguments passed to builtin functions that don't take them are
ignored.

>>> {}.clear(x=2)
>>>

instead of

>>> {}.clear(x=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: clear() takes no keyword arguments
2001-05-29 16:23:26 +00:00
Tim Peters 4324aa3572 Cruft cleanup: Removed the unused last_is_sticky argument from the internal
_PyTuple_Resize().
2001-05-28 22:30:08 +00:00
Tim Peters 3c6b148a67 SF bug #425836: Reference leak in filter().
Mark Hammond claimed that the iterized filter() forgot to decref the
iterator upon return.  He was right!
2001-05-21 08:07:05 +00:00
Fred Drake d657303910 Fix whitespace botch. 2001-05-18 21:03:40 +00:00