Commit Graph

87 Commits

Author SHA1 Message Date
Armin Rigo 7ccbca93a2 Forward-port of r52136,52138: a review of overflow-detecting code.
* unified the way intobject, longobject and mystrtoul handle
  values around -sys.maxint-1.

* in general, trying to entierely avoid overflows in any computation
  involving signed ints or longs is extremely involved.  Fixed a few
  simple cases where a compiler might be too clever (but that's all
  guesswork).

* more overflow checks against bad data in marshal.c.

* 2.5 specific: fixed a number of places that were still confusing int
  and Py_ssize_t.  Some of them could potentially have caused
  "real-world" breakage.

* list.pop(x): fixing overflow issues on x was messy.  I just reverted
  to PyArg_ParseTuple("n"), which does the right thing.  (An obscure
  test was trying to give a Decimal to list.pop()... doesn't make
  sense any more IMHO)

* trying to write a few tests...
2006-10-04 12:17:45 +00:00
Skip Montanaro 7ff54e7706 C++ compiler cleanup: migrate to modsupport.h 2006-04-18 00:53:48 +00:00
Martin v. Löwis 5cb6936672 Make Py_BuildValue, PyObject_CallFunction and
PyObject_CallMethod aware of PY_SSIZE_T_CLEAN.
2006-04-14 09:08:42 +00:00
Martin v. Löwis b1ed7fac12 Replace INT_MAX with PY_SSIZE_T_MAX. 2006-04-13 07:52:27 +00:00
Neal Norwitz 4fe4ed2525 Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup. 2006-03-16 08:20:19 +00:00
Neal Norwitz 3e90fa5940 Try to cleanup the error handling a bit so there aren't false positives
from static analysis.  v was already checked for NULL above, so we don't
need a second check.
2006-03-06 23:07:34 +00:00
Martin v. Löwis 0b300be895 Fix more memory leaks. Will backport to 2.4. 2006-03-01 21:33:54 +00:00
Martin v. Löwis d96ee90993 Use Py_ssize_t to count the 2006-02-16 14:37:16 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Tim Peters 35c3f4f249 do_mkvalue(), 'I' and 'k' cases: squash legitimate
compiler warnings about mixing signed and unsigned types
in comparisons.
2005-12-24 06:23:41 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
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 *.
2005-12-10 18:50:16 +00:00
Georg Brandl f06e30af4a bug #1281408: make Py_BuildValue work with unsigned longs and long longs 2005-11-24 15:37:42 +00:00
Neal Norwitz 7bcabc60a3 Fix a few more memory leaks
Document more info about the benefits of configuring without
pymalloc when running valgrind
2005-11-20 23:58:38 +00:00
Michael W. Hudson c849e63eb0 This is Pete Shinners' patch from his bug report
[ 984722 ] Py_BuildValue loses reference counts on error

I'm ever-so-slightly uneasy at the amount of work this can do with an
exception pending, but I don't think that this can result in anything
more serious than a strange error message.
2004-07-14 11:28:06 +00:00
Jack Jansen fb2765666f Getting rid of support for the ancient Apple MPW compiler. 2003-11-19 15:24:47 +00:00
Martin v. Löwis f8d59d28e0 Patch #828384: Don't discard nested exception in AddObject. 2003-10-24 20:05:32 +00:00
Jeremy Hylton c44dbc46fe Better error message 2003-06-21 21:35:25 +00:00
Jack Jansen dbd6503e97 dded missing k and K format specifiers to Py_BuildValue and friends. 2003-04-17 22:01:10 +00:00
Martin v. Löwis b9a0f91218 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285. 2003-03-29 10:06:18 +00:00
Jeremy Hylton 4f0dcc9a9a Provide __module__ attributes for functions defined in C and Python.
__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.
2003-01-31 18:33:18 +00:00
Fred Drake ceead6d957 Style consistency, so "grep ^function ..." works as expected. 2003-01-30 15:08:25 +00:00
Just van Rossum bbfd859521 Fixed potential crash: v can be NULL here, so use Py_XDECREF rather than Py_DECREF 2002-12-15 13:45:32 +00:00
Fred Drake 233cc5987b Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
sense now that extension types can support __init__ directly rather
than requiring function constructors.
2002-08-14 20:57:56 +00:00
Martin v. Löwis 75d2d94e0f Patch #554716: Use __va_copy where available. 2002-07-28 10:23:27 +00:00
Fred Drake 8311518a58 PyModule_AddObject(): Added missing exceptions.
Closes SF bug #523473.
2002-06-17 17:16:57 +00:00
Fred Drake 7bf9715a8b Introduce two new flag bits that can be set in a PyMethodDef method
descriptor, as used for the tp_methods slot of a type.  These new flag
bits are both optional, and mutually exclusive.  Most methods will not
use either.  These flags are used to create special method types which
exist in the same namespace as normal methods without having to use
tedious construction code to insert the new special method objects in
the type's tp_dict after PyType_Ready() has been called.

