summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix and test (manually w/xx module) passing NULLs to PyObject_Str() andNeal Norwitz2006-03-141-5/+7
| | | | | | | | | | | | | PyObject_Unicode(). This problem was originally reported from Coverity and addresses mail on python-dev "checkin r43015". This inlines the conversion of the string to unicode and cleans up/simplifies some code at the end of the PyObject_Unicode(). We really need a complete C API test module for all public APIs and passing good and bad parameter values. Will backport.
* Fix bug found by Coverity: don't allow NULL argument to PyUnicode_CheckExactGeorg Brandl2006-03-131-2/+2
|
* Change int to Py_ssize_t in several places.Martin v. Löwis2006-03-071-2/+2
| | | | | Add (int) casts to silence compiler warnings. Raise Python exceptions for overflows.
* Oops, forgot to include this in the last checkin.Neal Norwitz2006-03-041-1/+1
| | | | Actually define Py_RefTotal as a Py_ssize_t.
* Use %ld and casts to long for refcount printing, in absense of a universallyThomas Wouters2006-03-011-8/+18
| | | | | available %zd format character. Mark with an XXX comment so we can fix this, later.
* Revert backwards-incompatible const changes.Martin v. Löwis2006-02-271-2/+2
|
* Merge ssize_t branch.Martin v. Löwis2006-02-151-11/+12
|
* Add const to several API functions that take char *.Jeremy Hylton2005-12-101-5/+5
| | | | | | | | | | | | | | | | | | | In C++, it's an error to pass a string literal to a char* function without a const_cast(). Rather than require every C++ extension module to put a cast around string literals, fix the API to state the const-ness. I focused on parts of the API where people usually pass literals: PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type slots, etc. Predictably, there were a large set of functions that needed to be fixed as a result of these changes. The most pervasive change was to make the keyword args list passed to PyArg_ParseTupleAndKewords() to be a const char *kwlist[]. One cast was required as a result of the changes: A type object mallocs the memory for its tp_doc slot and later frees it. PyTypeObject says that tp_doc is const char *; but if the type was created by type_new(), we know it is safe to cast to char *.
* Change the %s format specifier for str objects so that it returns aNeil Schemenauer2005-08-121-9/+29
| | | | | unicode instance if the argument is not an instance of basestring and calling __str__ on the argument returns a unicode instance.
* Make subclasses of int, long, complex, float, and unicode perform typeBrett Cannon2005-04-261-25/+24
| | | | | | | conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald.
* Dima Dorfman's patch for coercion/comparison of C types (patch #995939), withArmin Rigo2004-12-231-16/+11
| | | | | a minor change after the coercion, to accept two objects not necessarily of the same type but with the same tp_compare.
* Remove 'extern' declaration for _Py_SwappedOp.Brett Cannon2004-09-251-1/+1
|
* A static swapped_op[] array was defined in 3 different C files, & I thinkTim Peters2004-09-231-4/+4
| | | | | I need to define it again. Bite the bullet and define it once as an extern, _Py_SwappedOp[].
* Move a comment back to its rightful location.Michael W. Hudson2004-09-141-2/+2
|
* SF bug #1004669: Type returned from .keys() is not checkedRaymond Hettinger2004-08-071-0/+5
|
* Remove unused macros in .c filesNeal Norwitz2004-07-081-2/+0
|
* Make weak references subclassable:Fred Drake2004-07-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | - weakref.ref and weakref.ReferenceType will become aliases for each other - weakref.ref will be a modern, new-style class with proper __new__ and __init__ methods - weakref.WeakValueDictionary will have a lighter memory footprint, using a new weakref.ref subclass to associate the key with the value, allowing us to have only a single object of overhead for each dictionary entry (currently, there are 3 objects of overhead per entry: a weakref to the value, a weakref to the dictionary, and a function object used as a weakref callback; the weakref to the dictionary could be avoided without this change) - a new macro, PyWeakref_CheckRefExact(), will be added - PyWeakref_CheckRef() will check for subclasses of weakref.ref This closes SF patch #983019.
* SF Bug #215126: Over restricted type checking on eval() functionRaymond Hettinger2004-07-021-1/+1
| | | | | | The builtin eval() function now accepts any mapping for the locals argument. Time sensitive steps guarded by PyDict_CheckExact() to keep from slowing down the normal case. My timings so no measurable impact.
* Two new public API functions, Py_IncRef and Py_DecRef. Useful forThomas Heller2004-04-221-0/+12
| | | | dynamic embedders of Python.
* Fix typo in comment.Raymond Hettinger2004-03-211-1/+1
|
* Add identity shortcut to PyObject_RichCompareBool.Raymond Hettinger2004-03-211-1/+11
|
* Removed two unneeded lines from PyObject_Compare().Brett Cannon2004-01-271-2/+0
| | | | Closes bug #885293 (thanks, Josiah Carlson).
* Getting rid of all the code inside #ifdef macintosh too.Jack Jansen2003-11-201-4/+0
|
* Getting rid of support for the ancient Apple MPW compiler.Jack Jansen2003-11-191-8/+0
|
* Deleting cyclic object comparison.Armin Rigo2003-10-281-180/+8
| | | | | SF patch 825639 http://mail.python.org/pipermail/python-dev/2003-October/039445.html
* Fix forMichael W. Hudson2003-08-151-1/+6
| | | | | | | | | [ 784825 ] fix obscure crash in descriptor handling Should be applied to release23-maint and in all likelyhood release22-maint, too. Certainly doesn't apply to release21-maint.
* _Py_PrintReferenceAddresses(): also print the type name. In real useTim Peters2003-04-181-1/+2
| | | | | | | | | I'm finding some pretty baffling output, like reprs consisting entirely of three left parens. At least this will let us know what type the object is (it's not str -- there's no quote character in the repr). New tool combinerefs.py, to combine the two output blocks produced via PYTHONDUMPREFS.
* _Py_PrintReferences(): Changed to print object address at start of eachTim Peters2003-04-171-1/+16
| | | | | | | | | | | | | | | new line. New pvt API function _Py_PrintReferenceAddresses(): Prints only the addresses and refcnts of the live objects. This is always safe to call, because it has no dependence on Python's C API. Py_Finalize(): If envar PYTHONDUMPREFS is set, call (the new) _Py_PrintReferenceAddresses() right before dumping final pymalloc stats. We can't print the reprs of the objects here because too much of the interpreter has been shut down. You need to correlate the addresses displayed here with the object reprs printed by the earlier PYTHONDUMPREFS call to _Py_PrintReferences().
* - pythunrun.c, Py_Finalize(): move the call to _Py_PrintReferences()Guido van Rossum2003-04-151-1/+1
| | | | | | | | | | | | | | | | | | | even farther down, to just before the call to _PyObject_DebugMallocStats(). This required the following changes: - pystate.c, PyThreadState_GetDict(): changed not to raise an exception or issue a fatal error when no current thread state is available, but simply return NULL without raising an exception (ever). - object.c, Py_ReprEnter(): when PyThreadState_GetDict() returns NULL, don't raise an exception but return 0. This means that when printing a container that's recursive, printing will go on and on and on. But that shouldn't happen in the case we care about (see first bullet). - Updated Misc/NEWS and Doc/api/init.tex to reflect changes to PyThreadState_GetDict() definition.
* Typo in comment.Tim Peters2003-03-231-1/+1
|
* Improved new Py_TRACE_REFS gimmicks.Tim Peters2003-03-231-14/+36
| | | | | | | | | | | Arranged that all the objects exposed by __builtin__ appear in the list of all objects. I basically peed away two days tracking down a mystery leak in sys.gettotalrefcount() in a ZODB app (== tons of code), because the object leaking the references didn't appear in the sys.getobjects(0) list. The object happened to be False. Now False is in the list, along with other popular & previously missing leak candidates (like None). Alas, we still don't have a choke point covering *all* Python objects, so the list of all objects may still be incomplete.
* Refactored some of the Py_TRACE_REFS code. New private API functionTim Peters2003-03-231-10/+14
| | | | | | | _Py_AddToAllObjects() that simply inserts an object at the front of the doubly-linked list of all objects. Changed PyType_Ready() (the closest thing we've got to a choke point for type objects) to call that.
* Oops! Used a wrong preprocessor symbol.Tim Peters2003-03-231-1/+1
|
* When Py_TRACE_REFS is defined, a list of all live objects is maintained inTim Peters2003-03-231-2/+15
| | | | | | | | | | | a doubly-linked list, exposed by sys.getobjects(). Unfortunately, it's not really all live objects, and it seems my fate to bump into programs where sys.gettotalrefcount() keeps going up but where the reference leaks aren't accounted for by anything in the list of all objects. This patch helps a little: if COUNT_ALLOCS is also defined, from now on type objects will also appear in this list, provided at least one object of a type has been allocated.
* Renamed PyObject_GenericGetIter to PyObject_SelfIterRaymond Hettinger2003-03-171-1/+1
| | | | | | to more accurately describe what the function does. Suggested by Thomas Wouters.
* Created PyObject_GenericGetIter().Raymond Hettinger2003-03-171-0/+7
| | | | Factors out the common case of returning self.
* 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.
* default_3way_compare(): use PyNumber_Check(), rather than testing forGuido van Rossum2003-02-181-3/+3
| | | | tp_as_number directly.
* 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.
* 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.
* Fix SF bug #667147, Segmentation fault printing str subclassNeal Norwitz2003-01-131-3/+16
| | | | | | | Fix infinite recursion which occurred when printing an object whose __str__() returned self. Will backport
* Remove _Py_ResetReferences. Fixes bug #529750 "Circular reference makesNeil Schemenauer2002-11-171-7/+0
| | | | | | Py_Init crash". refchain cannot be cleared because objects can live across Py_Finalize() and Py_Initialize() if they are kept alive by circular references.
* PyObject_Init[Var] is almost always called from the PyObject_NEW[_VAR]Guido van Rossum2002-10-111-10/+4
| | | | | | | | | | macros. The 'op' argument is then the result from PyObject_MALLOC, and that can of course be NULL. In that case, PyObject_Init[Var] would raise a SystemError with "NULL object passed to PyObject_Init[Var]". But there's nothing the caller of the macro can do about this. So PyObject_Init[Var] should call just PyErr_NoMemory. Will backport.
* Speedup for PyObject_IsTrue(): check for True and False first.Guido van Rossum2002-08-241-0/+4
| | | | | Because all built-in tests return bools now, this is the most common path!
* Speedup for PyObject_RichCompareBool(): PyObject_RichCompare() almostGuido van Rossum2002-08-241-1/+4
| | | | | always returns a bool, so avoid calling PyObject_IsTrue() in that case.
* Another modest speedup in PyObject_GenericGetAttr(): inline the callGuido van Rossum2002-08-191-2/+26
| | | | to _PyType_Lookup().
* Inline call to _PyObject_GetDictPtr() in PyObject_GenericGetAttr().Guido van Rossum2002-08-191-3/+20
| | | | This causes a modest speedup.
* Replace abort with Py_FatalError.Martin v. Löwis2002-08-071-1/+1
|
* Excise DL_IMPORT/EXPORT from object.h, and related files. This patchMark Hammond2002-07-291-2/+2
| | | | | also adds 'extern' to PyAPI_DATA rather than at each declaration, as discussed with Tim and Guido.
* object.h special-build macro minefield: renamed all the new lexicalTim Peters2002-07-111-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | helper macros to something saner, and used them appropriately in other files too, to reduce #ifdef blocks. classobject.c, instance_dealloc(): One of my worst Python Memories is trying to fix this routine a few years ago when COUNT_ALLOCS was defined but Py_TRACE_REFS wasn't. The special-build code here is way too complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS build, the instance is no longer in the doubly-linked list of live objects while its __del__ method is executing, and that may be visible via sys.getobjects() called from a __del__ method. Tough -- the object is presumed dead while its __del__ is executing anyway, and not calling _Py_NewReference() at the start allows enormous code simplification. typeobject.c, call_finalizer(): The special-build instance_dealloc() pain apparently spread to here too via cut-'n-paste, and this is much simpler now too. In addition, I didn't understand why this routine was calling _PyObject_GC_TRACK() after a resurrection, since there's no plausible way _PyObject_GC_UNTRACK() could have been called on the object by this point. I suspect it was left over from pasting the instance_delloc() code. Instead asserted that the object is still tracked. Caution: I suspect we don't have a test that actually exercises the subtype_dealloc() __del__-resurrected-me code.