1991-02-19 08:39:46 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* System module */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Various bits of information used by the interpreter are collected in
|
|
|
|
module 'sys'.
|
1990-12-20 11:06:42 -04:00
|
|
|
Function member:
|
1995-03-20 11:09:40 -04:00
|
|
|
- exit(sts): raise SystemExit
|
1990-10-14 09:07:46 -03:00
|
|
|
Data members:
|
|
|
|
- stdin, stdout, stderr: standard file objects
|
|
|
|
- modules: the table of modules (dictionary)
|
1990-12-20 11:06:42 -04:00
|
|
|
- path: module search path (list of strings)
|
|
|
|
- argv: script arguments (list of strings)
|
|
|
|
- ps1, ps2: optional primary and secondary prompts (strings)
|
1990-10-14 09:07:46 -03:00
|
|
|
*/
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
#include "Python.h"
|
2005-10-20 16:59:25 -03:00
|
|
|
#include "code.h"
|
2000-12-06 17:47:46 -04:00
|
|
|
#include "frameobject.h"
|
2003-04-09 16:06:21 -03:00
|
|
|
#include "eval.h"
|
1990-10-14 09:07:46 -03:00
|
|
|
|
1992-03-23 14:20:18 -04:00
|
|
|
#include "osdefs.h"
|
1990-12-20 11:06:42 -04:00
|
|
|
|
2002-10-07 23:44:31 -03:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include "windows.h"
|
|
|
|
#endif /* MS_WINDOWS */
|
|
|
|
|
1996-09-11 20:12:24 -03:00
|
|
|
#ifdef MS_COREDLL
|
1996-04-08 23:37:57 -03:00
|
|
|
extern void *PyWin_DLLhModule;
|
1997-09-29 20:34:23 -03:00
|
|
|
/* A string loaded from the DLL at startup: */
|
|
|
|
extern const char *PyWin_DLLVersionString;
|
1996-04-08 23:37:57 -03:00
|
|
|
#endif
|
|
|
|
|
2003-05-03 06:14:54 -03:00
|
|
|
#ifdef __VMS
|
|
|
|
#include <unixlib.h>
|
|
|
|
#endif
|
|
|
|
|
2003-05-10 04:10:12 -03:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LANGINFO_H
|
|
|
|
#include <locale.h>
|
|
|
|
#include <langinfo.h>
|
|
|
|
#endif
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
PySys_GetObject(char *name)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2004-03-24 18:22:12 -04:00
|
|
|
PyThreadState *tstate = PyThreadState_GET();
|
1997-08-02 00:10:38 -03:00
|
|
|
PyObject *sd = tstate->interp->sysdict;
|
1999-10-05 19:17:41 -03:00
|
|
|
if (sd == NULL)
|
|
|
|
return NULL;
|
1997-08-02 00:10:38 -03:00
|
|
|
return PyDict_GetItemString(sd, name);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE *
|
2000-07-22 15:47:25 -03:00
|
|
|
PySys_GetFile(char *name, FILE *def)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
|
|
|
FILE *fp = NULL;
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *v = PySys_GetObject(name);
|
|
|
|
if (v != NULL && PyFile_Check(v))
|
|
|
|
fp = PyFile_AsFile(v);
|
1990-10-14 09:07:46 -03:00
|
|
|
if (fp == NULL)
|
|
|
|
fp = def;
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-07-22 15:47:25 -03:00
|
|
|
PySys_SetObject(char *name, PyObject *v)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2004-03-24 18:22:12 -04:00
|
|
|
PyThreadState *tstate = PyThreadState_GET();
|
1997-08-02 00:10:38 -03:00
|
|
|
PyObject *sd = tstate->interp->sysdict;
|
1992-01-26 14:15:48 -04:00
|
|
|
if (v == NULL) {
|
1997-08-02 00:10:38 -03:00
|
|
|
if (PyDict_GetItemString(sd, name) == NULL)
|
1992-01-26 14:15:48 -04:00
|
|
|
return 0;
|
|
|
|
else
|
1997-08-02 00:10:38 -03:00
|
|
|
return PyDict_DelItemString(sd, name);
|
1992-01-26 14:15:48 -04:00
|
|
|
}
|
1990-10-14 09:07:46 -03:00
|
|
|
else
|
1997-08-02 00:10:38 -03:00
|
|
|
return PyDict_SetItemString(sd, name, v);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2001-01-11 01:41:27 -04:00
|
|
|
static PyObject *
|
2001-08-16 10:15:00 -03:00
|
|
|
sys_displayhook(PyObject *self, PyObject *o)
|
2001-01-11 01:41:27 -04:00
|
|
|
{
|
2001-08-16 10:15:00 -03:00
|
|
|
PyObject *outf;
|
2004-03-24 18:22:12 -04:00
|
|
|
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
2001-01-11 01:41:27 -04:00
|
|
|
PyObject *modules = interp->modules;
|
|
|
|
PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
|
|
|
|
|
2001-07-23 10:32:43 -03:00
|
|
|
if (builtins == NULL) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "lost __builtin__");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-01-11 01:41:27 -04:00
|
|
|
/* Print value except if None */
|
|
|
|
/* After printing, also assign to '_' */
|
|
|
|
/* Before, set '_' to None to avoid recursion */
|
|
|
|
if (o == Py_None) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
|
|
|
|
return NULL;
|
|
|
|
if (Py_FlushLine() != 0)
|
|
|
|
return NULL;
|
2001-01-11 05:27:34 -04:00
|
|
|
outf = PySys_GetObject("stdout");
|
|
|
|
if (outf == NULL) {
|
2001-01-11 01:41:27 -04:00
|
|
|
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-01-11 05:27:34 -04:00
|
|
|
if (PyFile_WriteObject(o, outf, 0) != 0)
|
2001-01-11 01:41:27 -04:00
|
|
|
return NULL;
|
2001-01-11 05:27:34 -04:00
|
|
|
PyFile_SoftSpace(outf, 1);
|
2001-01-11 01:41:27 -04:00
|
|
|
if (Py_FlushLine() != 0)
|
|
|
|
return NULL;
|
|
|
|
if (PyObject_SetAttrString(builtins, "_", o) != 0)
|
|
|
|
return NULL;
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(displayhook_doc,
|
2001-03-22 22:46:52 -04:00
|
|
|
"displayhook(object) -> None\n"
|
2001-01-11 01:41:27 -04:00
|
|
|
"\n"
|
2006-03-02 18:07:40 -04:00
|
|
|
"Print an object to sys.stdout and also save it in __builtin__.\n"
|
2002-06-09 10:33:54 -03:00
|
|
|
);
|
2001-03-22 22:46:52 -04:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
sys_excepthook(PyObject* self, PyObject* args)
|
|
|
|
{
|
|
|
|
PyObject *exc, *value, *tb;
|
2001-10-24 17:47:48 -03:00
|
|
|
if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
|
2001-03-22 22:46:52 -04:00
|
|
|
return NULL;
|
|
|
|
PyErr_Display(exc, value, tb);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(excepthook_doc,
|
2001-03-22 22:46:52 -04:00
|
|
|
"excepthook(exctype, value, traceback) -> None\n"
|
|
|
|
"\n"
|
2002-06-09 10:33:54 -03:00
|
|
|
"Handle an exception by displaying it with a traceback on sys.stderr.\n"
|
|
|
|
);
|
2001-01-11 01:41:27 -04:00
|
|
|
|
1997-05-05 17:56:21 -03:00
|
|
|
static PyObject *
|
2003-02-28 23:20:41 -04:00
|
|
|
sys_exc_info(PyObject *self, PyObject *noargs)
|
1997-05-05 17:56:21 -03:00
|
|
|
{
|
|
|
|
PyThreadState *tstate;
|
2004-03-24 18:22:12 -04:00
|
|
|
tstate = PyThreadState_GET();
|
1997-05-05 17:56:21 -03:00
|
|
|
return Py_BuildValue(
|
|
|
|
"(OOO)",
|
|
|
|
tstate->exc_type != NULL ? tstate->exc_type : Py_None,
|
|
|
|
tstate->exc_value != NULL ? tstate->exc_value : Py_None,
|
|
|
|
tstate->exc_traceback != NULL ?
|
|
|
|
tstate->exc_traceback : Py_None);
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(exc_info_doc,
|
1998-06-27 16:43:25 -03:00
|
|
|
"exc_info() -> (type, value, traceback)\n\
|
|
|
|
\n\
|
2003-02-28 23:20:41 -04:00
|
|
|
Return information about the most recent exception caught by an except\n\
|
|
|
|
clause in the current stack frame or in an older stack frame."
|
|
|
|
);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
sys_exc_clear(PyObject *self, PyObject *noargs)
|
|
|
|
{
|
2004-03-24 18:22:12 -04:00
|
|
|
PyThreadState *tstate = PyThreadState_GET();
|
2003-02-28 23:20:41 -04:00
|
|
|
PyObject *tmp_type, *tmp_value, *tmp_tb;
|
|
|
|
tmp_type = tstate->exc_type;
|
|
|
|
tmp_value = tstate->exc_value;
|
|
|
|
tmp_tb = tstate->exc_traceback;
|
|
|
|
tstate->exc_type = NULL;
|
|
|
|
tstate->exc_value = NULL;
|
|
|
|
tstate->exc_traceback = NULL;
|
|
|
|
Py_XDECREF(tmp_type);
|
|
|
|
Py_XDECREF(tmp_value);
|
|
|
|
Py_XDECREF(tmp_tb);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(exc_clear_doc,
|
|
|
|
"exc_clear() -> None\n\
|
|
|
|
\n\
|
|
|
|
Clear global information on the current exception. Subsequent calls to\n\
|
|
|
|
exc_info() will return (None,None,None) until another exception is raised\n\
|
|
|
|
in the current thread or the execution stack returns to a frame where\n\
|
|
|
|
another exception is being handled."
|
2002-06-09 10:33:54 -03:00
|
|
|
);
|
1998-06-27 16:43:25 -03:00
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
sys_exit(PyObject *self, PyObject *args)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2002-03-27 09:03:09 -04:00
|
|
|
PyObject *exit_code = 0;
|
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
merge in bad ways, so I'll have to merge that extra-carefully (probably manually.)
Merged revisions 46495-46605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r46495 | tim.peters | 2006-05-28 03:52:38 +0200 (Sun, 28 May 2006) | 2 lines
Added missing svn:eol-style property to text files.
........
r46497 | tim.peters | 2006-05-28 12:41:29 +0200 (Sun, 28 May 2006) | 3 lines
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both: `className` was referenced before being checked for NULL.
........
r46499 | fredrik.lundh | 2006-05-28 14:06:46 +0200 (Sun, 28 May 2006) | 5 lines
needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only),
and use it for string copy operations. this gives a 20% speedup on some
string benchmarks.
........
r46501 | michael.hudson | 2006-05-28 17:51:40 +0200 (Sun, 28 May 2006) | 26 lines
Quality control, meet exceptions.c.
Fix a number of problems with the need for speed code:
One is doing this sort of thing:
Py_DECREF(self->field);
self->field = newval;
Py_INCREF(self->field);
without being very sure that self->field doesn't start with a
value that has a __del__, because that almost certainly can lead
to segfaults.
As self->args is constrained to be an exact tuple we may as well
exploit this fact consistently. This leads to quite a lot of
simplification (and, hey, probably better performance).
Add some error checking in places lacking it.
Fix some rather strange indentation in the Unicode code.
Delete some trailing whitespace.
More to come, I haven't fixed all the reference leaks yet...
........
r46502 | george.yoshida | 2006-05-28 18:39:09 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1080727: add "encoding" parameter to doctest.DocFileSuite
Contributed by Bjorn Tillenius.
........
r46503 | martin.v.loewis | 2006-05-28 18:57:38 +0200 (Sun, 28 May 2006) | 4 lines
Rest of patch #1490384: Commit icon source, remove
claim that Erik von Blokland is the author of the
installer picture.
........
r46504 | michael.hudson | 2006-05-28 19:40:29 +0200 (Sun, 28 May 2006) | 16 lines
Quality control, meet exceptions.c, round two.
Make some functions that should have been static static.
Fix a bunch of refleaks by fixing the definition of
MiddlingExtendsException.
Remove all the __new__ implementations apart from
BaseException_new. Rewrite most code that needs it to cope with
NULL fields (such code could get excercised anyway, the
__new__-removal just makes it more likely). This involved
editing the code for WindowsError, which I can't test.
This fixes all the refleaks in at least the start of a regrtest
-R :: run.
........
r46505 | marc-andre.lemburg | 2006-05-28 19:46:58 +0200 (Sun, 28 May 2006) | 10 lines
Initial version of systimes - a module to provide platform dependent
performance measurements.
The module is currently just a proof-of-concept implementation, but
will integrated into pybench once it is stable enough.
License: pybench license.
Author: Marc-Andre Lemburg.
........
r46507 | armin.rigo | 2006-05-28 21:13:17 +0200 (Sun, 28 May 2006) | 15 lines
("Forward-port" of r46506)
Remove various dependencies on dictionary order in the standard library
tests, and one (clearly an oversight, potentially critical) in the
standard library itself - base64.py.
Remaining open issues:
* test_extcall is an output test, messy to make robust
* tarfile.py has a potential bug here, but I'm not familiar
enough with this code. Filed in as SF bug #1496501.
* urllib2.HTTPPasswordMgr() returns a random result if there is more
than one matching root path. I'm asking python-dev for
clarification...
........
r46508 | georg.brandl | 2006-05-28 22:11:45 +0200 (Sun, 28 May 2006) | 4 lines
The empty string is a valid import path.
(fixes #1496539)
........
r46509 | georg.brandl | 2006-05-28 22:23:12 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1496206: urllib2 PasswordMgr ./. default ports
........
r46510 | georg.brandl | 2006-05-28 22:57:09 +0200 (Sun, 28 May 2006) | 3 lines
Fix refleaks in UnicodeError get and set methods.
........
r46511 | michael.hudson | 2006-05-28 23:19:03 +0200 (Sun, 28 May 2006) | 3 lines
use the UnicodeError traversal and clearing functions in UnicodeError
subclasses.
........
r46512 | thomas.wouters | 2006-05-28 23:32:12 +0200 (Sun, 28 May 2006) | 4 lines
Make last patch valid C89 so Windows compilers can deal with it.
........
r46513 | georg.brandl | 2006-05-28 23:42:54 +0200 (Sun, 28 May 2006) | 3 lines
Fix ref-antileak in _struct.c which eventually lead to deallocating None.
........
r46514 | georg.brandl | 2006-05-28 23:57:35 +0200 (Sun, 28 May 2006) | 4 lines
Correct None refcount issue in Mac modules. (Are they
still used?)
........
r46515 | armin.rigo | 2006-05-29 00:07:08 +0200 (Mon, 29 May 2006) | 3 lines
A clearer error message when passing -R to regrtest.py with
release builds of Python.
........
r46516 | georg.brandl | 2006-05-29 00:14:04 +0200 (Mon, 29 May 2006) | 3 lines
Fix C function calling conventions in _sre module.
........
r46517 | georg.brandl | 2006-05-29 00:34:51 +0200 (Mon, 29 May 2006) | 3 lines
Convert audioop over to METH_VARARGS.
........
r46518 | georg.brandl | 2006-05-29 00:38:57 +0200 (Mon, 29 May 2006) | 3 lines
METH_NOARGS functions do get called with two args.
........
r46519 | georg.brandl | 2006-05-29 11:46:51 +0200 (Mon, 29 May 2006) | 4 lines
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Fix refleak in exceptions.
........
r46520 | nick.coghlan | 2006-05-29 14:43:05 +0200 (Mon, 29 May 2006) | 7 lines
Apply modified version of Collin Winter's patch #1478788
Renames functional extension module to _functools and adds a Python
functools module so that utility functions like update_wrapper can be
added easily.
........
r46522 | georg.brandl | 2006-05-29 15:53:16 +0200 (Mon, 29 May 2006) | 3 lines
Convert fmmodule to METH_VARARGS.
........
r46523 | georg.brandl | 2006-05-29 16:13:21 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494605.
........
r46524 | georg.brandl | 2006-05-29 16:28:05 +0200 (Mon, 29 May 2006) | 3 lines
Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.
........
r46525 | georg.brandl | 2006-05-29 16:33:55 +0200 (Mon, 29 May 2006) | 3 lines
Fix compiler warning.
........
r46526 | georg.brandl | 2006-05-29 16:39:00 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494787 (pyclbr counts whitespace as superclass name)
........
r46527 | bob.ippolito | 2006-05-29 17:47:29 +0200 (Mon, 29 May 2006) | 1 line
simplify the struct code a bit (no functional changes)
........
r46528 | armin.rigo | 2006-05-29 19:59:47 +0200 (Mon, 29 May 2006) | 2 lines
Silence a warning.
........
r46529 | georg.brandl | 2006-05-29 21:39:45 +0200 (Mon, 29 May 2006) | 3 lines
Correct some value converting strangenesses.
........
r46530 | nick.coghlan | 2006-05-29 22:27:44 +0200 (Mon, 29 May 2006) | 1 line
When adding a module like functools, it helps to let SVN know about the file.
........
r46531 | georg.brandl | 2006-05-29 22:52:54 +0200 (Mon, 29 May 2006) | 4 lines
Patches #1497027 and #972322: try HTTP digest auth first,
and watch out for handler name collisions.
........
r46532 | georg.brandl | 2006-05-29 22:57:01 +0200 (Mon, 29 May 2006) | 3 lines
Add News entry for last commit.
........
r46533 | georg.brandl | 2006-05-29 23:04:52 +0200 (Mon, 29 May 2006) | 4 lines
Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
........
r46534 | georg.brandl | 2006-05-29 23:58:42 +0200 (Mon, 29 May 2006) | 3 lines
Convert more modules to METH_VARARGS.
........
r46535 | georg.brandl | 2006-05-30 00:00:30 +0200 (Tue, 30 May 2006) | 3 lines
Whoops.
........
r46536 | fredrik.lundh | 2006-05-30 00:42:07 +0200 (Tue, 30 May 2006) | 4 lines
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
the current behaviour ;-)
........
r46537 | bob.ippolito | 2006-05-30 00:55:48 +0200 (Tue, 30 May 2006) | 1 line
struct: modulo math plus warning on all endian-explicit formats for compatibility with older struct usage (ugly)
........
r46539 | bob.ippolito | 2006-05-30 02:26:01 +0200 (Tue, 30 May 2006) | 1 line
Add a length check to aifc to ensure it doesn't write a bogus file
........
r46540 | tim.peters | 2006-05-30 04:25:25 +0200 (Tue, 30 May 2006) | 10 lines
deprecated_err(): Stop bizarre warning messages when the tests
are run in the order:
test_genexps (or any other doctest-based test)
test_struct
test_doctest
The `warnings` module needs an advertised way to save/restore
its internal filter list.
........
r46541 | tim.peters | 2006-05-30 04:26:46 +0200 (Tue, 30 May 2006) | 2 lines
Whitespace normalization.
........
r46542 | tim.peters | 2006-05-30 04:30:30 +0200 (Tue, 30 May 2006) | 2 lines
Set a binary svn:mime-type property on this UTF-8 encoded file.
........
r46543 | neal.norwitz | 2006-05-30 05:18:50 +0200 (Tue, 30 May 2006) | 1 line
Simplify further by using AddStringConstant
........
r46544 | tim.peters | 2006-05-30 06:16:25 +0200 (Tue, 30 May 2006) | 6 lines
Convert relevant dict internals to Py_ssize_t.
I don't have a box with nearly enough RAM, or an OS,
that could get close to tickling this, though (requires
a dict w/ at least 2**31 entries).
........
r46545 | neal.norwitz | 2006-05-30 06:19:21 +0200 (Tue, 30 May 2006) | 1 line
Remove stray | in comment
........
r46546 | neal.norwitz | 2006-05-30 06:25:05 +0200 (Tue, 30 May 2006) | 1 line
Use Py_SAFE_DOWNCAST for safety. Fix format strings. Remove 2 more stray | in comment
........
r46547 | neal.norwitz | 2006-05-30 06:43:23 +0200 (Tue, 30 May 2006) | 1 line
No DOWNCAST is required since sizeof(Py_ssize_t) >= sizeof(int) and Py_ReprEntr returns an int
........
r46548 | tim.peters | 2006-05-30 07:04:59 +0200 (Tue, 30 May 2006) | 3 lines
dict_print(): Explicitly narrow the return value
from a (possibly) wider variable.
........
r46549 | tim.peters | 2006-05-30 07:23:59 +0200 (Tue, 30 May 2006) | 5 lines
dict_print(): So that Neal & I don't spend the rest of
our lives taking turns rewriting code that works ;-),
get rid of casting illusions by declaring a new variable
with the obvious type.
........
r46550 | georg.brandl | 2006-05-30 09:04:55 +0200 (Tue, 30 May 2006) | 3 lines
Restore exception pickle support. #1497319.
........
r46551 | georg.brandl | 2006-05-30 09:13:29 +0200 (Tue, 30 May 2006) | 3 lines
Add a test case for exception pickling. args is never NULL.
........
r46552 | neal.norwitz | 2006-05-30 09:21:10 +0200 (Tue, 30 May 2006) | 1 line
Don't fail if the (sub)pkgname already exist.
........
r46553 | georg.brandl | 2006-05-30 09:34:45 +0200 (Tue, 30 May 2006) | 3 lines
Disallow keyword args for exceptions.
........
r46554 | neal.norwitz | 2006-05-30 09:36:54 +0200 (Tue, 30 May 2006) | 5 lines
I'm impatient. I think this will fix a few more problems with the buildbots.
I'm not sure this is the best approach, but I can't think of anything better.
If this creates problems, feel free to revert, but I think it's safe and
should make things a little better.
........
r46555 | georg.brandl | 2006-05-30 10:17:00 +0200 (Tue, 30 May 2006) | 4 lines
Do the check for no keyword arguments in __init__ so that
subclasses of Exception can be supplied keyword args
........
r46556 | georg.brandl | 2006-05-30 10:47:19 +0200 (Tue, 30 May 2006) | 3 lines
Convert test_exceptions to unittest.
........
r46557 | andrew.kuchling | 2006-05-30 14:52:01 +0200 (Tue, 30 May 2006) | 1 line
Add SoC name, and reorganize this section a bit
........
r46559 | tim.peters | 2006-05-30 17:53:34 +0200 (Tue, 30 May 2006) | 11 lines
PyLong_FromString(): Continued fraction analysis (explained in
a new comment) suggests there are almost certainly large input
integers in all non-binary input bases for which one Python digit
too few is initally allocated to hold the final result. Instead
of assert-failing when that happens, allocate more space. Alas,
I estimate it would take a few days to find a specific such case,
so this isn't backed up by a new test (not to mention that such
a case may take hours to run, since conversion time is quadratic
in the number of digits, and preliminary attempts suggested that
the smallest such inputs contain at least a million digits).
........
r46560 | fredrik.lundh | 2006-05-30 19:11:48 +0200 (Tue, 30 May 2006) | 3 lines
changed find/rfind to return -1 for matches outside the source string
........
r46561 | bob.ippolito | 2006-05-30 19:37:54 +0200 (Tue, 30 May 2006) | 1 line
Change wrapping terminology to overflow masking
........
r46562 | fredrik.lundh | 2006-05-30 19:39:58 +0200 (Tue, 30 May 2006) | 3 lines
changed count to return 0 for slices outside the source string
........
r46568 | tim.peters | 2006-05-31 01:28:02 +0200 (Wed, 31 May 2006) | 2 lines
Whitespace normalization.
........
r46569 | brett.cannon | 2006-05-31 04:19:54 +0200 (Wed, 31 May 2006) | 5 lines
Clarify wording on default values for strptime(); defaults are used when better
values cannot be inferred.
Closes bug #1496315.
........
r46572 | neal.norwitz | 2006-05-31 09:43:27 +0200 (Wed, 31 May 2006) | 1 line
Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64
........
r46573 | neal.norwitz | 2006-05-31 10:01:08 +0200 (Wed, 31 May 2006) | 1 line
Revert last checkin, it is better to do make distclean
........
r46574 | neal.norwitz | 2006-05-31 11:02:44 +0200 (Wed, 31 May 2006) | 3 lines
On 64-bit platforms running test_struct after test_tarfile would fail
since the deprecation warning wouldn't be raised.
........
r46575 | thomas.heller | 2006-05-31 13:37:58 +0200 (Wed, 31 May 2006) | 3 lines
PyTuple_Pack is not available in Python 2.3, but ctypes must stay
compatible with that.
........
r46576 | andrew.kuchling | 2006-05-31 15:18:56 +0200 (Wed, 31 May 2006) | 1 line
'functional' module was renamed to 'functools'
........
r46577 | kristjan.jonsson | 2006-05-31 15:35:41 +0200 (Wed, 31 May 2006) | 1 line
Fixup the PCBuild8 project directory. exceptions.c have moved to Objects, and the functionalmodule.c has been replaced with _functoolsmodule.c. Other minor changes to .vcproj files and .sln to fix compilation
........
r46578 | andrew.kuchling | 2006-05-31 16:08:48 +0200 (Wed, 31 May 2006) | 15 lines
[Bug #1473048]
SimpleXMLRPCServer and DocXMLRPCServer don't look at
the path of the HTTP request at all; you can POST or
GET from / or /RPC2 or /blahblahblah with the same results.
Security scanners that look for /cgi-bin/phf will therefore report
lots of vulnerabilities.
Fix: add a .rpc_paths attribute to the SimpleXMLRPCServer class,
and report a 404 error if the path isn't on the allowed list.
Possibly-controversial aspect of this change: the default makes only
'/' and '/RPC2' legal. Maybe this will break people's applications
(though I doubt it). We could just set the default to an empty tuple,
which would exactly match the current behaviour.
........
r46579 | andrew.kuchling | 2006-05-31 16:12:47 +0200 (Wed, 31 May 2006) | 1 line
Mention SimpleXMLRPCServer change
........
r46580 | tim.peters | 2006-05-31 16:28:07 +0200 (Wed, 31 May 2006) | 2 lines
Trimmed trailing whitespace.
........
r46581 | tim.peters | 2006-05-31 17:33:22 +0200 (Wed, 31 May 2006) | 4 lines
_range_error(): Speed and simplify (there's no real need for
loops here). Assert that size_t is actually big enough, and
that f->size is at least one. Wrap a long line.
........
r46582 | tim.peters | 2006-05-31 17:34:37 +0200 (Wed, 31 May 2006) | 2 lines
Repaired error in new comment.
........
r46584 | neal.norwitz | 2006-06-01 07:32:49 +0200 (Thu, 01 Jun 2006) | 4 lines
Remove ; at end of macro. There was a compiler recently that warned
about extra semi-colons. It may have been the HP C compiler.
This file will trigger a bunch of those warnings now.
........
r46585 | georg.brandl | 2006-06-01 08:39:19 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
........
r46586 | georg.brandl | 2006-06-01 10:27:32 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly allocate complex types with tp_alloc. (bug #1498638)
........
r46587 | georg.brandl | 2006-06-01 14:30:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Correctly dispatch Faults in loads (patch #1498627)
........
r46588 | georg.brandl | 2006-06-01 15:00:49 +0200 (Thu, 01 Jun 2006) | 3 lines
Some code style tweaks, and remove apply.
........
r46589 | armin.rigo | 2006-06-01 15:19:12 +0200 (Thu, 01 Jun 2006) | 5 lines
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
[ 1456209 ] dictresize() vulnerability ( <- backport candidate ).
........
r46590 | tim.peters | 2006-06-01 15:41:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Whitespace normalization.
........
r46591 | tim.peters | 2006-06-01 15:49:23 +0200 (Thu, 01 Jun 2006) | 2 lines
Record bugs 1275608 and 1456209 as being fixed.
........
r46592 | tim.peters | 2006-06-01 15:56:26 +0200 (Thu, 01 Jun 2006) | 5 lines
Re-enable a new empty-string test added during the NFS sprint,
but disabled then because str and unicode strings gave different
results. The implementations were repaired later during the
sprint, but the new test remained disabled.
........
r46594 | tim.peters | 2006-06-01 17:50:44 +0200 (Thu, 01 Jun 2006) | 7 lines
Armin committed his patch while I was reviewing it (I'm sure
he didn't know this), so merged in some changes I made during
review. Nothing material apart from changing a new `mask` local
from int to Py_ssize_t. Mostly this is repairing comments that
were made incorrect, and adding new comments. Also a few
minor code rewrites for clarity or helpful succinctness.
........
r46599 | neal.norwitz | 2006-06-02 06:45:53 +0200 (Fri, 02 Jun 2006) | 1 line
Convert docstrings to comments so regrtest -v prints method names
........
r46600 | neal.norwitz | 2006-06-02 06:50:49 +0200 (Fri, 02 Jun 2006) | 2 lines
Fix memory leak found by valgrind.
........
r46601 | neal.norwitz | 2006-06-02 06:54:52 +0200 (Fri, 02 Jun 2006) | 1 line
More memory leaks from valgrind
........
r46602 | neal.norwitz | 2006-06-02 08:23:00 +0200 (Fri, 02 Jun 2006) | 11 lines
Patch #1357836:
Prevent an invalid memory read from test_coding in case the done flag is set.
In that case, the loop isn't entered. I wonder if rather than setting
the done flag in the cases before the loop, if they should just exit early.
This code looks like it should be refactored.
Backport candidate (also the early break above if decoding_fgets fails)
........
r46603 | martin.blais | 2006-06-02 15:03:43 +0200 (Fri, 02 Jun 2006) | 1 line
Fixed struct test to not use unittest.
........
r46605 | tim.peters | 2006-06-03 01:22:51 +0200 (Sat, 03 Jun 2006) | 10 lines
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got
displayed in seemingly random order (the hash-induced order
produced by dict.__repr__). None of this was documented.
Now pprint functions always sort dicts by key, and the docs
promise it.
This was proposed and agreed to during the PyCon 2006 core
sprint -- I just didn't have time for it before now.
........
2006-06-08 11:42:34 -03:00
|
|
|
if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
|
2002-03-27 09:03:09 -04:00
|
|
|
return NULL;
|
1991-12-31 09:15:35 -04:00
|
|
|
/* Raise SystemExit so callers may catch it or clean up. */
|
2002-03-27 09:03:09 -04:00
|
|
|
PyErr_SetObject(PyExc_SystemExit, exit_code);
|
1991-12-31 09:15:35 -04:00
|
|
|
return NULL;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(exit_doc,
|
1998-06-27 16:43:25 -03:00
|
|
|
"exit([status])\n\
|
|
|
|
\n\
|
|
|
|
Exit the interpreter by raising SystemExit(status).\n\
|
|
|
|
If the status is omitted or None, it defaults to zero (i.e., success).\n\
|
2002-03-23 16:46:35 -04:00
|
|
|
If the status is numeric, it will be used as the system exit status.\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
If it is another kind of object, it will be printed and the system\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
exit status will be one (i.e., failure)."
|
|
|
|
);
|
1998-06-27 16:43:25 -03:00
|
|
|
|
2001-11-09 16:59:39 -04:00
|
|
|
#ifdef Py_USING_UNICODE
|
|
|
|
|
2000-05-09 16:57:01 -03:00
|
|
|
static PyObject *
|
2001-08-16 10:15:00 -03:00
|
|
|
sys_getdefaultencoding(PyObject *self)
|
2000-05-09 16:57:01 -03:00
|
|
|
{
|
|
|
|
return PyString_FromString(PyUnicode_GetDefaultEncoding());
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(getdefaultencoding_doc,
|
2000-06-07 06:13:41 -03:00
|
|
|
"getdefaultencoding() -> string\n\
|
2000-05-09 16:57:01 -03:00
|
|
|
\n\
|
|
|
|
Return the current default string encoding used by the Unicode \n\
|
2002-06-09 10:33:54 -03:00
|
|
|
implementation."
|
|
|
|
);
|
2000-05-09 16:57:01 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
sys_setdefaultencoding(PyObject *self, PyObject *args)
|
2000-05-09 16:57:01 -03:00
|
|
|
{
|
|
|
|
char *encoding;
|
2000-06-07 06:13:41 -03:00
|
|
|
if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
|
2000-05-09 16:57:01 -03:00
|
|
|
return NULL;
|
|
|
|
if (PyUnicode_SetDefaultEncoding(encoding))
|
|
|
|
return NULL;
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(setdefaultencoding_doc,
|
2000-06-07 06:13:41 -03:00
|
|
|
"setdefaultencoding(encoding)\n\
|
2000-05-09 16:57:01 -03:00
|
|
|
\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
Set the current default string encoding used by the Unicode implementation."
|
|
|
|
);
|
2000-05-09 16:57:01 -03:00
|
|
|
|
2003-03-05 11:13:47 -04:00
|
|
|
static PyObject *
|
|
|
|
sys_getfilesystemencoding(PyObject *self)
|
|
|
|
{
|
|
|
|
if (Py_FileSystemDefaultEncoding)
|
|
|
|
return PyString_FromString(Py_FileSystemDefaultEncoding);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(getfilesystemencoding_doc,
|
|
|
|
"getfilesystemencoding() -> string\n\
|
|
|
|
\n\
|
|
|
|
Return the encoding used to convert Unicode filenames in\n\
|
|
|
|
operating system filenames."
|
|
|
|
);
|
|
|
|
|
2001-08-17 15:39:25 -03:00
|
|
|
#endif
|
|
|
|
|
2001-06-27 16:19:46 -03:00
|
|
|
/*
|
|
|
|
* Cached interned string objects used for calling the profile and
|
|
|
|
* trace functions. Initialized by trace_init().
|
|
|
|
*/
|
2004-03-24 17:57:10 -04:00
|
|
|
static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
2001-06-27 16:19:46 -03:00
|
|
|
|
|
|
|
static int
|
|
|
|
trace_init(void)
|
|
|
|
{
|
2004-03-24 17:57:10 -04:00
|
|
|
static char *whatnames[7] = {"call", "exception", "line", "return",
|
|
|
|
"c_call", "c_exception", "c_return"};
|
2001-06-27 16:19:46 -03:00
|
|
|
PyObject *name;
|
|
|
|
int i;
|
2004-03-24 17:57:10 -04:00
|
|
|
for (i = 0; i < 7; ++i) {
|
2001-06-27 16:19:46 -03:00
|
|
|
if (whatstrings[i] == NULL) {
|
|
|
|
name = PyString_InternFromString(whatnames[i]);
|
|
|
|
if (name == NULL)
|
|
|
|
return -1;
|
|
|
|
whatstrings[i] = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
call_trampoline(PyThreadState *tstate, PyObject* callback,
|
|
|
|
PyFrameObject *frame, int what, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *args = PyTuple_New(3);
|
|
|
|
PyObject *whatstr;
|
|
|
|
PyObject *result;
|
|
|
|
|
|
|
|
if (args == NULL)
|
|
|
|
return NULL;
|
|
|
|
Py_INCREF(frame);
|
|
|
|
whatstr = whatstrings[what];
|
|
|
|
Py_INCREF(whatstr);
|
|
|
|
if (arg == NULL)
|
|
|
|
arg = Py_None;
|
|
|
|
Py_INCREF(arg);
|
|
|
|
PyTuple_SET_ITEM(args, 0, (PyObject *)frame);
|
|
|
|
PyTuple_SET_ITEM(args, 1, whatstr);
|
|
|
|
PyTuple_SET_ITEM(args, 2, arg);
|
|
|
|
|
|
|
|
/* call the Python-level function */
|
|
|
|
PyFrame_FastToLocals(frame);
|
|
|
|
result = PyEval_CallObject(callback, args);
|
|
|
|
PyFrame_LocalsToFast(frame, 1);
|
|
|
|
if (result == NULL)
|
|
|
|
PyTraceBack_Here(frame);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
Py_DECREF(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
profile_trampoline(PyObject *self, PyFrameObject *frame,
|
|
|
|
int what, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyThreadState *tstate = frame->f_tstate;
|
|
|
|
PyObject *result;
|
|
|
|
|
2001-10-04 11:48:42 -03:00
|
|
|
if (arg == NULL)
|
|
|
|
arg = Py_None;
|
2001-06-27 16:19:46 -03:00
|
|
|
result = call_trampoline(tstate, self, frame, what, arg);
|
|
|
|
if (result == NULL) {
|
|
|
|
PyEval_SetProfile(NULL, NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Py_DECREF(result);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
trace_trampoline(PyObject *self, PyFrameObject *frame,
|
|
|
|
int what, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyThreadState *tstate = frame->f_tstate;
|
|
|
|
PyObject *callback;
|
|
|
|
PyObject *result;
|
|
|
|
|
|
|
|
if (what == PyTrace_CALL)
|
|
|
|
callback = self;
|
|
|
|
else
|
|
|
|
callback = frame->f_trace;
|
|
|
|
if (callback == NULL)
|
|
|
|
return 0;
|
|
|
|
result = call_trampoline(tstate, callback, frame, what, arg);
|
|
|
|
if (result == NULL) {
|
|
|
|
PyEval_SetTrace(NULL, NULL);
|
|
|
|
Py_XDECREF(frame->f_trace);
|
|
|
|
frame->f_trace = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (result != Py_None) {
|
|
|
|
PyObject *temp = frame->f_trace;
|
|
|
|
frame->f_trace = NULL;
|
|
|
|
Py_XDECREF(temp);
|
|
|
|
frame->f_trace = result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Py_DECREF(result);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2001-06-16 18:02:31 -03:00
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
sys_settrace(PyObject *self, PyObject *args)
|
1992-03-23 14:20:18 -04:00
|
|
|
{
|
2001-06-27 16:19:46 -03:00
|
|
|
if (trace_init() == -1)
|
2001-06-16 18:02:31 -03:00
|
|
|
return NULL;
|
1997-04-29 15:33:38 -03:00
|
|
|
if (args == Py_None)
|
2001-06-27 16:19:46 -03:00
|
|
|
PyEval_SetTrace(NULL, NULL);
|
1992-04-05 11:17:55 -03:00
|
|
|
else
|
2001-06-27 16:19:46 -03:00
|
|
|
PyEval_SetTrace(trace_trampoline, args);
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-03-23 14:20:18 -04:00
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(settrace_doc,
|
1998-06-27 16:43:25 -03:00
|
|
|
"settrace(function)\n\
|
|
|
|
\n\
|
|
|
|
Set the global debug tracing function. It will be called on each\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
function call. See the debugger chapter in the library manual."
|
|
|
|
);
|
1998-06-27 16:43:25 -03:00
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
sys_setprofile(PyObject *self, PyObject *args)
|
1992-03-23 14:20:18 -04:00
|
|
|
{
|
2001-06-27 16:19:46 -03:00
|
|
|
if (trace_init() == -1)
|
2001-06-16 18:02:31 -03:00
|
|
|
return NULL;
|
1997-04-29 15:33:38 -03:00
|
|
|
if (args == Py_None)
|
2001-06-27 16:19:46 -03:00
|
|
|
PyEval_SetProfile(NULL, NULL);
|
1992-04-05 11:17:55 -03:00
|
|
|
else
|
2001-06-27 16:19:46 -03:00
|
|
|
PyEval_SetProfile(profile_trampoline, args);
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-03-23 14:20:18 -04:00
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(setprofile_doc,
|
1998-06-27 16:43:25 -03:00
|
|
|
"setprofile(function)\n\
|
|
|
|
\n\
|
|
|
|
Set the profiling function. It will be called on each function call\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
and return. See the profiler chapter in the library manual."
|
|
|
|
);
|
1998-06-27 16:43:25 -03:00
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
sys_setcheckinterval(PyObject *self, PyObject *args)
|
1995-01-09 13:46:13 -04:00
|
|
|
{
|
2002-09-03 17:10:45 -03:00
|
|
|
if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_Py_CheckInterval))
|
1995-01-09 13:46:13 -04:00
|
|
|
return NULL;
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1995-01-09 13:46:13 -04:00
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(setcheckinterval_doc,
|
1998-06-27 16:43:25 -03:00
|
|
|
"setcheckinterval(n)\n\
|
|
|
|
\n\
|
|
|
|
Tell the Python interpreter to check for asynchronous events every\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
n instructions. This also affects how often thread switches occur."
|
|
|
|
);
|
1998-06-27 16:43:25 -03:00
|
|
|
|
2003-07-06 15:36:54 -03:00
|
|
|
static PyObject *
|
|
|
|
sys_getcheckinterval(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
return PyInt_FromLong(_Py_CheckInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(getcheckinterval_doc,
|
|
|
|
"getcheckinterval() -> current check interval; see setcheckinterval()."
|
|
|
|
);
|
|
|
|
|
2004-06-08 05:17:44 -03:00
|
|
|
#ifdef WITH_TSC
|
|
|
|
static PyObject *
|
|
|
|
sys_settscdump(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
int bool;
|
|
|
|
PyThreadState *tstate = PyThreadState_Get();
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "i:settscdump", &bool))
|
|
|
|
return NULL;
|
|
|
|
if (bool)
|
|
|
|
tstate->interp->tscdump = 1;
|
|
|
|
else
|
|
|
|
tstate->interp->tscdump = 0;
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
2006-01-05 22:40:53 -04:00
|
|
|
|
2004-06-08 05:17:44 -03:00
|
|
|
}
|
|
|
|
|
2006-01-05 22:40:53 -04:00
|
|
|
PyDoc_STRVAR(settscdump_doc,
|
2004-06-08 05:17:44 -03:00
|
|
|
"settscdump(bool)\n\
|
|
|
|
\n\
|
|
|
|
If true, tell the Python interpreter to dump VM measurements to\n\
|
|
|
|
stderr. If false, turn off dump. The measurements are based on the\n\
|
2004-08-12 15:19:17 -03:00
|
|
|
processor's time-stamp counter."
|
2006-01-05 22:40:53 -04:00
|
|
|
);
|
2004-06-13 17:32:17 -03:00
|
|
|
#endif /* TSC */
|
2004-06-08 05:17:44 -03:00
|
|
|
|
2000-08-31 16:23:01 -03:00
|
|
|
static PyObject *
|
|
|
|
sys_setrecursionlimit(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
int new_limit;
|
|
|
|
if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit))
|
|
|
|
return NULL;
|
|
|
|
if (new_limit <= 0) {
|
2006-01-05 22:40:53 -04:00
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"recursion limit must be positive");
|
2000-08-31 16:23:01 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
Py_SetRecursionLimit(new_limit);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(setrecursionlimit_doc,
|
2000-08-31 16:23:01 -03:00
|
|
|
"setrecursionlimit(n)\n\
|
|
|
|
\n\
|
|
|
|
Set the maximum depth of the Python interpreter stack to n. This\n\
|
|
|
|
limit prevents infinite recursion from causing an overflow of the C\n\
|
|
|
|
stack and crashing Python. The highest possible limit is platform-\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
dependent."
|
|
|
|
);
|
2000-08-31 16:23:01 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2001-08-16 10:15:00 -03:00
|
|
|
sys_getrecursionlimit(PyObject *self)
|
2000-08-31 16:23:01 -03:00
|
|
|
{
|
|
|
|
return PyInt_FromLong(Py_GetRecursionLimit());
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(getrecursionlimit_doc,
|
2000-08-31 16:23:01 -03:00
|
|
|
"getrecursionlimit()\n\
|
|
|
|
\n\
|
|
|
|
Return the current value of the recursion limit, the maximum depth\n\
|
|
|
|
of the Python interpreter stack. This limit prevents infinite\n\
|
2002-06-26 17:39:20 -03:00
|
|
|
recursion from causing an overflow of the C stack and crashing Python."
|
2002-06-09 10:33:54 -03:00
|
|
|
);
|
2000-08-31 16:23:01 -03:00
|
|
|
|
2002-10-07 23:44:31 -03:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
PyDoc_STRVAR(getwindowsversion_doc,
|
|
|
|
"getwindowsversion()\n\
|
|
|
|
\n\
|
|
|
|
Return information about the running version of Windows.\n\
|
|
|
|
The result is a tuple of (major, minor, build, platform, text)\n\
|
|
|
|
All elements are numbers, except text which is a string.\n\
|
|
|
|
Platform may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP\n\
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
sys_getwindowsversion(PyObject *self)
|
|
|
|
{
|
|
|
|
OSVERSIONINFO ver;
|
|
|
|
ver.dwOSVersionInfoSize = sizeof(ver);
|
|
|
|
if (!GetVersionEx(&ver))
|
|
|
|
return PyErr_SetFromWindowsErr(0);
|
|
|
|
return Py_BuildValue("HHHHs",
|
|
|
|
ver.dwMajorVersion,
|
|
|
|
ver.dwMinorVersion,
|
|
|
|
ver.dwBuildNumber,
|
|
|
|
ver.dwPlatformId,
|
|
|
|
ver.szCSDVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MS_WINDOWS */
|
|
|
|
|
2001-07-18 13:17:16 -03:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
static PyObject *
|
|
|
|
sys_setdlopenflags(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
int new_val;
|
2004-03-24 18:22:12 -04:00
|
|
|
PyThreadState *tstate = PyThreadState_GET();
|
2001-07-18 13:17:16 -03:00
|
|
|
if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))
|
|
|
|
return NULL;
|
|
|
|
if (!tstate)
|
|
|
|
return NULL;
|
|
|
|
tstate->interp->dlopenflags = new_val;
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(setdlopenflags_doc,
|
2001-07-18 13:17:16 -03:00
|
|
|
"setdlopenflags(n) -> None\n\
|
|
|
|
\n\
|
|
|
|
Set the flags that will be used for dlopen() calls. Among other\n\
|
2002-01-28 20:53:41 -04:00
|
|
|
things, this will enable a lazy resolving of symbols when importing\n\
|
2001-07-18 13:17:16 -03:00
|
|
|
a module, if called as sys.setdlopenflags(0)\n\
|
2002-01-28 20:53:41 -04:00
|
|
|
To share symbols across extension modules, call as\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)"
|
|
|
|
);
|
2001-07-18 13:17:16 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
sys_getdlopenflags(PyObject *self, PyObject *args)
|
|
|
|
{
|
2004-03-24 18:22:12 -04:00
|
|
|
PyThreadState *tstate = PyThreadState_GET();
|
2001-07-18 13:17:16 -03:00
|
|
|
if (!tstate)
|
|
|
|
return NULL;
|
|
|
|
return PyInt_FromLong(tstate->interp->dlopenflags);
|
|
|
|
}
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(getdlopenflags_doc,
|
2001-07-18 13:17:16 -03:00
|
|
|
"getdlopenflags() -> int\n\
|
|
|
|
\n\
|
|
|
|
Return the current value of the flags that are used for dlopen()\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
calls. The flag constants are defined in the dl module."
|
|
|
|
);
|
2001-07-18 13:17:16 -03:00
|
|
|
#endif
|
|
|
|
|
1992-09-03 17:25:30 -03:00
|
|
|
#ifdef USE_MALLOPT
|
|
|
|
/* Link with -lmalloc (or -lmpc) on an SGI */
|
|
|
|
#include <malloc.h>
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
sys_mdebug(PyObject *self, PyObject *args)
|
1992-09-03 17:25:30 -03:00
|
|
|
{
|
|
|
|
int flag;
|
2000-03-30 20:38:29 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "i:mdebug", &flag))
|
1992-09-03 17:25:30 -03:00
|
|
|
return NULL;
|
|
|
|
mallopt(M_DEBUG, flag);
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-09-03 17:25:30 -03:00
|
|
|
}
|
|
|
|
#endif /* USE_MALLOPT */
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2001-10-24 17:47:48 -03:00
|
|
|
sys_getrefcount(PyObject *self, PyObject *arg)
|
1995-08-29 06:18:14 -03:00
|
|
|
{
|
2006-03-07 08:08:51 -04:00
|
|
|
return PyInt_FromSsize_t(arg->ob_refcnt);
|
1995-08-29 06:18:14 -03:00
|
|
|
}
|
|
|
|
|
2002-07-07 16:59:50 -03:00
|
|
|
#ifdef Py_REF_DEBUG
|
2000-06-20 05:12:48 -03:00
|
|
|
static PyObject *
|
2001-08-16 10:15:00 -03:00
|
|
|
sys_gettotalrefcount(PyObject *self)
|
2000-06-20 05:12:48 -03:00
|
|
|
{
|
2006-04-21 07:40:58 -03:00
|
|
|
return PyInt_FromSsize_t(_Py_GetRefTotal());
|
2000-06-20 05:12:48 -03:00
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
#endif /* Py_REF_DEBUG */
|
2000-06-20 05:12:48 -03:00
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(getrefcount_doc,
|
1998-06-27 16:43:25 -03:00
|
|
|
"getrefcount(object) -> integer\n\
|
|
|
|
\n\
|
2002-06-20 18:36:19 -03:00
|
|
|
Return the reference count of object. The count returned is generally\n\
|
|
|
|
one higher than you might expect, because it includes the (temporary)\n\
|
|
|
|
reference as an argument to getrefcount()."
|
2002-06-09 10:33:54 -03:00
|
|
|
);
|
1998-06-27 16:43:25 -03:00
|
|
|
|
1995-08-29 06:18:14 -03:00
|
|
|
#ifdef COUNT_ALLOCS
|
|
|
|
static PyObject *
|
2001-08-16 10:15:00 -03:00
|
|
|
sys_getcounts(PyObject *self)
|
1995-08-29 06:18:14 -03:00
|
|
|
{
|
2000-07-09 00:09:57 -03:00
|
|
|
extern PyObject *get_counts(void);
|
1995-08-29 06:18:14 -03:00
|
|
|
|
|
|
|
return get_counts();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STRVAR(getframe_doc,
|
2000-12-06 17:47:46 -04:00
|
|
|
"_getframe([depth]) -> frameobject\n\
|
|
|
|
\n\
|
|
|
|
Return a frame object from the call stack. If optional integer depth is\n\
|
|
|
|
given, return the frame object that many calls below the top of the stack.\n\
|
|
|
|
If that is deeper than the call stack, ValueError is raised. The default\n\
|
|
|
|
for depth is zero, returning the frame at the top of the call stack.\n\
|
|
|
|
\n\
|
|
|
|
This function should be used for internal and specialized\n\
|
2002-06-09 10:33:54 -03:00
|
|
|
purposes only."
|
|
|
|
);
|
2000-12-06 17:47:46 -04:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
sys_getframe(PyObject *self, PyObject *args)
|
|
|
|
{
|
2004-03-24 18:22:12 -04:00
|
|
|
PyFrameObject *f = PyThreadState_GET()->frame;
|
2000-12-06 17:47:46 -04:00
|
|
|
int depth = -1;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while (depth > 0 && f != NULL) {
|
|
|
|
f = f->f_back;
|
|
|
|
--depth;
|
|
|
|
}
|
|
|
|
if (f == NULL) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"call stack is not deep enough");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
Py_INCREF(f);
|
|
|
|
return (PyObject*)f;
|
|
|
|
}
|
|
|
|
|
2003-04-09 16:06:21 -03:00
|
|
|
PyDoc_STRVAR(call_tracing_doc,
|
|
|
|
"call_tracing(func, args) -> object\n\
|
|
|
|
\n\
|
|
|
|
Call func(*args), while tracing is enabled. The tracing state is\n\
|
|
|
|
saved, and restored afterwards. This is intended to be called from\n\
|
|
|
|
a debugger from a checkpoint, to recursively debug some other code."
|
|
|
|
);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
sys_call_tracing(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
PyObject *func, *funcargs;
|
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
merge in bad ways, so I'll have to merge that extra-carefully (probably manually.)
Merged revisions 46495-46605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r46495 | tim.peters | 2006-05-28 03:52:38 +0200 (Sun, 28 May 2006) | 2 lines
Added missing svn:eol-style property to text files.
........
r46497 | tim.peters | 2006-05-28 12:41:29 +0200 (Sun, 28 May 2006) | 3 lines
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both: `className` was referenced before being checked for NULL.
........
r46499 | fredrik.lundh | 2006-05-28 14:06:46 +0200 (Sun, 28 May 2006) | 5 lines
needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only),
and use it for string copy operations. this gives a 20% speedup on some
string benchmarks.
........
r46501 | michael.hudson | 2006-05-28 17:51:40 +0200 (Sun, 28 May 2006) | 26 lines
Quality control, meet exceptions.c.
Fix a number of problems with the need for speed code:
One is doing this sort of thing:
Py_DECREF(self->field);
self->field = newval;
Py_INCREF(self->field);
without being very sure that self->field doesn't start with a
value that has a __del__, because that almost certainly can lead
to segfaults.
As self->args is constrained to be an exact tuple we may as well
exploit this fact consistently. This leads to quite a lot of
simplification (and, hey, probably better performance).
Add some error checking in places lacking it.
Fix some rather strange indentation in the Unicode code.
Delete some trailing whitespace.
More to come, I haven't fixed all the reference leaks yet...
........
r46502 | george.yoshida | 2006-05-28 18:39:09 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1080727: add "encoding" parameter to doctest.DocFileSuite
Contributed by Bjorn Tillenius.
........
r46503 | martin.v.loewis | 2006-05-28 18:57:38 +0200 (Sun, 28 May 2006) | 4 lines
Rest of patch #1490384: Commit icon source, remove
claim that Erik von Blokland is the author of the
installer picture.
........
r46504 | michael.hudson | 2006-05-28 19:40:29 +0200 (Sun, 28 May 2006) | 16 lines
Quality control, meet exceptions.c, round two.
Make some functions that should have been static static.
Fix a bunch of refleaks by fixing the definition of
MiddlingExtendsException.
Remove all the __new__ implementations apart from
BaseException_new. Rewrite most code that needs it to cope with
NULL fields (such code could get excercised anyway, the
__new__-removal just makes it more likely). This involved
editing the code for WindowsError, which I can't test.
This fixes all the refleaks in at least the start of a regrtest
-R :: run.
........
r46505 | marc-andre.lemburg | 2006-05-28 19:46:58 +0200 (Sun, 28 May 2006) | 10 lines
Initial version of systimes - a module to provide platform dependent
performance measurements.
The module is currently just a proof-of-concept implementation, but
will integrated into pybench once it is stable enough.
License: pybench license.
Author: Marc-Andre Lemburg.
........
r46507 | armin.rigo | 2006-05-28 21:13:17 +0200 (Sun, 28 May 2006) | 15 lines
("Forward-port" of r46506)
Remove various dependencies on dictionary order in the standard library
tests, and one (clearly an oversight, potentially critical) in the
standard library itself - base64.py.
Remaining open issues:
* test_extcall is an output test, messy to make robust
* tarfile.py has a potential bug here, but I'm not familiar
enough with this code. Filed in as SF bug #1496501.
* urllib2.HTTPPasswordMgr() returns a random result if there is more
than one matching root path. I'm asking python-dev for
clarification...
........
r46508 | georg.brandl | 2006-05-28 22:11:45 +0200 (Sun, 28 May 2006) | 4 lines
The empty string is a valid import path.
(fixes #1496539)
........
r46509 | georg.brandl | 2006-05-28 22:23:12 +0200 (Sun, 28 May 2006) | 3 lines
Patch #1496206: urllib2 PasswordMgr ./. default ports
........
r46510 | georg.brandl | 2006-05-28 22:57:09 +0200 (Sun, 28 May 2006) | 3 lines
Fix refleaks in UnicodeError get and set methods.
........
r46511 | michael.hudson | 2006-05-28 23:19:03 +0200 (Sun, 28 May 2006) | 3 lines
use the UnicodeError traversal and clearing functions in UnicodeError
subclasses.
........
r46512 | thomas.wouters | 2006-05-28 23:32:12 +0200 (Sun, 28 May 2006) | 4 lines
Make last patch valid C89 so Windows compilers can deal with it.
........
r46513 | georg.brandl | 2006-05-28 23:42:54 +0200 (Sun, 28 May 2006) | 3 lines
Fix ref-antileak in _struct.c which eventually lead to deallocating None.
........
r46514 | georg.brandl | 2006-05-28 23:57:35 +0200 (Sun, 28 May 2006) | 4 lines
Correct None refcount issue in Mac modules. (Are they
still used?)
........
r46515 | armin.rigo | 2006-05-29 00:07:08 +0200 (Mon, 29 May 2006) | 3 lines
A clearer error message when passing -R to regrtest.py with
release builds of Python.
........
r46516 | georg.brandl | 2006-05-29 00:14:04 +0200 (Mon, 29 May 2006) | 3 lines
Fix C function calling conventions in _sre module.
........
r46517 | georg.brandl | 2006-05-29 00:34:51 +0200 (Mon, 29 May 2006) | 3 lines
Convert audioop over to METH_VARARGS.
........
r46518 | georg.brandl | 2006-05-29 00:38:57 +0200 (Mon, 29 May 2006) | 3 lines
METH_NOARGS functions do get called with two args.
........
r46519 | georg.brandl | 2006-05-29 11:46:51 +0200 (Mon, 29 May 2006) | 4 lines
Fix refleak in socketmodule. Replace bogus Py_BuildValue calls.
Fix refleak in exceptions.
........
r46520 | nick.coghlan | 2006-05-29 14:43:05 +0200 (Mon, 29 May 2006) | 7 lines
Apply modified version of Collin Winter's patch #1478788
Renames functional extension module to _functools and adds a Python
functools module so that utility functions like update_wrapper can be
added easily.
........
r46522 | georg.brandl | 2006-05-29 15:53:16 +0200 (Mon, 29 May 2006) | 3 lines
Convert fmmodule to METH_VARARGS.
........
r46523 | georg.brandl | 2006-05-29 16:13:21 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494605.
........
r46524 | georg.brandl | 2006-05-29 16:28:05 +0200 (Mon, 29 May 2006) | 3 lines
Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.
........
r46525 | georg.brandl | 2006-05-29 16:33:55 +0200 (Mon, 29 May 2006) | 3 lines
Fix compiler warning.
........
r46526 | georg.brandl | 2006-05-29 16:39:00 +0200 (Mon, 29 May 2006) | 3 lines
Fix #1494787 (pyclbr counts whitespace as superclass name)
........
r46527 | bob.ippolito | 2006-05-29 17:47:29 +0200 (Mon, 29 May 2006) | 1 line
simplify the struct code a bit (no functional changes)
........
r46528 | armin.rigo | 2006-05-29 19:59:47 +0200 (Mon, 29 May 2006) | 2 lines
Silence a warning.
........
r46529 | georg.brandl | 2006-05-29 21:39:45 +0200 (Mon, 29 May 2006) | 3 lines
Correct some value converting strangenesses.
........
r46530 | nick.coghlan | 2006-05-29 22:27:44 +0200 (Mon, 29 May 2006) | 1 line
When adding a module like functools, it helps to let SVN know about the file.
........
r46531 | georg.brandl | 2006-05-29 22:52:54 +0200 (Mon, 29 May 2006) | 4 lines
Patches #1497027 and #972322: try HTTP digest auth first,
and watch out for handler name collisions.
........
r46532 | georg.brandl | 2006-05-29 22:57:01 +0200 (Mon, 29 May 2006) | 3 lines
Add News entry for last commit.
........
r46533 | georg.brandl | 2006-05-29 23:04:52 +0200 (Mon, 29 May 2006) | 4 lines
Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
........
r46534 | georg.brandl | 2006-05-29 23:58:42 +0200 (Mon, 29 May 2006) | 3 lines
Convert more modules to METH_VARARGS.
........
r46535 | georg.brandl | 2006-05-30 00:00:30 +0200 (Tue, 30 May 2006) | 3 lines
Whoops.
........
r46536 | fredrik.lundh | 2006-05-30 00:42:07 +0200 (Tue, 30 May 2006) | 4 lines
fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on
the current behaviour ;-)
........
r46537 | bob.ippolito | 2006-05-30 00:55:48 +0200 (Tue, 30 May 2006) | 1 line
struct: modulo math plus warning on all endian-explicit formats for compatibility with older struct usage (ugly)
........
r46539 | bob.ippolito | 2006-05-30 02:26:01 +0200 (Tue, 30 May 2006) | 1 line
Add a length check to aifc to ensure it doesn't write a bogus file
........
r46540 | tim.peters | 2006-05-30 04:25:25 +0200 (Tue, 30 May 2006) | 10 lines
deprecated_err(): Stop bizarre warning messages when the tests
are run in the order:
test_genexps (or any other doctest-based test)
test_struct
test_doctest
The `warnings` module needs an advertised way to save/restore
its internal filter list.
........
r46541 | tim.peters | 2006-05-30 04:26:46 +0200 (Tue, 30 May 2006) | 2 lines
Whitespace normalization.
........
r46542 | tim.peters | 2006-05-30 04:30:30 +0200 (Tue, 30 May 2006) | 2 lines
Set a binary svn:mime-type property on this UTF-8 encoded file.
........
r46543 | neal.norwitz | 2006-05-30 05:18:50 +0200 (Tue, 30 May 2006) | 1 line
Simplify further by using AddStringConstant
........
r46544 | tim.peters | 2006-05-30 06:16:25 +0200 (Tue, 30 May 2006) | 6 lines
Convert relevant dict internals to Py_ssize_t.
I don't have a box with nearly enough RAM, or an OS,
that could get close to tickling this, though (requires
a dict w/ at least 2**31 entries).
........
r46545 | neal.norwitz | 2006-05-30 06:19:21 +0200 (Tue, 30 May 2006) | 1 line
Remove stray | in comment
........
r46546 | neal.norwitz | 2006-05-30 06:25:05 +0200 (Tue, 30 May 2006) | 1 line
Use Py_SAFE_DOWNCAST for safety. Fix format strings. Remove 2 more stray | in comment
........
r46547 | neal.norwitz | 2006-05-30 06:43:23 +0200 (Tue, 30 May 2006) | 1 line
No DOWNCAST is required since sizeof(Py_ssize_t) >= sizeof(int) and Py_ReprEntr returns an int
........
r46548 | tim.peters | 2006-05-30 07:04:59 +0200 (Tue, 30 May 2006) | 3 lines
dict_print(): Explicitly narrow the return value
from a (possibly) wider variable.
........
r46549 | tim.peters | 2006-05-30 07:23:59 +0200 (Tue, 30 May 2006) | 5 lines
dict_print(): So that Neal & I don't spend the rest of
our lives taking turns rewriting code that works ;-),
get rid of casting illusions by declaring a new variable
with the obvious type.
........
r46550 | georg.brandl | 2006-05-30 09:04:55 +0200 (Tue, 30 May 2006) | 3 lines
Restore exception pickle support. #1497319.
........
r46551 | georg.brandl | 2006-05-30 09:13:29 +0200 (Tue, 30 May 2006) | 3 lines
Add a test case for exception pickling. args is never NULL.
........
r46552 | neal.norwitz | 2006-05-30 09:21:10 +0200 (Tue, 30 May 2006) | 1 line
Don't fail if the (sub)pkgname already exist.
........
r46553 | georg.brandl | 2006-05-30 09:34:45 +0200 (Tue, 30 May 2006) | 3 lines
Disallow keyword args for exceptions.
........
r46554 | neal.norwitz | 2006-05-30 09:36:54 +0200 (Tue, 30 May 2006) | 5 lines
I'm impatient. I think this will fix a few more problems with the buildbots.
I'm not sure this is the best approach, but I can't think of anything better.
If this creates problems, feel free to revert, but I think it's safe and
should make things a little better.
........
r46555 | georg.brandl | 2006-05-30 10:17:00 +0200 (Tue, 30 May 2006) | 4 lines
Do the check for no keyword arguments in __init__ so that
subclasses of Exception can be supplied keyword args
........
r46556 | georg.brandl | 2006-05-30 10:47:19 +0200 (Tue, 30 May 2006) | 3 lines
Convert test_exceptions to unittest.
........
r46557 | andrew.kuchling | 2006-05-30 14:52:01 +0200 (Tue, 30 May 2006) | 1 line
Add SoC name, and reorganize this section a bit
........
r46559 | tim.peters | 2006-05-30 17:53:34 +0200 (Tue, 30 May 2006) | 11 lines
PyLong_FromString(): Continued fraction analysis (explained in
a new comment) suggests there are almost certainly large input
integers in all non-binary input bases for which one Python digit
too few is initally allocated to hold the final result. Instead
of assert-failing when that happens, allocate more space. Alas,
I estimate it would take a few days to find a specific such case,
so this isn't backed up by a new test (not to mention that such
a case may take hours to run, since conversion time is quadratic
in the number of digits, and preliminary attempts suggested that
the smallest such inputs contain at least a million digits).
........
r46560 | fredrik.lundh | 2006-05-30 19:11:48 +0200 (Tue, 30 May 2006) | 3 lines
changed find/rfind to return -1 for matches outside the source string
........
r46561 | bob.ippolito | 2006-05-30 19:37:54 +0200 (Tue, 30 May 2006) | 1 line
Change wrapping terminology to overflow masking
........
r46562 | fredrik.lundh | 2006-05-30 19:39:58 +0200 (Tue, 30 May 2006) | 3 lines
changed count to return 0 for slices outside the source string
........
r46568 | tim.peters | 2006-05-31 01:28:02 +0200 (Wed, 31 May 2006) | 2 lines
Whitespace normalization.
........
r46569 | brett.cannon | 2006-05-31 04:19:54 +0200 (Wed, 31 May 2006) | 5 lines
Clarify wording on default values for strptime(); defaults are used when better
values cannot be inferred.
Closes bug #1496315.
........
r46572 | neal.norwitz | 2006-05-31 09:43:27 +0200 (Wed, 31 May 2006) | 1 line
Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64
........
r46573 | neal.norwitz | 2006-05-31 10:01:08 +0200 (Wed, 31 May 2006) | 1 line
Revert last checkin, it is better to do make distclean
........
r46574 | neal.norwitz | 2006-05-31 11:02:44 +0200 (Wed, 31 May 2006) | 3 lines
On 64-bit platforms running test_struct after test_tarfile would fail
since the deprecation warning wouldn't be raised.
........
r46575 | thomas.heller | 2006-05-31 13:37:58 +0200 (Wed, 31 May 2006) | 3 lines
PyTuple_Pack is not available in Python 2.3, but ctypes must stay
compatible with that.
........
r46576 | andrew.kuchling | 2006-05-31 15:18:56 +0200 (Wed, 31 May 2006) | 1 line
'functional' module was renamed to 'functools'
........
r46577 | kristjan.jonsson | 2006-05-31 15:35:41 +0200 (Wed, 31 May 2006) | 1 line
Fixup the PCBuild8 project directory. exceptions.c have moved to Objects, and the functionalmodule.c has been replaced with _functoolsmodule.c. Other minor changes to .vcproj files and .sln to fix compilation
........
r46578 | andrew.kuchling | 2006-05-31 16:08:48 +0200 (Wed, 31 May 2006) | 15 lines
[Bug #1473048]
SimpleXMLRPCServer and DocXMLRPCServer don't look at
the path of the HTTP request at all; you can POST or
GET from / or /RPC2 or /blahblahblah with the same results.
Security scanners that look for /cgi-bin/phf will therefore report
lots of vulnerabilities.
Fix: add a .rpc_paths attribute to the SimpleXMLRPCServer class,
and report a 404 error if the path isn't on the allowed list.
Possibly-controversial aspect of this change: the default makes only
'/' and '/RPC2' legal. Maybe this will break people's applications
(though I doubt it). We could just set the default to an empty tuple,
which would exactly match the current behaviour.
........
r46579 | andrew.kuchling | 2006-05-31 16:12:47 +0200 (Wed, 31 May 2006) | 1 line
Mention SimpleXMLRPCServer change
........
r46580 | tim.peters | 2006-05-31 16:28:07 +0200 (Wed, 31 May 2006) | 2 lines
Trimmed trailing whitespace.
........
r46581 | tim.peters | 2006-05-31 17:33:22 +0200 (Wed, 31 May 2006) | 4 lines
_range_error(): Speed and simplify (there's no real need for
loops here). Assert that size_t is actually big enough, and
that f->size is at least one. Wrap a long line.
........
r46582 | tim.peters | 2006-05-31 17:34:37 +0200 (Wed, 31 May 2006) | 2 lines
Repaired error in new comment.
........
r46584 | neal.norwitz | 2006-06-01 07:32:49 +0200 (Thu, 01 Jun 2006) | 4 lines
Remove ; at end of macro. There was a compiler recently that warned
about extra semi-colons. It may have been the HP C compiler.
This file will trigger a bunch of those warnings now.
........
r46585 | georg.brandl | 2006-06-01 08:39:19 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly unpickle 2.4 exceptions via __setstate__ (patch #1498571)
........
r46586 | georg.brandl | 2006-06-01 10:27:32 +0200 (Thu, 01 Jun 2006) | 3 lines
Correctly allocate complex types with tp_alloc. (bug #1498638)
........
r46587 | georg.brandl | 2006-06-01 14:30:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Correctly dispatch Faults in loads (patch #1498627)
........
r46588 | georg.brandl | 2006-06-01 15:00:49 +0200 (Thu, 01 Jun 2006) | 3 lines
Some code style tweaks, and remove apply.
........
r46589 | armin.rigo | 2006-06-01 15:19:12 +0200 (Thu, 01 Jun 2006) | 5 lines
[ 1497053 ] Let dicts propagate the exceptions in user __eq__().
[ 1456209 ] dictresize() vulnerability ( <- backport candidate ).
........
r46590 | tim.peters | 2006-06-01 15:41:46 +0200 (Thu, 01 Jun 2006) | 2 lines
Whitespace normalization.
........
r46591 | tim.peters | 2006-06-01 15:49:23 +0200 (Thu, 01 Jun 2006) | 2 lines
Record bugs 1275608 and 1456209 as being fixed.
........
r46592 | tim.peters | 2006-06-01 15:56:26 +0200 (Thu, 01 Jun 2006) | 5 lines
Re-enable a new empty-string test added during the NFS sprint,
but disabled then because str and unicode strings gave different
results. The implementations were repaired later during the
sprint, but the new test remained disabled.
........
r46594 | tim.peters | 2006-06-01 17:50:44 +0200 (Thu, 01 Jun 2006) | 7 lines
Armin committed his patch while I was reviewing it (I'm sure
he didn't know this), so merged in some changes I made during
review. Nothing material apart from changing a new `mask` local
from int to Py_ssize_t. Mostly this is repairing comments that
were made incorrect, and adding new comments. Also a few
minor code rewrites for clarity or helpful succinctness.
........
r46599 | neal.norwitz | 2006-06-02 06:45:53 +0200 (Fri, 02 Jun 2006) | 1 line
Convert docstrings to comments so regrtest -v prints method names
........
r46600 | neal.norwitz | 2006-06-02 06:50:49 +0200 (Fri, 02 Jun 2006) | 2 lines
Fix memory leak found by valgrind.
........
r46601 | neal.norwitz | 2006-06-02 06:54:52 +0200 (Fri, 02 Jun 2006) | 1 line
More memory leaks from valgrind
........
r46602 | neal.norwitz | 2006-06-02 08:23:00 +0200 (Fri, 02 Jun 2006) | 11 lines
Patch #1357836:
Prevent an invalid memory read from test_coding in case the done flag is set.
In that case, the loop isn't entered. I wonder if rather than setting
the done flag in the cases before the loop, if they should just exit early.
This code looks like it should be refactored.
Backport candidate (also the early break above if decoding_fgets fails)
........
r46603 | martin.blais | 2006-06-02 15:03:43 +0200 (Fri, 02 Jun 2006) | 1 line
Fixed struct test to not use unittest.
........
r46605 | tim.peters | 2006-06-03 01:22:51 +0200 (Sat, 03 Jun 2006) | 10 lines
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got
displayed in seemingly random order (the hash-induced order
produced by dict.__repr__). None of this was documented.
Now pprint functions always sort dicts by key, and the docs
promise it.
This was proposed and agreed to during the PyCon 2006 core
sprint -- I just didn't have time for it before now.
........
2006-06-08 11:42:34 -03:00
|
|
|
if (!PyArg_UnpackTuple(args, "call_tracing", 2, 2, &func, &funcargs))
|
2003-04-09 16:06:21 -03:00
|
|
|
return NULL;
|
|
|
|
return _PyEval_CallTracing(func, funcargs);
|
|
|
|
}
|
|
|
|
|
2003-02-05 19:13:00 -04:00
|
|
|
PyDoc_STRVAR(callstats_doc,
|
|
|
|
"callstats() -> tuple of integers\n\
|
|
|
|
\n\
|
|
|
|
Return a tuple of function call statistics, if CALL_PROFILE was defined\n\
|
|
|
|
when Python was built. Otherwise, return None.\n\
|
|
|
|
\n\
|
|
|
|
When enabled, this function returns detailed, implementation-specific\n\
|
|
|
|
details about the number of function calls executed. The return value is\n\
|
|
|
|
a 11-tuple where the entries in the tuple are counts of:\n\
|
|
|
|
0. all function calls\n\
|
|
|
|
1. calls to PyFunction_Type objects\n\
|
|
|
|
2. PyFunction calls that do not create an argument tuple\n\
|
|
|
|
3. PyFunction calls that do not create an argument tuple\n\
|
|
|
|
and bypass PyEval_EvalCodeEx()\n\
|
|
|
|
4. PyMethod calls\n\
|
|
|
|
5. PyMethod calls on bound methods\n\
|
|
|
|
6. PyType calls\n\
|
|
|
|
7. PyCFunction calls\n\
|
|
|
|
8. generator calls\n\
|
|
|
|
9. All other calls\n\
|
|
|
|
10. Number of stack pops performed by call_function()"
|
|
|
|
);
|
2000-12-06 17:47:46 -04:00
|
|
|
|
2006-04-21 07:40:58 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1996-05-23 19:45:41 -03:00
|
|
|
#ifdef Py_TRACE_REFS
|
1996-05-24 17:48:31 -03:00
|
|
|
/* Defined in objects.c because it uses static globals if that file */
|
2000-07-09 00:09:57 -03:00
|
|
|
extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
|
1995-08-29 06:18:14 -03:00
|
|
|
#endif
|
1996-05-24 17:48:31 -03:00
|
|
|
|
1997-01-24 00:07:45 -04:00
|
|
|
#ifdef DYNAMIC_EXECUTION_PROFILE
|
|
|
|
/* Defined in ceval.c because it uses static globals if that file */
|
2000-07-09 00:09:57 -03:00
|
|
|
extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *);
|
1997-01-24 00:07:45 -04:00
|
|
|
#endif
|
|
|
|
|
2006-04-21 07:40:58 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyMethodDef sys_methods[] = {
|
1997-01-24 00:07:45 -04:00
|
|
|
/* Might as well keep this in alphabetic order */
|
2006-01-05 22:40:53 -04:00
|
|
|
{"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
|
2003-02-05 19:13:00 -04:00
|
|
|
callstats_doc},
|
2001-08-16 10:15:00 -03:00
|
|
|
{"displayhook", sys_displayhook, METH_O, displayhook_doc},
|
2003-02-28 23:20:41 -04:00
|
|
|
{"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
|
|
|
|
{"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc},
|
2001-08-16 10:15:00 -03:00
|
|
|
{"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
|
2002-03-27 09:03:09 -04:00
|
|
|
{"exit", sys_exit, METH_VARARGS, exit_doc},
|
2001-08-17 15:39:25 -03:00
|
|
|
#ifdef Py_USING_UNICODE
|
2006-01-05 22:40:53 -04:00
|
|
|
{"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
|
|
|
|
METH_NOARGS, getdefaultencoding_doc},
|
2001-08-17 15:39:25 -03:00
|
|
|
#endif
|
2001-07-18 13:17:16 -03:00
|
|
|
#ifdef HAVE_DLOPEN
|
2006-01-05 22:40:53 -04:00
|
|
|
{"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
|
2001-08-16 10:15:00 -03:00
|
|
|
getdlopenflags_doc},
|
2001-07-18 13:17:16 -03:00
|
|
|
#endif
|
1995-08-29 06:18:14 -03:00
|
|
|
#ifdef COUNT_ALLOCS
|
2001-08-16 10:15:00 -03:00
|
|
|
{"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
|
1995-08-29 06:18:14 -03:00
|
|
|
#endif
|
1997-01-24 00:07:45 -04:00
|
|
|
#ifdef DYNAMIC_EXECUTION_PROFILE
|
2001-08-16 10:15:00 -03:00
|
|
|
{"getdxp", _Py_GetDXProfile, METH_VARARGS},
|
1997-01-24 00:07:45 -04:00
|
|
|
#endif
|
2003-03-05 11:13:47 -04:00
|
|
|
#ifdef Py_USING_UNICODE
|
|
|
|
{"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
|
2006-01-05 22:40:53 -04:00
|
|
|
METH_NOARGS, getfilesystemencoding_doc},
|
2003-03-05 11:13:47 -04:00
|
|
|
#endif
|
1996-05-23 19:45:41 -03:00
|
|
|
#ifdef Py_TRACE_REFS
|
2001-08-16 10:15:00 -03:00
|
|
|
{"getobjects", _Py_GetObjects, METH_VARARGS},
|
2002-07-07 16:59:50 -03:00
|
|
|
#endif
|
|
|
|
#ifdef Py_REF_DEBUG
|
2001-08-16 10:15:00 -03:00
|
|
|
{"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
|
1995-08-29 06:18:14 -03:00
|
|
|
#endif
|
2001-10-24 17:47:48 -03:00
|
|
|
{"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},
|
2001-08-16 10:15:00 -03:00
|
|
|
{"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
|
2000-08-31 16:23:01 -03:00
|
|
|
getrecursionlimit_doc},
|
2001-08-16 10:15:00 -03:00
|
|
|
{"_getframe", sys_getframe, METH_VARARGS, getframe_doc},
|
2002-10-07 23:44:31 -03:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
{"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
|
|
|
|
getwindowsversion_doc},
|
|
|
|
#endif /* MS_WINDOWS */
|
1992-09-03 17:25:30 -03:00
|
|
|
#ifdef USE_MALLOPT
|
2001-08-16 10:15:00 -03:00
|
|
|
{"mdebug", sys_mdebug, METH_VARARGS},
|
1992-09-03 17:25:30 -03:00
|
|
|
#endif
|
2001-08-17 15:39:25 -03:00
|
|
|
#ifdef Py_USING_UNICODE
|
2001-08-16 10:15:00 -03:00
|
|
|
{"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
|
2006-01-05 22:40:53 -04:00
|
|
|
setdefaultencoding_doc},
|
2001-08-17 15:39:25 -03:00
|
|
|
#endif
|
2001-08-16 10:15:00 -03:00
|
|
|
{"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
|
2006-01-05 22:40:53 -04:00
|
|
|
setcheckinterval_doc},
|
2003-07-06 15:36:54 -03:00
|
|
|
{"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
|
2006-01-05 22:40:53 -04:00
|
|
|
getcheckinterval_doc},
|
2001-07-18 13:17:16 -03:00
|
|
|
#ifdef HAVE_DLOPEN
|
2006-01-05 22:40:53 -04:00
|
|
|
{"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
|
2001-08-16 10:15:00 -03:00
|
|
|
setdlopenflags_doc},
|
2001-07-18 13:17:16 -03:00
|
|
|
#endif
|
2002-03-03 11:12:58 -04:00
|
|
|
{"setprofile", sys_setprofile, METH_O, setprofile_doc},
|
2001-08-16 10:15:00 -03:00
|
|
|
{"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
|
2000-08-31 16:23:01 -03:00
|
|
|
setrecursionlimit_doc},
|
2004-06-08 05:17:44 -03:00
|
|
|
#ifdef WITH_TSC
|
|
|
|
{"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},
|
|
|
|
#endif
|
2002-03-03 11:12:58 -04:00
|
|
|
{"settrace", sys_settrace, METH_O, settrace_doc},
|
2003-04-09 16:06:21 -03:00
|
|
|
{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
|
1990-12-20 11:06:42 -04:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
list_builtin_module_names(void)
|
1993-01-26 09:33:44 -04:00
|
|
|
{
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *list = PyList_New(0);
|
1993-01-26 09:33:44 -04:00
|
|
|
int i;
|
|
|
|
if (list == NULL)
|
|
|
|
return NULL;
|
1997-11-04 13:04:34 -04:00
|
|
|
for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
|
1997-05-05 17:56:21 -03:00
|
|
|
PyObject *name = PyString_FromString(
|
1997-11-04 13:04:34 -04:00
|
|
|
PyImport_Inittab[i].name);
|
1993-01-26 09:33:44 -04:00
|
|
|
if (name == NULL)
|
|
|
|
break;
|
1997-04-29 15:33:38 -03:00
|
|
|
PyList_Append(list, name);
|
|
|
|
Py_DECREF(name);
|
1993-01-26 09:33:44 -04:00
|
|
|
}
|
1997-04-29 15:33:38 -03:00
|
|
|
if (PyList_Sort(list) != 0) {
|
|
|
|
Py_DECREF(list);
|
1994-08-30 05:27:36 -03:00
|
|
|
list = NULL;
|
|
|
|
}
|
1997-01-06 18:55:54 -04:00
|
|
|
if (list) {
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *v = PyList_AsTuple(list);
|
|
|
|
Py_DECREF(list);
|
1997-01-06 18:55:54 -04:00
|
|
|
list = v;
|
|
|
|
}
|
1993-01-26 09:33:44 -04:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2000-12-15 18:02:05 -04:00
|
|
|
static PyObject *warnoptions = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
PySys_ResetWarnOptions(void)
|
|
|
|
{
|
|
|
|
if (warnoptions == NULL || !PyList_Check(warnoptions))
|
|
|
|
return;
|
|
|
|
PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PySys_AddWarnOption(char *s)
|
|
|
|
{
|
|
|
|
PyObject *str;
|
|
|
|
|
|
|
|
if (warnoptions == NULL || !PyList_Check(warnoptions)) {
|
|
|
|
Py_XDECREF(warnoptions);
|
|
|
|
warnoptions = PyList_New(0);
|
|
|
|
if (warnoptions == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
str = PyString_FromString(s);
|
|
|
|
if (str != NULL) {
|
|
|
|
PyList_Append(warnoptions, str);
|
|
|
|
Py_DECREF(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-06 00:34:39 -03:00
|
|
|
/* XXX This doc string is too long to be a single string literal in VC++ 5.0.
|
|
|
|
Two literals concatenated works just fine. If you have a K&R compiler
|
|
|
|
or other abomination that however *does* understand longer strings,
|
|
|
|
get rid of the !!! comment in the middle and the quotes that surround it. */
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_VAR(sys_doc) =
|
|
|
|
PyDoc_STR(
|
1998-06-27 16:43:25 -03:00
|
|
|
"This module provides access to some objects used or maintained by the\n\
|
|
|
|
interpreter and to functions that interact strongly with the interpreter.\n\
|
|
|
|
\n\
|
|
|
|
Dynamic objects:\n\
|
|
|
|
\n\
|
|
|
|
argv -- command line arguments; argv[0] is the script pathname if known\n\
|
|
|
|
path -- module search path; path[0] is the script directory, else ''\n\
|
|
|
|
modules -- dictionary of loaded modules\n\
|
2001-03-22 22:46:52 -04:00
|
|
|
\n\
|
|
|
|
displayhook -- called to show results in an interactive session\n\
|
|
|
|
excepthook -- called to handle any uncaught exception other than SystemExit\n\
|
|
|
|
To customize printing in an interactive session or to install a custom\n\
|
|
|
|
top-level exception handler, assign other functions to replace these.\n\
|
|
|
|
\n\
|
|
|
|
exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\
|
|
|
|
Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
\n\
|
|
|
|
stdin -- standard input file object; used by raw_input() and input()\n\
|
|
|
|
stdout -- standard output file object; used by the print statement\n\
|
|
|
|
stderr -- standard error object; used for error messages\n\
|
2001-03-22 22:46:52 -04:00
|
|
|
By assigning other file objects (or objects that behave like files)\n\
|
|
|
|
to these, it is possible to redirect all of the interpreter's I/O.\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
\n\
|
|
|
|
last_type -- type of last uncaught exception\n\
|
|
|
|
last_value -- value of last uncaught exception\n\
|
|
|
|
last_traceback -- traceback of last uncaught exception\n\
|
|
|
|
These three are only available in an interactive session after a\n\
|
|
|
|
traceback has been printed.\n\
|
|
|
|
\n\
|
|
|
|
exc_type -- type of exception currently being handled\n\
|
|
|
|
exc_value -- value of exception currently being handled\n\
|
|
|
|
exc_traceback -- traceback of exception currently being handled\n\
|
|
|
|
The function exc_info() should be used instead of these three,\n\
|
|
|
|
because it is thread-safe.\n\
|
1999-01-14 15:07:00 -04:00
|
|
|
"
|
2002-06-09 10:33:54 -03:00
|
|
|
)
|
2001-03-22 22:46:52 -04:00
|
|
|
/* concatenating string here */
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STR(
|
1999-01-14 15:07:00 -04:00
|
|
|
"\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
Static objects:\n\
|
|
|
|
\n\
|
|
|
|
maxint -- the largest supported integer (the smallest is -maxint-1)\n\
|
2001-06-27 03:28:56 -03:00
|
|
|
maxunicode -- the largest supported character\n\
|
2002-01-28 20:53:41 -04:00
|
|
|
builtin_module_names -- tuple of module names built into this interpreter\n\
|
2000-04-13 12:29:10 -03:00
|
|
|
version -- the version of this interpreter as a string\n\
|
|
|
|
version_info -- version information as a tuple\n\
|
|
|
|
hexversion -- version information encoded as a single integer\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
copyright -- copyright notice pertaining to this interpreter\n\
|
|
|
|
platform -- platform identifier\n\
|
|
|
|
executable -- pathname of this Python interpreter\n\
|
|
|
|
prefix -- prefix used to find the Python library\n\
|
|
|
|
exec_prefix -- prefix used to find the machine-specific Python library\n\
|
2001-03-22 22:46:52 -04:00
|
|
|
"
|
2002-06-09 10:33:54 -03:00
|
|
|
)
|
2001-03-22 22:46:52 -04:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
/* concatenating string here */
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STR(
|
2001-03-22 22:46:52 -04:00
|
|
|
"dllhandle -- [Windows only] integer handle of the Python DLL\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
winver -- [Windows only] version number of the Python DLL\n\
|
2001-03-22 22:46:52 -04:00
|
|
|
"
|
2002-06-09 10:33:54 -03:00
|
|
|
)
|
2001-03-22 22:46:52 -04:00
|
|
|
#endif /* MS_WINDOWS */
|
2002-06-09 10:33:54 -03:00
|
|
|
PyDoc_STR(
|
2001-03-22 22:46:52 -04:00
|
|
|
"__stdin__ -- the original stdin; don't touch!\n\
|
|
|
|
__stdout__ -- the original stdout; don't touch!\n\
|
|
|
|
__stderr__ -- the original stderr; don't touch!\n\
|
|
|
|
__displayhook__ -- the original displayhook; don't touch!\n\
|
|
|
|
__excepthook__ -- the original excepthook; don't touch!\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
\n\
|
|
|
|
Functions:\n\
|
|
|
|
\n\
|
2001-01-11 01:41:27 -04:00
|
|
|
displayhook() -- print an object to the screen, and save it in __builtin__._\n\
|
2001-03-22 22:46:52 -04:00
|
|
|
excepthook() -- print an exception and its traceback to sys.stderr\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
exc_info() -- return thread-safe information about the current exception\n\
|
2003-02-28 23:20:41 -04:00
|
|
|
exc_clear() -- clear the exception state for the current thread\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
exit() -- exit the interpreter by raising SystemExit\n\
|
2001-07-18 13:17:16 -03:00
|
|
|
getdlopenflags() -- returns flags to be used for dlopen() calls\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
getrefcount() -- return the reference count for an object (plus one :-)\n\
|
2000-08-31 16:23:01 -03:00
|
|
|
getrecursionlimit() -- return the max recursion depth for the interpreter\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
setcheckinterval() -- control how often the interpreter checks for events\n\
|
2001-07-18 13:17:16 -03:00
|
|
|
setdlopenflags() -- set the flags to be used for dlopen() calls\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
setprofile() -- set the global profiling function\n\
|
2000-08-31 16:23:01 -03:00
|
|
|
setrecursionlimit() -- set the max recursion depth for the interpreter\n\
|
1998-06-27 16:43:25 -03:00
|
|
|
settrace() -- set the global debug tracing function\n\
|
2000-08-14 17:59:57 -03:00
|
|
|
"
|
2002-06-09 10:33:54 -03:00
|
|
|
)
|
2000-08-14 17:59:57 -03:00
|
|
|
/* end of sys_doc */ ;
|
1998-06-27 16:43:25 -03:00
|
|
|
|
2005-01-23 05:41:49 -04:00
|
|
|
static int
|
|
|
|
_check_and_flush (FILE *stream)
|
|
|
|
{
|
|
|
|
int prev_fail = ferror (stream);
|
|
|
|
return fflush (stream) || prev_fail ? EOF : 0;
|
|
|
|
}
|
|
|
|
|
2006-01-05 19:38:54 -04:00
|
|
|
/* Subversion branch and revision management */
|
|
|
|
static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
|
|
|
|
static const char headurl[] = "$HeadURL$";
|
|
|
|
static int svn_initialized;
|
|
|
|
static char patchlevel_revision[50]; /* Just the number */
|
|
|
|
static char branch[50];
|
|
|
|
static char shortbranch[50];
|
|
|
|
static const char *svn_revision;
|
|
|
|
|
2006-01-05 22:42:46 -04:00
|
|
|
static void
|
|
|
|
svnversion_init(void)
|
2006-01-05 19:38:54 -04:00
|
|
|
{
|
|
|
|
const char *python, *br_start, *br_end, *br_end2, *svnversion;
|
2006-02-16 10:37:16 -04:00
|
|
|
Py_ssize_t len;
|
|
|
|
int istag;
|
2006-01-05 19:38:54 -04:00
|
|
|
|
|
|
|
if (svn_initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
python = strstr(headurl, "/python/");
|
|
|
|
if (!python)
|
|
|
|
Py_FatalError("subversion keywords missing");
|
|
|
|
|
|
|
|
br_start = python + 8;
|
|
|
|
br_end = strchr(br_start, '/');
|
2006-01-05 22:40:53 -04:00
|
|
|
/* Works even for trunk,
|
2006-01-05 19:38:54 -04:00
|
|
|
as we are in trunk/Python/sysmodule.c */
|
|
|
|
br_end2 = strchr(br_end+1, '/');
|
|
|
|
|
|
|
|
istag = strncmp(br_start, "tags", 4) == 0;
|
|
|
|
if (strncmp(br_start, "trunk", 5) == 0) {
|
|
|
|
strcpy(branch, "trunk");
|
|
|
|
strcpy(shortbranch, "trunk");
|
|
|
|
|
2006-01-05 22:40:53 -04:00
|
|
|
}
|
2006-01-05 19:38:54 -04:00
|
|
|
else if (istag || strncmp(br_start, "branches", 8) == 0) {
|
|
|
|
len = br_end2 - br_start;
|
|
|
|
strncpy(branch, br_start, len);
|
|
|
|
branch[len] = '\0';
|
|
|
|
|
|
|
|
len = br_end2 - (br_end + 1);
|
|
|
|
strncpy(shortbranch, br_end + 1, len);
|
|
|
|
shortbranch[len] = '\0';
|
2006-01-05 22:40:53 -04:00
|
|
|
}
|
2006-01-05 19:38:54 -04:00
|
|
|
else {
|
|
|
|
Py_FatalError("bad HeadURL");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
svnversion = _Py_svnversion();
|
|
|
|
if (strcmp(svnversion, "exported") != 0)
|
|
|
|
svn_revision = svnversion;
|
|
|
|
else if (istag) {
|
|
|
|
len = strlen(_patchlevel_revision);
|
|
|
|
strncpy(patchlevel_revision, _patchlevel_revision + 11,
|
|
|
|
len - 13);
|
|
|
|
patchlevel_revision[len - 13] = '\0';
|
|
|
|
svn_revision = patchlevel_revision;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
svn_revision = "";
|
2006-01-05 22:40:53 -04:00
|
|
|
|
2006-01-05 19:38:54 -04:00
|
|
|
svn_initialized = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return svnversion output if available.
|
|
|
|
Else return Revision of patchlevel.h if on branch.
|
|
|
|
Else return empty string */
|
|
|
|
const char*
|
|
|
|
Py_SubversionRevision()
|
|
|
|
{
|
|
|
|
svnversion_init();
|
|
|
|
return svn_revision;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
Py_SubversionShortBranch()
|
|
|
|
{
|
|
|
|
svnversion_init();
|
|
|
|
return shortbranch;
|
|
|
|
}
|
|
|
|
|
1997-08-02 00:10:38 -03:00
|
|
|
PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
_PySys_Init(void)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
1997-08-02 00:10:38 -03:00
|
|
|
PyObject *m, *v, *sysdict;
|
|
|
|
PyObject *sysin, *sysout, *syserr;
|
2000-04-13 17:03:20 -03:00
|
|
|
char *s;
|
2003-05-10 04:10:12 -03:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
char buf[10];
|
|
|
|
#endif
|
1997-08-02 00:10:38 -03:00
|
|
|
|
1998-06-27 16:43:25 -03:00
|
|
|
m = Py_InitModule3("sys", sys_methods, sys_doc);
|
2006-01-19 02:09:39 -04:00
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
1997-04-29 15:33:38 -03:00
|
|
|
sysdict = PyModule_GetDict(m);
|
1997-08-02 00:10:38 -03:00
|
|
|
|
2005-10-02 21:54:56 -03:00
|
|
|
{
|
|
|
|
/* XXX: does this work on Win/Win64? (see posix_fstat) */
|
|
|
|
struct stat sb;
|
|
|
|
if (fstat(fileno(stdin), &sb) == 0 &&
|
|
|
|
S_ISDIR(sb.st_mode)) {
|
2006-03-09 01:58:11 -04:00
|
|
|
/* There's nothing more we can do. */
|
|
|
|
/* Py_FatalError() will core dump, so just exit. */
|
|
|
|
PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2005-10-02 21:54:56 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-27 14:56:16 -04:00
|
|
|
/* Closing the standard FILE* if sys.std* goes aways causes problems
|
|
|
|
* for embedded Python usages. Closing them when somebody explicitly
|
|
|
|
* invokes .close() might be possible, but the FAQ promises they get
|
|
|
|
* never closed. However, we still need to get write errors when
|
|
|
|
* writing fails (e.g. because stdout is redirected), so we flush the
|
|
|
|
* streams and check for errors before the file objects are deleted.
|
|
|
|
* On OS X, fflush()ing stdin causes an error, so we exempt stdin
|
|
|
|
* from that procedure.
|
|
|
|
*/
|
|
|
|
sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
|
2005-01-23 05:41:49 -04:00
|
|
|
sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
|
|
|
|
syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
|
1997-04-29 15:33:38 -03:00
|
|
|
if (PyErr_Occurred())
|
1997-08-02 00:10:38 -03:00
|
|
|
return NULL;
|
2003-05-10 04:10:12 -03:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
if(isatty(_fileno(stdin))){
|
|
|
|
sprintf(buf, "cp%d", GetConsoleCP());
|
|
|
|
if (!PyFile_SetEncoding(sysin, buf))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(isatty(_fileno(stdout))) {
|
|
|
|
sprintf(buf, "cp%d", GetConsoleOutputCP());
|
|
|
|
if (!PyFile_SetEncoding(sysout, buf))
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
if(isatty(_fileno(stderr))) {
|
|
|
|
sprintf(buf, "cp%d", GetConsoleOutputCP());
|
|
|
|
if (!PyFile_SetEncoding(syserr, buf))
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-05-10 04:10:12 -03:00
|
|
|
#endif
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
PyDict_SetItemString(sysdict, "stdin", sysin);
|
|
|
|
PyDict_SetItemString(sysdict, "stdout", sysout);
|
|
|
|
PyDict_SetItemString(sysdict, "stderr", syserr);
|
1998-02-19 16:53:06 -04:00
|
|
|
/* Make backup copies for cleanup */
|
|
|
|
PyDict_SetItemString(sysdict, "__stdin__", sysin);
|
|
|
|
PyDict_SetItemString(sysdict, "__stdout__", sysout);
|
|
|
|
PyDict_SetItemString(sysdict, "__stderr__", syserr);
|
2001-03-22 22:46:52 -04:00
|
|
|
PyDict_SetItemString(sysdict, "__displayhook__",
|
|
|
|
PyDict_GetItemString(sysdict, "displayhook"));
|
|
|
|
PyDict_SetItemString(sysdict, "__excepthook__",
|
|
|
|
PyDict_GetItemString(sysdict, "excepthook"));
|
1997-08-02 00:10:38 -03:00
|
|
|
Py_XDECREF(sysin);
|
|
|
|
Py_XDECREF(sysout);
|
|
|
|
Py_XDECREF(syserr);
|
1997-04-29 15:33:38 -03:00
|
|
|
PyDict_SetItemString(sysdict, "version",
|
|
|
|
v = PyString_FromString(Py_GetVersion()));
|
1999-01-27 12:33:19 -04:00
|
|
|
Py_XDECREF(v);
|
1999-01-03 08:55:39 -04:00
|
|
|
PyDict_SetItemString(sysdict, "hexversion",
|
|
|
|
v = PyInt_FromLong(PY_VERSION_HEX));
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_XDECREF(v);
|
2006-01-05 19:38:54 -04:00
|
|
|
svnversion_init();
|
|
|
|
v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision);
|
|
|
|
PyDict_SetItemString(sysdict, "subversion", v);
|
2005-12-17 21:27:35 -04:00
|
|
|
Py_XDECREF(v);
|
2000-04-13 14:44:51 -03:00
|
|
|
/*
|
|
|
|
* These release level checks are mutually exclusive and cover
|
|
|
|
* the field, so don't get too fancy with the pre-processor!
|
|
|
|
*/
|
|
|
|
#if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA
|
2000-04-13 17:03:20 -03:00
|
|
|
s = "alpha";
|
2000-08-31 12:21:11 -03:00
|
|
|
#elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_BETA
|
2000-04-13 17:03:20 -03:00
|
|
|
s = "beta";
|
2000-08-31 12:21:11 -03:00
|
|
|
#elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA
|
2000-04-13 17:03:20 -03:00
|
|
|
s = "candidate";
|
2000-08-31 12:21:11 -03:00
|
|
|
#elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL
|
2000-04-13 17:03:20 -03:00
|
|
|
s = "final";
|
2000-04-13 14:44:51 -03:00
|
|
|
#endif
|
2000-04-13 12:29:10 -03:00
|
|
|
PyDict_SetItemString(sysdict, "version_info",
|
2000-04-13 17:03:20 -03:00
|
|
|
v = Py_BuildValue("iiisi", PY_MAJOR_VERSION,
|
2000-04-13 12:29:10 -03:00
|
|
|
PY_MINOR_VERSION,
|
2000-04-13 17:03:20 -03:00
|
|
|
PY_MICRO_VERSION, s,
|
2000-04-13 14:44:51 -03:00
|
|
|
PY_RELEASE_SERIAL));
|
2000-04-13 12:29:10 -03:00
|
|
|
Py_XDECREF(v);
|
2002-09-03 10:25:17 -03:00
|
|
|
PyDict_SetItemString(sysdict, "api_version",
|
|
|
|
v = PyInt_FromLong(PYTHON_API_VERSION));
|
|
|
|
Py_XDECREF(v);
|
1997-04-29 15:33:38 -03:00
|
|
|
PyDict_SetItemString(sysdict, "copyright",
|
|
|
|
v = PyString_FromString(Py_GetCopyright()));
|
|
|
|
Py_XDECREF(v);
|
|
|
|
PyDict_SetItemString(sysdict, "platform",
|
|
|
|
v = PyString_FromString(Py_GetPlatform()));
|
|
|
|
Py_XDECREF(v);
|
1997-05-22 17:41:20 -03:00
|
|
|
PyDict_SetItemString(sysdict, "executable",
|
|
|
|
v = PyString_FromString(Py_GetProgramFullPath()));
|
|
|
|
Py_XDECREF(v);
|
1997-04-29 15:33:38 -03:00
|
|
|
PyDict_SetItemString(sysdict, "prefix",
|
|
|
|
v = PyString_FromString(Py_GetPrefix()));
|
|
|
|
Py_XDECREF(v);
|
|
|
|
PyDict_SetItemString(sysdict, "exec_prefix",
|
|
|
|
v = PyString_FromString(Py_GetExecPrefix()));
|
|
|
|
Py_XDECREF(v);
|
|
|
|
PyDict_SetItemString(sysdict, "maxint",
|
|
|
|
v = PyInt_FromLong(PyInt_GetMax()));
|
|
|
|
Py_XDECREF(v);
|
2001-08-17 15:39:25 -03:00
|
|
|
#ifdef Py_USING_UNICODE
|
2001-06-27 03:28:56 -03:00
|
|
|
PyDict_SetItemString(sysdict, "maxunicode",
|
|
|
|
v = PyInt_FromLong(PyUnicode_GetMax()));
|
|
|
|
Py_XDECREF(v);
|
2001-08-17 15:39:25 -03:00
|
|
|
#endif
|
1997-04-29 15:33:38 -03:00
|
|
|
PyDict_SetItemString(sysdict, "builtin_module_names",
|
1995-01-02 15:04:15 -04:00
|
|
|
v = list_builtin_module_names());
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_XDECREF(v);
|
2000-08-14 12:47:03 -03:00
|
|
|
{
|
|
|
|
/* Assumes that longs are at least 2 bytes long.
|
|
|
|
Should be safe! */
|
|
|
|
unsigned long number = 1;
|
2000-08-15 01:24:43 -03:00
|
|
|
char *value;
|
2000-08-14 12:47:03 -03:00
|
|
|
|
|
|
|
s = (char *) &number;
|
|
|
|
if (s[0] == 0)
|
2000-08-15 01:24:43 -03:00
|
|
|
value = "big";
|
2000-08-14 12:47:03 -03:00
|
|
|
else
|
2000-08-15 01:24:43 -03:00
|
|
|
value = "little";
|
|
|
|
PyDict_SetItemString(sysdict, "byteorder",
|
2000-08-16 20:03:57 -03:00
|
|
|
v = PyString_FromString(value));
|
|
|
|
Py_XDECREF(v);
|
2000-08-14 12:47:03 -03:00
|
|
|
}
|
1996-08-23 15:14:47 -03:00
|
|
|
#ifdef MS_COREDLL
|
1997-04-29 15:33:38 -03:00
|
|
|
PyDict_SetItemString(sysdict, "dllhandle",
|
2000-06-28 19:07:35 -03:00
|
|
|
v = PyLong_FromVoidPtr(PyWin_DLLhModule));
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_XDECREF(v);
|
|
|
|
PyDict_SetItemString(sysdict, "winver",
|
1997-09-29 20:34:23 -03:00
|
|
|
v = PyString_FromString(PyWin_DLLVersionString));
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_XDECREF(v);
|
1996-04-08 23:37:57 -03:00
|
|
|
#endif
|
2000-12-15 18:02:05 -04:00
|
|
|
if (warnoptions == NULL) {
|
|
|
|
warnoptions = PyList_New(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Py_INCREF(warnoptions);
|
|
|
|
}
|
|
|
|
if (warnoptions != NULL) {
|
2001-01-13 18:06:05 -04:00
|
|
|
PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
|
2000-12-15 18:02:05 -04:00
|
|
|
}
|
2006-01-05 22:40:53 -04:00
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
if (PyErr_Occurred())
|
1997-08-02 00:10:38 -03:00
|
|
|
return NULL;
|
|
|
|
return m;
|
1990-11-18 13:41:40 -04:00
|
|
|
}
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
makepathobject(char *path, int delim)
|
1990-11-18 13:41:40 -04:00
|
|
|
{
|
1990-12-20 11:06:42 -04:00
|
|
|
int i, n;
|
|
|
|
char *p;
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *v, *w;
|
2006-01-05 22:40:53 -04:00
|
|
|
|
1990-12-20 11:06:42 -04:00
|
|
|
n = 1;
|
|
|
|
p = path;
|
|
|
|
while ((p = strchr(p, delim)) != NULL) {
|
|
|
|
n++;
|
|
|
|
p++;
|
|
|
|
}
|
1997-04-29 15:33:38 -03:00
|
|
|
v = PyList_New(n);
|
1990-12-20 11:06:42 -04:00
|
|
|
if (v == NULL)
|
|
|
|
return NULL;
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
p = strchr(path, delim);
|
|
|
|
if (p == NULL)
|
|
|
|
p = strchr(path, '\0'); /* End of string */
|
1997-04-29 15:33:38 -03:00
|
|
|
w = PyString_FromStringAndSize(path, (int) (p - path));
|
1990-12-20 11:06:42 -04:00
|
|
|
if (w == NULL) {
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_DECREF(v);
|
1990-12-20 11:06:42 -04:00
|
|
|
return NULL;
|
1990-11-18 13:41:40 -04:00
|
|
|
}
|
1997-04-29 15:33:38 -03:00
|
|
|
PyList_SetItem(v, i, w);
|
1990-12-20 11:06:42 -04:00
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
|
|
|
path = p+1;
|
1990-11-18 13:41:40 -04:00
|
|
|
}
|
1990-12-20 11:06:42 -04:00
|
|
|
return v;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-22 15:47:25 -03:00
|
|
|
PySys_SetPath(char *path)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *v;
|
1990-12-20 11:06:42 -04:00
|
|
|
if ((v = makepathobject(path, DELIM)) == NULL)
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_FatalError("can't create sys.path");
|
|
|
|
if (PySys_SetObject("path", v) != 0)
|
|
|
|
Py_FatalError("can't assign sys.path");
|
|
|
|
Py_DECREF(v);
|
1990-12-20 11:06:42 -04:00
|
|
|
}
|
|
|
|
|
1997-04-29 15:33:38 -03:00
|
|
|
static PyObject *
|
2000-07-22 15:47:25 -03:00
|
|
|
makeargvobject(int argc, char **argv)
|
1990-12-20 11:06:42 -04:00
|
|
|
{
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *av;
|
1992-01-14 14:42:53 -04:00
|
|
|
if (argc <= 0 || argv == NULL) {
|
|
|
|
/* Ensure at least one (empty) argument is seen */
|
|
|
|
static char *empty_argv[1] = {""};
|
|
|
|
argv = empty_argv;
|
|
|
|
argc = 1;
|
|
|
|
}
|
1997-04-29 15:33:38 -03:00
|
|
|
av = PyList_New(argc);
|
1990-12-20 11:06:42 -04:00
|
|
|
if (av != NULL) {
|
1990-11-18 13:41:40 -04:00
|
|
|
int i;
|
1990-12-20 11:06:42 -04:00
|
|
|
for (i = 0; i < argc; i++) {
|
2003-05-03 06:14:54 -03:00
|
|
|
#ifdef __VMS
|
|
|
|
PyObject *v;
|
|
|
|
|
|
|
|
/* argv[0] is the script pathname if known */
|
|
|
|
if (i == 0) {
|
|
|
|
char* fn = decc$translate_vms(argv[0]);
|
|
|
|
if ((fn == (char *)0) || fn == (char *)-1)
|
|
|
|
v = PyString_FromString(argv[0]);
|
|
|
|
else
|
|
|
|
v = PyString_FromString(
|
|
|
|
decc$translate_vms(argv[0]));
|
|
|
|
} else
|
|
|
|
v = PyString_FromString(argv[i]);
|
|
|
|
#else
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *v = PyString_FromString(argv[i]);
|
2003-05-03 06:14:54 -03:00
|
|
|
#endif
|
1990-12-20 11:06:42 -04:00
|
|
|
if (v == NULL) {
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_DECREF(av);
|
1990-12-20 11:06:42 -04:00
|
|
|
av = NULL;
|
|
|
|
break;
|
1990-11-18 13:41:40 -04:00
|
|
|
}
|
1997-04-29 15:33:38 -03:00
|
|
|
PyList_SetItem(av, i, v);
|
1990-11-18 13:41:40 -04:00
|
|
|
}
|
|
|
|
}
|
1990-12-20 11:06:42 -04:00
|
|
|
return av;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-22 15:47:25 -03:00
|
|
|
PySys_SetArgv(int argc, char **argv)
|
1990-12-20 11:06:42 -04:00
|
|
|
{
|
2003-02-19 11:25:10 -04:00
|
|
|
#if defined(HAVE_REALPATH)
|
|
|
|
char fullpath[MAXPATHLEN];
|
|
|
|
#elif defined(MS_WINDOWS)
|
2003-01-08 10:33:48 -04:00
|
|
|
char fullpath[MAX_PATH];
|
|
|
|
#endif
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *av = makeargvobject(argc, argv);
|
|
|
|
PyObject *path = PySys_GetObject("path");
|
1990-12-20 11:06:42 -04:00
|
|
|
if (av == NULL)
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_FatalError("no mem for sys.argv");
|
|
|
|
if (PySys_SetObject("argv", av) != 0)
|
|
|
|
Py_FatalError("can't assign sys.argv");
|
1996-07-30 17:35:50 -03:00
|
|
|
if (path != NULL) {
|
1997-04-25 12:38:31 -03:00
|
|
|
char *argv0 = argv[0];
|
1996-07-30 17:35:50 -03:00
|
|
|
char *p = NULL;
|
2006-02-15 13:27:45 -04:00
|
|
|
Py_ssize_t n = 0;
|
1997-04-29 15:33:38 -03:00
|
|
|
PyObject *a;
|
1997-04-25 12:38:31 -03:00
|
|
|
#ifdef HAVE_READLINK
|
|
|
|
char link[MAXPATHLEN+1];
|
|
|
|
char argv0copy[2*MAXPATHLEN+1];
|
|
|
|
int nr = 0;
|
2005-09-15 10:00:34 -03:00
|
|
|
if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0)
|
1997-04-25 12:38:31 -03:00
|
|
|
nr = readlink(argv0, link, MAXPATHLEN);
|
|
|
|
if (nr > 0) {
|
|
|
|
/* It's a symlink */
|
|
|
|
link[nr] = '\0';
|
|
|
|
if (link[0] == SEP)
|
|
|
|
argv0 = link; /* Link to absolute path */
|
|
|
|
else if (strchr(link, SEP) == NULL)
|
|
|
|
; /* Link without path */
|
|
|
|
else {
|
|
|
|
/* Must join(dirname(argv0), link) */
|
|
|
|
char *q = strrchr(argv0, SEP);
|
|
|
|
if (q == NULL)
|
|
|
|
argv0 = link; /* argv0 without path */
|
|
|
|
else {
|
|
|
|
/* Must make a copy */
|
|
|
|
strcpy(argv0copy, argv0);
|
|
|
|
q = strrchr(argv0copy, SEP);
|
|
|
|
strcpy(q+1, link);
|
|
|
|
argv0 = argv0copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_READLINK */
|
1996-09-10 11:44:21 -03:00
|
|
|
#if SEP == '\\' /* Special case for MS filename syntax */
|
2005-09-15 10:00:34 -03:00
|
|
|
if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0) {
|
1996-09-10 11:44:21 -03:00
|
|
|
char *q;
|
2003-01-08 10:33:48 -04:00
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
char *ptemp;
|
|
|
|
if (GetFullPathName(argv0,
|
|
|
|
sizeof(fullpath),
|
|
|
|
fullpath,
|
|
|
|
&ptemp)) {
|
|
|
|
argv0 = fullpath;
|
|
|
|
}
|
|
|
|
#endif
|
1997-04-25 12:38:31 -03:00
|
|
|
p = strrchr(argv0, SEP);
|
1996-09-10 11:44:21 -03:00
|
|
|
/* Test for alternate separator */
|
1997-04-25 12:38:31 -03:00
|
|
|
q = strrchr(p ? p : argv0, '/');
|
1996-09-10 11:44:21 -03:00
|
|
|
if (q != NULL)
|
|
|
|
p = q;
|
|
|
|
if (p != NULL) {
|
1997-04-25 12:38:31 -03:00
|
|
|
n = p + 1 - argv0;
|
1996-09-10 11:44:21 -03:00
|
|
|
if (n > 1 && p[-1] != ':')
|
|
|
|
n--; /* Drop trailing separator */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else /* All other filename syntaxes */
|
2005-09-15 10:00:34 -03:00
|
|
|
if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0) {
|
2003-02-19 11:25:10 -04:00
|
|
|
#if defined(HAVE_REALPATH)
|
|
|
|
if (realpath(argv0, fullpath)) {
|
|
|
|
argv0 = fullpath;
|
|
|
|
}
|
|
|
|
#endif
|
1997-04-25 12:38:31 -03:00
|
|
|
p = strrchr(argv0, SEP);
|
2003-02-19 11:25:10 -04:00
|
|
|
}
|
1996-09-10 11:44:21 -03:00
|
|
|
if (p != NULL) {
|
2001-04-10 19:07:43 -03:00
|
|
|
#ifndef RISCOS
|
1997-04-25 12:38:31 -03:00
|
|
|
n = p + 1 - argv0;
|
2001-04-10 19:07:43 -03:00
|
|
|
#else /* don't include trailing separator */
|
|
|
|
n = p - argv0;
|
|
|
|
#endif /* RISCOS */
|
1996-09-10 11:44:21 -03:00
|
|
|
#if SEP == '/' /* Special case for Unix filename syntax */
|
|
|
|
if (n > 1)
|
|
|
|
n--; /* Drop trailing separator */
|
|
|
|
#endif /* Unix */
|
|
|
|
}
|
|
|
|
#endif /* All others */
|
1997-04-29 15:33:38 -03:00
|
|
|
a = PyString_FromStringAndSize(argv0, n);
|
1996-07-30 17:35:50 -03:00
|
|
|
if (a == NULL)
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_FatalError("no mem for sys.path insertion");
|
|
|
|
if (PyList_Insert(path, 0, a) < 0)
|
|
|
|
Py_FatalError("sys.path.insert(0) failed");
|
|
|
|
Py_DECREF(a);
|
1996-07-23 22:31:37 -03:00
|
|
|
}
|
1997-04-29 15:33:38 -03:00
|
|
|
Py_DECREF(av);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
1998-05-12 11:59:24 -03:00
|
|
|
|
|
|
|
|
|
|
|
/* APIs to write to sys.stdout or sys.stderr using a printf-like interface.
|
|
|
|
Adapted from code submitted by Just van Rossum.
|
|
|
|
|
|
|
|
PySys_WriteStdout(format, ...)
|
|
|
|
PySys_WriteStderr(format, ...)
|
|
|
|
|
|
|
|
The first function writes to sys.stdout; the second to sys.stderr. When
|
|
|
|
there is a problem, they write to the real (C level) stdout or stderr;
|
1998-10-12 15:22:10 -03:00
|
|
|
no exceptions are raised.
|
1998-05-12 11:59:24 -03:00
|
|
|
|
|
|
|
Both take a printf-style format string as their first argument followed
|
|
|
|
by a variable length argument list determined by the format string.
|
|
|
|
|
|
|
|
*** WARNING ***
|
|
|
|
|
|
|
|
The format should limit the total size of the formatted output string to
|
|
|
|
1000 bytes. In particular, this means that no unrestricted "%s" formats
|
|
|
|
should occur; these should be limited using "%.<N>s where <N> is a
|
|
|
|
decimal number calculated so that <N> plus the maximum size of other
|
|
|
|
formatted text does not exceed 1000 bytes. Also watch out for "%f",
|
|
|
|
which can print hundreds of digits for very large numbers.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-07-22 15:47:25 -03:00
|
|
|
mywrite(char *name, FILE *fp, const char *format, va_list va)
|
1998-05-12 11:59:24 -03:00
|
|
|
{
|
|
|
|
PyObject *file;
|
1998-10-12 15:22:10 -03:00
|
|
|
PyObject *error_type, *error_value, *error_traceback;
|
1998-05-12 11:59:24 -03:00
|
|
|
|
1998-10-12 15:22:10 -03:00
|
|
|
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
1998-05-12 11:59:24 -03:00
|
|
|
file = PySys_GetObject(name);
|
|
|
|
if (file == NULL || PyFile_AsFile(file) == fp)
|
|
|
|
vfprintf(fp, format, va);
|
|
|
|
else {
|
|
|
|
char buffer[1001];
|
2001-12-02 04:29:16 -04:00
|
|
|
const int written = PyOS_vsnprintf(buffer, sizeof(buffer),
|
|
|
|
format, va);
|
1998-05-12 11:59:24 -03:00
|
|
|
if (PyFile_WriteString(buffer, file) != 0) {
|
|
|
|
PyErr_Clear();
|
|
|
|
fputs(buffer, fp);
|
|
|
|
}
|
2006-04-21 07:40:58 -03:00
|
|
|
if (written < 0 || (size_t)written >= sizeof(buffer)) {
|
2001-11-28 17:44:53 -04:00
|
|
|
const char *truncated = "... truncated";
|
|
|
|
if (PyFile_WriteString(truncated, file) != 0) {
|
|
|
|
PyErr_Clear();
|
|
|
|
fputs(truncated, fp);
|
|
|
|
}
|
|
|
|
}
|
1998-05-12 11:59:24 -03:00
|
|
|
}
|
1998-10-12 15:22:10 -03:00
|
|
|
PyErr_Restore(error_type, error_value, error_traceback);
|
1998-05-12 11:59:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PySys_WriteStdout(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, format);
|
|
|
|
mywrite("stdout", stdout, format, va);
|
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PySys_WriteStderr(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, format);
|
|
|
|
mywrite("stderr", stderr, format, va);
|
|
|
|
va_end(va);
|
|
|
|
}
|