summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
Commit message (Collapse)AuthorAgeFilesLines
* Fixed "u#" parser marker to pass through Unicode objects as-is withoutMarc-André Lemburg2002-01-091-2/+6
| | | | | | going through the buffer interface API. Added tests for this to the _testcapi module and updated docs.
* mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, toTim Peters2001-12-031-3/+3
| | | | | | | | | | | | | | | use wrappers on all platforms, to make this as consistent as possible x- platform (in particular, make sure there's at least one \0 byte in the output buffer). Also document more of the truth about what these do. getargs.c, seterror(): Three computations of remaining buffer size were backwards, thus telling PyOS_snprintf the buffer is larger than it actually is. This matters a lot now that PyOS_snprintf ensures there's a trailing \0 byte (because it didn't get the truth about the buffer size, it was storing \0 beyond the true end of the buffer). sysmodule.c, mywrite(): Simplify, now that PyOS_vsnprintf guarantees to produce a \0 byte.
* SF bug 486278 SystemError: Python/getargs.c:1086: bad.Tim Peters2001-11-291-7/+10
| | | | | | | | | | vgetargskeywords(): Now that this routine is checking for bad input (rather than dump core in some cases), some bad calls are raising errors that previously "worked". This patch makes the error strings more revealing, and changes the exceptions from SystemError to RuntimeError (under the theory that SystemError is more of a "can't happen!" assert- like thing, and so inappropriate for bad arguments to a public C API function).
* Two screwups fixed for sizeof(char *) instead of sizeof(char []).Jeremy Hylton2001-11-281-77/+82
| | | | | Also change all the helper functions to pass along the size of the msgbuf and use PyOS_snprintf() when writing into the buffer.
* Use PyOS_snprintf() at some cost even though it was correct before.Jeremy Hylton2001-11-281-6/+7
| | | | | | seterror() uses a char array and a pointer to the current position in that array. Use snprintf() and compute the amount of space left in the buffer based on the current pointer position.
* Use PyOS_snprintf when possible.Jeremy Hylton2001-11-281-34/+41
|
* Fixes for possible buffer overflows in sprintf() usages.Marc-André Lemburg2001-11-281-14/+9
|
* vgetargskeywords()Tim Peters2001-10-271-16/+17
| | | | | | | | | | + Squash another potential buffer overrun. + Simplify the keyword-arg loop by decrementing the count of keywords remaining instead of incrementing Yet Another Variable; also break out early if the number of keyword args remaining hits 0. Since I hit the function's closing curly brace with this patch, that's enough of this for now <wink>.
* vgetargskeywords: Now that it's clear that nkwlist must equal max, andTim Peters2001-10-271-4/+3
| | | | we're ensuring that's true during the format parse, get rid of nkwlist.
* vgetargskeywords: Prevent another potential sprintf buffer overrun.Tim Peters2001-10-271-2/+2
|
* vgetargskeywords: Verify kwlist has the required length while parsingTim Peters2001-10-271-20/+24
| | | | | the format, instead of waiting until after we can overindex it by mistake.
* vgetargskeywords: Removed all PyErr_Clear() calls. It's possible thatTim Peters2001-10-271-4/+8
| | | | | this routine will report an error now when it didn't before, but, if so, it's a legitimate error that should never have been suppressed.
* vgetargskeywords: The keywords arg is a dict (if non-NULL), so use theTim Peters2001-10-271-5/+5
| | | | | dict API everywhere on it instead of sometimes using the slower mapping API.
* vgetargskeywords: Removed one of the mysterious PyErr_Clear() calls.Tim Peters2001-10-271-10/+1
| | | | | | | The "need" for this was probably removed by an earlier patch that stopped the loop right before it from passing NULL to a dict lookup routine. I still haven't convinced myself that the next loop is correct, so am leaving the next mysterious PyErr_Clear() call in for now.
* vgetargskeywords:Tim Peters2001-10-271-16/+9
| | | | | | | | | | | | + Generally test nkeywords against 0 instead of keywords against NULL (saves a little work if an empty keywords dict is passed, and is conceptually more on-target regardless). + When a call erroneously specifies a keyword argument both by position and by keyword name: - It was easy to provoke this routine into an internal buffer overrun by using a long argument name. Now uses PyErr_format instead (which computes a safe buffer size). - Improved the error msg.
* vgetargskeywords:Tim Peters2001-10-271-20/+7
| | | | | | + Got rid of now-redundant dict typecheck. + Renamed nkwds to nkwlist. Now all the "counting" vrbls have names related to the things they're counting in an obvious way.
* vgetargskeywords:Tim Peters2001-10-271-12/+13
| | | | | | | + Renamed argslen to nargs. + Renamed kwlen to nkeywords. This one was especially confusing because kwlen wasn't the length of the kwlist argument, but of the keywords argument.
* vgetargskeywords:Tim Peters2001-10-271-15/+10
| | | | | | | + Removed now-redundant tuple typecheck. + Renamed "tplen" local to "argslen" (it's the length of the "args" argument; I suppose "tp" was for "Tim Peters should rename me someday <wink>).
* PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (ITim Peters2001-10-271-30/+34
| | | | | | | | | | | introduced this bug just a little while ago, when *adding* internal error checks). vgetargskeywords: Rewrote the section that crawls over the format string. + Added block comment so it won't take the next person 15 minutes to reverse-engineer what it's doing. + Lined up the "else" clauses. + Rearranged the ifs in decreasing order of likelihood (for speed).
* PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,Tim Peters2001-10-271-1/+16
| | | | | | and raise an error if they're insane. vgetargskeywords: the same, except that since this is an internal routine, just assert that the arguments are sane.
* tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexedTim Peters2001-10-271-3/+13
| | | | | | | | | | | | | | the kwlist vector whenever there was a mix of positional and keyword arguments, and the number of positional arguments exceeded the length of the kwlist vector. If there was just one more positional arg than keyword, the kwlist-terminating NULL got passed to PyMapping_HasKeyString, which set an internal error that vgetargskeywords() then squashed (but it's impossible to say whether it knew it was masking an error). If more than one more positional argument, it went on to pass random trash to PyMapping_HasKeyString, which is why the example at the start happened to kill the process. Pure bugfix candidate.
* vgetargskeywords(): remove test that can't succeed. Not a bugfix, justTim Peters2001-10-271-13/+7
| | | | removing useless obfuscation.
* PyArg_UnpackTuple(): New argument unpacking function suggested by JimFred Drake2001-10-231-0/+60
| | | | Fulton, based on code Jim supplied.
* Style conformance: function name begins a new line *consistently*.Fred Drake2001-10-231-7/+11
| | | | Make convertbuffer() static like the prototype says. Not used elsewhere.
* Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().Jeremy Hylton2001-10-111-5/+11
| | | | | convertbuffer() uses the buffer interface's getreadbuffer(), but 't' should use getcharbuffer().
* One more place where PyString_AsString() was used after aJeremy Hylton2001-10-101-1/+1
| | | | PyString_Check() had already succeeded.
* Use AS_STRING() following the check and avoid an extra call.Jeremy Hylton2001-10-101-1/+1
|
* Fix core dump in PyArg_ParseTuple() with Unicode arguments.Jeremy Hylton2001-09-101-15/+17
| | | | | | | | | Reported by Fredrik Lundh on python-dev. The conversimple() code that handles Unicode arguments and converts them to the default encoding now calls converterr() with the original Unicode argument instead of the NULL returned by the failed encoding attempt.
* The "O!" format code should implement an isinstance() testGuido van Rossum2001-08-281-1/+1
| | | | rather than a type equality test.
* Patch #445762: Support --disable-unicodeMartin v. Löwis2001-08-171-1/+21
| | | | | | | | - Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
* Add _PyUnicode_AsDefaultEncodedString to unicodeobject.h.Jeremy Hylton2001-07-301-5/+0
| | | | | | | And remove all the extern decls in the middle of .c files. Apparently, it was excluded from the header file because it is intended for internal use by the interpreter. It's still intended for internal use and documented as such in the header file.
* Change cascaded if stmts to switch stmt in vgetargs1().Jeremy Hylton2001-05-291-19/+25
| | | | | | | | In the default branch, keep three ifs that are used if level == 0, the most common case. Note that first if here is a slight optimization for the 'O' format. Second part of SF patch 426072.
* Internal refactoring of convertsimple() and friends.Jeremy Hylton2001-05-291-515/+514
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Note that lots of code was re-indented. Replace two-step of convertsimple() and convertsimple1() with convertsimple() and helper converterr(), which is called to format error messages when convertsimple() fails. The old code did all the real work in convertsimple1(), but deferred error message formatting to conversimple(). The result was paying the price of a second function call on every call just to format error messages in the failure cases. Factor out of the buffer-handling code in convertsimple() and package it as convertbuffer(). Add two macros to ease readability of Unicode coversions, UNICODE_DEFAULT_ENCODING() and CONV_UNICODE, an error string. The convertsimple() routine had awful indentation problems, primarily because there were two tabs between the case line and the body of the case statements. This patch reformats the entire function to have a single tab between case line and case body, which makes the code easier to read (and consistent with ceval). The introduction of converterr() exacerbated the problem and prompted this fix. Also, eliminate non-standard whitespace after opening paren and before closing paren in a few if statements. (This checkin is part of SF patch 426072.)
* Fix whitespace botch.Fred Drake2001-05-181-1/+1
|
* vgetargs1() and vgetargskeywords(): Replace uses of PyTuple_Size() andJeremy Hylton2001-05-181-10/+8
| | | | | PyTuple_GetItem() with PyTuple_GET_SIZE() and PyTuple_GET_ITEM(). The code has already done a PyTuple_Check().
* Add support for Windows using "mbcs" as the default Unicode encoding when ↵Mark Hammond2001-05-131-1/+1
| | | | dealing with the file system. As discussed on python-dev and in patch 410465.
* Added new parser markers 'et' and 'et#' which do not recode stringMarc-André Lemburg2001-05-021-4/+20
| | | | | | | objects but instead assume that they use the requested encoding. This is needed on Windows to enable opening files by passing in Unicode file names.
* Related to SF bug 132008 (PyList_Reverse blows up).Tim Peters2001-02-121-0/+2
| | | | | | | | _testcapimodule.c make sure PyList_Reverse doesn't blow up again getargs.c assert args isn't NULL at the top of vgetargs1 instead of waiting for a NULL-pointer dereference at the end
* Better error message when non-dictionary received for **kwargJeremy Hylton2001-01-251-2/+7
|
* This patch makes sure that the function name always appears in the errorKa-Ping Yee2001-01-151-26/+35
| | | | | | | message, and tries to make the messages more consistent and helpful when the wrong number of arguments or duplicate keyword arguments are supplied. Comes with more tests for test_extcall.py and and an update to an error message in test/output/test_pyexpat.
* vgetargskeywords(): Patch for memory leak identified in bug #119862.Barry Warsaw2000-12-111-0/+1
|
* Clarified some of the error messages, esp. "read-only characterGuido van Rossum2000-12-011-17/+16
| | | | buffer" replaced by "string or read-only character buffer".
* Rationalize use of limits.h, moving the inclusion to Python.h.Fred Drake2000-09-261-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.
* Special case the "s#" PyArg_Parse() token for Unicode objects:Marc-André Lemburg2000-09-211-26/+53
| | | | | | | | | | | | "s#" will now return a pointer to the default encoded string data of the Unicode object instead of a pointer to the raw UTF-16 data. The latter is still available via PyObject_AsReadBuffer(). The patch also adds an optimization for string objects which is based on the fact that string objects return the raw character data for getreadbuffer access and are always single-segment.
* Added B format char to Py_BuildValue (same as b,h,i, but makesJack Jansen2000-09-151-1/+1
| | | | bgen-generated code work).
* This patch hopefully fixes the problem with "es#" and "es" inMarc-André Lemburg2000-09-081-0/+2
| | | | PyArg_ParseTupleAndKeywords() and closes bug #113807.
* REMOVED all CWI, CNRI and BeOpen copyright markings.Guido van Rossum2000-09-011-9/+0
| | | | This should match the situation in the 1.6b1 tree.
* Changed H specifier to mean "bitfield", i.e. any value fromJack Jansen2000-08-051-5/+27
| | | | | | -32768..65535 is acceptable. Added B specifier (with values from -128..255). No L added (which would have completed the set) because l already accepts any value (and the letter L is taken for quadwords).
* This patch finalizes the move from UTF-8 to a default encoding inMarc-André Lemburg2000-08-031-4/+6
| | | | | | | | | | | | | | | | | | the Python Unicode implementation. The internal buffer used for implementing the buffer protocol is renamed to defenc to make this change visible. It now holds the default encoded version of the Unicode object and is calculated on demand (NULL otherwise). Since the default encoding defaults to ASCII, this will mean that Unicode objects which hold non-ASCII characters will no longer work on C APIs using the "s" or "t" parser markers. C APIs must now explicitly provide Unicode support via the "u", "U" or "es"/"es#" parser markers in order to work with non-ASCII Unicode strings. (Note: this patch will also have to be applied to the 1.6 branch of the CVS tree.)
* Mass ANSIfication of function definitions. Doesn't cover all 'extern'Thomas Wouters2000-07-221-95/+12
| | | | declarations yet, those come later.