Commit Graph

128 Commits

Author SHA1 Message Date
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
Guido van Rossum db847bd9ea Plug memory leak in Py_BuildValue when using {...} to construct dictionaries. 1997-11-20 20:35:45 +00:00
Guido van Rossum 2e58ff3ef5 Fix importing of shared libraries from inside packages.
This is a bit of a hack: when the shared library is loaded, the module
name is "package.module", but the module calls Py_InitModule*() with just
"module" for the name.  The shared library loader squirrels away the true
name of the module in _Py_PackageContext, and Py_InitModule*() will
substitute this (if the name actually matches).
1997-11-19 18:53:33 +00:00
Guido van Rossum 40b33c648a Removed fatal errors from Py_Initmodule4() (and thus from
Py_Initmodule(), which is a macro wrapper around it).

The return value is now a NULL pointer if the initialization failed.
This may make old modules fail with a SEGFAULT, since they don't
expect this kind of failure.  That's OK, since (a) it "never" happens,
and (b) they would fail with a fatal error otherwise, anyway.

Tons of extension modules should now check the return value of
Py_Initmodule*() -- that's on my TODO list.
1997-08-02 03:07:46 +00:00
Guido van Rossum 79f25d9a7b Quickly renamed the remaining files -- this directory is done. 1997-04-29 20:08:16 +00:00
Guido van Rossum d266eb460e New permission notice, includes CNRI. 1996-10-25 14:44:06 +00:00
Sjoerd Mullender 996e6dc959 Corrected format string in api_version_warning. 1996-01-23 16:07:29 +00:00
Guido van Rossum 59461c7052 use PROTO macro around fn prototype 1995-03-09 12:10:50 +00:00
Guido van Rossum d1b9393ba5 support "O&" taking an object constructor a void* 1995-01-20 16:56:02 +00:00
Guido van Rossum 2ac3bc2c05 rename method arg because of typedef conflict 1995-01-17 16:31:01 +00:00
Guido van Rossum 970a0a20b8 api version checking 1995-01-09 17:47:20 +00:00
Guido van Rossum 50620fa9b8 New newmethodobject() interface takes struct methodlist pointer
instead of individual components; initmodule3() now has doc string
argument as well
1995-01-07 12:43:18 +00:00
Guido van Rossum 6d023c98b0 Added 1995 to copyright message.
bltinmodule.c: fixed coerce() nightmare in ternary pow().
modsupport.c (initmodule2): pass METH_FREENAME flag to newmethodobject().
pythonrun.c: move flushline() into and around print_error().
1995-01-04 19:12:13 +00:00
Guido van Rossum 1ae940a587 Lots of changes, most minor (fatal() instead of abort(), use of
err_fetch/err_restore and so on).  But...
NOTE: import.c has been rewritten and all the DL stuff is now in the
new file importdl.c.
1995-01-02 19:04:15 +00:00
Guido van Rossum fe3f1a256b * Python/{modsupport.c,getargs.c,Makefile.in},
Include/modsupport.h: moved getargs() to its own file and
	re-implemented it entirely to support optional arguments, multiple
	arguments without surrounding parentheses
	(when called as newgetargs()), and better error messages
1994-09-29 09:42:55 +00:00
Guido van Rossum 1d5735e846 Merge back to main trunk 1994-08-30 08:27:36 +00:00
Guido van Rossum f1dc566328 * Makefile: added all: and default: targets.
* many files: made some functions static; removed "extern int errno;".
* frozenmain.c: fixed bugs introduced on 24 June...
* flmodule.c: remove 1.5 bw compat hacks, add new functions in 2.2a
  (and some old functions that were omitted).
* timemodule.c: added MSDOS floatsleep version .
* pgenmain.c: changed exit() to goaway() and added defn of goaway().
* intrcheck.c: add hack (to UNIX only) so interrupting 3 times
  will exit from a hanging program.  The second interrupt prints
  a message explaining this to the user.
