Commit Graph

1377 Commits

Author SHA1 Message Date
Guido van Rossum 0628dcfe1f "Fix" for SF bug #520644: __slots__ are not pickled.
As promised in my response to the bug report, I'm not really fixing
it; in fact, one could argule over what the proper fix should do.
Instead, I'm adding a little magic that raises TypeError if you try to
pickle an instance of a class that has __slots__ but doesn't define or
override __getstate__.  This is done by adding a bozo __getstate__
that always raises TypeError.
2002-03-14 23:03:14 +00:00
Guido van Rossum cd637aae56 Fix for SF bug #529050 - ModuleType.__new__ crash.
There were several places that assumed the md_dict field was always
set, but it needn't be.  Fixed these to be more careful.

I changed PyModule_GetDict() to initialize md_dict to a new dictionary
if it's NULL.

Bugfix candidate.
2002-03-12 20:37:02 +00:00
Tim Peters 8f01b680c8 Change Windows file.truncate() to (a) restore the original file position,
and (b) stop trying to prevent file growth.

Beef up the file.truncate() docs.

Change test_largefile.py to stop assuming that f.truncate() moves the
file pointer to the truncation point, and to verify instead that it leaves
the file position alone.  Remove the test for what happens when a
specified size exceeds the original file size (it's ill-defined, according
to the Single Unix Spec).
2002-03-12 03:04:44 +00:00
Tim Peters fb05db2cae file_truncate(): provide full "large file" support on Windows, by
dropping MS's inadequate _chsize() function.  This was inspired by
SF patch 498109 ("fileobject truncate support for win32"), which I
rejected.

libstdtypes.tex:  Someone who knows should update the availability
blurb.  For example, if it's available on Linux, it would be good to
say so.

test_largefile:  Uncommented the file.truncate() tests, and reworked to
do more.  The old comment about "permission errors" in the truncation
tests under Windows was almost certainly due to that the file wasn't open
for *write* access at this point, so of course MS wouldn't let you
truncate it.  I'd be appalled if a Unixish system did.

CAUTION:  Someone should run this test on Linux (etc) too.  The
truncation part was commented out before.  Note that test_largefile isn't
run by default.
2002-03-11 00:24:00 +00:00
Guido van Rossum dfce3bf908 Bugfix candidate.
Adapter from SF patch 528038; fixes SF bug 527816.

The wrapper for __nonzero__ should be wrap_inquiry rather than
wrap_unaryfunc, since the slot returns an int, not a PyObject *.
2002-03-10 14:11:16 +00:00
Martin v. Löwis c8bb9eba31 Patch #494047: removes 64-bit ?: to cope on plan9. 2002-03-09 12:02:59 +00:00
Tim Peters dc5a508761 SF bug 525705: [2.2] underflow raise OverflowException.
Another year in the quest to out-guess random C behavior.

Added macros Py_ADJUST_ERANGE1(X) and Py_ADJUST_ERANGE2(X, Y).  The latter
is useful for functions with complex results.  Two corrections to errno-
after-libm-call are attempted:

1. If the platform set errno to ERANGE due to underflow, clear errno.
   Some unknown subset of libm versions and link options do this.  It's
   allowed by C89, but I never figured anyone would do it.

2. If the platform did not set errno but overflow occurred, force
   errno to ERANGE.  C89 required setting errno to ERANGE, but C99
   doesn't.  Some unknown subset of libm versions and link options do
   it the C99 way now.

