summaryrefslogtreecommitdiff
path: root/Python/bltinmodule.c
AgeCommit message (Collapse)AuthorLines
2002-04-30backport tim_one's patch:Anthony Baxter-2/+2
Repair widespread misuse of _PyString_Resize. Since it's clear people don't understand how this function works, also beefed up the docs. The most common usage error is of this form (often spread out across gotos): if (_PyString_Resize(&s, n) < 0) { Py_DECREF(s); s = NULL; goto outtahere; } The error is that if _PyString_Resize runs out of memory, it automatically decrefs the input string object s (which also deallocates it, since its refcount must be 1 upon entry), and sets s to NULL. So if the "if" branch ever triggers, it's an error to call Py_DECREF(s): s is already NULL! A correct way to write the above is the simpler (and intended) if (_PyString_Resize(&s, n) < 0) goto outtahere; Bugfix candidate. Original patch(es): python/dist/src/Python/bltinmodule.c:2.253
2002-04-20Backport fixes for two nested scopes bugs.Jeremy Hylton-1/+7
frameobject.c: make sure free and cell vars make it into locals, which makes eval work. bltinmodule.c & ceval.c: make sure a code object with free variables that is passed to exec or eval raises an exception. Also duplicate the current trunk test suite in the 2.1 branch, except for certain necessary changes: different warnings raised by 2.1, need for __future__.
2001-05-23Backport Tim's checkin 2.199:Thomas Wouters-9/+19
Fix buglet reported on c.l.py: map(fnc, file.xreadlines()) blows up. Took away map()'s insistence that sequences support __len__, and cleaned up the convoluted code that made it *look* like it really cared about __len__ (in fact the old ->len field was only *used* as a flag bit, as the main loop only looked at its sign bit, setting the field to -1 when IndexError got raised; renamed the field to ->saw_IndexError instead).
2001-04-07SF patch #413552 - Premature decref on objectTim Peters-3/+7
Jeffery Collins pointed out that filterstring decrefs a character object before it's done using it. This works by accident today because another module always happens to have an active reference too at the time. The accident doesn't work after his Pippy modifications, and since it *is* an accident even in the mainline Python, it should work by design there too. The patch accomplishes that.
2001-03-22Extend support for from __future__ import nested_scopesJeremy Hylton-2/+14
If a module has a future statement enabling nested scopes, they are also enable for the exec statement and the functions compile() and execfile() if they occur in the module. If Python is run with the -i option, which enters interactive mode after executing a script, and the script it runs enables nested scopes, they are also enabled in interactive mode. XXX The use of -i with -c "from __future__ import nested_scopes" is not supported. What's the point? To support these changes, many function variants have been added to pythonrun.c. All the variants names end with Flags and they take an extra PyCompilerFlags * argument. It is possible that this complexity will be eliminated in a future version of the interpreter in which nested scopes are not optional.
2001-03-21Move the code implementing isinstance() and issubclass() to new CGuido van Rossum-96/+6
APIs, PyObject_IsInstance() and PyObject_IsSubclass() -- both returning an int, or -1 for errors.
2001-01-19Backed out the unistr() builtin.Marc-André Lemburg-18/+0
2001-01-19clearer error messages for apply() and "no locals"Jeremy Hylton-4/+6
2001-01-19Fix for the bug in complex() just reported by Ping.Guido van Rossum-1/+7
2001-01-17This patch adds a new builtin unistr() which behaves like str()Marc-André Lemburg-0/+18
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.
2001-01-17Use rich comparisons in min and max.Guido van Rossum-9/+9
2001-01-12Update the docstring for apply() so that "args" is marked as optionalFred Drake-1/+1
(since it is).
2001-01-12(Modified) patch by Ping - SF Patch #102681.Guido van Rossum-27/+33
- Make error messages from issubclass() and isinstance() a bit more descriptive (Ping, modified by Guido) - Couple of tiny fixes to other docstrings (Ping) - Get rid of trailing whitespace (Guido)
2001-01-04Add NotImplemented to the builtin module.Neil Schemenauer-0/+3
2000-12-23CHange error messages for ord(), using "string" instead of "string or Unicode"Andrew M. Kuchling-2/+3
2000-12-20Whoops! Two stray characters crept in to my last check-inAndrew M. Kuchling-1/+1
2000-12-20Patch #102955, fixing one of the warnings in bug #121479:Andrew M. Kuchling-5/+7
Simplifies ord()'s logic at the cost of some code duplication, removing a " `ord' might be used uninitialized in this function" warning
2000-12-04Make isinstance() more permissive in what types of arguments itNeil Schemenauer-17/+9
accepts. Clarify exception messages for isinstance() and issubclass(). Closes bug #124106.
2000-10-24Ka-Ping Yee <ping@lfw.org>:Fred Drake-26/+26
Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
2000-09-26Rationalize use of limits.h, moving the inclusion to Python.h.Fred Drake-3/+0
Add definitions of INT_MAX and LONG_MAX to pyport.h. Remove includes of limits.h and conditional definitions of INT_MAX and LONG_MAX elsewhere. This closes SourceForge patch #101659 and bug #115323.
2000-09-19This patch adds a new Python C API called PyString_AsStringAndSize()Marc-André Lemburg-6/+3
which implements the automatic conversion from Unicode to a string object using the default encoding. The new API is then put to use to have eval() and exec accept Unicode objects as code parameter. This closes bugs #110924 and #113890. As side-effect, the traditional C APIs PyString_Size() and PyString_AsString() will also accept Unicode objects as parameters.
2000-09-18Deferred the attribute name object type checking to the underlyingMarc-André Lemburg-4/+4
PyObject_Set/GetAttr() calls. This patch fixes bug #113829.
2000-09-01REMOVED all CWI, CNRI and BeOpen copyright markings.Guido van Rossum-9/+0
This should match the situation in the 1.6b1 tree.
2000-08-27Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),Guido van Rossum-4/+1
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-18comples_from_string(): Move s_buffer[] up to the top-level functionBarry Warsaw-2/+1
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-12Clean up a couple of warnings on Win64. The downcast of the strlen size_tTrent Mick-1/+1
return value to int is safe here because in each case it previouls checked that there will be no overflow.
2000-08-03Both PEP 201 Lockstep Iteration and SF patch #101030 have beenBarry Warsaw-0/+56
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-07-31merge Include/my*.h into Include/pyport.hPeter Schneider-Kamp-2/+0
marked my*.h as obsolete
2000-07-23Another missed ansification.Thomas Wouters-4/+1
2000-07-22Mass ANSIfication of function definitions. Doesn't cover all 'extern'Thomas Wouters-179/+60
declarations yet, those come later.
2000-07-12replace PyXXX_Length calls with PyXXX_Size callsJeremy Hylton-1/+1
2000-07-09Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.Tim Peters-4/+4
2000-07-09Get rid of unused vars in builtin_unicode (they were causingTim Peters-2/+0
legit warnings).
2000-07-07Fixed unicode() to use the new API PyUnicode_FromEncodedObject().Marc-André Lemburg-14/+1
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-03Include limits.h if we have it.Jack Jansen-0/+3
2000-06-30Change copyright notice - 2nd try.Guido van Rossum-6/+0
2000-06-30Change copyright notice.Guido van Rossum-21/+6
2000-06-28Trent Mick:Guido van Rossum-3/+10
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-20Christopher Fandrich <cfandrich@8cs.com>:Fred Drake-3/+6
Fix memory leak in initializing __debug__.
2000-05-25All the exception building related stuff has been moved out of thisBarry Warsaw-190/+1
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-25bltin_exc: Removed the leaf_exc flag in the structure, which was onlyBarry Warsaw-35/+29
used to build the fallback string-based exception.
2000-05-09M.-A. Lemburg <mal@lemburg.com>:Fred Drake-2/+2
Fixed docs according to the new behaviour (the Unicode encoding is no longer fixed to UTF-8).
2000-05-03Vladimir Marangozov's long-awaited malloc restructuring.Guido van Rossum-1/+1
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-03A bit of cleanup:Guido van Rossum-34/+5
- 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-02_PyBuiltin_Init_2(): Remove the misleading comment.Barry Warsaw-1/+0
2000-05-02initerrors(): Remove this function. String-based standard exceptionsBarry Warsaw-96/+4
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-04-13When refering to Unicode characters in exception messages andFred Drake-5/+5
docstrings, the documentation guidelines call for "Unicode", not "unicode". Comply.
2000-04-12ord: provide better error messagesJeremy Hylton-8/+19
2000-04-11Marc-Andre Lemburg:Guido van Rossum-4/+17
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-05Marc-Andre's third try at this bulk patch seems to work (except thatGuido van Rossum-8/+45
his copy of test_contains.py seems to be broken -- the lines he deleted were already absent). Checkin messages: New Unicode support for int(), float(), complex() and long(). - new APIs PyInt_FromUnicode() and PyLong_FromUnicode() - added support for Unicode to PyFloat_FromString() - new encoding API PyUnicode_EncodeDecimal() which converts Unicode to a decimal char* string (used in the above new APIs) - shortcuts for calls like int(<int object>) and float(<float obj>) - tests for all of the above Unicode compares and contains checks: - comparing Unicode and non-string types now works; TypeErrors are masked, all other errors such as ValueError during Unicode coercion are passed through (note that PyUnicode_Compare does not implement the masking -- PyObject_Compare does this) - contains now works for non-string types too; TypeErrors are masked and 0 returned; all other errors are passed through Better testing support for the standard codecs. Misc minor enhancements, such as an alias dbcs for the mbcs codec. Changes: - PyLong_FromString() now applies the same error checks as does PyInt_FromString(): trailing garbage is reported as error and not longer silently ignored. The only characters which may be trailing the digits are 'L' and 'l' -- these are still silently ignored. - string.ato?() now directly interface to int(), long() and float(). The error strings are now a little different, but the type still remains the same. These functions are now ready to get declared obsolete ;-) - PyNumber_Int() now also does a check for embedded NULL chars in the input string; PyNumber_Long() already did this (and still does) Followed by: Looks like I've gone a step too far there... (and test_contains.py seem to have a bug too). I've changed back to reporting all errors in PyUnicode_Contains() and added a few more test cases to test_contains.py (plus corrected the join() NameError).