Commit Graph

1540 Commits

Author SHA1 Message Date
Jack Jansen fd0226b327 Use c2pstr() in stead of Pstring() to convert C-strings to
Pascal-strings. Safer, because Pstring converts in-place and the
pathname may be reused later for error messages.
2000-12-12 22:36:57 +00:00
Barry Warsaw 0705028076 vgetargskeywords(): Patch for memory leak identified in bug #119862. 2000-12-11 20:01:55 +00:00
Barry Warsaw b6a54d2a2c _getframe(): New sys module function for getting at the stack frame.
Implements and closes SF patch #102106, with Guido's suggested
documentation changes.
2000-12-06 21:47:46 +00:00
Neil Schemenauer cc343caf41 Make isinstance() more permissive in what types of arguments it
accepts. Clarify exception messages for isinstance() and
issubclass().  Closes bug #124106.
2000-12-04 15:42:11 +00:00
Guido van Rossum 60a1e7fc99 Clarified some of the error messages, esp. "read-only character
buffer" replaced by "string or read-only character buffer".
2000-12-01 12:59:05 +00:00
Guido van Rossum 83fb073a03 Plug a memory leak in com_import_stmt(): the tuple created to hold the
"..." in "from M import ..." was never DECREFed.  Leak reported by
James Slaughter and nailed by Barry, who also provided an earlier
version of this patch.
2000-11-27 22:22:36 +00:00
Tim Peters 102e457a01 SF bug 119622: compile errors due to redundant atof decls. I don't understand
the bug report (for details, look at it), but agree there's no need for Python
to declare atof itself:  we #include stdlib.h, and ANSI C sez atof is declared
there already.
2000-11-14 20:44:53 +00:00
Guido van Rossum 128bcf4520 Fix syntax error. Submitted by Bill Bumgarner. Apparently this is
still in use, for Apple Mac OSX.
2000-11-13 19:45:45 +00:00
Guido van Rossum 215c340aa3 Rip out DOS-8x3 support. 2000-11-13 17:26:32 +00:00
Thomas Wouters 2cffc7d420 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
regardless of whether the system getopt() does what we want. This avoids the
hassle with prototypes and externs, and the check to see if the system
getopt() does what we want. Prefix optind, optarg and opterr with _PyOS_ to
avoid name clashes. Add new include file to define the right symbols. Fix
Demo/pyserv/pyserv.c to include getopt.h itself, instead of relying on
Python to provide it.
2000-11-03 08:18:37 +00:00
Jeremy Hylton 6b4ec5135b Fix for SF bug #117241
When a method is called with no regular arguments and * args, defer
the first arg is subclass check until after the * args have been
expanded.

N.B. The CALL_FUNCTION implementation is getting really hairy; should
review it to see if it can be simplified.
2000-10-30 17:15:20 +00:00
Guido van Rossum c8fcdcba36 Patch 102114, Bug 11725. On OpenBSD (but apparently not on the other
BSDs) you need a leading underscore in the dlsym() lookup name.
2000-10-25 22:07:45 +00:00
Fred Drake 661ea26b3d Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity.

This (mostly) closes SourceForge patch #101839.
2000-10-24 19:57:45 +00:00
Fred Drake 237b5f44c7 Andy Dustman <adustman@users.sourceforge.net>:
Eliminate unused variables to appease compiler.
2000-10-12 20:58:32 +00:00
Thomas Wouters 0be483fd4d Do a better job at staying on-screen :P (Sorry, it's late here.) I'm
assuming here that the ANSI-C adjacent-string-concatenation technique is
allowable, now that Python requires an ANSI C compiler.
2000-10-11 23:26:11 +00:00
Thomas Wouters 8fb62a2e9a Adjust debugging code in the implementation of the DUP_TOPX bytecode, use
Py_FatalError() instead, and clarify the message somewhat. As discussed on
python-dev.
2000-10-11 23:20:09 +00:00
Fred Drake 48fba733b9 Remove the last gcc -Wall warning about possible use of an uninitialized
variable.  w should be initialized before entering the bytecode
interpretation loop since we only need one initialization to satisfy the
compiler.
2000-10-11 13:54:07 +00:00
Tim Peters 35ba689cab Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,
by making the DUP_TOPX code utterly straightforward.  This also gets rid
of all normal-case internal DUP_TOPX if/branches, and allows replacing one
POP() with TOP() in each case, so is a good idea regardless.
2000-10-11 07:04:49 +00:00
Fred Drake e693df94ed Avoid a couple of "value computed is not used" warnings from gcc -Wall;
these computations are required for their side effects in traversing the
variable arguments list.

Reported by Marc-Andre Lemburg <mal@lemburg.com>.
2000-10-10 21:10:35 +00:00
Fred Drake a6c2eb5e1e Donn Cave <donn@u.washington.edu>:
Do not assume that all platforms using a MetroWorks compiler can use
POSIX threads; the assumption breaks on BeOS.  This fix only helps
for BeOS.

This closes SourceForge patch #101772.
2000-10-06 15:48:38 +00:00
Tim Peters 98dc065c1b SF "bug" 115973: patches from Norman Vine so that shared libraries and
Tkinter work under Cygwin.  Accepted on faith & reasonableness.
2000-10-05 19:24:26 +00:00
Mark Hammond 1f7838bcc0 Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ] 2000-10-05 10:54:45 +00:00
Barry Warsaw 84294487df _PyImport_Fini(): Closed small memory leak when an embedded app calls
Py_Initialize()/Py_Finalize() in a loop.  _PyImport_Filetab needed to
be deallocated.  Partial closure of SF #110681, Jitterbug PR#398.
2000-10-03 16:02:05 +00:00
Tim Peters 42c83afd14 The 2.0b2 change to write .pyc files in exclusive mode (if possible)
unintentionally caused them to get written in text mode under Windows.
As a result, when .pyc files were later read-- in binary mode --the
magic number was always wrong (note that .pyc magic numbers deliberately
include \r and \n characters, so this was "good" breakage, 100% across
all .pyc files, not random corruption in a subset).  Fixed that.
2000-09-29 04:03:10 +00:00
Fred Drake d5fadf75e4 Rationalize use of limits.h, moving the inclusion to Python.h.
Add definitions of INT_MAX and LONG_MAX to pyport.h.
Remove includes of limits.h and conditional definitions of INT_MAX
and LONG_MAX elsewhere.

This closes SourceForge patch #101659 and bug #115323.
2000-09-26 05:46:01 +00:00
Fred Drake 9e2851566c Andrew Kuchling <akuchlin@mems-exchange.org>:
Add three new convenience functions to the PyModule_*() family:
PyModule_AddObject(), PyModule_AddIntConstant(), PyModule_AddStringConstant().

This closes SourceForge patch #101233.
2000-09-23 03:24:27 +00:00
Marc-André Lemburg 0afff388ce Special case the "s#" PyArg_Parse() token for Unicode objects:
"s#" will now return a pointer to the default encoded string data
of the Unicode object instead of a pointer to the raw UTF-16
data.

The latter is still available via PyObject_AsReadBuffer().

The patch also adds an optimization for string objects which is
based on the fact that string objects return the raw character data
for getreadbuffer access and are always single-segment.
2000-09-21 21:08:30 +00:00
Guido van Rossum 55a8338d7f On Unix, use O_EXCL when creating the .pyc/.pyo files, to avoid a race condition 2000-09-20 20:31:38 +00:00
Marc-André Lemburg d1ba443206 This patch adds a new Python C API called PyString_AsStringAndSize()
which implements the automatic conversion from Unicode to a string
object using the default encoding.

The new API is then put to use to have eval() and exec accept
Unicode objects as code parameter. This closes bugs #110924
and #113890.

As side-effect, the traditional C APIs PyString_Size() and
PyString_AsString() will also accept Unicode objects as
parameters.
2000-09-19 21:04:18 +00:00
Tim Peters e84b74039b Obscure marshal fixes:
When reading a short, sign-extend on platforms where shorts are
    bigger than 16 bits.
    When reading a long, repair the unportable sign extension that was
    being done for 64-bit machines (it assumed that signed right shift
    sign-extends).
2000-09-19 08:54:13 +00:00
Guido van Rossum 9e8181b809 Make better use of GNU Pth -- patch by Andy Dustman.
I can't test this, so I'm just checking it in with blind faith in Andy.
I've tested that it doesn't broeak a non-Pth build on Linux.

Changes include:

- There's a --with-pth configure option.

- Instead of _GNU_PTH, we test for HAVE_PTH.

- Better signal handling.

- (The config.h.in file is regenerated in a slightly different order.)
2000-09-19 00:46:46 +00:00
Marc-André Lemburg 691270feee Deferred the attribute name object type checking to the underlying
PyObject_Set/GetAttr() calls.

This patch fixes bug #113829.
2000-09-18 16:22:27 +00:00
Guido van Rossum 6f25618be5 Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
sigaction() (if HAVE_SIGACTION is defined).
2000-09-16 16:32:19 +00:00
Jack Jansen a454ebd924 Added B format char to Py_BuildValue (same as b,h,i, but makes
bgen-generated code work).
2000-09-15 12:52:19 +00:00
Jack Jansen b763b9d9d5 Cast UCHAR_MAX to int before doing the comparison for overflow of the
B format char.
2000-09-15 12:51:01 +00:00
Fred Drake fd1f1be98d com_continue_stmt(): Improve error message when continue is found
in a try statement in a loop.

This is related to SourceForge bug #110830.
2000-09-08 16:31:24 +00:00
Marc-André Lemburg bbcf2a7c81 This patch hopefully fixes the problem with "es#" and "es" in
PyArg_ParseTupleAndKeywords() and closes bug #113807.
2000-09-08 11:49:37 +00:00
Guido van Rossum f26cda62b6 The GCC version is loooooooooong; put it on a new line. 2000-09-05 04:40:39 +00:00
Guido van Rossum f4d189f70b All right. More uniformity, and extra blank lines. 2000-09-04 01:27:04 +00:00
Guido van Rossum 7ca7b5ac93 Use periods, not semicolons between Copyright and All Rights Reserved. 2000-09-04 01:22:12 +00:00
Vladimir Marangozov 547936c86f Fix the char* vs. const char* mismatch for the argument of aix_loaderror() 2000-09-04 00:54:56 +00:00
Guido van Rossum 76ad68ae6e Change the copyright notice according to CNRI's wishes, with
BeOpen.com added to the front.

(Even if maybe we won't print this long banner at startup, the string
must still be defined for sys.copyright.)
2000-09-03 03:35:50 +00:00
Fredrik Lundh 1fa0b895ec changed \x to consume exactly two hex digits. implements PEP-223
for 8-bit strings.
2000-09-02 20:11:27 +00:00
Tim Peters 412f246024 PyInterpreterState_New is not thread-safe, and the recent fix to _PyPclose
can cause it to get called by multiple threads simultaneously.

Ditto for PyInterpreterState_Delete.

Of the former, the docs say "The interpreter lock need not be held, but may
be held if it is necessary to serialize calls to this function".  This
kinda implies it both is and isn't thread-safe.

Of the latter, the docs merely say "The interpreter lock need not be
held.", and the clause about serializing is absent.

I expect it was *believed* these are both thread-safe, and the bit about
serializing via the global lock was meant as a permission rather than a
caution.

I also expect we've never seen a problem here because the Python core
(prior to the _PyPclose fix) only calls these functions once per run.
The Py_NewInterpreter subsystem exposed by the C API (but not used by
Python itself) also calls them, but that subsystem appears to be very
rarely used.

Whatever, they're both thread-safe now.
2000-09-02 09:16:15 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Vladimir Marangozov 7bd25be508 Cosmetics on Py_Get/SetRecursionLimit (for the style guide) 2000-09-01 11:07:19 +00:00
Jeremy Hylton b69a27e5b2 code part of patch #100895 by Fredrik Lundh
PyErr_Format computes size of buffer needed rather than relying on
static buffer.
2000-09-01 03:49:47 +00:00
Tim Peters d320c348f8 Revert removal of void from function definition. Guido sez I can take it
out again after we complete switching to C++ <wink>.  Thanks to Greg Stein
for hitting me.
2000-09-01 03:34:26 +00:00
Jeremy Hylton b709df3810 refactor __del__ exception handler into PyErr_WriteUnraisable
add sanity check to gc: if an exception occurs during GC, call
PyErr_WriteUnraisable and then call Py_FatalEror.
2000-09-01 02:47:25 +00:00
Guido van Rossum 349ff6f7e2 Set the recursion limit to 1000 -- 2500 was not enough, let's be
conservative.
2000-09-01 01:52:08 +00:00
Tim Peters 51de6906be Supply missing prototypes for new Py_{Get,Set}RecursionLimit; fixes compiler wngs;
un-analize Get's definition ("void" is needed only in declarations, not defns, &
is generally considered bad style in the latter).
2000-09-01 00:01:58 +00:00
Jeremy Hylton ee5adfbae6 add user-modifiable recursion_limit
ceval.c:
    define recurion_limit (static), default value is 2500
    define Py_GetRecursionLimit and Py_SetRecursionLimit
    raise RuntimeError if limit is exceeded
PC/config.h:
    remove plat-specific definition
sysmodule.c:
    add sys.(get|set)recursionlimit
2000-08-31 19:23:01 +00:00
Fred Drake 592f2d6c85 _PySys_Init(): When setting up sys.version_info, use #if/#elif.../#endif
instead of four #if/#endif blocks.  This shortens the
                code and improves readability.