Bugfix candidate, but hold off until some Linux people actually try it,
with and without -lieee.  I'll send a help plea to Python-Dev.
2002-03-09 04:58:24 +00:00
Jeremy Hylton 0522d9891a Fix leak of NotImplemented in previous checkin to PyNumber_Add().
If result == Py_NotImplemented, always DECREF it before assigning a
new value to result.
2002-03-08 21:28:54 +00:00
Jeremy Hylton 6ae6a43a77 Fix for SF bug 516727: MyInt(2) + "3" -> NotImplemented
PyNumber_Add() tries the nb_add slot first, then falls back to
sq_concat.  However, tt didn't check the return value of sq_concat.
If sq_concat returns NotImplemented, raise the standard TypeError.
2002-03-08 21:11:37 +00:00
Michael W. Hudson 70ffddf8af Guido pointed out that I was missing a couple decrefs. 2002-03-07 15:13:40 +00:00
Michael W. Hudson ce358e3015 Apply (my) patch:
[ 526072 ] pickling os.stat results round II

structseq's constructors can now take "invisible" fields in a dict.
Gave the constructors better error messages.
their __reduce__ method puts these fields in a dict.

(this is all in aid of getting os.stat_result's to pickle portably)

Also fixes

[ 526039 ] devious code can crash structseqs

Thought needed about how much of this counts as a bugfix.  Certainly
#526039 needs to be fixed.
2002-03-06 17:07:49 +00:00
Michael W. Hudson 7bb466a1a5 A fix & test for
[ 496873 ] structseqs unpicklable

by adding a __reduce__ method to structseqs.

Will also commit this to the 2.2.1 branch momentarily.
2002-03-05 13:27:58 +00:00
Tim Peters a5d78cc208 Whether platform malloc(0) returns NULL has nothing to do with whether
platform realloc(p, 0) returns NULL, so MALLOC_ZERO_RETURNS_NULL can
be correctly undefined yet realloc(p, 0) can return NULL anyway.

Prevent realloc(p, 0) doing free(p) and returning NULL via a different
hack.  Would probably be better to get rid of MALLOC_ZERO_RETURNS_NULL
entirely.

Bugfix candidate.
2002-03-02 08:43:19 +00:00
Tim Peters 5329cdb3ce _PyLong_Copy(): was creating a copy of the absolute value, but should
copy the sign too.  Added a test to test_descr to ensure that it does.

Bugfix candidate.
2002-03-02 04:18:04 +00:00
Tim Peters db30ac41de Revert the last odd change to PyNumber_Long: the problem it was trying
to fix was almost certainly a bug in _PyLong_Copy (which I'll fix next).
2002-03-02 04:14:21 +00:00
Guido van Rossum 2eb0b87d14 SF patch 514641 (Naofumi Honda) - Negative ob_size of LongObjects
Due to the bizarre definition of _PyLong_Copy(), creating an instance
of a subclass of long with a negative value could cause core dumps
later on.  Unfortunately it looks like the behavior of _PyLong_Copy()
is quite intentional, so the fix is more work than feels comfortable.

This fix is almost, but not quite, the code that Naofumi Honda added;
in addition, I added a test case.
2002-03-01 22:24:49 +00:00
Andrew MacIntyre 5e9c80d906 %#x/%#X format conversion cleanup (see patch #450267):
Objects/
    stringobject.c
    unicodeobject.c
2002-02-28 11:38:24 +00:00
Andrew MacIntyre c487439aa7 OS/2 EMX port changes (Objects part of patch #450267):
Objects/
    fileobject.c
    stringobject.c
    unicodeobject.c

This commit doesn't include the cleanup patches for stringobject.c and
unicodeobject.c which are shown separately in the patch manager.  Those
patches will be regenerated and applied in a subsequent commit, so as
to preserve a fallback position (this commit to those files).
2002-02-26 11:36:35 +00:00
Martin v. Löwis f9bd6b09e1 Allow __doc__ to be of arbitrary type. Patch by James Henstridge,
fixes #504343. 2.2.1 candidate.
2002-02-18 17:46:48 +00:00
Martin v. Löwis a5854c24a2 Patch #508038: Do not use a type as a variable name. 2002-02-16 23:39:10 +00:00
Guido van Rossum fa2e4c27d2 Declare real and imag as read-only attributes.
This fixes SF bug #514858 (Gregory Smith): complex not entirely
immutable

2.2.1 Bugfix candidate!
2002-02-08 21:26:07 +00:00
Marc-André Lemburg bd3be8f0ca Fix to the UTF-8 encoder: it failed on 0-length input strings.
Fix for the UTF-8 decoder: it will now accept isolated surrogates
(previously it raised an exception which causes round-trips to
fail).

Added new tests for UTF-8 round-trip safety (we rely on UTF-8 for
marshalling Unicode objects, so we better make sure it works for
all Unicode code points, including isolated surrogates).

Bumped the PYC magic in a non-standard way -- please review. This
was needed because the old PYC format used illegal UTF-8 sequences
for isolated high surrogates which now raise an exception.
2002-02-07 11:33:49 +00:00
Marc-André Lemburg dc724d6e35 Cosmetics. 2002-02-06 18:20:19 +00:00
Marc-André Lemburg e7c6ee4b8a Whitespace fixes. 2002-02-06 18:18:03 +00:00
Marc-André Lemburg 3688a882d3 Fix for the UTF-8 memory allocation bug and the UTF-8 encoding
bug related to lone high surrogates.
2002-02-06 18:09:02 +00:00
Guido van Rossum e75bfde7e9 Bugfix candidate.
Fix SF bug #511603: Error calling str on subclass of int

Explicitly fill in tp_str with the same pointer as tp_repr.
2002-02-01 15:34:10 +00:00
Neal Norwitz 2a47c0fa23 Fix spelling mistakes. Bugfix candidates. 2002-01-29 00:53:41 +00:00
Martin v. Löwis 1f803f782c Updated patch #487906: Revise inline docs. 2002-01-16 10:53:24 +00:00
Martin v. Löwis cdc4451222 Include <unistd.h> in Python.h. Fixes #500924. 2002-01-12 11:05:12 +00:00
Martin v. Löwis b0d71d0ec6 Implement PyObject_DelItemString. Fixes #498915. 2002-01-05 10:50:30 +00:00
Neal Norwitz 649b75954a SF Patch #494863, file.xreadlines() should raise ValueError if file is closed
This makes xreadlines behave like all other file methods
(other than close() which just returns).
2002-01-01 19:07:13 +00:00
Fred Drake 2a908f6b7b proxy_compare(): Make sure that we unwrap both objects being compared if
both are proxy objects.
2001-12-19 16:44:30 +00:00
Guido van Rossum f884b74910 - PyType_Ready(): Initialize the ob_type field to &PyType_Type if it's
NULL, so that you can call PyType_Ready() to initialize a type that
  is to be separately compiled with C on Windows.

inherit_special():  Add a long comment explaining that you have to set
tp_new if your base class is PyBaseObject_Type.
2001-12-17 17:14:22 +00:00
Sjoerd Mullender 564980bd86 Portability fix: Not every compiler implements the extension of
unescaped newlines in strings.
2001-12-17 11:39:56 +00:00
Guido van Rossum 33c1a8893d SF patch #493452: docstrings for staticmethod/classmethod (Skip
Montanaro)

(With minor adjustments.)
2001-12-17 02:53:53 +00:00
Guido van Rossum 2b8235e485 SF bug #493561: incorrect format string descrobject.c (Neal Norwitz)
%300s should be %.300s, twice.
2001-12-15 05:00:30 +00:00
Guido van Rossum e54616cb6f (Merge into trunk.)
Fix for SF bug #492345.  (I could've sworn I checked this in, but
apparently I didn't!)

This code:

    class Classic:
        pass

    class New(Classic):
        __metaclass__ = type

attempts to create a new-style class with only classic bases -- but it
doesn't work right.  Attempts to fix it so it works caused problems
elsewhere, so I'm now raising a TypeError in this case.
2001-12-14 04:19:56 +00:00
Fred Drake 526c7a0101 Ensure that complex() only accepts a string argument as the first arg,
and only if there is no second arg.
This closes SF patch #479551.
2001-12-13 19:52:22 +00:00
Tim Peters 77d8a4fc91 float_floor_div: An expression like 3.//1j crashed the interpreter, or
delivered bizarre results.  Check float_divmod for a Py_NotImplemented
return and pass it along (instead of treating Py_NotImplemented as a
2-tuple).
CONVERT_TO_DOUBLE:  Added comments; this macro is obscure.
2001-12-11 20:31:34 +00:00
Tim Peters 63a3571e17 float_int_div(): For clarity, move this closer to the other float
division functions, and rename to float_floor_div.
2001-12-11 19:57:24 +00:00
Tim Peters f582b82fe9 SF bug #491415 PyDict_UpdateFromSeq2() unused
PyDict_UpdateFromSeq2():  removed it.
PyDict_MergeFromSeq2():  made it public and documented it.
PyDict_Merge() docs:  updated to reveal <wink> that the second
argument can be any mapping object.
2001-12-11 18:51:08 +00:00
Fred Drake ef8ebd1e74 Make sure that when we invoke callback functions associated with weak
references, we do not allow any outstanding exceptions "leak" into the
callback's execution state.
This closes SF bug #478534.
2001-12-10 23:44:54 +00:00
Guido van Rossum 7171f1c8d8 Well what do you know. The Python implementation contained the same
bug as the C code. :-(
2001-12-10 18:06:21 +00:00
Guido van Rossum ba2485f947 Fix the Python property class in a comment right. 2001-12-10 18:03:34 +00:00
Guido van Rossum b75ba918d6 property_descr_get(): Fix a curious bug in the property() type: when
no get function was defined, the property's doc string was
inaccessible.  This was because the test for prop_get was made
*before* the test for a NULL/None object argument.

Also changed the property class defined in Python in a comment to test
for NULL to decide between get and delete; this makes it less Python
but then, assigning None to a property doesn't delete it!
2001-12-10 18:00:15 +00:00
Guido van Rossum 169192e818 SF patch #491049 (David Jacobs): Small PyString_FromString optimization
PyString_FromString():
  Since the length of the string is already being stored in size,
  changed the strcpy() to a memcpy() for a small speed improvement.
2001-12-10 15:45:54 +00:00
Guido van Rossum f70590f990 _PyTuple_Resize(): this dumped core on tuple(globals()) for me. Turns
out the for loop at the end intended to zero out new items wasn't
doing anything, because sv->ob_size was already equal to newsize.  The
fix slightly refactors the function, introducing a variable oldsize
and doing away with sizediff (which was used only once), and using
oldsize and newsize consistently.  I also added comments explaining
what the two for loops do.  (Looking at the CVS annotation of this
function, it's no miracle a bug crept in -- this has been patched by
many different folks! :-)
2001-12-07 20:00:04 +00:00
Tim Peters 62de65b25e PyString_FromString: this requires its argument be non-NULL, but doesn't
check it.  Added an assert() to that effect.
2001-12-06 20:29:32 +00:00
Guido van Rossum 604ddf80d8 Fix for #489669 (Neil Norwitz): memory leak in test_descr (unicode).
This is best reproduced by

  while 1:
      class U(unicode):
          pass
      U(u"xxxxxx")

The unicode_dealloc() code wasn't properly freeing the str and defenc
fields of the Unicode object when freeing a subtype instance.  Fixed
this by a subtle refactoring that actually reduces the amount of code
slightly.
2001-12-06 20:03:56 +00:00
Jeremy Hylton 1a48ca8c53 Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
PyCell_Set() incremenets the reference count, so the earlier XINCREF
causes a leak.

Also make a number of small performance improvements to the code on
the assumption that most of the time variables are not rebound across
a FastToLocals() / LocalsToFast() pair.

Replace uses of PyCell_Set() and PyCell_Get() with PyCell_SET() and
PyCell_GET(), since the frame is guaranteed to contain cells.
2001-12-06 15:48:16 +00:00