summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Fix from Greg Chapman from SF bug #695651: a complex subclassGuido van Rossum2003-03-021-2/+3
| | | | | | | | | | | | | | constructor, when passed a single complex argument, returns the argument unchanged. This should be done only for the complex base class; a complex subclass should of course cast the value to the subclass in this case. The fix also revealed a segfault in complex_getnewargs(): the argument for the Py_BuildValue() format code "D" is the *address* of a Py_complex struct, not the value. (This corroborated by the API documentation.) I expect this needs to be backported to 2.2.3.
* Removed duplicate test from inner loop.Raymond Hettinger2003-03-011-6/+1
| | | | The PyIter_Check is already performed by PyObject_GetIter.
* Fix SF bug #689659, 64-bit int and long hash keys incompatibleNeal Norwitz2003-02-231-2/+4
| | | | | On a 64-bit machine, a dictionary could contain duplicate int/long keys if the value was > 2**32.
* Implementing the salient parts of __reduce_ex__ in C.Guido van Rossum2003-02-211-6/+229
| | | | | | | This still falls back to helpers in copy_reg for: - pickle protocols < 2 - calculating the list of slot names (done only once per class) - the __newobj__ function (which is used as a token but never called)
* Strange control flow in PyInt_AsLong. When nb_int is called insideThomas Heller2003-02-201-3/+3
| | | | | | | | the PyInt_AsLong function, and this returns a long, the value is first retrieved with PyLong_AsLong, but afterwards overwritten by a call to PyInt_AS_LONG. Fixes SF #690253.
* PyObject_Generic{Get,Set}Attr:Guido van Rossum2003-02-191-2/+4
| | | | | | | | | | Don't access tp_descr_{get,set} of a descriptor without checking the flag bits of the descriptor's type. While we know that the main type (the type of the object whose attribute is being accessed) has all the right flag bits (or else PyObject_Generic{Get,Set}Attr wouldn't be called), we don't know that for its class attributes! Will backport to 2.2.
* Introducing __reduce_ex__, which is called with a protocol number argumentGuido van Rossum2003-02-181-4/+10
| | | | | if it exists in preference over __reduce__. Now Tim can go implement this in cPickle.c.
* Removed unreferenced label.Tim Peters2003-02-181-2/+1
|
* The recent changes to super(), in particular supercheck(), broke whenGuido van Rossum2003-02-181-9/+7
| | | | | | | | using super() for an instance in a metaclass situation. Because the class was a metaclass, the instance was a class, and hence the PyType_Check() branch was taken. But this branch didn't apply. Make it so that if this branch doesn't apply, the other branch is still tried. All tests pass.
* Make __module__ writable except in restricted mode (like for classic classes).Guido van Rossum2003-02-182-2/+2
|
* Make __module__ settable on functions and methods.Jeremy Hylton2003-02-182-2/+2
|
* default_3way_compare(): use PyNumber_Check(), rather than testing forGuido van Rossum2003-02-181-3/+3
| | | | tp_as_number directly.
* Make PyNumber_Check() a bit more careful, since all sorts of thingsGuido van Rossum2003-02-181-1/+3
| | | | now have tp_as_number. Check for nb_int or nb_float.
* Add closing ) in commentNeal Norwitz2003-02-151-1/+1
|
* cPickle.c, load_build(): Taught cPickle how to pick apartTim Peters2003-02-151-1/+11
| | | | | | | | | | | | | | | | | | the optional proto 2 slot state. pickle.py, load_build(): CAUTION: Noted that cPickle's load_build and pickle's load_build really don't do the same things with the state, and didn't before this patch either. cPickle never tries to do .update(), and has no backoff if instance.__dict__ can't be retrieved. There are no tests that can tell the difference, and part of what cPickle's load_build() did looked accidental to me, so I don't know what the true intent is here. pickletester.py, test_pickle.py: Got rid of the hack for exempting cPickle from running some of the proto 2 tests. dictobject.c, PyDict_Next(): documented intended use.
* SF patch #685738 by Michael Stone.Guido van Rossum2003-02-131-1/+19
| | | | | | | This changes the default __new__ to refuse arguments iff tp_init is the default __init__ implementation -- thus making it a TypeError when you try to pass arguments to a constructor if the class doesn't override at least __init__ or __new__.
* Issue a warning when int('0...', 0) returns an int with the signGuido van Rossum2003-02-121-2/+12
| | | | | | | | folded; this will change in Python 2.4. On a 32-bit machine, this happens for 0x80000000 through 0xffffffff, and for octal constants in the same value range. No warning is issued if an explicit base is given, *or* if the string contains a sign (since in those cases no sign folding ever happens).
* Implement another useful feature for proxies: in super(X, x), x mayGuido van Rossum2003-02-121-17/+83
| | | | now be a proxy for an X instance, as long as issubclass(x.__class__, X).
* Add missing cast in previous fix.Guido van Rossum2003-02-121-1/+2
|
* SF #532767: isinstance(x, X) should work when x is a proxy for an XGuido van Rossum2003-02-121-6/+19
| | | | | instance, as long as x.__class__ is X or a subclass thereof. Did a little cleanup of PyObject_IsInstance() too.
* Add more missing PyErr_NoMemory() after failled memory allocsNeal Norwitz2003-02-111-1/+1
|
* Fix from SF #681367: inherit tp_as_buffer. This only applies to CGuido van Rossum2003-02-111-0/+2
| | | | types -- Python types already inherited this.
* Put proper tests in classmethod_get(). Remove the type argument toGuido van Rossum2003-02-111-16/+47
| | | | | | descr_check(); it wasn't useful. Change the type argument of the various _get() methods to PyObject * because the call signature of tp_descr_get doesn't guarantee its type.
* Refactor instancemethod_descr_get() to (a) be more clear, (b) be safeGuido van Rossum2003-02-111-8/+18
| | | | | in the light of weird args, and (c) not to expect None (which is now changed to NULL by slot_tp_descr_get()).
* Inline create_specialmethod() -- since METH_CLASS is done differentlyGuido van Rossum2003-02-111-15/+5
| | | | | now, it was only called once, and its existence merely obfuscates the control flow.
* Add basic arg sanity checking to wrap_descr_get(). This is calledGuido van Rossum2003-02-111-0/+9
| | | | | | | when Python code calls a descriptor's __get__ method. It should translate None to NULL in both argument positions, and insist that at least one of the argument positions is not NULL after this transformation.
* Get rid of the "bozo" __getstate__ that was inserted when __slots__Guido van Rossum2003-02-101-32/+0
| | | | | | was used. This simplifies some logic in copy_reg.py (used by pickling). It also broke a test, but this was rewritten to test the new feature. :-)
* Fold long lines.Guido van Rossum2003-02-101-4/+7
|
* Fix SF bug #683467, 'int' ability to generate longs not inheritedNeal Norwitz2003-02-101-2/+16
| | | | | | When subclassing from an int but not overriding __new__, long values were not converted properly. Try to convert longs into an int.
* Fix two refcounting bugsWalter Dörwald2003-02-091-2/+4
|
* SF patch #683187, fix universal newline problems on errorNeal Norwitz2003-02-091-1/+4
|
* Comment typo fixAndrew M. Kuchling2003-02-061-1/+1
|
* Fix for SF #668433. I'm not explaining it here; ample comments are inGuido van Rossum2003-02-051-0/+93
| | | | the code.
* Refactor the logic for setting f_builtins.Jeremy Hylton2003-02-051-24/+31
| | | | | | | For the case where the current globals match the previous frame's globals, eliminates three tests in two if statements. For the case where we just get __builtins__ from a module, eliminate a couple of tests.
* SF bug 681122: Built-in function dir() causes refcount leak in baseclasses.Tim Peters2003-02-051-1/+4
| | | | | | merge_class_dict(): This was missing a decref. Bugfix candidate.
* _PyLong_Sign(): remove an assert that needed a variable ndigits thatGuido van Rossum2003-02-031-3/+2
| | | | | | | | | wasn't used outside the assert (and hence caused a compiler warning about an unused variable in NDEBUG mode). The assert wasn't very useful any more. _PyLong_NumBits(): moved the calculation of ndigits after asserting that v != NULL.
* long_from_binary_base(): Sped this a little by computing the # of bitsTim Peters2003-02-021-6/+6
| | | | needed outside the first loop.
* Tightened a too-generous assert.Tim Peters2003-02-021-1/+1
|
* long(string, base) now takes time linear in len(string) when base is aTim Peters2003-02-021-15/+108
| | | | | power of 2. Enabled the tail end of test_long() in pickletester.py because it no longer takes forever when run from test_pickle.py.
* cPickle.c: Full support for the new LONG1 and LONG4. Added comments.Tim Peters2003-02-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Assorted code cleanups; e.g., sizeof(char) is 1 by definition, so there's no need to do things like multiply by sizeof(char) in hairy malloc arguments. Fixed an undetected-overflow bug in readline_file(). longobject.c: Fixed a really stupid bug in the new _PyLong_NumBits. pickle.py: Fixed stupid bug in save_long(): When proto is 2, it wrote LONG1 or LONG4, but forgot to return then -- it went on to append the proto 1 LONG opcode too. Fixed equally stupid cancelling bugs in load_long1() and load_long4(): they *returned* the unpickled long instead of pushing it on the stack. The return values were ignored. Tests passed before only because save_long() pickled the long twice. Fixed bugs in encode_long(). Noted that decode_long() is quadratic-time despite our hopes, because long(string, 16) is still quadratic-time in len(string). It's hex() that's linear-time. I don't know a way to make decode_long() linear-time in Python, short of maybe transforming the 256's-complement bytes into marshal's funky internal format, and letting marshal decode that. It would be more valuable to make long(string, 16) linear time. pickletester.py: Added a global "protocols" vector so tests can try all the protocols in a sane way. Changed test_ints() and test_unicode() to do so. Added a new test_long(), but the tail end of it is disabled because it "takes forever" under pickle.py (but runs very quickly under cPickle: cPickle proto 2 for longs is linear-time).
* Removed all uses of the out-of-favor __safe_for_unpickling__ magicTim Peters2003-02-011-1/+0
| | | | attr, and copy_reg.safe_constructors.
* Squash compiler wng about signed/unsigned comparison mismatch.Tim Peters2003-01-311-1/+1
|
* Provide __module__ attributes for functions defined in C and Python.Jeremy Hylton2003-01-312-6/+68
| | | | | | | | | | | | | | __module__ is the string name of the module the function was defined in, just like __module__ of classes. In some cases, particularly for C functions, the __module__ may be None. Change PyCFunction_New() from a function to a macro, but keep an unused copy of the function around so that we don't change the binary API. Change pickle's save_global() to use whichmodule() if __module__ is None, but add the __module__ logic to whichmodule() since it might be used outside of pickle.
* Change the treatment of positions returned by PEP293Walter Dörwald2003-01-311-9/+17
| | | | | | | | | | | | | | | | error handers in the Unicode codecs: Negative positions are treated as being relative to the end of the input and out of bounds positions result in an IndexError. Also update the PEP and include an explanation of this in the documentation for codecs.register_error. Fixes a small bug in iconv_codecs: if the position from the callback is negative *add* it to the size instead of substracting it. From SF patch #677429.
* _PyLong_NumBits(): The definition of this was too specific to the quirkyTim Peters2003-01-311-8/+17
| | | | | | | | | needs of pickling longs. Backed off to a definition that's much easier to understand. The pickler will have to work a little harder, but other uses are more likely to be correct <0.5 wink>. _PyLong_Sign(): New teensy function to characterize a long, as to <0, ==0, or >0.
* Implement appropriate __getnewargs__ for all immutable subclassable builtinGuido van Rossum2003-01-297-4/+72
| | | | | | | | types. The special handling for these can now be removed from save_newobj(). Add some testing for this. Also add support for setting the 'fast' flag on the Python Pickler class, which suppresses use of the memo.
* Added new private API function _PyLong_NumBits. This will be used at theTim Peters2003-01-281-0/+35
| | | | | | | start for the C implemention of new pickle LONG1 and LONG4 opcodes (the linear-time way to pickle a long is to call _PyLong_AsByteArray, but the caller has no idea how big an array to allocate, and correct calculation is a bit subtle).
* Fix SF bug# 676155, RuntimeWarning with tp_compareNeal Norwitz2003-01-281-1/+4
| | | | Check return value of PyLong_AsDouble(), it can return an error.
* Recursive compare machinery: The code that intended to exempt tuplesTim Peters2003-01-201-9/+14
| | | | | | | | | | | | was broken because new-in-2.3 code added a tp_as_mapping slot to tuples. Repaired that. Added basic docs to check_recursion(). The code that intended to exempt tuples and strings was also broken here, and in 2.2: these should use PyXYZ_CheckExact(), not PyXYZ_Check() -- we can't know whether subclass instances are immutable. This part (and this part alone) is a bugfix candidate.
* SF # 669553, fix memory (ref) leaksNeal Norwitz2003-01-191-1/+8
| | | | Will backport.