2000-08-31 15:21:11 +00:00
Fred Drake 399739f79f PyOS_CheckStack(): Better ANSI'fy this while we're at it. 2000-08-31 05:52:44 +00:00
Fred Drake e8de31cbd0 Add a comment explaining the return value of PyOS_CheckStack(). 2000-08-31 05:38:39 +00:00
Paul Prescod e68140dd3c Better error message with UnboundLocalError 2000-08-30 20:25:01 +00:00
Barry Warsaw 093abe005d eval_code2(): Guido provides this patch for his suggested elaboration
of extended print.  If the file object being printed to is None, then
sys.stdout is used.
2000-08-29 04:56:13 +00:00
Thomas Wouters dd13e4f91f Replace the run-time 'future-bytecode-stream-inspection' hack to find out
how 'import' was called with a compiletime mechanism: create either a tuple
of the import arguments, or None (in the case of a normal import), add it to
the code-block constants, and load it onto the stack before calling
IMPORT_NAME.
2000-08-27 20:31:27 +00:00
Tim Peters e868211e10 Hard to believe Guido compiled this! Function lacked a return stmt. 2000-08-27 20:18:17 +00:00
Thomas Wouters e753ef8d1b Re-allow 'import mod.submod as s', and change its meaning to what it should
mean; the same as 'from mod import submod as s'.
2000-08-27 20:16:32 +00:00
Guido van Rossum 0df002c45b Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
PyRun_FileEx().  These are the same as their non-Ex counterparts but
have an extra argument, a flag telling them to close the file when
done.

Then this is used by Py_Main() and execfile() to close the file after
it is parsed but before it is executed.

Adding APIs seems strange given the feature freeze but it's the only
way I see to close the bug report without incompatible changes.