1993-07-05 10:31:29 +00:00
Guido van Rossum e537240c25 * Changed many files to use mkvalue() instead of newtupleobject().
* Fixcprt.py: added [-y file] option, do only files younger than file.
* modsupport.[ch]: added vmkvalue().
* intobject.c: use mkvalue().
* stringobject.c: added "formatstring"; renamed string* to string_*;
  ceval.c: call formatstring for string % value.
* longobject.c: close memory leak in divmod.
* parsetok.c: set result node to NULL when returning an error.
1993-03-16 12:15:04 +00:00
Guido van Rossum bf80e5407f * stdwinmodule.c: various new commands: setwin{pos,size},
listfontnames, bitmap ops.
* listobject.c: use mkvalue() when possible; avoid weird error when
  calling append() without args.
* modsupport.c: new feature in getargs(): if the format string
  contains a semicolor the string after that is used as the error
  message instead of "bad argument list (format %s)" when there's an
  error.
1993-02-08 15:49:17 +00:00
Guido van Rossum 34679b7661 * Added Fixcprt.py: script to fix copyright message.
* various modules: added 1993 to copyright.
* thread.c: added copyright notice.
* ceval.c: minor change to error message for "+"
* stdwinmodule.c: check for error from wfetchcolor
* config.c: MS-DOS fixes (define PYTHONPATH, use DELIM, use osdefs.h)
* Add declaration of inittab to import.h
* sysmodule.c: added sys.builtin_module_names
* xxmodule.c, xxobject.c: fix minor errors
1993-01-26 13:33:44 +00:00
Guido van Rossum a2b7f40513 * Configure.py: use #!/usr/local/bin/python
* posixmodule.c: move extern function declarations to top
* listobject.c: cmp() arguments must be void* if __STDC__
* Makefile, allobjects.h, panelmodule.c, modsupport.c: get rid of
  strdup() -- it is a portability risk
* Makefile: enclosed ranlib command in parentheses for Sequent Make
  which aborts if the command is not found even if '-' is present
* timemodule.c: time() returns a floating point number, in microsecond
  precision if BSD_TIME is defined.
1993-01-04 09:09:59 +00:00
Guido van Rossum a93265a666 suppress unnecessary error message if too many arguments are passed 1992-08-27 07:45:12 +00:00
Guido van Rossum 96caaee836 check for embedded \0 in strings for z and s formats 1992-08-14 15:12:03 +00:00
Guido van Rossum 899dcf36a0 Added parameter decls to do_mkvalue for non-template machines 1992-05-15 11:04:59 +00:00
Guido van Rossum fc61adb5f1 Merged with Steve Miale's version 1992-04-13 15:53:41 +00:00
Guido van Rossum 3cfe6faffe Added mkvalue() function 1992-04-13 10:48:55 +00:00
Guido van Rossum bab9d03855 Copyright for 1992 added 1992-04-05 14:26:55 +00:00
Guido van Rossum 292bb8ea33 Shut up lint 1992-03-27 17:23:29 +00:00
Guido van Rossum 922cfad5a3 New getargs() function: a single varargs function,
guided by a format string, makes all get*arg() functions unnecessary.
1992-01-27 16:47:03 +00:00
Guido van Rossum c06022966f Add "varargs" attribute. 1991-12-16 13:07:24 +00:00
Guido van Rossum c5da350310 getlonglongargs --> getlonglongarg
Added getlongobjectarg.
1991-09-10 14:56:32 +00:00
Guido van Rossum 139e57b2a4 Support for long integers 1991-07-27 21:39:31 +00:00
Guido van Rossum ef0068ff9d Added getintintintarg() (3 int args) 1991-07-01 18:47:30 +00:00
Guido van Rossum 7a904edcbf Moved get*doublearg() routines here from mathmodule.c 1991-04-03 19:06:26 +00:00
Guido van Rossum f70e43a073 Added copyright notice. 1991-02-19 12:39:46 +00:00
Guido van Rossum 3f5da24ea3 "Compiling" version 1990-12-20 15:06:42 +00:00
Guido van Rossum 68c35d01d6 Move err_badarg() and err_nomme() to errors.c. 1990-10-14 20:02:48 +00:00
Guido van Rossum 85a5fbbdfe Initial revision 1990-10-14 12:07:46 +00:00