If METH_CLASS is specified, the method will represent a class method
like that returned by the classmethod() built-in.

If METH_STATIC is specified, the method will represent a static method
like that returned by the staticmethod() built-in.

These flags may not be used in the PyMethodDef table for modules since
these special method types are not meaningful in that case; a
ValueError will be raised if these flags are found in that context.
2002-03-28 05:33:33 +00:00
Martin v. Löwis 339d0f720e Patch #445762: Support --disable-unicode
- 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.
2001-08-17 18:39:25 +00:00
Fred Drake 289898cdbb Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,
the object being inserted was not being DECREFed.

This closes SF bug #444486.
2001-08-04 03:11:25 +00:00
Marc-André Lemburg e5006ebc9d This patch turns the Python API mismatch notice into a standard
Python warning which can be catched by means of the Python warning
framework.

It also adds two new APIs which hopefully make it easier for Python
to switch to buffer overflow safe [v]snprintf() APIs for error
reporting et al. The two new APIs are PyOS_snprintf() and
PyOS_vsnprintf() and work just like the standard ones in many
C libs. On platforms which have snprintf(), the native APIs are used,
on all other an emulation with snprintf() tries to do its best.
2001-07-31 13:24:44 +00:00
Fred Drake aec79247b1 Py_BuildValue(): Add "D" conversion to create a Python complex value from
a Py_complex C value.

Patch by Walter Dörwald.
This partially closes SF patch #407148.
2001-03-12 21:03:26 +00:00
Fred Drake d5fadf75e4 Rationalize use of limits.h, moving the inclusion to Python.h.
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-26 05:46:01 +00:00
Fred Drake 9e2851566c Andrew Kuchling <akuchlin@mems-exchange.org>:
Add three new convenience functions to the PyModule_*() family:
PyModule_AddObject(), PyModule_AddIntConstant(), PyModule_AddStringConstant().

This closes SourceForge patch #101233.
2000-09-23 03:24:27 +00:00
Jack Jansen b763b9d9d5 Cast UCHAR_MAX to int before doing the comparison for overflow of the
B format char.
2000-09-15 12:51:01 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Guido van Rossum 413407f103 Add a test that Py_IsInitialized() in Py_InitModule4(). See
python-dev discussion.

This should catch future version incompatibilities on Windows.  Alas,
this doesn't help for 1.5 vs. 1.6; but it will help for 1.6 vs. 2.0.
2000-08-04 14:00:14 +00:00
Thomas Wouters f70ef4f860 Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
2000-07-22 18:47:25 +00:00
Tim Peters dbd9ba6a6c Nuke all remaining occurrences of Py_PROTO and Py_FPROTO. 2000-07-09 03:09:57 +00:00
Jack Jansen d50338fbd9 Added support for H (unsigned short) specifier in PyArg_ParseTuple and
Py_BuildValue.
2000-07-06 12:22:00 +00:00
Jack Jansen 41aa8e523d Include limits.h if we have it. 2000-07-03 21:39:47 +00:00
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Guido van Rossum 582acece2e Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
tests.
2000-06-28 22:07:35 +00:00
Fred Drake 25d34473c3 Brian Hooper <brian_takashi@hotmail.com>:
Here's a patch which changes modsupport to add 'u' and 'u#',
to support building Unicode objects from a null-terminated
Py_UNICODE *, and a Py_UNICODE * with length, respectively.

[Conversion from 'U' to 'u' by Fred, based on python-dev comments.]

Note that the use of None for NULL values of the Py_UNICODE* value is
still in; I'm not sure of the conclusion on that issue.
2000-04-28 14:42:37 +00:00
Guido van Rossum 3dbba6ec3a Change rare occurrences of #if HAVE_LONG_LONG to #ifdef. 1999-01-25 21:48:56 +00:00
Guido van Rossum c38e7d4c4b Oops, forgot a pair of {}'s. (Greg Couch) 1998-12-23 19:53:45 +00:00
Guido van Rossum d341500d8f Add 'N' format character to Py_BuildValue -- like 'O' but doesn't INCREF.
Patch and suggestion by Greg Couch.
1998-12-23 05:01:38 +00:00
Guido van Rossum 3293b07df5 Patch by Mark Hammond to support 64-bit ints on MS platforms.
The MS compiler doesn't call it 'long long', it uses __int64,
so a new #define, LONG_LONG, has been added and all occurrences
of 'long long' are replaced with it.
1998-08-25 16:07:15 +00:00
Guido van Rossum c4099e6b3c # Fix strange type (methonname instead of methodname). 1998-08-08 20:51:26 +00:00
Guido van Rossum 1a8791e0b8 Changes for BeOS, QNX and long long, by Chris Herborth. 1998-08-04 22:46:29 +00:00
Guido van Rossum 233f4b54d3 Two error messages still used the old name of the functio mkvalue() --
which is now Py_BuildValue().
1998-07-07 22:32:19 +00:00