[ Bug #110616 ] source file stays open after parsing is done (PR#209)
2000-08-27 19:21:52 +00:00
Fredrik Lundh 2f15b25da2 implements PyOS_CheckStack for Windows and MSVC. this fixes a
couple of potential stack overflows, including bug #110615.

closes patch #101238
2000-08-27 19:15:31 +00:00
Thomas Wouters 0ae722e0a2 Oops, one pop too many. 2000-08-27 19:01:33 +00:00
Guido van Rossum fee3a2dd8c Charles Waldman's patch to reinitialize the interpreter lock after a
fork.  This solves the test_fork1 problem.  (ceval.c, signalmodule.c,
intrcheck.c)

SourceForge: [ Patch #101226 ] make threading fork-safe
2000-08-27 17:34:07 +00:00
Marc-André Lemburg dc3d606bd9 Fix to [ Bug #111165 ] doc-string removal masked by PYTHONOPTIMIZE 2000-08-25 21:00:46 +00:00
Thomas Wouters b59290f5b2 Fix allowable node-types for assignment, need to add 'listmaker'.
(This fix is a bit broken, just as the test already was: the test for
testlist and listmaker are done always, whereas the test for exprlist and
the actual abort() are only done if Py_DEBUG is defined. Suggestions
welcome, I guess ;)
2000-08-25 05:41:11 +00:00
Fred Drake 6d63adfbb7 Improve the exceptions raised by PyErr_BadInternalCall(); adding the
filename and line number of the call site to allow esier debugging.

This closes SourceForge patch #101214.
2000-08-24 22:38:39 +00:00
Thomas Wouters 434d0828d8 Support for three-token characters (**=, >>=, <<=) which was written by
Michael Hudson, and support in general for the augmented assignment syntax.
The graminit.c patch is large!
2000-08-24 20:11:32 +00:00
Fred Drake ef8ace3a6f Charles G. Waldman <cgw@fnal.gov>:
Add the EXTENDED_ARG opcode to the virtual machine, allowing 32-bit
arguments to opcodes instead of being forced to stick to the 16-bit
limit.  This is especially useful for machine-generated code, which
can be too long for the SET_LINENO parameter to fit into 16 bits.

This closes the implementation portion of SourceForge patch #100893.
2000-08-24 00:32:09 +00:00
Trent Mick 635f6fb0e9 This patch partly (some stuff went in already) ports Python to Monterey.
- Fix bug in thread_pthread.h::PyThread_get_thread_ident() where
  sizeof(pthread) < sizeof(long).
- Add 'configure' for:
	- SIZEOF_PTHREAD is pthread_t can be included via <pthread.h>
	- setting Monterey system name
	- appropriate CC,LINKCC,LDSHARED,OPT, and CCSHARED for Monterey
- Add section in README for Monterey build
2000-08-23 21:33:05 +00:00
Fred Drake b745a0481b Remove the dependency information for version.o; this is not part of
the sources/build process any more.
2000-08-23 21:16:10 +00:00
Skip Montanaro 46dfa5f4ed require list comprehensions to start with a for clause 2000-08-22 02:43:07 +00:00
Barry Warsaw 24703a02e7 com_print_stmt(): Guido rightly points out that the stream expression
in extended prints should only be evaluated once.  This patch plays
stack games (documented!) to fix this.
2000-08-21 17:07:20 +00:00
Barry Warsaw 45ab2b65f6 Thomas reminds me to bump the MAGIC number for the extended print
opcode additions.
2000-08-21 16:35:06 +00:00
Barry Warsaw 23c9ec87cf PEP 214, Extended print Statement, has been accepted by the BDFL.
eval_code2(): Implement new bytecodes PRINT_ITEM_TO and
PRINT_NEWLINE_TO, as per accepted SF patch #100970.

Also update graminit.c based on related Grammar/Grammar changes.
2000-08-21 15:44:01 +00:00
Barry Warsaw 29c574e30c PEP 214, Extended print Statement, has been accepted by the BDFL.
com_print_stmt(): Implement recognition of, and byte compilation for,
extended print using new byte codes PRINT_ITEM_TO and
PRINT_NEWLINE_TO.
2000-08-21 15:38:56 +00:00
Thomas Wouters 0400515ff0 Fix the bug Sjoerd Mullender discovered, where find_from_args() wasn't
trying hard enough to find out what the arguments to an import were. There
is no test-case for this bug, yet, but this is what it looked like:

from encodings import cp1006, cp1026
ImportError: cannot import name cp1026

'__import__' was called with only the first name in the 'arguments' list.
2000-08-20 14:01:53 +00:00
Thomas Wouters 8bad612881 Disallow "import mod.submod as m", because the result is ambiguous. Does it
load mod.submod as m, or mod as m ? Both can be achieved differently, and
unambiguously. Also attempt to document this restriction (editor
appreciated!)

Note that this is an artificial check during compile, because incorporating
this in the grammar is hard, and then adjusting the compiler to do the right
thing with the right nodes is harder.
2000-08-19 20:55:02 +00:00
Barry Warsaw 73f77b4495 com_error(): Quiet gcc -Wall warning. 2000-08-18 19:59:20 +00:00
Fred Drake 04e654a63c Remove a couple of warnings turned up by "gcc -Wall". 2000-08-18 19:53:25 +00:00
Vladimir Marangozov 0888ff17bd Do not set a MemoryError exception over another MemoryError exception,
thus preserving the first one that has been raised.
2000-08-18 18:01:06 +00:00
Barry Warsaw 87bec35d74 SyntaxError__classinit__(): Slight reorg for simplicity. 2000-08-18 05:05:37 +00:00
Barry Warsaw 5ca1ef9238 comples_from_string(): Move s_buffer[] up to the top-level function
scope.  Previously, s_buffer[] was defined inside the
PyUnicode_Check() scope, but referred to in the outer scope via
assignment to s.  This quiets an Insure portability warning.
2000-08-18 05:02:16 +00:00
Thomas Wouters 5215225ea1 Apply SF patch #101135, adding 'import module as m' and 'from module import
name as n'. By doing some twists and turns, "as" is not a reserved word.

There is a slight change in semantics for 'from module import name' (it will
now honour the 'global' keyword) but only in cases that are explicitly
undocumented.
2000-08-17 22:55:00 +00:00
Barry Warsaw f2581c97f2 _PySys_Init(): Fix another Insure discovered memory leak; the PyString
created from the "big"/"little" constant needs to be decref'd.
2000-08-16 23:03:57 +00:00
Barry Warsaw 77c9f50422 SyntaxError__str__(): Fix two memory problems discovered by Insure.
First, the allocated buffer was never freed after using it to create
the PyString object.  Second, it was possible that have_filename would
be false (meaning that filename was not a PyString object), but that
the code would still try to PyString_GET_SIZE() it.
2000-08-16 19:43:17 +00:00
Tim Peters b59ab42487 Fix new compiler warnings. Unused var in compile.c. Argsize mismatches
in binascii.c (only on platforms with signed chars -- although Py_CHARMASK
is documented as returning an int, it only does so on platforms with
signed chars).
2000-08-15 16:41:26 +00:00
Fred Drake 185a29b08f my_basename(): Removes the leading path components from a path name,
returning a pointer to the start of the file's "base" name;
	similar to os.path.basename().

SyntaxError__str__():  Use my_basename() to keep the length of the
	file name included in the exception message short.
2000-08-15 16:20:36 +00:00
Fred Drake a811a5b13a Remove the osdefs.h #include; it was not needed in the final version of
my last set of changes.
2000-08-15 16:13:37 +00:00
Fred Drake dcf08e0dfe When raising a SyntaxError, make a best-effort attempt to set the
filename and lineno attributes, but do not mask the SyntaxError if we
fail.

This is part of what is needed to close SoruceForge bug #110628
(Jitterbug PR#278).

Wrap a long line to fit in under 80 columns.
2000-08-15 15:49:44 +00:00
Fred Drake 83cb797380 When raising a SyntaxError, make a best-effort attempt to set the
filename and lineno attributes, but do not mask the SyntaxError if we
fail.

This is part of what is needed to close SoruceForge bug #110628
(Jitterbug PR#278).
2000-08-15 15:49:03 +00:00
Fred Drake 1aba577093 SyntaxError__str__(): Do more formatting of the exception here, rather
than depending on the site that raises the exception.  If the
	filename and lineno attributes are set on the exception object,
	use them to augment the message displayed.

This is part of what is needed to close SoruceForge bug #110628
(Jitterbug PR#278).
2000-08-15 15:46:16 +00:00
Fred Drake a2b6ad6e27 Guido pointed out that all names in the sys module have no underscore, 2000-08-15 04:24:43 +00:00
Mark Hammond 557a044f74 Fix the parent of WindowsError - both the comments in this source file, and the previous exceptions.py have WindowsError as a sub-class of OSError. 2000-08-15 00:37:32 +00:00
Fred Drake ccede59889 The attempt to protect against MS_WIN16 compilers that do not support long
string literals has not been tested on an MS_WIN16 platform; the trailing
";" was inside the #ifndef MS_WIN16, which should cause an error (missing
semi-colon) when compiled with that symbol #defined.
2000-08-14 20:59:57 +00:00
Fred Drake 099325e01b Add a byte_order value to the sys module. The value is "big" for
big-endian machines and "little" for little-endian machines.
2000-08-14 15:47:03 +00:00
Thomas Wouters 87df80d542 The list comp patch checked for the second child node of the 'listmaker'
node, without checking if the node actually had more than one child. It can
have only one node, though: '[' test ']'. This fixes it.
2000-08-13 17:05:17 +00:00
Thomas Wouters 361852f80e The list comprehensions patch partly reversed the removal of UNPACK_LIST,
re-introducing com_assign_list, now unused. Removed it.
2000-08-12 22:03:16 +00:00
Trent Mick 29b83810bd Clean up a couple of warnings on Win64. The downcast of the strlen size_t
return value to int is safe here because in each case it previouls checked that
there will be no overflow.
2000-08-12 21:35:36 +00:00
Skip Montanaro 803d6e5451 list comprehensions. see
http://sourceforge.net/patch/?func=detailpatch&patch_id=100654&group_id=5470

for details.
2000-08-12 18:09:51 +00:00
Thomas Wouters 0be5aab04d Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
did the same anyway.

I'm not sure what to do with Tools/compiler/compiler/* -- that isn't part of
distutils, is it ? Should it try to be compatible with old bytecode version ?
2000-08-11 22:15:52 +00:00
Fredrik Lundh 6947d0b65e -- from Trent Mick: [Patch #101010] replace use of INT_PTR
with uintptr_t (fix MSVC 5.0 build)
2000-08-07 20:16:28 +00:00
Guido van Rossum 6c2f0c73a1 When returning an error from jcompile() (which is passed through by
PyNode_Compile()), make sure that an exception is actually set --
otherwise someone stomped on our error.  [2.0 checkin of this fix.]
2000-08-07 19:22:43 +00:00
Guido van Rossum ed473a46fc Avoid dumping core when PyErr_NormalizeException() is called without
an exception set.  This shouldn't happen, but we see it at times...
2000-08-07 19:18:27 +00:00
Moshe Zadka aa39a7edf7 Initialized opcode and oparg to silence a gcc -Wall warning. 2000-08-07 06:34:45 +00:00
Thomas Wouters e8643c465d Fix some strange indentation and grammar that have been bugging me for
weeks.
2000-08-05 21:37:50 +00:00
Jack Jansen cc22fbe3db Changed H specifier to mean "bitfield", i.e. any value from
-32768..65535 is acceptable. Added B specifier (with values from
-128..255). No L added (which would have completed the set) because l
already accepts any value (and the letter L is taken for quadwords).
2000-08-05 21:29:58 +00:00
Moshe Zadka 9fb6af9640 Removing warnings by gcc -Wall -- cast ugly || to void. 2000-08-04 21:27:47 +00:00
Guido van Rossum 413407f103 Add a test that Py_IsInitialized() in Py_InitModule4(). See
python-dev discussion.

This should catch future version incompatibilities on Windows.  Alas,
this doesn't help for 1.5 vs. 1.6; but it will help for 1.6 vs. 2.0.
2000-08-04 14:00:14 +00:00
Marc-André Lemburg bff879cabb This patch finalizes the move from UTF-8 to a default encoding in
the Python Unicode implementation.

The internal buffer used for implementing the buffer protocol
is renamed to defenc to make this change visible. It now holds the
default encoded version of the Unicode object and is calculated
on demand (NULL otherwise).

Since the default encoding defaults to ASCII, this will mean that
Unicode objects which hold non-ASCII characters will no longer
work on C APIs using the "s" or "t" parser markers. C APIs must now
explicitly provide Unicode support via the "u", "U" or "es"/"es#"
parser markers in order to work with non-ASCII Unicode strings.

(Note: this patch will also have to be applied to the 1.6 branch
 of the CVS tree.)
2000-08-03 18:46:08 +00:00
Guido van Rossum 16b1ad9c7d Changing the CNRI copyright notice according to CNRI's instructions.
This is a notice without a date, which apparently is not a claim to
copyright but only advice to the reader.  IANAL. :-)
2000-08-03 16:24:25 +00:00
Barry Warsaw bd599b5928 Both PEP 201 Lockstep Iteration and SF patch #101030 have been
accepted by the BDFL.

builtin_zip(): New function to implement the zip() function described
in the above proposal.

zip_doc[]: Docstring for zip().

builtin_methods[]: added entry for zip()
2000-08-03 15:45:29 +00:00
Fred Drake 19c6afb42b Include the dependence of sysmodule on the patchlevel.h include, so
that sys.version_info will be built properly.
2000-08-01 17:46:22 +00:00
Peter Schneider-Kamp 7e01890986 merge Include/my*.h into Include/pyport.h
marked my*.h as obsolete
2000-07-31 15:28:04 +00:00
Thomas Wouters 334fb8985b Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Leave the actual #define in for API compatibility.
2000-07-25 12:56:38 +00:00
Thomas Wouters 1e0c2f4bee Create a new section of pyport.h to hold all external function declarations
for systems that are missing those declarations from system include files.
Start by moving a pointy-haired ones from their previous locations to the
new section.

(The gethostname() one, for instance, breaks on several systems, because
some define it as (char *, size_t) and some as (char *, int).)

I purposely decided not to include the summary of used #defines like Tim did
in the first section of pyport.h. In my opinion, the number of #defines
likedly to be used by this section would make such an overview unwieldy. I
would suggest documenting the non-obvious ones, though.
2000-07-24 16:06:23 +00:00
Thomas Wouters 8ec68fded2 Prototype yet another forward declaration. 2000-07-24 14:39:50 +00:00
Thomas Wouters e28c296f0f Another missed ansification. 2000-07-23 22:21:32 +00:00
Tim Peters 8315ea5790 Included assert.h in Python.h -- it's absurd that this basic tool of
good C practice hasn't been available to everything all along.
Added Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) macro to pyport.h; this
just casts VALUE from type WIDE to type NARROW, but assert-fails if
Py_DEBUG is defined and info is lost due to casting.
Replaced a line in Fredrik's fix to marshal.c to use the new macro.
2000-07-23 19:28:35 +00:00
Fredrik Lundh 115343849c -- changed w_more to take an integer instead of a char
(this is what the callers expect).
2000-07-23 18:24:06 +00:00
Thomas Wouters 2f2370bfc9 Oops. One of last nights ANSIfication patches accidentily upped the bytecode
MAGIC number. When updating it next time, be sure it's higher than 50715 *
constants. (Shouldn't be a problem if everyone keeps to the proper
algorithm.)
2000-07-23 09:20:08 +00:00
Thomas Wouters b4bd21cf79 ANSIfy as many declarations as possible. 2000-07-22 23:38:01 +00:00
Thomas Wouters f70ef4f860 Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
2000-07-22 18:47:25 +00:00
Thomas Wouters 0452d1f316 Fix two instances of empty argument lists, and fix style
('PyObject** x' -> 'PyObject **x')
2000-07-22 18:45:06 +00:00
Thomas Wouters 7e47402264 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
comments, docstrings or error messages. I fixed two minor things in
test_winreg.py ("didn't" -> "Didn't" and "Didnt" -> "Didn't").

There is a minor style issue involved: Guido seems to have preferred English
grammar (behaviour, honour) in a couple places. This patch changes that to
American, which is the more prominent style in the source. I prefer English
myself, so if English is preferred, I'd be happy to supply a patch myself ;)
2000-07-16 12:04:32 +00:00
Peter Schneider-Kamp 9a5086c598 just fixing the indentation 2000-07-13 06:24:29 +00:00
Peter Schneider-Kamp 11384c60f6 raise error on duplicate function arguments
example:

>>> def f(a,a):print a
...
SyntaxError: duplicate argument in function definition
2000-07-13 06:15:04 +00:00
Skip Montanaro 6980dff3db delete obsolete SYMANTEC__CFM68K__ #ifdefs 2000-07-12 17:21:42 +00:00
Jeremy Hylton 03657cfdb0 replace PyXXX_Length calls with PyXXX_Size calls 2000-07-12 13:05:33 +00:00
Tim Peters bf26e07049 Worm around MSVC6 error on single string literal > 2Kb. 2000-07-12 04:02:10 +00:00
Jack Jansen cbf630f0a9 Include macglue.h for some function prototypes, and renamed a few
mac-specific functions to have a PyMac_ name.
2000-07-11 21:59:16 +00:00
Fred Drake 85f363990c Create two new exceptions: IndentationError and TabError. These are
used for indentation related errors.  This patch includes Ping's
improvements for indentation-related error messages.

Closes SourceForge patches #100734 and #100856.
2000-07-11 17:53:00 +00:00
Barry Warsaw b78165566e Exception__str__(): In case 1, be sure to decref the tmp local
variable.  This crushes another memory leak.  Slight rewrite
included.
2000-07-09 22:27:10 +00:00
Barry Warsaw 7dfeb42939 EnvironmentError__init__(): The two case clauses were missing
`break's.  This first missing break caused a memory leak when case 3
fell through case 2 in the following example:

import os
os.chmod('/missing', 0600)
2000-07-09 04:56:25 +00:00
Tim Peters dbd9ba6a6c Nuke all remaining occurrences of Py_PROTO and Py_FPROTO. 2000-07-09 03:09:57 +00:00
Tim Peters 4be47c0f76 Get rid of unused vars in builtin_unicode (they were causing
legit warnings).
2000-07-09 02:11:18 +00:00
Marc-André Lemburg 1b1bcc9935 Fixed unicode() to use the new API PyUnicode_FromEncodedObject().
This adds support for instance to the constructor (instances
have to define __str__ and can return Unicode objects via that
hook; string return values are decoded into Unicode using the
current default encoding).
2000-07-07 13:48:25 +00:00
Jack Jansen d50338fbd9 Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Py_BuildValue.
2000-07-06 12:22:00 +00:00
Jack Jansen 41aa8e523d Include limits.h if we have it. 2000-07-03 21:39:47 +00:00
Barry Warsaw 8fcaa92c5f init_exceptions(): Decref `doc' so it doesn't leak. 2000-07-01 04:45:52 +00:00
Guido van Rossum db67739d4f Jack Jansen, Mac patch:
Include limits.h if we have it.
2000-07-01 01:09:43 +00:00
Guido van Rossum f12d7a02a0 Jack Jansen, Mac patch:
If we have stat.h include it if we don't have sys/stat.h
2000-07-01 01:08:11 +00:00
Guido van Rossum 63e97ad4ea Jack Jansen, Mac patch:
Include stat.h if needed; different Mac filename compare
2000-07-01 01:06:56 +00:00
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Fred Drake 615ae55eca Trent Mick <trentm@activestate.com>:
The common technique for printing out a pointer has been to cast to a long
and use the "%lx" printf modifier. This is incorrect on Win64 where casting
to a long truncates the pointer. The "%p" formatter should be used instead.

The problem as stated by Tim:
> Unfortunately, the C committee refused to define what %p conversion "looks
> like" -- they explicitly allowed it to be implementation-defined. Older
> versions of Microsoft C even stuck a colon in the middle of the address (in
> the days of segment+offset addressing)!

The result is that the hex value of a pointer will maybe/maybe not have a 0x
prepended to it.


Notes on the patch:

There are two main classes of changes:
- in the various repr() functions that print out pointers
- debugging printf's in the various thread_*.h files (these are why the
patch is large)


Closes SourceForge patch #100505.
2000-06-30 16:20:13 +00:00
Fred Drake 4c82b2366f Trent Mick <trentm@activestate.com>:
This patch fixes possible overflow in the use of
PyOS_GetLastModificationTime in getmtime.c and Python/import.c.

Currently PyOS_GetLastModificationTime returns a C long. This can
overflow on Win64 where sizeof(time_t) > sizeof(long). Besides it
should logically return a time_t anyway (this patch changes this).

As well, import.c uses PyOS_GetLastModificationTime for .pyc
timestamping.  There has been recent discussion about the .pyc header
format on python-dev.  This patch adds oveflow checking to import.c so
that an exception will be raised if the modification time
overflows. There are a few other minor 64-bit readiness changes made
to the module as well:

- size_t instead of int or long for function-local buffer and string
length variables

- one buffer overflow check was added (raises an exception on possible
overflow, this overflow chance exists on 32-bit platforms as well), no
other possible buffer overflows existed (from my analysis anyway)

Closes SourceForge patch #100509.
2000-06-30 16:18:57 +00:00
Fred Drake a44d353e2b Trent Mick <trentm@activestate.com>:
The common technique for printing out a pointer has been to cast to a long
and use the "%lx" printf modifier. This is incorrect on Win64 where casting
to a long truncates the pointer. The "%p" formatter should be used instead.

The problem as stated by Tim:
> Unfortunately, the C committee refused to define what %p conversion "looks
> like" -- they explicitly allowed it to be implementation-defined. Older
> versions of Microsoft C even stuck a colon in the middle of the address (in
> the days of segment+offset addressing)!

The result is that the hex value of a pointer will maybe/maybe not have a 0x
prepended to it.


Notes on the patch:

There are two main classes of changes:
- in the various repr() functions that print out pointers
- debugging printf's in the various thread_*.h files (these are why the
patch is large)


Closes SourceForge patch #100505.
2000-06-30 15:01:00 +00:00
Jeremy Hylton 4e542a3d99 replace constant 1 with symbolic constant METH_VARARGS
another typo caught by Rob Hooft
2000-06-30 04:59:59 +00:00
Jeremy Hylton 9262b8ab1f another typo caught by Rob Hooft 2000-06-30 04:59:17 +00:00
Fredrik Lundh 34a96371c3 - workaround to make 1.6 build under MSVC 5.0. hopefully,
trent (who broke it in the first place ;-) will come up
  with a cleaner solution.
2000-06-29 17:25:30 +00:00
Guido van Rossum 338311378e Change the loop index in normalizestring() to size_t too, to avoid a
warning on Windows.
2000-06-29 14:50:15 +00:00
Guido van Rossum 5e08cb8e50 Vladimir Marangozov:
This patch fixes a problem on AIX with the signed int case code in
getargs.c, after Trent Mick's intervention about MIN/MAX overflow
checks. The AIX compiler/optimizer generates bogus code with the
default flags "-g -O" causing test_builtin to fail: int("10", 16) <>
16L. Swapping the two checks in the signed int code makes the problem
go away.

Also, make the error messages fit in 80 char lines in the
source.
2000-06-28 23:53:56 +00:00
Guido van Rossum 98626cd7ac Urmpf. Quality control on this patch lapsed a bit. :-(
The depth field was never decremented inside w_object(), and it was
never initialized in PyMarshal_WriteObjectToFile().

This caused imports from .pyc files to fil mysteriously when the .pyc
file was written by the broken code -- w_object() would bail out
early, but PyMarshal_WriteObjectToFile() doesn't check the error or
return an error code, and apparently the marshalling code doesn't call
PyErr_Check() either.  (That's a separate patch if I feel like it.)
2000-06-28 23:24:19 +00:00
Guido van Rossum 582acece2e Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
tests.
2000-06-28 22:07:35 +00:00
Guido van Rossum 106f2dae86 Trent Mick:
Various small fixes to the builtin module to ensure no buffer
overflows.

- chunk #1:
Proper casting to ensure no truncation, and hence no surprises, in the
comparison.

- chunk #2:
The id() function guarantees a unique return value for different
objects.  It does this by returning the pointer to the object. By
returning a PyInt, on Win64 (sizeof(long) < sizeof(void*)) the pointer
is truncated and the guarantee may be proven false. The appropriate
return function is PyLong_FromVoidPtr, this returns a PyLong if that
is necessary to return the pointer without truncation.

[GvR: note that this means that id() can now return a long on Win32
platforms.  This *might* break some code...]

- chunk #3:
Ensure no overflow in raw_input(). Granted the user would have to pass
in >2GB of data but it *is* a possible buffer overflow condition.
2000-06-28 21:12:25 +00:00
Fred Drake 6da0b9148c Michael Hudson <mwh21@cam.ac.uk>:
As I really do not have anything better to do at the moment, I have written
a patch to Python/marshal.c that prevents Python dumping core when trying
to marshal stack bustingly deep (or recursive) data structure.

It just throws an exception; even slightly clever handling of recursive
data is what pickle is for...

[Fred Drake:]  Moved magic constant 5000 to a #define.

This closes SourceForge patch #100645.
2000-06-28 18:47:56 +00:00
Jeremy Hylton 94988067b9 Add new parser error code, E_OVERFLOW. This error is returned when
the number of children of a node exceeds the max possible value for
the short that is used to count them.  The Python runtime converts
this parser error into the SyntaxError "expression too long."
2000-06-20 19:10:44 +00:00
Jeremy Hylton 2d15d9d869 mark SyntaxError__str__ as METH_VARARGS 2000-06-20 18:36:26 +00:00
Mark Hammond 440d898230 Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Also removed a redundant cast from sys.getrefcount(), as discussed on the patches list.
2000-06-20 08:12:48 +00:00
Fred Drake 5550de3084 Christopher Fandrich <cfandrich@8cs.com>:
Fix memory leak in initializing __debug__.
2000-06-20 04:54:19 +00:00
Marc-André Lemburg 99964b86b2 Marc-Andre Lemburg <mal@lemburg.com>:
Changed the API names for setting the default encoding.
These are now in line with the other hooks API names
(no underscores).
2000-06-07 09:13:41 +00:00
Barry Warsaw 675ac285ae The standard exception classes. Moved here from ../Modules/_exceptions.c 2000-05-26 19:05:16 +00:00
Barry Warsaw f17861badc Added exceptions.o to the list of object to build in this subdir. 2000-05-26 19:04:27 +00:00
Barry Warsaw 78e6c671db All the exception building related stuff has been moved out of this
module and into _exceptions.c.  This includes all the PyExc_* globals,
the bltin_exc table, init_class_exc(), fini_instances(),
finierrors().

Renamed _PyBuiltin_Init_1() to _PyBuiltin_Init() since the two phase
initializations are necessary any more.

Removed as obsolete _PyBuiltin_Init_2(), _PyBuiltin_Fini_1() and
_PyBuiltin_Fini_2().
2000-05-25 23:15:05 +00:00
Barry Warsaw f242aa0d1e Py_Initialize(): Now that standard exceptions are builtin, we don't
need two phase init or fini of the builtin module.  Change the call of
_PyBuiltin_Init_1() to _PyBuiltin_Init().  Add a call to
init_exceptions().

Py_Finalize(): Don't call _PyBuiltin_Fini_1().  Instead call
fini_exceptions() but move this to before the thread state is
cleared.
2000-05-25 23:09:49 +00:00
Barry Warsaw 1226588e57 bltin_exc: Removed the leaf_exc flag in the structure, which was only
used to build the fallback string-based exception.
2000-05-25 03:18:53 +00:00
Guido van Rossum ede8c6eea1 Bill Tutt:
Calling Sleep(0) for a spinlock can cause a priority inversion, adding
comments to explain what's going on.
2000-05-11 12:53:51 +00:00
Guido van Rossum cf3ba65749 At Bob Kahn's request, add CNRI to the copyright string (but not to
the notice yet).
2000-05-10 20:06:00 +00:00
Fred Drake 230cae7474 Trent Mick <trentm@activestate.com>:
Limit the 'b' formatter of PyArg_ParseTuple to valid values of an unsigned
char, i.e. [0,UCHAR_MAX]. It is expected that this is the common usage of 'b'.
An OverflowError is raised if the parsed value is outside this range.
2000-05-09 21:50:00 +00:00
Fred Drake 8b4d01d9f9 M.-A. Lemburg <mal@lemburg.com>:
Added APIs to allow setting and querying the system's
current string encoding: sys.set_string_encoding()
and sys.get_string_encoding().
2000-05-09 19:57:01 +00:00
Fred Drake 766de83ab1 M.-A. Lemburg <mal@lemburg.com>:
Moved some docs to the include file.

Added a NULL check to _PyCodec_Lookup() to make it
core dump safe.
2000-05-09 19:55:59 +00:00
Fred Drake c640b18d96 M.-A. Lemburg <mal@lemburg.com>:
Fixed docs according to the new behaviour (the Unicode
encoding is no longer fixed to UTF-8).
2000-05-09 19:55:16 +00:00
Guido van Rossum 20c6add7ff Trent Mick:
Change static slice_index() to extern _PyEval_SliceIndex() (with
different return value interpretation: 0 for failure, 1 for success).
2000-05-08 14:06:50 +00:00
Guido van Rossum 80dc16baaa Trent Mick:
Changes the 'b', 'h', and 'i' formatters in PyArg_ParseTuple to raise an
Overflow exception if they overflow (previously they just silently
overflowed).

Changes by Guido: always accept values [0..255] (in addition to
[CHAR_MIN..CHAR_MAX]) for 'b' format; changed some spaces into tabs in
other code.
2000-05-08 14:02:41 +00:00
Guido van Rossum 07bd90e92d Andy Dustman: add GNU pth user-space thread support. 2000-05-08 13:41:38 +00:00
Guido van Rossum 4cea605e75 Quick fix by Mark Hammond -- Yakov changed a dprintf call but it was
referencing an undefined variable, so we better change it back.
2000-05-05 14:29:59 +00:00
Guido van Rossum 706262bde0 Fast NonRecursiveMutex support by Yakov Markovitch, markovitch@iso.ru,
who wrote:

Here's the new version of thread_nt.h.  More particular, there is a
new version of thread lock that uses kernel object (e.g. semaphore)
only in case of contention; in other case it simply uses interlocked
functions, which are faster by the order of magnitude.  It doesn't
make much difference without threads present, but as soon as thread
machinery initialised and (mostly) the interpreter global lock is on,
difference becomes tremendous.  I've included a small script, which
initialises threads and launches pystone.  With original thread_nt.h,
Pystone results with initialised threads are twofold worse then w/o
threads.  With the new version, only 10% worse.  I have used this
patch for about 6 months (with threaded and non-threaded
applications).  It works remarkably well (though I'd desperately
prefer Python was free-threaded; I hope, it will soon).
2000-05-04 18:47:15 +00:00
Guido van Rossum cc229ea76f Add useless 'return 1' to prtrace() to shut up VC++. 2000-05-04 00:55:17 +00:00
Guido van Rossum b18618dab7 Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives.
For documentation read the comments in mymalloc.h and objimpl.h.

(This is not exactly what Vladimir posted to the patches list; I've
made a few changes, and Vladimir sent me a fix in private email for a
problem that only occurs in debug mode.  I'm also holding back on his
change to main.c, which seems unnecessary to me.)
2000-05-03 23:44:39 +00:00
Guido van Rossum a7cfca23e1 A bit of cleanup:
- When 'import exceptions' fails, don't suggest to use -v to print the traceback;
  this doesn't actually work.
- Remove comment about fallback to string exceptions.
- Remove a PyErr_Occurred() check after all is said and done that can
  never trigger.
- Remove static function newstdexception() which is no longer called.
2000-05-03 22:03:46 +00:00
Fred Drake 25871c001f Brian Hooper <brian_takashi@hotmail.com>:
Added 'u' and 'u#' tags for PyArg_ParseTuple - these turn a
PyUnicodeObject argument into a Py_UNICODE * buffer, or a Py_UNICODE *
buffer plus a length with the '#'.  Also added an analog to 'U'
for Py_BuildValue.
2000-05-03 15:17:02 +00:00
Barry Warsaw fa5c315afa PyErr_GivenExceptionMatches(): Check for err==NULL and exc==NULL and
return 0 (exceptions don't match).  This means that if an ImportError
is raised because exceptions.py can't be imported, the interpreter
will exit "cleanly" with an error message instead of just core
dumping.

PyErr_SetFromErrnoWithFilename(), PyErr_SetFromWindowsErrWithFilename():
Don't test on Py_UseClassExceptionsFlag.
2000-05-02 19:27:51 +00:00
Barry Warsaw 48719d3d1f _PyBuiltin_Init_2(): Remove the misleading comment. 2000-05-02 19:24:39 +00:00
Barry Warsaw 47eeb9bdad initerrors(): Remove this function. String-based standard exceptions
are no longer supported (i.e. -X option is removed).

_PyBuiltin_Init_1(): Don't call initerrors().  This does mean that it
is possible to raise an ImportError before that exception has been
initialized, say because exceptions.py can't be found, or contains
bogosity.  See changes to errors.c for how this is handled.

_PyBuiltin_Init_2(): Don't test Py_UseClassExceptionsFlag, just go
ahead and initialize the class-based standard exceptions.  If this
fails, we throw a Py_FatalError.
2000-05-02 19:24:06 +00:00
Barry Warsaw 3ce096459e Py_UseClassExceptionsFlag is deprecated. We keep the C variable for C
API consistency, but nothing sets it or checks it now.
2000-05-02 19:18:59 +00:00
Barry Warsaw ee98e4e75d Ignore a bunch of generated files. 2000-05-02 18:34:30 +00:00
Guido van Rossum 96774c1347 Marc-Andre Lemburg:
Changed all references to the MAGIC constant to use a global
pyc_magic instead. This global is initially set to MAGIC, but can be
changed by the _PyImport_Init() function to provide for
special features implemented in the compiler which are settable
using command line switches and affect the way PYC files are
generated.

Currently this change is only done for the -U flag.
2000-05-01 20:19:08 +00:00
Guido van Rossum b16d197d66 Marc-Andre Lemburg:
Added Py_UnicodeFlag for use by the -U command line option.
2000-05-01 17:55:15 +00:00
Guido van Rossum fdc8bdb67b Marc-Andre Lemburg:
Support for the new -U command line option option:
with the option enabled the Python compiler
interprets all "..." strings as u"..." (same with r"..." and
ur"...").
2000-05-01 17:54:56 +00:00
Guido van Rossum 22b65a8edc Robin Becker: The following patch seems to fix a module case bug in
1.6a2 caused by wrong return values in routine allcaps83.  [GvR: I
also changed the case for end-s>8 to return 0.]
2000-05-01 17:36:58 +00:00
Guido van Rossum 1cb6cd0ec5 As Marc-Andre Lemburg points out, the magic number needs to change
because we've added Unicode marshalling to the repertoire.
2000-04-28 19:03:54 +00:00
Guido van Rossum a2ace6ae25 Charles G Waldman:
Follow a suggestion in an /*XXX*/ comment [in com_add()] to speed up
compilation by using supplemental dictionaries to keep track of names
and constants, eliminating quadratic behavior.  With this patch in
place, the time to import a 5000-line file with lots of constants [at
the global level] is reduced from 20 seconds to under 3 on my system.
2000-04-28 16:42:25 +00:00
Fred Drake 25d34473c3 Brian Hooper <brian_takashi@hotmail.com>:
Here's a patch which changes modsupport to add 'u' and 'u#',
to support building Unicode objects from a null-terminated
Py_UNICODE *, and a Py_UNICODE * with length, respectively.

[Conversion from 'U' to 'u' by Fred, based on python-dev comments.]

Note that the use of None for NULL values of the Py_UNICODE* value is
still in; I'm not sure of the conclusion on that issue.
2000-04-28 14:42:37 +00:00
Guido van Rossum eca4784781 Mark Hammond: For Windows debug builds, we now only offer to dump
remaining object references if the environment variable PYTHONDUMPREFS
exists.  The default behaviour caused problems for background or
otherwise invisible processes that use the debug build of Python.
2000-04-27 23:44:15 +00:00
Guido van Rossum 700c6ff1fb Marc-Andre Lemburg:
Fixed a memory leak found by Fredrik Lundh.  Instead of
PyUnicode_AsUTF8String() we now use _PyUnicode_AsUTF8String() which
returns the string object without incremented refcount (and assures
that the so obtained object remains alive until the Unicode object is
garbage collected).
2000-04-27 20:13:18 +00:00
Guido van Rossum b33aa1a51e Jack Jansen: The new version of the GUSI i/o library on the Macintosh
has a few slightly different calls from the old one.
2000-04-24 15:08:18 +00:00
Guido van Rossum 095249fc8c Jack Jansen: Posix threads are now supported on the Macintosh too. 2000-04-24 15:06:51 +00:00
Guido van Rossum 25826c93c4 Charles Waldman writes:
"""
Running "test_extcall" repeatedly results in memory leaks.

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

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

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

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

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

[I think the circular reference is more like kw['x']['kw'] == kw. --GvR]
2000-04-21 21:17:39 +00:00
Jeremy Hylton 4a3dd2dcc2 Fix PR#7 comparisons of recursive objects
Note that comparisons of deeply nested objects can still dump core in
extreme cases.
2000-04-14 19:13:24 +00:00
Fred Drake 6d27c1eb32 Simplify creation of the version_info value for clarity, per
suggestion from Greg Stein.
2000-04-13 20:03:20 +00:00
Fred Drake 93a20bf87c Capitulate, changing version_info to a 5-tuple:
major, minor, micro, level, serial

Values are now monotonically increasing with each new release.
2000-04-13 17:44:51 +00:00
Fred Drake 801c08d700 Define version_info to be a tuple (major, minor, micro, level); level
is a string "a2", "b1", "c1", or '' for a final release.

Added version_info and hexversion to the module docstring.
2000-04-13 15:29:10 +00:00
Fred Drake 4e998bc658 M.-A. Lemburg <mal@lemburg.com>:
Fixed problem with Unicode string concatenation:
u = (u"abc" u"abc") previously dumped core.
2000-04-13 14:10:44 +00:00
Fred Drake 078b24f000 When refering to Unicode characters in exception messages and
docstrings, the documentation guidelines call for "Unicode", not
"unicode".  Comply.
2000-04-13 02:42:50 +00:00
Jeremy Hylton 394b54d01a ord: provide better error messages 2000-04-12 21:19:47 +00:00
Guido van Rossum 3afba7644b Marc-Andre Lemburg:
Added special case to unicode(): when being passed a
Unicode object as first argument, return the object as-is.
Raises an exception when given a Unicode object *and* an
encoding name.
2000-04-11 15:38:23 +00:00
Guido van Rossum 44679590e0 Patch by Vladimir Marangozov to include the function name when
comparing code objects.  This give sless surprising results in
-Optimized code.  It also sorts code objects by name, now.

[I changed the patch to hash() slightly to touch fewer lines.]
2000-04-10 16:20:31 +00:00
Guido van Rossum 5db862dd0c Skip Montanaro: add string precisions to calls to PyErr_Format
to prevent possible buffer overruns.
2000-04-10 12:46:51 +00:00
Guido van Rossum a396a883af Vladimir Marangozov: This fixes the line number in the string
representation of code objects when optimization is on (python -O). It
was always reported as -1 instead of the real lineno.
2000-04-07 01:21:36 +00:00
Guido van Rossum 9e896b37c7 Marc-Andre's third try at this bulk patch seems to work (except that
his copy of test_contains.py seems to be broken -- the lines he
deleted were already absent).  Checkin messages:


New Unicode support for int(), float(), complex() and long().

- new APIs PyInt_FromUnicode() and PyLong_FromUnicode()
- added support for Unicode to PyFloat_FromString()
- new encoding API PyUnicode_EncodeDecimal() which converts
  Unicode to a decimal char* string (used in the above new
  APIs)
- shortcuts for calls like int(<int object>) and float(<float obj>)
- tests for all of the above

Unicode compares and contains checks:
- comparing Unicode and non-string types now works; TypeErrors
  are masked, all other errors such as ValueError during
  Unicode coercion are passed through (note that PyUnicode_Compare
  does not implement the masking -- PyObject_Compare does this)
- contains now works for non-string types too; TypeErrors are
  masked and 0 returned; all other errors are passed through

Better testing support for the standard codecs.

Misc minor enhancements, such as an alias dbcs for the mbcs codec.

Changes:
- PyLong_FromString() now applies the same error checks as
  does PyInt_FromString(): trailing garbage is reported
  as error and not longer silently ignored. The only characters
  which may be trailing the digits are 'L' and 'l' -- these
  are still silently ignored.
- string.ato?() now directly interface to int(), long() and
  float(). The error strings are now a little different, but
  the type still remains the same. These functions are now
  ready to get declared obsolete ;-)
- PyNumber_Int() now also does a check for embedded NULL chars
  in the input string; PyNumber_Long() already did this (and
  still does)

Followed by:

Looks like I've gone a step too far there... (and test_contains.py
seem to have a bug too).

I've changed back to reporting all errors in PyUnicode_Contains()
and added a few more test cases to test_contains.py (plus corrected
the join() NameError).
2000-04-05 20:11:21 +00:00
Guido van Rossum b95de4f847 Marc-Andre Lemburg: Error reporting in the codec registry and lookup
mechanism is enhanced to be more informative.
2000-03-31 17:25:23 +00:00
Guido van Rossum 7a5b796322 Thomas Heller fixes a typo in an error message. 2000-03-31 13:52:29 +00:00
Jeremy Hylton 387b1011a1 rename args variable in CALL_FUNCTION to callargs (avoids name
override)

add missing DECREFs in error handling code of CALL_FUNCTION
2000-03-31 01:22:54 +00:00
Guido van Rossum 6d10887cdc Change traceback error message to "most recent call last" from
"innermost last".  The latter was mysterious to newbies.
2000-03-31 00:39:23 +00:00
Guido van Rossum ffc0f4fb36 Use modern PyArg_ParseTuple style, with function names.
(Mostly.)
2000-03-31 00:38:29 +00:00
Guido van Rossum 2efa369861 Use modern PyArg_ParseTuple style, with function names. 2000-03-31 00:37:41 +00:00
Jeremy Hylton 074c3e62d1 Two fixes for extended call syntax:
If a non-tuple sequence is passed as the *arg, convert it to a tuple
before checking its length.
If named keyword arguments are used in combination with **kwargs, make
a copy of kwargs before inserting the new keys.
2000-03-30 23:55:31 +00:00
Barry Warsaw b2ba9d8963 eval_code2(): Oops, in the last checkin, we shouldn't check for
PyErr_Occurred(), just set x=NULL and break.  Oh, and make Jeremy stop
nagging me about the "special" indentation for this block.
2000-03-29 18:36:49 +00:00
Barry Warsaw 4961ef7086 eval_code2(): In the extended calling syntax opcodes, you must check
the return value of PySequence_Length().  If an exception occurred,
the returned length will be -1.  Make sure this doesn't get obscurred,
and that the bogus length isn't used.
2000-03-29 18:30:03 +00:00
Jeremy Hylton e4fb958fc2 remove reference (vestigal) to CALL_FUNCTION_STAR 2000-03-29 00:10:44 +00:00
Jeremy Hylton 7690151c7e slightly modified version of Greg Ewing's extended call syntax patch
executive summary:
Instead of typing 'apply(f, args, kwargs)' you can type 'f(*arg, **kwargs)'.
Some file-by-file details follow.

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

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

Python/ceval.c:
    extend TypeError "keyword parameter redefined" message to include
        the name of the offending keyword
    reindent CALL_FUNCTION using four spaces
    add handling of sequences and dictionaries using extend calls
    fix function import_from to use PyErr_Format
2000-03-28 23:49:17 +00:00
Guido van Rossum 24bdb0474f Marc-Andre Lemburg:
The attached patch set includes a workaround to get Python with
Unicode compile on BSDI 4.x (courtesy Thomas Wouters; the cause
is a bug in the BSDI wchar.h header file) and Python interfaces
for the MBCS codec donated by Mark Hammond.

Also included are some minor corrections w/r to the docs of
the new "es" and "es#" parser markers (use PyMem_Free() instead
of free(); thanks to Mark Hammond for finding these).

The unicodedata tests are now in a separate file
(test_unicodedata.py) to avoid problems if the module cannot
be found.
2000-03-28 20:29:59 +00:00
Guido van Rossum 50fbb15b16 Typo fixed by Mark Hammond. 2000-03-28 02:00:29 +00:00
Guido van Rossum d8855fde88 Marc-Andre Lemburg:
Attached you find the latest update of the Unicode implementation.
The patch is against the current CVS version.

It includes the fix I posted yesterday for the core dump problem
in codecs.c (was introduced by my previous patch set -- sorry),
adds more tests for the codecs and two new parser markers
"es" and "es#".
2000-03-24 22:14:19 +00:00
Guido van Rossum 5ba3c843db Marc-Andre Lemburg:
Andy Robinson noted a core dump in the codecs.c file. This
was introduced by my latest patch which fixed a memory leak
in codecs.c. The bug causes all successful codec lookups to fail.
2000-03-24 20:52:23 +00:00
Barry Warsaw 51ac58039f On 17-Mar-2000, Marc-Andre Lemburg said:
Attached you find an update of the Unicode implementation.

    The patch is against the current CVS version. I would appreciate
    if someone with CVS checkin permissions could check the changes
    in.

    The patch contains all bugs and patches sent this week and also
    fixes a leak in the codecs code and a bug in the free list code
    for Unicode objects (which only shows up when compiling Python
    with Py_DEBUG; thanks to MarkH for spotting this one).
2000-03-20 16:36:48 +00:00
Guido van Rossum d724b23420 Christian Tismer's "trashcan" patch:
Added wrapping macros to dictobject.c, listobject.c, tupleobject.c,
frameobject.c, traceback.c that safely prevends core dumps
on stack overflow. Macros and functions in object.c, object.h.
The method is an "elevator destructor" that turns cascading
deletes into tail recursive behavior when some limit is hit.
2000-03-13 16:01:29 +00:00
Guido van Rossum 2d0f5f932a Marc-Andre Lemburg: add new unicode files 2000-03-10 23:04:14 +00:00
Guido van Rossum c94044c11d Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Codec registry.
2000-03-10 23:03:54 +00:00
Guido van Rossum c279b53b4f Marc-Andre Lemburg: support marshalling Unicode objects (code 'u'). 2000-03-10 23:03:02 +00:00
Guido van Rossum e826ef0a89 Marc-Andre Lemburg: support for Unicode strings; 'U' expects a Unicode
object.
2000-03-10 23:02:17 +00:00
Guido van Rossum 5aa88f097f Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"..."). 2000-03-10 23:01:36 +00:00
Guido van Rossum 09095f3f61 Marc-Andre Lemburg: added new builtin functions unicode() and
unichr(); changed ord() to support Unicode strings; added new
exception UnicodeError; fixed a typo in doc string for buffer().
2000-03-10 23:00:52 +00:00
Guido van Rossum feee4b994f Python Codec Registry and support functions, written by Marc-Andre
Lemburg.
2000-03-10 22:57:27 +00:00
Guido van Rossum 0b55670968 Mark discovered a bug in his patch: he didn't *use* PyExc_WindowsError
in PyErr_SetFromWindowsErrWithFilename() like he intended to... :-)
2000-03-02 13:55:01 +00:00
Guido van Rossum 43713e5a28 Massive patch by Skip Montanaro to add ":name" to as many
PyArg_ParseTuple() format string arguments as possible.
2000-02-29 13:59:29 +00:00
Andrew M. Kuchling 2194b165db Allow using long integers as slice indexes 2000-02-23 22:18:48 +00:00
Fred Drake 145c26e3d3 Remove comment that Guido agree's doesn't make sense:
PyEval_EvalCode() is *not* a "backward compatible interface", it's the
one to use!
2000-02-21 17:59:48 +00:00
Guido van Rossum 584b16a1f3 Mark pointed out a buglet in his patch: i < _sys_nerr isn't strong
enough, it could be negative.  Add i > 0 test.  (Not i >= 0; zero isn't
a valid error number.)
2000-02-21 16:50:31 +00:00
Guido van Rossum 795e189d28 Patch by Mark Hammond:
* Changes to a recent patch by Chris Tismer to errors.c.  Chris' patch
always used FormatMessage() to get the error message passing the error code
from errno - but errno and FormatMessage use a different numbering scheme.
The main reason the patch looked OK was that ENOFILE==ERROR_FILE_NOT_FOUND -
but that is about the only shared error code :-).  The MS CRT docs tell you
to use _sys_errlist()/_sys_nerr.  My patch does also this, and adds a very
similar function specifically for win32 error codes.
2000-02-17 15:19:15 +00:00
Guido van Rossum 65a75b0d52 Changes by Mark Hammond related to the new WindowsError exception. 2000-02-17 15:18:10 +00:00
Guido van Rossum e817acd957 Patch by Jack Jansen:
If we attempt to import a dynamic module in a newer (or older) version
of Python give an error message tailored to the situation (Python too
new/old).
2000-02-14 17:58:25 +00:00
Guido van Rossum bffd683f73 The rest of the changes by Trent Mick and Dale Nagata for warning-free
compilation on NT Alpha.  Mostly added casts etc.
2000-01-20 22:32:56 +00:00
Guido van Rossum a400d8a96d Fix a bug in exec_statement() noted incidentally by Tim Peters in
PR#175 -- when exec is passed a code object, it didn't sync the locals
from the dictionary back into their fast representation.

Also took the time to remove some repetitive code there and to do the
syncing even when an exception is raised (since a partial effect
should still be synced).
2000-01-12 22:45:54 +00:00
Fred Drake 7b912120ca Adjusted apply() docstring based on comments from Gerrit Holl
<gerrit.holl@pobox.com>.
1999-12-23 14:16:55 +00:00
Guido van Rossum 96a8fb7e99 Cleanup patches from Greg Stein:
* in import.c, #ifdef out references to dynamic loading based on
  HAVE_DYNAMIC_LOADING

* clean out the platform-specific crud from importdl.c.
  [ maybe fold this function into import.c and drop the importdl.c file? Greg.]

* change GetDynLoadFunc's "funcname" parameter to "shortname". change
  "name" to "fqname" for clarification.

* each GetDynLoadFunc now creates its own funcname value.

  WARNING: as I mentioned previously, we may run into an issue with a
  missing "_" on some platforms. Testing will show this pretty quickly,
  however.

* move pathname munging into dynload_shlib.c
1999-12-22 14:09:35 +00:00
Guido van Rossum 96b5ee88ee Vladimir Marangozov:
Here's a patch that avoids a warning caused by the "const char* pathname"
declaration for _PyImport_GetDynLoadFunc (in dynload_aix). The "aix_load"
function's 1st arg is prototyped as "char *pathname".
1999-12-21 15:55:47 +00:00
Guido van Rossum 95288862bb For Windows, need to add #include <windows.h>. 1999-12-20 22:55:03 +00:00
Guido van Rossum db3ec1b21e Support for selecting the correct dynload_<platform>.c file.
This is part of a set of patches by Greg Stein.
1999-12-20 21:24:09 +00:00
Guido van Rossum ed1170e49f In _PyImport_Init(), dynamically construct the table of legal suffixes
from two static tables (one standard, one provided by the platform's
dynload_*.c variant).

This is part of a set of patches by Greg Stein.
1999-12-20 21:23:41 +00:00
Guido van Rossum 9f65081d90 Some rearrangements for the importdl.c restructuring.
This is part of a set of patches by Greg Stein.
1999-12-20 21:22:24 +00:00
Guido van Rossum 6ea9092625 Moved most of the platform-specific code to dynload_<platform>.c files.
(A few nite remain, these will probably disappear soon.)

This is part of a set of patches by Greg Stein.
1999-12-20 21:20:42 +00:00
Guido van Rossum 22a1d3671b The old platform-specific contents of importdl.c, broken down into one
file per platform (really: per style of Dl API; e.g. all platforms
using dlopen() are grouped together in dynload_shlib.c.).

This is part of a set of patches by Greg Stein.
1999-12-20 21:18:49 +00:00
Guido van Rossum 72badf5404 The cleanup code in com-init() at label fail_0000 should remove
c_varnames, not c_lnotab.
1999-12-20 20:40:12 +00:00
Guido van Rossum 001b9bebca Patch by Vladimir Marangozov, inspired by a bug report from Gary
Duzan, for AIX, to support C++ objects with static initializers, when
using the genuine IBM C++ compiler (namely xlC/xlC_r).

See accompanying patches to configure.in and acconfig.h.
1999-11-16 15:54:16 +00:00
Guido van Rossum ba98a42a0f Change the last PyErr_Format %s format to %.400s. 1999-11-15 19:29:33 +00:00
Guido van Rossum 25da5bebd8 Fix PR117. The error message is "keywords must be strings". Perhaps
not as descriptive as what Barry suggests, but this also catches the
(in my opinion important) case where some other C code besides apply()
constructs a kwdict that doesn't have the right format.  All the other
possibilities of getting it wrong (non-dict, wrong keywords etc) are
already caught so this makes sense to check here.
1999-10-26 00:12:20 +00:00
Barry Warsaw 226ae6ca12 Mainlining the string_methods branch. See branch revision log
messages for specific changes.
1999-10-12 19:54:53 +00:00
Guido van Rossum be2033697f In PySys_GetObject(), it's possible that tstate->interp->sysdict is
NULL.  In that case, return NULL rather than dumping core.

This fixes PR#91, submitted by Lele Gaifax.
1999-10-05 22:17:41 +00:00
Guido van Rossum 3aca65312a Tim Peters fixed PR#75: very long lines cause incorrect tracebacks. 1999-09-18 20:49:39 +00:00
Guido van Rossum 2174dcb061 Tim Peters writes:
For a long time I've seen absurd tracebacks under -O (e.g., negative
line numbers), but very rarely.  Since I was looking at tracebacks
anyway, thought I'd track it down.  Turns out to be Guido's only
predictable blind spot <wink -- "char" is signed on some non-GvR
systems>.  Patch follows.
1999-09-15 22:48:09 +00:00
Guido van Rossum 2adac0a637 Tim Peters discovered a bug in the Python-supplied getopt():
it doesn't recognize a lone dash as a non-flag argument.
Now it does.
1999-09-13 13:45:32 +00:00
Barry Warsaw f6202635f9 call_trace(): A fix for PR#73, if an exception occurred in the
tracefunc (or profilefunc -- we're not sure which), zap the global
trace and profile funcs so that we can't get into recursive loop when
instantiating the resulting class based exception.
1999-09-08 16:26:33 +00:00
Guido van Rossum 933c91ebcf Vladimir Marangozov fixes an AIX-specific problem, writing:
"""
Following up Robin Dunn's troubles with freeze, here's a patch that
fixes an oddity regarding the import logic of shared modules on AIX.

Symbol resolution of shared modules is now handled properly for the cases
when the python library is linked to a binary with an arbitrary name.
This includes the standard python[version] executable, but also applications
that are embedding the python core (i.e. linked with libpython[version].a,
the latter being static or shared).
"""
1999-08-04 18:00:12 +00:00
Fred Drake 3d587442f9 Fixed order of parameters in slice() docstring. The Library Reference
had it right!  Reported by Tim Hochberg <tim.hochberg@ieee.org>.
1999-07-19 15:21:16 +00:00
Guido van Rossum 7c85ab829d Marc-Andre Lemburg discovered that the switch from .pyc to .pyo files,
done by _PyImport_Init(), comes to late to affect the import of
exceptions.py by _PyBuiltin_Init_2().  Move  _PyImport_Init() up few lines.
1999-07-08 17:26:56 +00:00
Guido van Rossum 8746082175 Patch by Tim Peters:
Introduce a new builtin exception, UnboundLocalError, raised when ceval.c
tries to retrieve or delete a local name that isn't bound to a value.
Currently raises NameError, which makes this behavior a FAQ since the same
error is raised for "missing" global names too:  when the user has a global
of the same name as the unbound local, NameError makes no sense to them.
Even in the absence of shadowing, knowing whether a bogus name is local or
global is a real aid to quick understanding.

Example:

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

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

f()

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

D:\src\PCbuild>

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

[The ceval.c patch differs slightly from the second version that Tim
submitted; I decided not to raise UnboundLocalError for DELETE_NAME,
only for DELETE_LOCAL.  DELETE_NAME is only generated at the module
level, and since at that level a NameError is raised for referencing
an undefined name, it should also be raised for deleting one.]
1999-06-22 14:47:32 +00:00
Guido van Rossum 1d5ad90c1c CRITICAL PATCH!
We occasionally received reports from people getting "invalid tstate"
crashes (this is a fatal error in PyThreadState_Delete()).  Finally
several people were able to reproduce it reliably and Tim Peters
discovered that there is a race condition when multiple threads are
calling this function without holding the global interpreter lock (the
function may be called without holding that).

Solved the race condition by adding a lock around the mutating uses of
interp->tstate_head.  Tim and Jonathan Giddy have run tests that make
it likely that this fixes the crashes -- although Tim hasn't heard
from the person who reported the original problem.
1999-06-18 14:22:24 +00:00
Guido van Rossum 7f85186921 # Darn! Local variable l declared but not used in abstract_issubclass(). 1999-06-17 19:12:39 +00:00
Guido van Rossum 668213d3b8 Patch by Jim Fulton (code style tweaked a bit) to support
ExtensionClasses in isinstance() and issubclass().

  - abstract instance and class protocols are used *only* in those
    cases that would generate errors before the patch.  That is, there's
    no penalty for the normal case.

  - instance protocol: an object smells like an instance if it
    has a __class__ attribute that smells like a class.

  - class protocol: an object smells like a class if it has a
    __bases__ attribute that is a tuple with elements that
    smell like classes (although not all elements may actually get
    sniffed ;).
1999-06-16 17:28:37 +00:00
Guido van Rossum eda232fdac Allow longer strings (up to 80 chars each) for version, build,
compiler info.
1999-04-22 12:03:40 +00:00
Guido van Rossum 743007d2fe Patch by Christian Tismer for Win32, to use FormatMessage() instead of
strerror().  This improves the quality of the error messages.
1999-04-21 15:27:31 +00:00
Guido van Rossum 495894ee66 While I can't really test this thoroughly, Pat Knight and the Solaris
man pages suggest that the proper thing to do is to add THR_NEW_LWP to
the flags on thr_create(), and that there really isn't a downside, so
I'll do that.
1999-04-13 14:32:12 +00:00
Guido van Rossum b738d26e2d Win/CE thread support by Mark Hammond. 1999-04-08 13:57:06 +00:00
Guido van Rossum b6987b13fe Alas, get rid of the Win specific hack to ask the user to press Return
before exiting when an error happened.  This didn't work right when
Python is invoked from a daemon.
1999-04-07 18:32:51 +00:00
Guido van Rossum 2571cc8bf5 Changes by Mark Hammond for Windows CE. Mostly of the form
#ifdef DONT_HAVE_header_H ... #endif around #include <header.h>.
1999-04-07 16:07:23 +00:00
Guido van Rossum 99fb7c70f4 Remove unused variable from complex_from_string() code. 1999-04-07 16:05:47 +00:00
Guido van Rossum 1195023b89 Patch by Nick and Stephanie Lockwood to implement complex() with a string
argument.  This closes TODO item 2.19.
1999-03-25 21:16:07 +00:00
Guido van Rossum 0daf022225 New builtin buffer() creates a derived read-only buffer from any
object that supports the buffer interface (e.g. strings, arrays).
1999-03-19 19:07:19 +00:00
Guido van Rossum 701f25ef9d Rob Riggs wrote:
"""
Spec says that on success pthread_create returns 0. It does not say
that an error code will be < 0. Linux glibc2 pthread_create() returns
ENOMEM (12) when one exceed process limits. (It looks like it should
return EAGAIN, but that's another story.)

For reference, see:
http://www.opengroup.org/onlinepubs/7908799/xsh/pthread_create.html
"""

[I have a feeling that similar bugs were fixed before; perhaps someone
could check that all error checks no check for != 0?]
1999-03-15 20:27:53 +00:00
Guido van Rossum eb894ebd0a Always test for an error return (usually NULL or -1) without setting
an exception.
1999-03-09 16:16:45 +00:00
Barry Warsaw 72b715d979 (initerrors): Make sure that the exception tuples ("base-classes" when
string-based exceptions are used) reflect the real class hierarchy,
i.e. that SystemExit derives from Exception not StandardError.
1999-02-24 00:35:43 +00:00
Guido van Rossum 124eff0225 Patch by Tim Peters to improve the range checks for range() and
xrange(), especially for platforms where int and long are different
sizes (so sys.maxint isn't actually the theoretical limit for the
length of a list, but the largest C int is -- sys.maxint is the
largest Python int, which is actually a C long).
1999-02-23 16:11:01 +00:00
Guido van Rossum 66368ccc55 Patch by Tommy Burnette to accept an arbitrary sequence when "(...)"
is used in the format string, instead of requiring a tuple.  This is
in line with the general trend towards accepting arbitrary sequences.
1999-02-17 23:16:43 +00:00
Barry Warsaw 3d05b1a0ae initmain(): Nailed a memory leak. bimod must be DECREF'd! 1999-01-29 21:30:22 +00:00
Barry Warsaw 7890203f49 bltin_exc[]: EnvironmentError is not a "leaf exception", so set it's
leaf_exc flag to zero otherwise the name leaks memory.
1999-01-29 20:29:49 +00:00
Barry Warsaw fa77e09dd0 builtin_map(): A better fix for the previous leak plug (remember
PyList_Append steals a reference even if it fails).

builtin_filter(): Had the same leak problem as builtin_map().
1999-01-28 18:49:12 +00:00
Guido van Rossum 541563ec7e Implement -OO; "unsafe" optimization that removes docstrings.
Marc-Andre Lemburg.
1999-01-28 15:08:09 +00:00
Barry Warsaw 2133287c3e builtin_map(): Nailed memory leak. PyList_Append() borrows a
reference, so you have to DECREF the appended value.  This was a fun
one!
1999-01-28 04:21:35 +00:00
Barry Warsaw f988e687a1 builtin_complex(): Nailed memory leak. This one's in the instance
test for classes with a __complex__() method.  The attribute is pulled
out of the instance with PyObject_GetAttr() but this transfers
ownership and the function object was never DECREF'd.
1999-01-27 23:13:59 +00:00
Barry Warsaw 3879333b9e PyImport_ReloadModule(): Nailed a small memory leak. In the
else-clause of the subname test, the parentname object was never
DECREF'd.
1999-01-27 17:54:20 +00:00
Guido van Rossum 54ecc3d24f Patches by William Lewis for Nextstep descendants. 1999-01-27 17:53:11 +00:00
Barry Warsaw c80baa3365 err_input(): Nailed a small memory leak. If the error is E_INTR, the
v temporary variable was never decref'd.  Test this by starting up the
interpreter, hitting C-c, then immediately exiting.

Same potential leak can occur if error is E_NOMEM, since the return is
done in the case block.  Added Py_XDECREF(v); to both blocks, just
before the return.
1999-01-27 16:39:40 +00:00
Barry Warsaw 54892c4b2c _PySys_Init(): Nailed small memory leak. The stringobject created for
sys.version was missing a Py_XDECREF().
1999-01-27 16:33:19 +00:00
Guido van Rossum 3dbba6ec3a Change rare occurrences of #if HAVE_LONG_LONG to #ifdef. 1999-01-25 21:48:56 +00:00
Guido van Rossum a71b5f4e1d Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
1.5.  Omit the second part.
1999-01-14 19:07:00 +00:00
Guido van Rossum e23cde2f8d Avoid overflow if possible in calculations for range(); report
unavoidable overflow as OverflowError.
1999-01-12 05:07:47 +00:00
Guido van Rossum 2c1f6be38e Hack for Windows so that if (1) the exit status is nonzero and (2) we
think we have our own DOS box (i.e. we're not started from a command
line shell), we print a message and wait for the user to hit a key
before the DOS box is closed.

The hacky heuristic for determining whether we have our *own* DOS box
(due to Mark Hammond) is to test whether we're on line zero...
1999-01-08 15:56:28 +00:00
Guido van Rossum df69365f5f Ty Sarna writes:
The following patches (relative to 1.5.2b1) enable Python dynamic
loading to work on NetBSD platforms that use ELF (presnetly mips and
alpha systems).  They automaticly determine wether the system is ELF or
a.out rather than using astatic list of platforms so that when other
NetBSD platforms move to ELF, python will continue to work without
change.
1999-01-07 21:50:41 +00:00
Guido van Rossum cad3d47f1e Chris Herborth writes:
Donn Cave tells me the PyImport_BeImageID() function isn't needed anymore.
1999-01-04 16:45:59 +00:00
Guido van Rossum e0d7dae3b8 Add sys.hexversion, which is an integer encoding the version in hexadecimal.
In other words, hex(sys.hexversion) == 0x010502b2 for Python 1.5.2b2.
This is derived from the new variable PY_VERSION_HEX defined in patchlevel.h.
(Cute, eh?)
1999-01-03 12:55:39 +00:00
Guido van Rossum 6e0a3499ab Use PY_VERSION instead of PATCHLEVEL. 1999-01-03 12:41:50 +00:00
Guido van Rossum 47ae028071 Call PyInitFrozenExtensions() as requested by Mark Hammond (his patch). 1999-01-02 21:42:48 +00:00
Guido van Rossum c38e7d4c4b Oops, forgot a pair of {}'s. (Greg Couch) 1998-12-23 19:53:45 +00:00
Guido van Rossum d341500d8f Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Patch and suggestion by Greg Couch.
1998-12-23 05:01:38 +00:00
Guido van Rossum 6058eb49ee Improve comment for PyImport_Import() as suggested by Bill Tutt. 1998-12-21 19:51:00 +00:00
Guido van Rossum 65d5b5763c Thanks to Chris Herborth, the thread primitives now have proper Py*
names in the source code (they already had those for the linker,
through some smart macros; but the source still had the old, un-Py names).
1998-12-21 19:32:43 +00:00
Guido van Rossum 885553e8d3 Use PyThreadState_GET() macro. 1998-12-21 18:33:30 +00:00
Guido van Rossum 18bc7c2276 Make current_tstate a global, _PyThreadState_Current. This is to
support a macro in pystate.h.
1998-12-21 18:27:28 +00:00
Guido van Rossum 1924a0677d Chris H. writes:
If we're going to put the PyOS_strtol() proto in intobject.h we should
include it here or the symbol isn't exported on PowerPC.
1998-12-18 22:02:37 +00:00
Guido van Rossum 0e1d0e95ea Patch by Chris Herborth:
have to use a const-correct prototype on BeOS or the compiler gets uppity.
1998-12-17 18:03:10 +00:00
Guido van Rossum 2edcf0d71c Move the prototype for dump_counts() to before where it is used.
(This only applies when COUNT_ALLOCS is defined.)
1998-12-15 16:12:00 +00:00
Guido van Rossum 46e9705eca Remove prototypes for PyOS_strto[u]l -- Chris Herborth. 1998-12-10 16:57:44 +00:00
Guido van Rossum ca90605678 Add more SET_LINENO instructions in long argument lists 1998-12-10 16:56:22 +00:00
Guido van Rossum 926f7b6615 Adding thread support for BeOS by Chris Herborth. 1998-12-07 21:56:59 +00:00
Guido van Rossum cf183acf15 Use PyInt_AS_LONG macro instead of explicit inlining. 1998-12-04 18:51:36 +00:00
Guido van Rossum f261526423 Need to add default decl of DL_IMPORT, for mymalloc.h 1998-12-04 18:50:20 +00:00
Barry Warsaw 344864fcfb Added new builtin standard exception: NotImplementedError (its C
counterpart is PyExc_NotImplementedError).
1998-12-01 18:52:06 +00:00
Guido van Rossum df12a59305 Fix cosmetic bug in delattr docstring discovered by JvR. 1998-11-23 22:13:04 +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 66468568df Jim Fulton writes:
"""
I had originally not realized that PyEval_GetGlobals did not
INCREF it's return value.  The fix is to add the INCREF,
as shown below.
"""
1998-10-22 15:46:50 +00:00
Guido van Rossum e0e59829e0 When errno is zero, avoid calling strerror() and use "Error" for the
message.
1998-10-14 20:38:13 +00:00
Guido van Rossum 2f3667a7b9 Replace fprintf(stderr, ...) with PySys_WriteStderr(...). 1998-10-12 18:23:55 +00:00
Guido van Rossum 8442af35fe Patches for mywrite() by Marc Lemburg: save/restore the error state
reliably; check return value of vsprintf().
1998-10-12 18:22:10 +00:00
Guido van Rossum b317f8aa0d Implement new format character 't#'. This is like s#, accepting an
object that implements the buffer interface, but requires a buffer
that contains 8-bit character data.  Greg Stein.
1998-10-08 02:21:21 +00:00
Guido van Rossum 5bd893b1ea The previous checkin contained an experiment of Greg Stein's that wasn't
meant for checkin, and which broke marshal.loads().
1998-10-08 01:45:47 +00:00
Guido van Rossum 0f8b30f8ce On Win32, use
LoadLibraryEx(pathname, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)
to search dependent DLLs in the directory of the pathname.
1998-10-08 01:44:41 +00:00
Guido van Rossum 2a570049ac Changes to deal with the sigcheck+intrcheck vs. signalmodule controversy. 1998-10-07 22:51:56 +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 9e46e56264 BSDI specific patches, inspired by Nigel Head and otto@mail.olympus.net.
Also (non-BSDI specific):

- Change the CHECK_STATUS() macro so it tests for nonzero error codes
instead of negative error codes only (this was needed for BSDI, but
appears to be correct according to the PTHREADS spec).

- use memset() to zero out the allocated lock structure.  Again, this
was needed for BSDI, but can't hurt elsewhere either.
1998-10-07 16:39:47 +00:00
Guido van Rossum 562f5b1480 Support PYTHONOPTIMIZE variable; by Marc Lemburg. 1998-10-07 14:50:42 +00:00
Guido van Rossum dfede31c7f Eh, better error message for the previous change. It now says
"non-default argument follows default argument".
1998-10-02 14:06:56 +00:00
Guido van Rossum 29d38cd088 Treat def f(a, b=1, c): ... as an error (missing default for c)
instead of silently supplying a default of None fore c.
1998-10-02 13:41:54 +00:00
Guido van Rossum e364b7d46a Renamed thread.h to pythread.h.
(Also removed whitespace after # in some BEOS related cpp directives.)
1998-10-01 20:43:23 +00:00
Guido van Rossum 49b560698b Renamed thread.h to pythread.h. 1998-10-01 20:42:43 +00:00
Guido van Rossum 2dcfc9618d On second though, NEXITFUNCS should be defined here and not in
pystate.h; pystate.h doesn't use it (I thought I wanted to move the
array there but that won't work).
1998-10-01 16:01:57 +00:00
Barry Warsaw 968f8cbace builtin_apply(): Second argument type check is relaxed to allow any sequence. 1998-10-01 15:33:12 +00:00
Guido van Rossum 566373e974 While scalling sys.modules, skip entries that don't have string keys,
to protect us from jokers who put items with non-string keys in
sys.modules.  Reported by Greg Stein.
1998-10-01 15:24:50 +00:00
Guido van Rossum 65f15d435e In FreeBSD when using ELF, an underscore is needed in front of the
function name.  (Vladimir Kushnir by way of Thomas Gellekum.)
1998-09-30 14:34:52 +00:00
Guido van Rossum 93d27547d0 Remove redundant definition of NEXITFUNCS.
(Reported by Jeff Rush.)
1998-09-28 22:15:37 +00:00
Barry Warsaw 98b6246c0c Several changes that Python carry on in the face of errors in the
initialization of class exceptions.  Specifically:

init_class_exc(): This function now returns an integer status of the
class exception initialization.  No fatal errors in this method now.
Also, use PySys_WriteStderr() when writing error messages.  When an
error occurs in this function, 0 is returned, but the partial creation
of the exception classes is not undone (this happens elsewhere).

Things that could trigger the fallback:

    - exceptions.py fails to be imported (due to syntax error, etc.)

    - one of the exception classes is missing (e.g. due to library
      version mismatch)

    - exception class can't be inserted into __builtin__'s dictionary

    - MemoryError instance can't be pre-allocated

    - some other PyErr_Occurred

newstdexception(): Changed the error message.  This is still a fatal
error because if the string based exceptions can't be created, we
really can't continue.

initerrors(): Be sure to xdecref the .exc field, which might be
non-NULL if class exceptions init was aborted.

_PyBuiltin_Init_2(): If class exception init fails, print a warning
message and reinstate the string based exceptions.
1998-09-14 18:51:11 +00:00
Guido van Rossum a0f0a33d05 Mac-specific mod to enable aliases on import paths.
(Jack Jansen and/or Just van Rossum)
1998-09-14 13:40:53 +00:00
Guido van Rossum d21744a1dd Apparently on AIX when using gcc you need to call pthread_init()
(which is not a POSIX threads call!).  Reported and confirmed by Brad
Howes.
1998-09-10 03:04:40 +00:00
Guido van Rossum a74d0e4c55 Correct typo in #ifdef: PY_THREAD_D4, should be PY_PTHREAD_D4.
Reported by Jonathan Giddy.
1998-09-04 13:38:32 +00:00
Guido van Rossum 746340d989 Should no longer surround PyOS_Readline() call with
Py_{BEGIN,END}_ALLOW_THREADS macros.  Also get rid of the declaration
for it (it's now in pythonrun.h).
1998-09-03 22:25:05 +00:00
Guido van Rossum 44ee479427 Add a 'volatile' to the declaration of threadid in get_thread_ident().
According to Vladimir Marangozov, this is necessary for AIX, where
high optimization levels inline this function and then get it wrong :-(
1998-08-27 19:21:53 +00:00
Guido van Rossum 53195c1a83 Don't release the interpreter lock around PyParser_ParseFile().
It is needed so that tokenizer.c can use PySys_WriteStderr().
1998-08-27 19:14:49 +00:00
Guido van Rossum afd3daedde __file__ used to be always set to the .pyc (or .pyo) file, even if
that file in fact did not exist or at least was not used.  Change this
so that __file__ is *only* set to the .pyc/.pyo file when it actually
read the code object from it; otherwise __file__ is set to the .py
file.
1998-08-25 18:44:34 +00:00
Guido van Rossum 90f827c67e Comment out the print statement about underflow. (This only seems to
happen when you use a non-keyword argument after a keyword argument,
and in this case you also get a syntax error.  I fully suspect that
the underflow is caused by the code that stops generating code when it
detects the syntax error, but I can't find the culprit right now.  I
know, I know.)
1998-08-25 18:22:17 +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 d0dc5b06a2 Restructure the file so that it is never empty. No longer needs
Metrowerks specific #ifdef.
1998-08-25 17:48:25 +00:00
Guido van Rossum 3293b07df5 Patch by Mark Hammond to support 64-bit ints on MS platforms.
The MS compiler doesn't call it 'long long', it uses __int64,
so a new #define, LONG_LONG, has been added and all occurrences
of 'long long' are replaced with it.
1998-08-25 16:07:15 +00:00
Guido van Rossum ab076fdb6f Ted Horst writes in psa-members@python.org:
This is a patch that Bill Bummgarner did for 1.4 that hasn't made its
way into the distribution yet.  This is important if you want to use
the ObjC module.
1998-08-24 14:15:44 +00:00
Guido van Rossum 0ba353608f Add DebugBreak() call to Py_FatalError() for Mark Hammond (only on
Win32 in Debug mode).
1998-08-13 13:33:16 +00:00
Guido van Rossum 0506a431d5 Patch by Just van Rossum that changes how we search for submodules of
frozen packages.  (I *think* this means that we can now have a
built-in module bar that's a submodule of a frozen package foo, by
registering the built-in module with a name "foo.bar" in the table of
builtin modules.)
1998-08-11 15:07:39 +00:00
Guido van Rossum c4099e6b3c # Fix strange type (methonname instead of methodname). 1998-08-08 20:51:26 +00:00
Guido van Rossum 9c241ba014 Added declarations for Mac code resource modules (Jack Jansen). 1998-08-06 13:36:43 +00:00
Guido van Rossum 0f84a349bb Added handling for Mac code resource modules (Jack Jansen). 1998-08-06 13:36:01 +00:00
Guido van Rossum 40552d0857 Gack. The module doc string is too long for VC++ 5.0.
However two string literals concatenated are fine!
Hope this doesn't break other platforms.
1998-08-06 03:34:39 +00:00
Fred Drake d807879b31 Make getversion.o dependent on ../Include/patchlevel.h as well. 1998-08-05 21:33:54 +00:00
Guido van Rossum 1a8791e0b8 Changes for BeOS, QNX and long long, by Chris Herborth. 1998-08-04 22:46:29 +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
Barry Warsaw 97d951533e PyErr_SetFromErrnoWithFilename(): New function which supports setting
an exception from errno, with a supplied filename (primarily used by
IOError and OSError).  If class exceptions are used then the exception
is instantiated with a 3-tuple: (errno, strerror, filename).  For
backwards compatibility reasons, if string exceptions are used,
filename is ignored.

PyErr_SetFromErrno(): Implement in terms of
PyErr_SetFromErrnoWithFilename().
1998-07-23 16:05:56 +00:00
Barry Warsaw d086a1a864 Added support for two new standard errors: EnvironmentError and
OSError.  The EnvironmentError serves primarily as the (common
implementation) base class for IOError and OSError.  OSError is used
by posixmodule.c

Also added tuple definition of EnvironmentError when using string
based exceptions.
1998-07-23 15:59:57 +00:00
Guido van Rossum fa4ac71dd6 Small changes to map() and filter():
(1) If a sequence S is shorter than len(S) indicated, don't fail --
just use the shorter size.  (I.e, len(S) is just a hint.)

(2) Implement the special case map(None, S) as list(S) -- it's faster.
1998-07-10 17:37:30 +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 bb71ab68f9 Reindented some OS/2 and hpux code that looked ugly or at least
inconsistent.
1998-07-08 13:47:12 +00:00
Guido van Rossum 233f4b54d3 Two error messages still used the old name of the functio mkvalue() --
which is now Py_BuildValue().
1998-07-07 22:32:19 +00:00
Guido van Rossum e32d1537f0 Sigh. The hack to enable special treatment for errno on SGI machines
must be enabled here, otherwise the errno we set on overflows is not
the errno that's being read by compile.c.  Wonder how many other files
that do their own "#include config.h" need this too :-(

(Because of the structure of autoconf, it's not so simple to get this
into config.h...)
1998-07-07 21:32:53 +00:00
Guido van Rossum b68cd421e1 Fix two smal memory leaks discovered by Vadim Chugunov. 1998-07-01 17:36:26 +00:00
Guido van Rossum 8ea9f4d10a Fix a stupid little bug: len() of an unsized returns -1 and leaves an
exception waiting to happen next...
1998-06-29 22:26:50 +00:00
Guido van Rossum 950ff2923a Experimental feature: add default argument to getattr(). 1998-06-29 13:38:57 +00:00
Guido van Rossum a5e1b008a9 Windows-specific hack to make sure that when LoadLibrary() is called,
the filename contains at least a rudimentary pathname.
(The bad part is that we need to call getcwd() because only a prefix
of ".\\" is not enough -- we prefix the drive letter.)
1998-06-27 21:53:17 +00:00
Guido van Rossum c3bc31e249 Added doc strings. Maybe the doc string for the module itself is a bit
long, but it sure helps!
1998-06-27 19:43:25 +00:00
Guido van Rossum f9d9c6c5d2 Added doc strings. 1998-06-26 21:23:49 +00:00
Guido van Rossum d9b5208e90 In raw_input(prompt), make sure that str(prompt) really a string
object before using it.
1998-06-26 18:25:38 +00:00
Guido van Rossum 323bf5e1f7 Ignore Windows case check for ALL CAPS 8.3 files 1998-06-24 03:54:06 +00:00
Guido van Rossum a45cb45965 When unmarshalling, add test for negative lengths on strings, tuples
and lists; if the size is negative, raise an exception.  Also raise an
exception when an undefined type is found -- all this to increase the
chance that garbage input causes an exception instead of a core dump.
1998-06-08 20:27:29 +00:00
Guido van Rossum 9396673a58 Remove a few unused locals (I love VC++ for this!). 1998-05-29 02:59:00 +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 09df08a105 A bunch of functions are now properly implemented in abstract.c, and
the code here becomes much simpler.  In particular: abs(), divmod(),
pow(), int(), long(), float(), len(), tuple(), list().

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.

A few other cosmetic things, such as properly reindenting slice().
1998-05-22 00:51:39 +00:00
Guido van Rossum adf0e437cb Trivial little change: when setting a member to an object, hold the
old value in a temporary and XDECREF it only after then new value has
been set.  This prevents the (unlikely) case where the destructor of
the member uses the containing object -- it would find it in an
undefined state.
1998-05-20 22:25:32 +00:00
Guido van Rossum 9c0afe5dc7 Fix a curious bug: statements like "import sys.time" would succeed,
because the path through the code would notice that sys.__path__ did
not exist and it would fall back to the default path (builtins +
sys.path) instead of failing).  No longer.
1998-05-19 15:09:05 +00:00
Guido van Rossum 6b077878a5 Remove use of RTLD_GLOBAL. 1998-05-18 13:42:45 +00:00
Guido van Rossum fccfe89753 Another veeeeeery old patch...
Date:    Thu, 14 Sep 1995 12:18:20 -0400
From:    Alan Morse <alan@dvcorp.com>
To:      python-list@cwi.nl
Subject: getargs bug in 1.2 and 1.3 BETA

We have found a bug in the part of the getargs code that we added
and submitted, and which was incorporated into 1.1.

The parsing of "O?" format specifiers is not handled correctly;
there is no "else" for the "if" and therefore it can never fail.
What's worse, the advancing of the varargs pointer is not
handled properly, so from then on it is out of sync, wreaking
all sorts of havoc. (If it had failed properly, then the out-of-sync
varargs would not have been an issue.)

Below is the context diff for the change.

Note that I have made a few stylistic changes beyond adding the
else case, namely:

1) Making the "O" case follow the convention established by the other
format specifiers of getting all their vararg arguments before
performing the test, rather than getting some before and some after
the test passes.

2) Making the logic of the tests parallel, so the "if" part indicates
that the format is accepted and the "else" part indicates that the
format has failed. They were inconsistent with each other and with the
the other format specifiers.

-Alan Morse (amorse@dvcorp.com)
1998-05-15 22:04:07 +00:00
Guido van Rossum 859b16c847 In debug mode on MS Windows, DLLs are called foo_d.pyd or foo_d.dll. 1998-05-15 20:22:08 +00:00
Guido van Rossum 532246ef55 Improved version of patch for HPUX from David Arnold. 1998-05-14 21:01:27 +00:00
Guido van Rossum 09cae1f8cd New APIs for embedding applications that want to add their own entries
to the table of built-in modules.  This should normally be called
*before* Py_Initialize().  When the malloc() or realloc() call fails,
-1 is returned and the existing table is unchanged.

After a similar function by Just van Rossum.

int PyImport_ExtendInittab(struct _inittab *newtab);
int PyImport_AppendInittab(char *name, void (*initfunc)());
1998-05-14 02:32:54 +00:00
Guido van Rossum ba7cc0cfba Remove unnecessary PyErr_Clear(). 1998-05-14 02:31:26 +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 a890e68807 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Adapted from code submitted by Just van Rossum.

   PySys_WriteStdout(format, ...)
   PySys_WriteStderr(format, ...)

      The first function writes to sys.stdout; the second to sys.stderr.  When
      there is a problem, they write to the real (C level) stdout or stderr;
      no exceptions are raised (but a pending exception may be cleared when a
      new exception is caught).

      Both take a printf-style format string as their first argument followed
      by a variable length argument list determined by the format string.

      *** WARNING ***

      The format should limit the total size of the formatted output string to
      1000 bytes.  In particular, this means that no unrestricted "%s" formats
      should occur; these should be limited using "%.<N>s where <N> is a
      decimal number calculated so that <N> plus the maximum size of other
      formatted text does not exceed 1000 bytes.  Also watch out for "%f",
      which can print hundreds of digits for very large numbers.
1998-05-12 14:59:24 +00:00
Guido van Rossum 1e162d3753 Implement round() slightly different, so that for negative ndigits no
additional errors happen in the last step.  The trick is to avoid
division by 0.1**n -- multiply by 10.0**n instead.
1998-05-09 14:42:25 +00:00
Guido van Rossum 89df70bfbb Support HPUX 10.20 DCE threads. 1998-05-07 13:28:23 +00:00
Guido van Rossum a937d14898 Fred's right -- we need PyList_SET_ITEM(). 1998-04-24 18:22:02 +00:00
Guido van Rossum 507338e5ca In-line the code in range() to set the list items; there's really no
need to call PyList_SetItem(v,i,w) when PyList_GET_ITEM(v,i)=w {sic}
will do.
1998-04-23 21:46:19 +00:00
Guido van Rossum 1f74016735 Support for OpenBSD :-( 1998-04-13 15:27:21 +00:00
Guido van Rossum 111c20b992 Reject empty module names -- otherwise __import__("") does something
weird!
1998-04-11 17:38:22 +00:00
Guido van Rossum cecadc469b Move #include <sys/param.h> to before osdefs.h (Donn Cave). 1998-04-10 23:45:14 +00:00
Guido van Rossum 8766a7797e Comment out a label on an #endif. 1998-04-10 23:44:32 +00:00
Guido van Rossum 730806d3d9 Make new gcc -Wall happy 1998-04-10 22:27:42 +00:00
Guido van Rossum 39b0f8976c Address warnings issued by the MSVC++ compiler 1998-04-10 21:52:06 +00:00
Guido van Rossum ede0439cd8 /* An extension mechanism to store arbitrary additional per-thread state.
PyThreadState_GetDict() returns a dictionary that can be used to hold such
   state; the caller should pick a unique key and store its state there.  If
   PyThreadState_GetDict() returns NULL, an exception has been raised (most
   likely MemoryError) and the caller should pass on the exception. */

PyObject *
PyThreadState_GetDict()
1998-04-10 20:18:25 +00:00
Guido van Rossum 560e8adef7 Translate E_INDENT to the clearest error message I can think of. 1998-04-10 19:43:42 +00:00
Guido van Rossum d295f120ae Make first raise argument optional 1998-04-09 21:39:57 +00:00
Guido van Rossum bf02fb28d9 Make sure that the message "Error in sys.exitfunc:" goes to sys.stderr
and not to C's stderr.
1998-04-03 21:12:12 +00:00
Guido van Rossum 6deac7a105 Make calls into ../PC/frozen_dllmain.c on MS_WIN32. 1998-04-03 21:11:15 +00:00
Guido van Rossum f015e18d9d Add primitive test for frozen package. 1998-04-03 21:10:36 +00:00
Guido van Rossum 8f74571596 Use a faster way to check for null bytes in the string argument for
int(), long(), float().
1998-03-13 21:30:14 +00:00
Guido van Rossum a5568d349b Support for frozen packages, matching the revamped Tools/freeze.
Frozen packages are indicated by a negative size (the code string
is the __import__.py file).  A frozen package module has its __path__
set to a string, the package name.
1998-03-05 03:45:08 +00:00
Guido van Rossum d65911b3f3 Oops -- overuse of dabbrev-expand introduced a strange bug, where
instead of 'locals' I was passing 'lock_import' to import_module_ex().
1998-03-03 22:33:27 +00:00
Guido van Rossum 75acc9ca1c Add a single Python-wide (!) lock on import. Only one thread at a
time can be in PyImport_ImportModuleEx().  Recursive calls from the
same thread are okay.

Potential problems:

- The lock should really be part of the interpreter state rather than
global, but that would require modifying more files, and I first want
to figure out whether this works at all.

- One could argue that the lock should be per module -- however that
would be complicated to implement.  We would have to have a linked
list of locks per module name, *or* invent a new object type to
represent a lock, so we can store the locks in the module or in a
separate dictionary.  Both seem unwarranted.  The one situation where
this can cause problems is when loading a module takes a long time,
e.g. when the module's initialization code interacts with the user --
during that time, no other threads can run.  I say, "too bad."
1998-03-03 22:26:50 +00:00
Guido van Rossum 0829c754bb Fix the handling of errors in Py_FlushLine() in a few places.
(Basically, the error is cleared...  Like almost everywhere else...)
1998-02-28 04:31:39 +00:00
Guido van Rossum 05f9dce34f Moved clear_carefully() to _PyModule_Clear() in moduleobject.c
(modified) and use that.

Some differences in the cleanup algorithm:

- Clear __main__ before the other modules.

- Delete more sys variables: including ps1, ps2, exitfunc, argv, and
even path -- this will prevent new imports!

- Restore stdin, stdout, stderr from __stdin__, __stdout__,
__stderr__, effectively deleting hooks that the user might have
installed -- so their (the hooks') destructors will run.
1998-02-19 20:58:44 +00:00
Guido van Rossum bd36dbaaa5 Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
__stderr__.  These will be used by the import cleanup.
1998-02-19 20:53:06 +00:00
Guido van Rossum aeca79b0f6 Small patches to the DJGPP version of check_case(). 1998-02-18 16:21:00 +00:00
Guido van Rossum 4d1b3b921d Added DJGPP version of check_case(), by Pit Scrorpion (Hans Nowak).
(BTW, the Mac version was by Jack Jansen.)
1998-02-13 23:27:59 +00:00
Guido van Rossum 0980bd9233 Add case checking feature on import.
This is an option for OS-es with case-insensitive but case-preserving
filesystems.  It is currently supported for Win32 and MacOS.  To
enable it, #define CHECK_IMPORT_CASE in your platform specific
config.h.  It is enabled by default on those systems where it is
supported.  On Win32, it can be disabled at runtime by setting the
environment variable PYTHONCASEOK (to any value).

When enabled, the feature checks that the case of the requested module
name matches that of the filename found in the filesystem, and raises
a NameError exception when they don't match.
1998-02-13 17:18:36 +00:00
Guido van Rossum e32bf6ead2 Added PyImport_ExecCodeModuleEx(), which adds an extra parameter to
pass it the true file.  This is used to set __file__ properly, instead
of believing what the code object carries with it.  (If the pointer
is NULL, the code object's co_filename is still used.)
1998-02-11 05:53:02 +00:00
Guido van Rossum 919b83d522 Set Py_FrozenFlag, to suppress error messages from getpath.c. 1998-02-06 22:30:29 +00:00
Guido van Rossum a61691e4e9 Ehm, three unrelated changes.
- Add Py_FrozenFlag, intended to suppress error messages fron
getpath.c in frozen binaries.

- Add Py_GetPythonHome() and Py_SetPythonHome(), intended to allow
embedders to force a different PYTHONHOME.

- Add new interface PyErr_PrintEx(flag); same as PyErr_Print() but
flag determines whether sys.last_* are set or not.  PyErr_Print()
now simply calls PyErr_PrintEx(1).
1998-02-06 22:27:24 +00:00
Guido van Rossum a0fec2b5df Two more refinements of the cleanup process.
(1) Explicitly clear __builtin__._ and sys.{last,exc}_* before
clearing anything else.  These are common places where user values
hide and people complain when their destructors fail.  Since the
modules containing them are deleted *last* of all, they would come too
late in the normal destruction order.  Sigh.

(2) Add some debugging aid to cleanup (after a suggestion by Marc
Lemburg) -- print the names of the modules being cleaned, and (when
-vv is used) print the names of the variables being cleared.
1998-02-06 17:16:02 +00:00
Guido van Rossum 42e8e5d164 Protect PyErr_Format format string argument from overflow. 1998-01-19 22:23:08 +00:00
Guido van Rossum 0d6b49eff2 Protect PyErr_Format format string argument from overflow (ironically,
the error was about a bad format string :-).
1998-01-19 22:22:44 +00:00
Guido van Rossum 73bacfc3d7 Add unistd.h for isatty(). 1998-01-19 22:05:22 +00:00
Guido van Rossum 15af20a337 Better #ifdefs for NetBSD, taking into account that at least on netBSD
1.3, dlopen() etc. are fully implemented, including dlerror().
From Jaromir Dolecek and Ty Sarna.
1998-01-19 22:03:52 +00:00
Guido van Rossum 4cc462e85b It seems obvious that when Py_Finalize() decides that there's nothing
to do, it should not call sys.exitfunc either...
1998-01-19 22:00:38 +00:00
Guido van Rossum 758eec0172 Rewritten PyImport_Cleanup() and its helper, clear_carefully(). They
now implement the following finalization strategy.

1. Whenever this code deletes a module, its directory is cleared
   carefully, as follows:
   - set all names to None that begin with exactly one underscore
   - set all names to None that don't begin with two underscores
   - clear the directory

2. Modules are deleted in the following order:
   - modules with a reference count of 1, except __builtin__ or __sys__
   - repeat until no more are found with a reference count of 1
   - __main__ if it's still there
   - all remaining modules except __builtin__ or sys
   - sys
   _ __builtin__
1998-01-19 21:58:26 +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 7d4f68c15f Oops -- '(' is also a legal start character of a new format... 1997-12-19 04:25:23 +00:00
Guido van Rossum e8c27bb3ea Oops! Should've renamed dos_8x3 to dos-8x3 here, too. 1997-12-17 18:57:16 +00:00
Guido van Rossum 330aafb0c2 For base 10, cast unsigned long to long before testing overflow.
This prevents 4294967296 from being an acceptable way to spell zero!
1997-12-15 17:27:35 +00:00
Guido van Rossum d6af46d4ae Need a cast when comparing type object in isinstance() 1997-12-10 05:51:47 +00:00
Guido van Rossum 231a41e708 Add explicit check for correct next character in format at end of
format.  This will complain about illegal formats like "O#" instead of
ignoring the '#'.
1997-12-09 20:36:39 +00:00
Guido van Rossum 19b55f2d17 Fix subtle bug in cleanup code in PyErr_NormalizeException(), detected
by Marc Lemburg.  There's a path through the code where *val is NULL,
but value isn't, and value should be DECREF'ed.
1997-12-09 14:11:39 +00:00
Guido van Rossum 1707aad27c Changed the finalization order again so that the reference count
printing (when Py_DEBUG is defined) happens while there's still a
current thread...
1997-12-08 23:43:45 +00:00
Guido van Rossum 595d7ba069 Jeff Rush: add definition for S_IFMT for VisualAge C/C++ under OS2. 1997-12-05 21:45:29 +00:00
Guido van Rossum 08052c7bb6 Add the flag RTLD_GLOBAL to the dlopen() options.
This exports symbols defined by the loaded extension to other
extensions (loaded later).

(I'm not quite sure about this but suppose it can't hurt...)
1997-12-02 20:43:18 +00:00
Guido van Rossum c425d2f87b Make stdin unbuffered too, when PYTHONUNBUFFERED is specified. 1997-12-02 20:41:39 +00:00
Guido van Rossum f5dd914196 Support type objects in isinstance().
E.g. isinstance('',types.StringType) will return true now instead of
raising a TypeError exception.  This is for JPython compatibility.
1997-12-02 19:11:45 +00:00
Guido van Rossum ddc3fb5734 Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
you can assign an object whose str() evaluates to the current
directory (or whatever).
1997-11-25 20:58:13 +00:00
Guido van Rossum 8e9ebfd337 os2 patch by Jeff Rush 1997-11-22 21:53:48 +00:00
Guido van Rossum db847bd9ea Plug memory leak in Py_BuildValue when using {...} to construct dictionaries. 1997-11-20 20:35:45 +00:00
Guido van Rossum 2e58ff3ef5 Fix importing of shared libraries from inside packages.
This is a bit of a hack: when the shared library is loaded, the module
name is "package.module", but the module calls Py_InitModule*() with just
"module" for the name.  The shared library loader squirrels away the true
name of the module in _Py_PackageContext, and Py_InitModule*() will
substitute this (if the name actually matches).
1997-11-19 18:53:33 +00:00
Guido van Rossum 858cb73bb2 Two changes (here we go again :-( ).
1) The __builtins__ variable in the __main__ module is set to the
__builtin__ module instead of its __dict__.

2) Get rid of the SIGHUP and SIGTERM handlers.  They can't be made to
work reliably when threads may be in use, they are Unix specific, and
Python programmers can now program this functionality is a safer way
using the signal module.
1997-11-19 16:15:37 +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