Commit Graph

1182 Commits

Author SHA1 Message Date
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