cinap_lenrekadd hg and python4bb9e2215 years agoHistory
1468 lines · 38.1 KB · C
RawDownload
} PyDoc_STRVAR(getrecursionlimit_doc,"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\recursion from causing an overflow of the C stack and crashing Python."); #ifdef MS_WINDOWSPyDoc_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 */ #ifdef HAVE_DLOPENstatic PyObject *sys_setdlopenflags(PyObject *self, PyObject *args){	int new_val;        PyThreadState *tstate = PyThreadState_GET();	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;} PyDoc_STRVAR(setdlopenflags_doc,"setdlopenflags(n) -> None\n\\n\Set the flags that will be used for dlopen() calls. Among other\n\things, this will enable a lazy resolving of symbols when importing\n\a module, if called as sys.setdlopenflags(0)\n\To share symbols across extension modules, call as\n\sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)"); static PyObject *sys_getdlopenflags(PyObject *self, PyObject *args){        PyThreadState *tstate = PyThreadState_GET();        if (!tstate)		return NULL;        return PyInt_FromLong(tstate->interp->dlopenflags);} PyDoc_STRVAR(getdlopenflags_doc,"getdlopenflags() -> int\n\\n\Return the current value of the flags that are used for dlopen()\n\calls. The flag constants are defined in the dl module.");#endif #ifdef USE_MALLOPT/* Link with -lmalloc (or -lmpc) on an SGI */#include <malloc.h> static PyObject *sys_mdebug(PyObject *self, PyObject *args){	int flag;	if (!PyArg_ParseTuple(args, "i:mdebug", &flag))		return NULL;	mallopt(M_DEBUG, flag);	Py_INCREF(Py_None);	return Py_None;}#endif /* USE_MALLOPT */ static PyObject *sys_getrefcount(PyObject *self, PyObject *arg){	return PyInt_FromSsize_t(arg->ob_refcnt);} #ifdef Py_REF_DEBUGstatic PyObject *sys_gettotalrefcount(PyObject *self){	return PyInt_FromSsize_t(_Py_GetRefTotal());}#endif /* Py_REF_DEBUG */ PyDoc_STRVAR(getrefcount_doc,"getrefcount(object) -> integer\n\\n\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()."); #ifdef COUNT_ALLOCSstatic PyObject *sys_getcounts(PyObject *self){	extern PyObject *get_counts(void); 	return get_counts();}#endif PyDoc_STRVAR(getframe_doc,"_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\purposes only."); static PyObject *sys_getframe(PyObject *self, PyObject *args){	PyFrameObject *f = PyThreadState_GET()->frame;	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;} PyDoc_STRVAR(current_frames_doc,"_current_frames() -> dictionary\n\\n\Return a dictionary mapping each current thread T's thread id to T's\n\current stack frame.\n\\n\This function should be used for specialized purposes only."); static PyObject *sys_current_frames(PyObject *self, PyObject *noargs){	return _PyThread_CurrentFrames();} 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;	if (!PyArg_UnpackTuple(args, "call_tracing", 2, 2, &func, &funcargs))		return NULL;	return _PyEval_CallTracing(func, funcargs);} 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()"); #ifdef __cplusplusextern "C" {#endif #ifdef Py_TRACE_REFS/* Defined in objects.c because it uses static globals if that file */extern PyObject *_Py_GetObjects(PyObject *, PyObject *);#endif #ifdef DYNAMIC_EXECUTION_PROFILE/* Defined in ceval.c because it uses static globals if that file */extern PyObject *_Py_GetDXProfile(PyObject *,  PyObject *);#endif #ifdef __cplusplus}#endif static PyMethodDef sys_methods[] = {	/* Might as well keep this in alphabetic order */	{"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,	 callstats_doc},	{"_current_frames", sys_current_frames, METH_NOARGS,	 current_frames_doc},	{"displayhook",	sys_displayhook, METH_O, displayhook_doc},	{"exc_info",	sys_exc_info, METH_NOARGS, exc_info_doc},	{"exc_clear",	sys_exc_clear, METH_NOARGS, exc_clear_doc},	{"excepthook",	sys_excepthook, METH_VARARGS, excepthook_doc},	{"exit",	sys_exit, METH_VARARGS, exit_doc},#ifdef Py_USING_UNICODE	{"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,	 METH_NOARGS, getdefaultencoding_doc},#endif#ifdef HAVE_DLOPEN	{"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,	 getdlopenflags_doc},#endif#ifdef COUNT_ALLOCS	{"getcounts",	(PyCFunction)sys_getcounts, METH_NOARGS},#endif#ifdef DYNAMIC_EXECUTION_PROFILE	{"getdxp",	_Py_GetDXProfile, METH_VARARGS},#endif#ifdef Py_USING_UNICODE	{"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,	 METH_NOARGS, getfilesystemencoding_doc},#endif#ifdef Py_TRACE_REFS	{"getobjects",	_Py_GetObjects, METH_VARARGS},#endif#ifdef Py_REF_DEBUG	{"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},#endif	{"getrefcount",	(PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},	{"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,	 getrecursionlimit_doc},	{"_getframe", sys_getframe, METH_VARARGS, getframe_doc},#ifdef MS_WINDOWS	{"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,	 getwindowsversion_doc},#endif /* MS_WINDOWS */#ifdef USE_MALLOPT	{"mdebug",	sys_mdebug, METH_VARARGS},#endif#ifdef Py_USING_UNICODE	{"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,	 setdefaultencoding_doc},#endif	{"setcheckinterval",	sys_setcheckinterval, METH_VARARGS,	 setcheckinterval_doc},	{"getcheckinterval",	sys_getcheckinterval, METH_NOARGS,	 getcheckinterval_doc},#ifdef HAVE_DLOPEN	{"setdlopenflags", sys_setdlopenflags, METH_VARARGS,	 setdlopenflags_doc},#endif	{"setprofile",	sys_setprofile, METH_O, setprofile_doc},	{"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,	 setrecursionlimit_doc},#ifdef WITH_TSC	{"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},#endif	{"settrace",	sys_settrace, METH_O, settrace_doc},	{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},	{NULL,		NULL}		/* sentinel */}; static PyObject *list_builtin_module_names(void){	PyObject *list = PyList_New(0);	int i;	if (list == NULL)		return NULL;	for (i = 0; PyImport_Inittab[i].name != NULL; i++) {		PyObject *name = PyString_FromString(			PyImport_Inittab[i].name);		if (name == NULL)			break;		PyList_Append(list, name);		Py_DECREF(name);	}	if (PyList_Sort(list) != 0) {		Py_DECREF(list);		list = NULL;	}	if (list) {		PyObject *v = PyList_AsTuple(list);		Py_DECREF(list);		list = v;	}	return list;} static PyObject *warnoptions = NULL; voidPySys_ResetWarnOptions(void){	if (warnoptions == NULL || !PyList_Check(warnoptions))		return;	PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);} voidPySys_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);	}} /* 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. */PyDoc_VAR(sys_doc) =PyDoc_STR("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\\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\\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\  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\\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\")/* concatenating string here */PyDoc_STR("\n\Static objects:\n\\n\maxint -- the largest supported integer (the smallest is -maxint-1)\n\maxunicode -- the largest supported character\n\builtin_module_names -- tuple of module names built into this interpreter\n\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\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\")#ifdef MS_WINDOWS/* concatenating string here */PyDoc_STR("dllhandle -- [Windows only] integer handle of the Python DLL\n\winver -- [Windows only] version number of the Python DLL\n\")#endif /* MS_WINDOWS */PyDoc_STR("__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\\n\Functions:\n\\n\displayhook() -- print an object to the screen, and save it in __builtin__._\n\excepthook() -- print an exception and its traceback to sys.stderr\n\exc_info() -- return thread-safe information about the current exception\n\exc_clear() -- clear the exception state for the current thread\n\exit() -- exit the interpreter by raising SystemExit\n\getdlopenflags() -- returns flags to be used for dlopen() calls\n\getrefcount() -- return the reference count for an object (plus one :-)\n\getrecursionlimit() -- return the max recursion depth for the interpreter\n\setcheckinterval() -- control how often the interpreter checks for events\n\setdlopenflags() -- set the flags to be used for dlopen() calls\n\setprofile() -- set the global profiling function\n\setrecursionlimit() -- set the max recursion depth for the interpreter\n\settrace() -- set the global debug tracing function\n\")/* end of sys_doc */ ; static int_check_and_flush (FILE *stream){  int prev_fail = ferror (stream);  return fflush (stream) || prev_fail ? EOF : 0;} /* Subversion branch and revision management */static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;static const char headurl[] = "$HeadURL: svn+ssh://pythondev@svn.python.org/python/tags/r251/Python/sysmodule.c $";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; static voidsvnversion_init(void){	const char *python, *br_start, *br_end, *br_end2, *svnversion;	Py_ssize_t len;	int istag; 	if (svn_initialized)		return; 	python = strstr(headurl, "/python/");	if (!python)		Py_FatalError("subversion keywords missing"); 	br_start = python + 8;	br_end = strchr(br_start, '/');	assert(br_end); 	/* Works even for trunk,	   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"); 	}	else if (istag || strncmp(br_start, "branches", 8) == 0) {		len = br_end2 - br_start;		strncpy(branch, br_start, len);

Lines 501–1000 of 1468. Previous lines