summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Two improvements to large file support:Guido van Rossum2001-03-011-30/+18
| | | | | | | | | | | | | | - In _portable_ftell(), try fgetpos() before ftello() and ftell64(). I ran into a situation on a 64-bit capable Linux where the C library's ftello() and ftell64() returned negative numbers despite fpos_t and off_t both being 64-bit types; fgetpos() did the right thing. - Define a new typedef, Py_off_t, which is either fpos_t or off_t, depending on which one is 64 bits. This removes the need for a lot of #ifdefs later on. (XXX Should this be moved to pyport.h? That file currently seems oblivious to large fille support, so for now I'll leave it here where it's needed.)
* Visit the closure during traversal and XDECREF it on during deallocation.Jeremy Hylton2001-03-011-0/+6
|
* Fix SF buf 404774 submitted by Gregory H. BallJeremy Hylton2001-02-281-1/+1
| | | | | A user program could delete a function's func_closure, which would cause it to crash when called.
* Add Vladimir Marangozov's object allocator. It is disabled by default. ThisNeil Schemenauer2001-02-272-0/+747
| | | | closes SF patch #401229.
* The return value from PyObject_ClearWeakRefs() is no longer meaningful,Fred Drake2001-02-262-5/+4
| | | | so make it void.
* instancemethod_setattro(): Raise TypeError if an attempt is made toBarry Warsaw2001-02-261-15/+2
| | | | | | set a function attribute on a method (either bound or unbound). This reverts to Python 2.0 behavior that no attributes of the method are writable, but provides a more informative error message.
* _Py_ReleaseInternedStrings(): Private API function to decref andBarry Warsaw2001-02-231-0/+10
| | | | | | release the interned string dictionary. This is useful for memory use debugging because it eliminates a huge source of noise from the reports. Only defined when INTERN_STRINGS is defined.
* _PyObject_Dump(): If argument is NULL, print "NULL" instead ofBarry Warsaw2001-02-221-3/+7
| | | | crashing.
* In try_3way_to_rich_compare(), swap the call to default_3way_compare()Guido van Rossum2001-02-221-2/+2
| | | | | | and the test for errors, so that an error in the default compare doesn't go undetected. This fixes SF Bug #132933 (submitted by effbot) -- list.sort doesn't detect comparision errors.
* reorganized PyUnicode_DecodeUnicodeEscape a bit (in order to make itFredrik Lundh2001-02-181-110/+69
| | | | less likely that bug #132817 ever appears again)
* Fix core dump whenever PyList_Reverse() was called.Guido van Rossum2001-02-121-11/+14
| | | | | | | | | | | This fixes SF bug #132008, reported by Warren J. Hack. The copyright for this patch (and this patch only) belongs to CNRI, as part of the (yet to be issued) 1.6.1 release. This is now checked into the HEAD branch. Tim will check in a test case to check for this specific bug, and an assertion in PyArgs_ParseTuple() to catch similar bugs in the future.
* Superseded by $(srcdir)/Makefile.pre.in.Neil Schemenauer2001-02-031-104/+0
|
* SF patch 103543 from tg@freebsd.org:Jeremy Hylton2001-02-011-1/+1
| | | | PyFPE_END_PROTECT() was called on undefined var
* PEP 205, Weak References -- initial checkin.Fred Drake2001-02-012-0/+28
|
* Rename dubiously named local variable 'cmpfunc' -- this is also aGuido van Rossum2001-01-291-5/+5
| | | | | | typedef, and at least one compiler choked on this. (SF patch #103457, by bquinlan)
* Remove f_closure slot of frameobject and use f_localsplus instead.Jeremy Hylton2001-01-291-23/+14
| | | | | | | | | | | | This change eliminates an extra malloc/free when a frame with free variables is created. Any cell vars or free vars are stored in f_localsplus after the locals and before the stack. eval_code2() fills in the appropriate values after handling initialization of locals. To track the size the frame has an f_size member that tracks the total size of f_localsplus. It used to be implicitly f_nlocals + f_stacksize.
* fix indentation glitchJeremy Hylton2001-01-291-1/+1
|
* Fixed .capitalize() method of Unicode objects to work like theMarc-André Lemburg2001-01-291-4/+18
| | | | | | corresponding string method. Added tests for this too. Patch written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
* The one thing I love more then writing code is deleting code.Moshe Zadka2001-01-291-33/+2
| | | | | | | | | * Removed func_hash and func_compare, so they can be treated as immutable content-less objects (address hash and comparison) * Added tests to that affect to test_funcattrs (also testing func_code is writable) * Reverse meaning of tests in test_opcodes which checked identical code gets identical functions
* Re-factored PyInstance_New() into PyInstance_New() and PyInstance_NewRaw().Fred Drake2001-01-281-13/+34
|
* PEP 227 implementationJeremy Hylton2001-01-252-3/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The majority of the changes are in the compiler. The mainloop changes primarily to implement the new opcodes and to pass a function's closure to eval_code2(). Frames and functions got new slots to hold the closure. Include/compile.h Add co_freevars and co_cellvars slots to code objects. Update PyCode_New() to take freevars and cellvars as arguments Include/funcobject.h Add func_closure slot to function objects. Add GetClosure()/SetClosure() functions (and corresponding macros) for getting at the closure. Include/frameobject.h PyFrame_New() now takes a closure. Include/opcode.h Add four new opcodes: MAKE_CLOSURE, LOAD_CLOSURE, LOAD_DEREF, STORE_DEREF. Remove comment about old requirement for opcodes to fit in 7 bits. compile.c Implement changes to code objects for co_freevars and co_cellvars. Modify symbol table to use st_cur_name (string object for the name of the current scope) and st_cur_children (list of nested blocks). Also define st_nested, which might more properly be called st_cur_nested. Add several DEF_XXX flags to track def-use information for free variables. New or modified functions of note: com_make_closure(struct compiling *, PyCodeObject *) Emit LOAD_CLOSURE opcodes as needed to pass cells for free variables into nested scope. com_addop_varname(struct compiling *, int, char *) Emits opcodes for LOAD_DEREF and STORE_DEREF. get_ref_type(struct compiling *, char *name) Return NAME_CLOSURE if ref type is FREE or CELL symtable_load_symbols(struct compiling *) Decides what variables are cell or free based on def-use info. Can now raise SyntaxError if nested scopes are mixed with exec or from blah import *. make_scope_info(PyObject *, PyObject *, int, int) Helper functions for symtable scope stack. symtable_update_free_vars(struct symtable *) After a code block has been analyzed, it must check each of its children for free variables that are not defined in the block. If a variable is free in a child and not defined in the parent, then it is defined by block the enclosing the current one or it is a global. This does the right logic. symtable_add_use() is now a macro for symtable_add_def() symtable_assign(struct symtable *, node *) Use goto instead of for (;;) Fixed bug in symtable where name of keyword argument in function call was treated as assignment in the scope of the call site. Ex: def f(): g(a=2) # a was considered a local of f ceval.c eval_code2() now take one more argument, a closure. Implement LOAD_CLOSURE, LOAD_DEREF, STORE_DEREF, MAKE_CLOSURE> Also: When name error occurs for global variable, report that the name was global in the error mesage. Objects/frameobject.c Initialize f_closure to be a tuple containing space for cellvars and freevars. f_closure is NULL if neither are present. Objects/funcobject.c Add support for func_closure. Python/import.c Change the magic number. Python/marshal.c Track changes to code objects.
* PEP 227 implementationJeremy Hylton2001-01-251-0/+115
| | | | | | A cell contains a reference to a single PyObject. It could be implemented as a mutable, one-element sequence, but the separate type has less overhead.
* Check the Py_TPFLAGS_HAVE_RICHCOMPARE flag before using theGuido van Rossum2001-01-241-7/+9
| | | | | tp_richcompare field! (Hopefully this will make Python 2.1 binary compatible with certain Zope extensions. :-)
* Show '\011', '\012', and '\015' as '\t', '\n', '\r' in strings.Ka-Ping Yee2001-01-242-12/+36
| | | | Switch from octal escapes to hex escapes for other nonprintable characters.
* Move uchhash functionality into unicodedata (after the recentFredrik Lundh2001-01-241-9/+11
| | | | | crop of changes, the files are small enough to do this). Also adds "name" and "lookup" functions to unicodedata.
* PyObject_Dump() -> _PyObject_Dump()Barry Warsaw2001-01-241-3/+3
| | | | PyGC_Dump() -> _PyGC_Dump()
* PyObject_Dump(): Use %p format to print the address of the pointer.Barry Warsaw2001-01-231-2/+4
| | | | PyGC_Dump(): Wrap this in a #ifdef WITH_CYCLE_GC.
* A few miscellaneous helpers.Barry Warsaw2001-01-231-2/+26
| | | | | | | | | | | | | | | | PyObject_Dump(): New function that is useful when debugging Python's C runtime. In something like gdb it can be a pain to get some useful information out of PyObject*'s. This function prints the str() of the object to stderr, along with the object's refcount and hex address. PyGC_Dump(): Similar to PyObject_Dump() but knows how to cast from the garbage collector prefix back to the PyObject* structure. [See Misc/gdbinit for some useful gdb hooks] none_dealloc(): Rather than SEGV if we accidentally decref None out of existance, we assign None's and NotImplemented's destructor slot to this function, which just calls abort().
* New special case in comparisons: None is smaller than any other objectGuido van Rossum2001-01-221-0/+6
| | | | (unless the object's type overrides this comparison).
* Once again, numeric-smelling objects compare smaller than non-numericGuido van Rossum2001-01-221-2/+17
| | | | ones.
* forgot to check in the new makeunicodedata.py scriptFredrik Lundh2001-01-211-1/+1
|
* Remove a smelly export.Neil Schemenauer2001-01-211-1/+1
|
* Better error message if ucnhash cannot be found (obscure attributeFredrik Lundh2001-01-201-3/+8
| | | | | | errors aren't that helpful), or doesn't contain what's expected from it. Also tweaked the test script so it compiles even if ucnhash is missing.
* Tim chastens:Barry Warsaw2001-01-201-1/+5
| | | | | | | | | | | | | | Barry, that comment belongs in the code, not in the checkin msg. The code *used* to do this correctly (as you well know, since you & I went thru considerable pain to fix this the first time). However, because the *reason* for the convolution wasn't recorded in the code as a comment, somebody threw it all away the first time it got reworked. c-code-isn't-often-self-explanatory-ly y'rs - tim default_3way_compare(): Stick the checkin message from 2.110 in a comment.
* default_3way_compare(): When comparing the pointers, they must be castBarry Warsaw2001-01-201-2/+2
| | | | | | | to integer types (i.e. Py_uintptr_t, our spelling of C9X's uintptr_t). ANSI specifies that pointer compares other than == and != to non-related structures are undefined. This quiets an Insure portability warning.
* Application and elaboration of patch #103305 to fix core dumps whenBarry Warsaw2001-01-191-30/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | del'ing func.func_dict. I took the opportunity to also clean up some other nits with the code, namely core dumps when del'ing func_defaults and KeyError instead of AttributeError when del'ing a non-existant function attribute. Specifically, func_memberlist: Move func_dict and __dict__ into here instead of special casing them in the setattro and getattro methods. I don't remember why I took them out of here before I first uploaded the PEP 232 patch. :/ func_getattro(): No need to special case __dict__/func_dict since their now in the func_memberlist and PyMember_Get() should Do The Right Thing (i.e. transforms NULL values into Py_None). func_setattro(): Document the intended behavior of del'ing or setting to None one of the special func_* attributes. I.e.: func_code - can only be set to a code object. It can't be del'd or set to None. func_defaults - can be del'd. Can only be set to None or a tuple. func_dict - can be del'd. Can only be set to None or a dictionary. Fix core dumps and incorrect exceptions as described above. Also, if we're del'ing an arbitrary function attribute but func_dict is NULL, don't create func_dict before discovering that we'll get an AttributeError anyway.
* refactored the unicodeobject/ucnhash interface, to hide theFredrik Lundh2001-01-191-103/+39
| | | | | | | implementation details inside the ucnhash module. also cleaned up the unicode copyright blurb a little; Secret Labs' internal revision history isn't that interesting...
* Derivative of patch #102549, "simpler, faster(!) implementation of string.join".Tim Peters2001-01-191-38/+52
| | | | | | | | Also fixes two long-standing bugs (present in 2.0): 1. .join() didn't check that the result size fit in an int. 2. string.join(s) when len(s)==1 returned s[0] regardless of s[0]'s type; e.g., "".join([3]) returned 3 (overly optimistic optimization). I resisted a keen temptation to make .join() apply str() automagically.
* Rich comparisons fallout: instance_hash() should check for bothGuido van Rossum2001-01-181-7/+14
| | | | | __cmp__ and __eq__ absent before deciding to do a quickie based on the object address. (Tim Peters discovered this.)
* Rich comparisons fallout: PyObject_Hash() should check for bothGuido van Rossum2001-01-181-1/+1
| | | | | tp_compare and tp_richcompare NULL before deciding to do a quickie based on the object address. (Tim Peters discovered this.)
* Changes to recursive-object comparisons, having to do with a test caseGuido van Rossum2001-01-181-107/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I found where rich comparison of unequal recursive objects gave unintuituve results. In a discussion with Tim, where we discovered that our intuition on when a<=b should be true was failing, we decided to outlaw ordering comparisons on recursive objects. (Once we have fixed our intuition and designed a matching algorithm that's practical and reasonable to implement, we can allow such orderings again.) - Refactored the recursive-object comparison framework; more is now done in the support routines so less needs to be done in the calling routines (even at the expense of slowing it down a bit -- this should normally never be invoked, it's mostly just there to avoid blowing up the interpreter). - Changed the framework so that the comparison operator used is also stored. (The dictionary now stores triples (v, w, op) instead of pairs (v, w).) - Changed the nesting limit to a more reasonable small 20; this only slows down comparisons of very deeply nested objects (unlikely to occur in practice), while speeding up comparisons of recursive objects (previously, this would first waste time and space on 500 nested comparisons before it would start detecting recursion). - Changed rich comparisons for recursive objects to raise a ValueError exception when recursion is detected for ordering oprators (<, <=, >, >=). Unrelated change: - Moved PyObject_Unicode() to just under PyObject_Str(), where it belongs. MAL's patch must've inserted in a random spot between two functions in the file -- between two helpers for rich comparison...
* Move distributed and duplicated config for stat() and fstat() into pyport.h.Tim Peters2001-01-181-20/+0
|
* Use rich comparisons to fulfill an old wish: complex numbers now raiseGuido van Rossum2001-01-181-49/+84
| | | | | | | | | | | exceptions when compared using <, <=, > or >=. NOTE: This is a tentative change: this means that cmp() involving complex numbers will raise an exception when the numbers differ, and that in turn means that e.g. dictionaries and certain other compounds (e.g. UserLists) containing complex numbers can't be compared either. So we'll have to decide whether this is acceptable. The alpha test cycle is a good time to keep an eye on this!
* Rich comparisons:Guido van Rossum2001-01-181-118/+45
| | | | | | | | | | | | | | | | | | | | | - Use PyObject_RichCompareBool() when comparing keys; this makes the error handling cleaner. - There were two implementations for dictionary comparison, an old one (#ifdef'ed out) and a new one. Got rid of the old one, which was abandoned years ago. - In the characterize() function, part of dictionary comparison, use PyObject_RichCompareBool() to compare keys and values instead. But continue to use PyObject_Compare() for comparing the final (deciding) elements. - Align the comments in the type struct initializer. Note: I don't implement rich comparison for dictionaries -- there doesn't seem to be much to be gained. (The existing comparison already decides that shorter dicts are always smaller than longer dicts.)
* Same treatment as listobject.c:Guido van Rossum2001-01-181-43/+104
| | | | | | | | | - tuplecontains(): call RichCompare(Py_EQ). - Get rid of tuplecompare(), in favor of new tuplerichcompare() (a clone of list_compare()). - Aligned the comments for large struct initializers.
* Fix a leak in instance_coerce(). This was introduced by Neil'sGuido van Rossum2001-01-171-2/+0
| | | | | | | | | earlier coercion changes, not by rich comparisons. When a coercion function returns 1 (meaning it cannot do it), it should not INCREF the arguments. When no __coerce__() method was found, instance_coerce() originally returned 0, pretending it did it. Neil changed the return value to 1, more accurately reflecting that it didn't do anything, but forgot to take out the two INCREF calls.
* Convert to rich comparisons:Guido van Rossum2001-01-171-90/+163
| | | | | | | | | | | | | | | | - sort's docompare() calls RichCompare(Py_LT). - list_contains(), list_index(), listcount(), listremove() call RichCompare(Py_EQ). - Get rid of list_compare(), in favor of new list_richcompare(). The latter does some nice shortcuts, like when == or != is requested, it first compares the lengths for trivial accept/reject. Then it goes over the items until it finds an index where the items differe; then it does more shortcut magic to minimize the number of additional comparisons. - Aligned the comments for large struct initializers.
* Deal properly (?) with comparing recursive datastructures.Guido van Rossum2001-01-171-62/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Use the compare nesting level and in-progress dictionary properly in PyObject_RichCompare(). - Change the in-progress code to use static variables instead of globals (both the nesting level and the key for the thread dict were globals but have no reason to be globals; the key can even be a function-static variable in get_inprogress_dict()). - Rewrote try_rich_to_3way_compare() to benefit from the similarity of the three cases, making it table-driven. - In try_rich_to_3way_compare(), test for EQ before LT and GT. This turns out essential when comparing recursive UserList instances; with the old code, these would recurse into rich comparison three times for each nesting level up to NESTING_LIMIT/2, making the total number of calls in the order of 3**(NESTING_LIMIT/2)! NOTE: I'm not 100% comfortable with this. It works for the standard test suite (which compares a few trivial recursive data structures only), but I'm not sure that the in-progress dictionary is used properly by the rich comparison code. Jeremy suggested that maybe the operation should be included in the dict. Currently I presume that objects in the dict are equal unless proven otherwise, and I set the outcome for the rich comparison accordingly: true for operators EQ, LE, GE, and false for the other three. But Jeremy seems to think that there may be counter-examples where this doesn't do the right thing.
* This patch adds a new builtin unistr() which behaves like str()Marc-André Lemburg2001-01-172-0/+48
| | | | | | | | | | except that it always returns Unicode objects. A new C API PyObject_Unicode() is also provided. This closes patch #101664. Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
* Rich comparisons fall-out:Guido van Rossum2001-01-171-14/+1
| | | | | | - Get rid of float_cmp(). - Renamed Py_TPFLAGS_NEWSTYLENUMBER to Py_TPFLAGS_CHECKTYPES.