Commit Graph

1365 Commits

Author SHA1 Message Date
Tim Peters 6d6c1a35e0 Merge of descr-branch back into trunk. 2001-08-02 04:15:00 +00:00
Tim Peters aa6111fc93 Add mysnprintf.c to Windows build, + squash compiler wngs in mysnprintf.c. 2001-07-31 22:10:29 +00:00
Marc-André Lemburg e5006ebc9d This patch turns the Python API mismatch notice into a standard
Python warning which can be catched by means of the Python warning
framework.

It also adds two new APIs which hopefully make it easier for Python
to switch to buffer overflow safe [v]snprintf() APIs for error
reporting et al. The two new APIs are PyOS_snprintf() and
PyOS_vsnprintf() and work just like the standard ones in many
C libs. On platforms which have snprintf(), the native APIs are used,
on all other an emulation with snprintf() tries to do its best.
2001-07-31 13:24:44 +00:00
Jeremy Hylton 302b54acd9 Do for hasattr() what was done for getattr()
Namely, an exception is raised if the second arg to hasattr() is not a
string or Unicode.
2001-07-30 22:45:19 +00:00
Jeremy Hylton 0eb1115f44 Fix for SF byg [ #420304 ] getattr function w/ default
Fix suggested by Michael Hudson: Raise TypeError if attribute name
passed to getattr() is not a string or Unicode.  There is some
unfortunate duplication of code between builtin_getattr() and
PyObject_GetAttr(), but it appears to be unavoidable.
2001-07-30 22:39:31 +00:00
Jeremy Hylton 3ce45389bd Add _PyUnicode_AsDefaultEncodedString to unicodeobject.h.
And remove all the extern decls in the middle of .c files.
Apparently, it was excluded from the header file because it is
intended for internal use by the interpreter.  It's still intended for
internal use and documented as such in the header file.
2001-07-30 22:34:24 +00:00
Jeremy Hylton 15c1c4f6d2 Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
If the code object has free variables, raise TypeError.
2001-07-30 21:50:55 +00:00
Tim Peters 76f373d081 Repair more now-obsolete references to config.h. 2001-07-26 21:34:59 +00:00
Marc-André Lemburg ae21df59c3 Undoing the UCS-4 patch addition which caused unichr() to return
surrogates for Unicode code points outside range(0x10000) on narrow
Python builds.
2001-07-26 16:29:25 +00:00
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