From 114c42641335bdc26cbf61c18c82b0f5c8a6d4f8 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 17 Oct 2012 23:52:17 +0200 Subject: Issue #16166: Add PY_LITTLE_ENDIAN and PY_BIG_ENDIAN macros and unified endianess detection and handling. --- Python/sysmodule.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 20bfa555b3..cafbb58667 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1561,7 +1561,6 @@ PyObject * _PySys_Init(void) { PyObject *m, *v, *sysdict, *version_info; - char *s; m = PyModule_Create(&sysmodule); if (m == NULL) @@ -1638,20 +1637,14 @@ _PySys_Init(void) PyLong_FromLong(0x10FFFF)); SET_SYS_FROM_STRING("builtin_module_names", list_builtin_module_names()); - { - /* Assumes that longs are at least 2 bytes long. - Should be safe! */ - unsigned long number = 1; - char *value; - - s = (char *) &number; - if (s[0] == 0) - value = "big"; - else - value = "little"; - SET_SYS_FROM_STRING("byteorder", - PyUnicode_FromString(value)); - } +#if PY_BIG_ENDIAN + SET_SYS_FROM_STRING("byteorder", + PyUnicode_FromString("big")); +#else + SET_SYS_FROM_STRING("byteorder", + PyUnicode_FromString("little")); +#endif + #ifdef MS_COREDLL SET_SYS_FROM_STRING("dllhandle", PyLong_FromVoidPtr(PyWin_DLLhModule)); -- cgit v1.2.1 From 4931f84d31839b5887f3bd299efc1cce34ef974e Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 19 Nov 2012 00:44:37 +0100 Subject: RISCOS support has been removed a long time ago. Remove last remains in sys.flags code. #16501 can be closed, too. --- Python/sysmodule.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index cafbb58667..92c5b67611 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1349,9 +1349,6 @@ static PyStructSequence_Field flags_fields[] = { {"no_site", "-S"}, {"ignore_environment", "-E"}, {"verbose", "-v"}, -#ifdef RISCOS - {"riscos_wimp", "???"}, -#endif /* {"unbuffered", "-u"}, */ /* {"skip_first", "-x"}, */ {"bytes_warning", "-b"}, @@ -1364,11 +1361,7 @@ static PyStructSequence_Desc flags_desc = { "sys.flags", /* name */ flags__doc__, /* doc */ flags_fields, /* fields */ -#ifdef RISCOS - 13 -#else 12 -#endif }; static PyObject* @@ -1393,9 +1386,6 @@ make_flags(void) SetFlag(Py_NoSiteFlag); SetFlag(Py_IgnoreEnvironmentFlag); SetFlag(Py_VerboseFlag); -#ifdef RISCOS - SetFlag(Py_RISCOSWimpFlag); -#endif /* SetFlag(saw_unbuffered_flag); */ /* SetFlag(skipfirstline); */ SetFlag(Py_BytesWarningFlag); -- cgit v1.2.1 From 350e0ff264038e3790d0182134de7959965dea7d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 9 Dec 2012 14:28:26 +0100 Subject: Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated. Also, the ``-R`` option to regrtest uses this function to guard against memory allocation leaks. --- Python/sysmodule.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 92c5b67611..20792c243c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -894,6 +894,19 @@ one higher than you might expect, because it includes the (temporary)\n\ reference as an argument to getrefcount()." ); +static PyObject * +sys_getallocatedblocks(PyObject *self) +{ + return PyLong_FromSsize_t(_Py_GetAllocatedBlocks()); +} + +PyDoc_STRVAR(getallocatedblocks_doc, +"getallocatedblocks() -> integer\n\ +\n\ +Return the number of memory blocks currently allocated, regardless of their\n\ +size." +); + #ifdef COUNT_ALLOCS static PyObject * sys_getcounts(PyObject *self) @@ -1062,6 +1075,8 @@ static PyMethodDef sys_methods[] = { {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, getdlopenflags_doc}, #endif + {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, + getallocatedblocks_doc}, #ifdef COUNT_ALLOCS {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, #endif -- cgit v1.2.1 From b03c761abdbc37cb2c9e487296711f566a80f249 Mon Sep 17 00:00:00 2001 From: Andrew Kuchling Date: Fri, 21 Jun 2013 10:58:41 -0400 Subject: #13226: update references from ctypes/DLFCN modules to os module --- Python/sysmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 20792c243c..2680e6bf27 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -774,7 +774,7 @@ Set the flags used by the interpreter for dlopen calls, such as when the\n\ interpreter loads extension modules. Among other things, this will enable\n\ a lazy resolving of symbols when importing a module, if called as\n\ sys.setdlopenflags(0). To share symbols across extension modules, call as\n\ -sys.setdlopenflags(ctypes.RTLD_GLOBAL). Symbolic names for the flag modules\n\ +sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag modules\n\ can be found in the os module (RTLD_xxx constants, e.g. os.RTLD_LAZY)."); static PyObject * @@ -790,7 +790,7 @@ PyDoc_STRVAR(getdlopenflags_doc, "getdlopenflags() -> int\n\ \n\ Return the current value of the flags that are used for dlopen calls.\n\ -The flag constants are defined in the ctypes and DLFCN modules."); +The flag constants are defined in the os module."); #endif /* HAVE_DLOPEN */ -- cgit v1.2.1 From 92d3e3cf6bfe7320aea27780a6525e6075624935 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 22 Jul 2013 22:24:54 +0200 Subject: Issue #18520: Add a new PyStructSequence_InitType2() function, same than PyStructSequence_InitType() except that it has a return value (0 on success, -1 on error). * PyStructSequence_InitType2() now raises MemoryError on memory allocation failure * Fix also some calls to PyDict_SetItemString(): handle error --- Python/sysmodule.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index e14de49e82..ed7588790e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1634,8 +1634,10 @@ _PySys_Init(void) SET_SYS_FROM_STRING("int_info", PyLong_GetInfo()); /* initialize hash_info */ - if (Hash_InfoType.tp_name == 0) - PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc); + if (Hash_InfoType.tp_name == NULL) { + if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0) + return NULL; + } SET_SYS_FROM_STRING("hash_info", get_hash_info()); SET_SYS_FROM_STRING("maxunicode", @@ -1676,8 +1678,11 @@ _PySys_Init(void) } /* version_info */ - if (VersionInfoType.tp_name == 0) - PyStructSequence_InitType(&VersionInfoType, &version_info_desc); + if (VersionInfoType.tp_name == NULL) { + if (PyStructSequence_InitType2(&VersionInfoType, + &version_info_desc) < 0) + return NULL; + } version_info = make_version_info(); SET_SYS_FROM_STRING("version_info", version_info); /* prevent user from creating new instances */ @@ -1688,8 +1693,10 @@ _PySys_Init(void) SET_SYS_FROM_STRING("implementation", make_impl_info(version_info)); /* flags */ - if (FlagsType.tp_name == 0) - PyStructSequence_InitType(&FlagsType, &flags_desc); + if (FlagsType.tp_name == 0) { + if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0) + return NULL; + } SET_SYS_FROM_STRING("flags", make_flags()); /* prevent user from creating new instances */ FlagsType.tp_init = NULL; @@ -1699,7 +1706,9 @@ _PySys_Init(void) #if defined(MS_WINDOWS) /* getwindowsversion */ if (WindowsVersionType.tp_name == 0) - PyStructSequence_InitType(&WindowsVersionType, &windows_version_desc); + if (PyStructSequence_InitType2(&WindowsVersionType, + &windows_version_desc) < 0) + return NULL; /* prevent user from creating new instances */ WindowsVersionType.tp_init = NULL; WindowsVersionType.tp_new = NULL; -- cgit v1.2.1 From e1b969a82c4ccc6be134d777a134ca7390e52da3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 22 Jul 2013 22:40:00 +0200 Subject: Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors --- Python/sysmodule.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ed7588790e..754bcfe654 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1565,17 +1565,24 @@ static struct PyModuleDef sysmodule = { PyObject * _PySys_Init(void) { - PyObject *m, *v, *sysdict, *version_info; + PyObject *m, *sysdict, *version_info; m = PyModule_Create(&sysmodule); if (m == NULL) return NULL; sysdict = PyModule_GetDict(m); -#define SET_SYS_FROM_STRING(key, value) \ - v = value; \ - if (v != NULL) \ - PyDict_SetItemString(sysdict, key, v); \ - Py_XDECREF(v) +#define SET_SYS_FROM_STRING(key, value) \ + do { \ + int res; \ + PyObject *v = (value); \ + if (v == NULL) \ + return NULL; \ + res = PyDict_SetItemString(sysdict, key, v); \ + if (res < 0) { \ + Py_DECREF(v); \ + return NULL; \ + } \ + } while (0) /* Check that stdin is not a directory Using shell redirection, you can redirect stdin to a directory, @@ -1597,10 +1604,10 @@ _PySys_Init(void) /* stdin/stdout/stderr are now set by pythonrun.c */ - PyDict_SetItemString(sysdict, "__displayhook__", - PyDict_GetItemString(sysdict, "displayhook")); - PyDict_SetItemString(sysdict, "__excepthook__", - PyDict_GetItemString(sysdict, "excepthook")); + SET_SYS_FROM_STRING("__displayhook__", + PyDict_GetItemString(sysdict, "displayhook")); + SET_SYS_FROM_STRING("__excepthook__", + PyDict_GetItemString(sysdict, "excepthook")); SET_SYS_FROM_STRING("version", PyUnicode_FromString(Py_GetVersion())); SET_SYS_FROM_STRING("hexversion", @@ -1664,18 +1671,15 @@ _PySys_Init(void) #endif if (warnoptions == NULL) { warnoptions = PyList_New(0); + if (warnoptions == NULL) + return NULL; } else { Py_INCREF(warnoptions); } - if (warnoptions != NULL) { - PyDict_SetItemString(sysdict, "warnoptions", warnoptions); - } + SET_SYS_FROM_STRING("warnoptions", warnoptions); - v = get_xoptions(); - if (v != NULL) { - PyDict_SetItemString(sysdict, "_xoptions", v); - } + SET_SYS_FROM_STRING("_xoptions", get_xoptions()); /* version_info */ if (VersionInfoType.tp_name == NULL) { -- cgit v1.2.1 From 011ede87bdf36ab2e4cbb24825eb6425d9d72184 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sat, 10 Aug 2013 16:36:18 +0200 Subject: Issue #16400: Add command line option for isolated mode. -I Run Python in isolated mode. This also implies -E and -s. In isolated mode sys.path contains neither the script?s directory nor the user?s site-packages directory. All PYTHON* environment variables are ignored, too. Further restrictions may be imposed to prevent the user from injecting malicious code. --- Python/sysmodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 754bcfe654..72004f8a14 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1369,6 +1369,7 @@ static PyStructSequence_Field flags_fields[] = { {"bytes_warning", "-b"}, {"quiet", "-q"}, {"hash_randomization", "-R"}, + {"isolated", "-I"}, {0} }; @@ -1376,7 +1377,7 @@ static PyStructSequence_Desc flags_desc = { "sys.flags", /* name */ flags__doc__, /* doc */ flags_fields, /* fields */ - 12 + 13 }; static PyObject* @@ -1406,6 +1407,7 @@ make_flags(void) SetFlag(Py_BytesWarningFlag); SetFlag(Py_QuietFlag); SetFlag(Py_HashRandomizationFlag); + SetFlag(Py_IsolatedFlag); #undef SetFlag if (PyErr_Occurred()) { @@ -1944,7 +1946,7 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) void PySys_SetArgv(int argc, wchar_t **argv) { - PySys_SetArgvEx(argc, argv, 1); + PySys_SetArgvEx(argc, argv, Py_IsolatedFlag == 0); } /* Reimplementation of PyFile_WriteString() no calling indirectly -- cgit v1.2.1 From 1bc931d1228fb6bd1c7bed55e77aa2bd2cc37cac Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 27 Oct 2013 17:15:42 +0100 Subject: Issue #18520: fix reference leak in _PySys_Init() --- Python/sysmodule.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 2d7e01bd7f..d8848ae977 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1573,6 +1573,17 @@ _PySys_Init(void) if (m == NULL) return NULL; sysdict = PyModule_GetDict(m); +#define SET_SYS_FROM_STRING_BORROW(key, value) \ + do { \ + int res; \ + PyObject *v = (value); \ + if (v == NULL) \ + return NULL; \ + res = PyDict_SetItemString(sysdict, key, v); \ + if (res < 0) { \ + return NULL; \ + } \ + } while (0) #define SET_SYS_FROM_STRING(key, value) \ do { \ int res; \ @@ -1580,8 +1591,8 @@ _PySys_Init(void) if (v == NULL) \ return NULL; \ res = PyDict_SetItemString(sysdict, key, v); \ + Py_DECREF(v); \ if (res < 0) { \ - Py_DECREF(v); \ return NULL; \ } \ } while (0) @@ -1606,10 +1617,10 @@ _PySys_Init(void) /* stdin/stdout/stderr are now set by pythonrun.c */ - SET_SYS_FROM_STRING("__displayhook__", - PyDict_GetItemString(sysdict, "displayhook")); - SET_SYS_FROM_STRING("__excepthook__", - PyDict_GetItemString(sysdict, "excepthook")); + SET_SYS_FROM_STRING_BORROW("__displayhook__", + PyDict_GetItemString(sysdict, "displayhook")); + SET_SYS_FROM_STRING_BORROW("__excepthook__", + PyDict_GetItemString(sysdict, "excepthook")); SET_SYS_FROM_STRING("version", PyUnicode_FromString(Py_GetVersion())); SET_SYS_FROM_STRING("hexversion", @@ -1679,9 +1690,9 @@ _PySys_Init(void) else { Py_INCREF(warnoptions); } - SET_SYS_FROM_STRING("warnoptions", warnoptions); + SET_SYS_FROM_STRING_BORROW("warnoptions", warnoptions); - SET_SYS_FROM_STRING("_xoptions", get_xoptions()); + SET_SYS_FROM_STRING_BORROW("_xoptions", get_xoptions()); /* version_info */ if (VersionInfoType.tp_name == NULL) { -- cgit v1.2.1 From ac1d52868507eab11a080e7600005366a5e1be26 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 29 Oct 2013 01:19:37 +0100 Subject: Issue #18408: Add a new PyFrame_FastToLocalsWithError() function to handle exceptions when merging fast locals into f_locals of a frame. PyEval_GetLocals() now raises an exception and return NULL on failure. --- Python/sysmodule.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index d8848ae977..97ce0594b5 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -332,12 +332,16 @@ static PyObject * call_trampoline(PyThreadState *tstate, PyObject* callback, PyFrameObject *frame, int what, PyObject *arg) { - PyObject *args = PyTuple_New(3); + PyObject *args; PyObject *whatstr; PyObject *result; + args = PyTuple_New(3); if (args == NULL) return NULL; + if (PyFrame_FastToLocalsWithError(frame) < 0) + return NULL; + Py_INCREF(frame); whatstr = whatstrings[what]; Py_INCREF(whatstr); @@ -349,7 +353,6 @@ call_trampoline(PyThreadState *tstate, PyObject* callback, 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) -- cgit v1.2.1 From 8bf32774bc8e990ca6e3a648cac9289d116caa13 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 6 Nov 2013 18:27:13 +0100 Subject: Issue #19512: sys_displayhook() now uses an identifier for "builtins" dictionary key and only decodes "\n" string once to write a newline. So "builtins" and "\n" are only decoded once from UTF-8, at the first call. --- Python/sysmodule.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 97ce0594b5..b8cf31d435 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -137,10 +137,13 @@ sys_displayhook(PyObject *self, PyObject *o) PyObject *outf; PyInterpreterState *interp = PyThreadState_GET()->interp; PyObject *modules = interp->modules; - PyObject *builtins = PyDict_GetItemString(modules, "builtins"); + PyObject *builtins; + static PyObject *newline = NULL; int err; _Py_IDENTIFIER(_); + _Py_IDENTIFIER(builtins); + builtins = _PyDict_GetItemId(modules, &PyId_builtins); if (builtins == NULL) { PyErr_SetString(PyExc_RuntimeError, "lost builtins module"); return NULL; @@ -173,7 +176,12 @@ sys_displayhook(PyObject *self, PyObject *o) return NULL; } } - if (PyFile_WriteString("\n", outf) != 0) + if (newline == NULL) { + newline = PyUnicode_FromString("\n"); + if (newline == NULL) + return NULL; + } + if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0) return NULL; if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0) return NULL; -- cgit v1.2.1 From b056c912da3f1933c658aa31ad246ec4b54beec5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 6 Nov 2013 22:36:40 +0100 Subject: Issue #19512: Add _PySys_GetObjectId() and _PySys_SetObjectId() functions --- Python/sysmodule.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b8cf31d435..32136e844f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -41,6 +41,16 @@ extern const char *PyWin_DLLVersionString; #include #endif +PyObject * +_PySys_GetObjectId(_Py_Identifier *key) +{ + PyThreadState *tstate = PyThreadState_GET(); + PyObject *sd = tstate->interp->sysdict; + if (sd == NULL) + return NULL; + return _PyDict_GetItemId(sd, key); +} + PyObject * PySys_GetObject(const char *name) { @@ -51,6 +61,21 @@ PySys_GetObject(const char *name) return PyDict_GetItemString(sd, name); } +int +_PySys_SetObjectId(_Py_Identifier *key, PyObject *v) +{ + PyThreadState *tstate = PyThreadState_GET(); + PyObject *sd = tstate->interp->sysdict; + if (v == NULL) { + if (_PyDict_GetItemId(sd, key) == NULL) + return 0; + else + return _PyDict_DelItemId(sd, key); + } + else + return _PyDict_SetItemId(sd, key, v); +} + int PySys_SetObject(const char *name, PyObject *v) { -- cgit v1.2.1 From abe98ac333cb6792ed82b144822738e50e38d443 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 6 Nov 2013 22:41:44 +0100 Subject: Issue #19512: add some common identifiers to only create common strings once, instead of creating temporary Unicode string objects Add also more identifiers in pythonrun.c to avoid temporary Unicode string objets for the interactive interpreter. --- Python/sysmodule.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 32136e844f..de33d55835 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -183,7 +183,7 @@ sys_displayhook(PyObject *self, PyObject *o) } if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0) return NULL; - outf = PySys_GetObject("stdout"); + outf = _PySys_GetObjectId(&_PyId_stdout); if (outf == NULL || outf == Py_None) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -1825,7 +1825,7 @@ PySys_SetPath(const wchar_t *path) PyObject *v; if ((v = makepathobject(path, DELIM)) == NULL) Py_FatalError("can't create sys.path"); - if (PySys_SetObject("path", v) != 0) + if (_PySys_SetObjectId(&_PyId_path, v) != 0) Py_FatalError("can't assign sys.path"); Py_DECREF(v); } @@ -1894,7 +1894,7 @@ sys_update_path(int argc, wchar_t **argv) wchar_t fullpath[MAX_PATH]; #endif - path = PySys_GetObject("path"); + path = _PySys_GetObjectId(&_PyId_path); if (path == NULL) return; @@ -2081,7 +2081,7 @@ sys_pyfile_write(const char *text, PyObject *file) */ static void -sys_write(char *name, FILE *fp, const char *format, va_list va) +sys_write(_Py_Identifier *key, FILE *fp, const char *format, va_list va) { PyObject *file; PyObject *error_type, *error_value, *error_traceback; @@ -2089,7 +2089,7 @@ sys_write(char *name, FILE *fp, const char *format, va_list va) int written; PyErr_Fetch(&error_type, &error_value, &error_traceback); - file = PySys_GetObject(name); + file = _PySys_GetObjectId(key); written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va); if (sys_pyfile_write(buffer, file) != 0) { PyErr_Clear(); @@ -2109,7 +2109,7 @@ PySys_WriteStdout(const char *format, ...) va_list va; va_start(va, format); - sys_write("stdout", stdout, format, va); + sys_write(&_PyId_stdout, stdout, format, va); va_end(va); } @@ -2119,19 +2119,19 @@ PySys_WriteStderr(const char *format, ...) va_list va; va_start(va, format); - sys_write("stderr", stderr, format, va); + sys_write(&_PyId_stderr, stderr, format, va); va_end(va); } static void -sys_format(char *name, FILE *fp, const char *format, va_list va) +sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va) { PyObject *file, *message; PyObject *error_type, *error_value, *error_traceback; char *utf8; PyErr_Fetch(&error_type, &error_value, &error_traceback); - file = PySys_GetObject(name); + file = _PySys_GetObjectId(key); message = PyUnicode_FromFormatV(format, va); if (message != NULL) { if (sys_pyfile_write_unicode(message, file) != 0) { @@ -2151,7 +2151,7 @@ PySys_FormatStdout(const char *format, ...) va_list va; va_start(va, format); - sys_format("stdout", stdout, format, va); + sys_format(&_PyId_stdout, stdout, format, va); va_end(va); } @@ -2161,6 +2161,6 @@ PySys_FormatStderr(const char *format, ...) va_list va; va_start(va, format); - sys_format("stderr", stderr, format, va); + sys_format(&_PyId_stderr, stderr, format, va); va_end(va); } -- cgit v1.2.1 From 359ed22ea49d63923b451351ebf80decaaa7b79e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 7 Nov 2013 23:07:29 +0100 Subject: Issue #19512, #19515: remove shared identifiers, move identifiers where they are used. Move also _Py_IDENTIFIER() defintions to the top in modified files to remove identifiers duplicated in the same file. --- Python/sysmodule.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index de33d55835..3ebb6c9493 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -41,6 +41,16 @@ extern const char *PyWin_DLLVersionString; #include #endif +_Py_IDENTIFIER(_); +_Py_IDENTIFIER(__sizeof__); +_Py_IDENTIFIER(buffer); +_Py_IDENTIFIER(builtins); +_Py_IDENTIFIER(encoding); +_Py_IDENTIFIER(path); +_Py_IDENTIFIER(stdout); +_Py_IDENTIFIER(stderr); +_Py_IDENTIFIER(write); + PyObject * _PySys_GetObjectId(_Py_Identifier *key) { @@ -104,8 +114,6 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) PyObject *encoded, *escaped_str, *repr_str, *buffer, *result; char *stdout_encoding_str; int ret; - _Py_IDENTIFIER(encoding); - _Py_IDENTIFIER(buffer); stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding); if (stdout_encoding == NULL) @@ -126,7 +134,6 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) buffer = _PyObject_GetAttrId(outf, &PyId_buffer); if (buffer) { - _Py_IDENTIFIER(write); result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded); Py_DECREF(buffer); Py_DECREF(encoded); @@ -165,8 +172,6 @@ sys_displayhook(PyObject *self, PyObject *o) PyObject *builtins; static PyObject *newline = NULL; int err; - _Py_IDENTIFIER(_); - _Py_IDENTIFIER(builtins); builtins = _PyDict_GetItemId(modules, &PyId_builtins); if (builtins == NULL) { @@ -183,7 +188,7 @@ sys_displayhook(PyObject *self, PyObject *o) } if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0) return NULL; - outf = _PySys_GetObjectId(&_PyId_stdout); + outf = _PySys_GetObjectId(&PyId_stdout); if (outf == NULL || outf == Py_None) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -854,7 +859,6 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) static char *kwlist[] = {"object", "default", 0}; PyObject *o, *dflt = NULL; PyObject *method; - _Py_IDENTIFIER(__sizeof__); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", kwlist, &o, &dflt)) @@ -1825,7 +1829,7 @@ PySys_SetPath(const wchar_t *path) PyObject *v; if ((v = makepathobject(path, DELIM)) == NULL) Py_FatalError("can't create sys.path"); - if (_PySys_SetObjectId(&_PyId_path, v) != 0) + if (_PySys_SetObjectId(&PyId_path, v) != 0) Py_FatalError("can't assign sys.path"); Py_DECREF(v); } @@ -1894,7 +1898,7 @@ sys_update_path(int argc, wchar_t **argv) wchar_t fullpath[MAX_PATH]; #endif - path = _PySys_GetObjectId(&_PyId_path); + path = _PySys_GetObjectId(&PyId_path); if (path == NULL) return; @@ -2004,7 +2008,6 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) { PyObject *writer = NULL, *args = NULL, *result = NULL; int err; - _Py_IDENTIFIER(write); if (file == NULL) return -1; @@ -2109,7 +2112,7 @@ PySys_WriteStdout(const char *format, ...) va_list va; va_start(va, format); - sys_write(&_PyId_stdout, stdout, format, va); + sys_write(&PyId_stdout, stdout, format, va); va_end(va); } @@ -2119,7 +2122,7 @@ PySys_WriteStderr(const char *format, ...) va_list va; va_start(va, format); - sys_write(&_PyId_stderr, stderr, format, va); + sys_write(&PyId_stderr, stderr, format, va); va_end(va); } @@ -2151,7 +2154,7 @@ PySys_FormatStdout(const char *format, ...) va_list va; va_start(va, format); - sys_format(&_PyId_stdout, stdout, format, va); + sys_format(&PyId_stdout, stdout, format, va); va_end(va); } @@ -2161,6 +2164,6 @@ PySys_FormatStderr(const char *format, ...) va_list va; va_start(va, format); - sys_format(&_PyId_stderr, stderr, format, va); + sys_format(&PyId_stderr, stderr, format, va); va_end(va); } -- cgit v1.2.1 From 1f4288b872047826fa7bc66ab5fe785e61a095b1 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 20 Nov 2013 11:46:18 +0100 Subject: ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'. Python now uses SipHash24 on all major platforms. --- Python/sysmodule.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 35a067145a..4028a01dab 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -658,7 +658,7 @@ PyDoc_STRVAR(hash_info_doc, "hash_info\n\ \n\ A struct sequence providing parameters used for computing\n\ -numeric hashes. The attributes are read only."); +hashes. The attributes are read only."); static PyStructSequence_Field hash_info_fields[] = { {"width", "width of the type used for hashing, in bits"}, @@ -667,6 +667,11 @@ static PyStructSequence_Field hash_info_fields[] = { {"inf", "value to be used for hash of a positive infinity"}, {"nan", "value to be used for hash of a nan"}, {"imag", "multiplier used for the imaginary part of a complex number"}, + {"algorithm", "name of the algorithm for hashing of str, bytes and " + "memoryviews"}, + {"hash_bits", "internal output size of hash algorithm"}, + {"seed_bits", "seed size of hash algorithm"}, + {"cutoff", "small string optimization cutoff"}, {NULL, NULL} }; @@ -674,7 +679,7 @@ static PyStructSequence_Desc hash_info_desc = { "sys.hash_info", hash_info_doc, hash_info_fields, - 5, + 9, }; static PyObject * @@ -682,9 +687,11 @@ get_hash_info(void) { PyObject *hash_info; int field = 0; + PyHash_FuncDef *hashfunc; hash_info = PyStructSequence_New(&Hash_InfoType); if (hash_info == NULL) return NULL; + hashfunc = PyHash_GetFuncDef(); PyStructSequence_SET_ITEM(hash_info, field++, PyLong_FromLong(8*sizeof(Py_hash_t))); PyStructSequence_SET_ITEM(hash_info, field++, @@ -695,6 +702,14 @@ get_hash_info(void) PyLong_FromLong(_PyHASH_NAN)); PyStructSequence_SET_ITEM(hash_info, field++, PyLong_FromLong(_PyHASH_IMAG)); + PyStructSequence_SET_ITEM(hash_info, field++, + PyUnicode_FromString(hashfunc->name)); + PyStructSequence_SET_ITEM(hash_info, field++, + PyLong_FromLong(hashfunc->hash_bits)); + PyStructSequence_SET_ITEM(hash_info, field++, + PyLong_FromLong(hashfunc->seed_bits)); + PyStructSequence_SET_ITEM(hash_info, field++, + PyLong_FromLong(Py_HASH_CUTOFF)); if (PyErr_Occurred()) { Py_CLEAR(hash_info); return NULL; @@ -1338,6 +1353,7 @@ exec_prefix -- prefix used to find the machine-specific Python library\n\ executable -- absolute path of the executable binary of the Python interpreter\n\ float_info -- a struct sequence with information about the float implementation.\n\ float_repr_style -- string indicating the style of repr() output for floats\n\ +hash_info -- a struct sequence with information about the hash algorithm.\n\ hexversion -- version information encoded as a single integer\n\ implementation -- Python implementation information.\n\ int_info -- a struct sequence with information about the int implementation.\n\ -- cgit v1.2.1 From ede64d46c3a6e8799206070d1c1e3120d0ca1df7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 13 Dec 2013 02:01:38 +0100 Subject: Issue #14432: Remove the thread state field from the frame structure. Fix a crash when a generator is created in a C thread that is destroyed while the generator is still used. The issue was that a generator contains a frame, and the frame kept a reference to the Python state of the destroyed C thread. The crash occurs when a trace function is setup. --- Python/sysmodule.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4028a01dab..961657ec61 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -367,7 +367,7 @@ trace_init(void) static PyObject * -call_trampoline(PyThreadState *tstate, PyObject* callback, +call_trampoline(PyObject* callback, PyFrameObject *frame, int what, PyObject *arg) { PyObject *args; @@ -405,12 +405,11 @@ static int profile_trampoline(PyObject *self, PyFrameObject *frame, int what, PyObject *arg) { - PyThreadState *tstate = frame->f_tstate; PyObject *result; if (arg == NULL) arg = Py_None; - result = call_trampoline(tstate, self, frame, what, arg); + result = call_trampoline(self, frame, what, arg); if (result == NULL) { PyEval_SetProfile(NULL, NULL); return -1; @@ -423,7 +422,6 @@ static int trace_trampoline(PyObject *self, PyFrameObject *frame, int what, PyObject *arg) { - PyThreadState *tstate = frame->f_tstate; PyObject *callback; PyObject *result; @@ -433,7 +431,7 @@ trace_trampoline(PyObject *self, PyFrameObject *frame, callback = frame->f_trace; if (callback == NULL) return 0; - result = call_trampoline(tstate, callback, frame, what, arg); + result = call_trampoline(callback, frame, what, arg); if (result == NULL) { PyEval_SetTrace(NULL, NULL); Py_XDECREF(frame->f_trace); -- cgit v1.2.1 From 015df829bb549c7051abbcb3a7ad7d9de01e4017 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 19 Dec 2013 17:16:42 +0100 Subject: Fix the C definition of the sys._debugmallocstats() function: the function has no parameter --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index d238561ecd..cf580f1040 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1186,7 +1186,7 @@ static PyMethodDef sys_methods[] = { {"settrace", sys_settrace, METH_O, settrace_doc}, {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc}, {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc}, - {"_debugmallocstats", sys_debugmallocstats, METH_VARARGS, + {"_debugmallocstats", sys_debugmallocstats, METH_NOARGS, debugmallocstats_doc}, {NULL, NULL} /* sentinel */ }; -- cgit v1.2.1 From 8531989aa308c3953619aafa8ad9c1106911ceca Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sat, 21 Dec 2013 16:19:10 +0100 Subject: Issue #16136: Remove VMS support and VMS-related code --- Python/sysmodule.c | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index cf580f1040..976d5a0c37 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -32,10 +32,6 @@ extern void *PyWin_DLLhModule; extern const char *PyWin_DLLVersionString; #endif -#ifdef __VMS -#include -#endif - #ifdef HAVE_LANGINFO_H #include #include @@ -1867,22 +1863,7 @@ makeargvobject(int argc, wchar_t **argv) if (av != NULL) { int i; for (i = 0; i < argc; i++) { -#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 = PyUnicode_FromString(argv[0]); - else - v = PyUnicode_FromString( - decc$translate_vms(argv[0])); - } else - v = PyUnicode_FromString(argv[i]); -#else PyObject *v = PyUnicode_FromWideChar(argv[i], -1); -#endif if (v == NULL) { Py_DECREF(av); av = NULL; -- cgit v1.2.1 From 5ba16378f2629852f6d7a28bf76798c996649dfa Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 28 Mar 2014 18:52:45 -0400 Subject: undefine SET_SYS_FROM_STRING_BORROW after its done being used (closes #21089) --- Python/sysmodule.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 9ec3bfa07b..64de2bf258 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1799,6 +1799,7 @@ _PySys_Init(void) #endif #undef SET_SYS_FROM_STRING +#undef SET_SYS_FROM_STRING_BORROW if (PyErr_Occurred()) return NULL; return m; -- cgit v1.2.1 From 5523a9277647b99d3598afa0e6742baadcf9c127 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 28 Apr 2014 13:07:06 +0200 Subject: Issue #13204: Calling sys.flags.__new__ would crash the interpreter, now it raises a TypeError. --- Python/sysmodule.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 64de2bf258..2366a8c66f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1622,6 +1622,7 @@ PyObject * _PySys_Init(void) { PyObject *m, *sysdict, *version_info; + int res; m = PyModule_Create(&sysmodule); if (m == NULL) @@ -1629,7 +1630,6 @@ _PySys_Init(void) sysdict = PyModule_GetDict(m); #define SET_SYS_FROM_STRING_BORROW(key, value) \ do { \ - int res; \ PyObject *v = (value); \ if (v == NULL) \ return NULL; \ @@ -1640,7 +1640,6 @@ _PySys_Init(void) } while (0) #define SET_SYS_FROM_STRING(key, value) \ do { \ - int res; \ PyObject *v = (value); \ if (v == NULL) \ return NULL; \ @@ -1759,6 +1758,9 @@ _PySys_Init(void) /* prevent user from creating new instances */ VersionInfoType.tp_init = NULL; VersionInfoType.tp_new = NULL; + res = PyDict_DelItemString(VersionInfoType.tp_dict, "__new__"); + if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) + PyErr_Clear(); /* implementation */ SET_SYS_FROM_STRING("implementation", make_impl_info(version_info)); @@ -1772,7 +1774,9 @@ _PySys_Init(void) /* prevent user from creating new instances */ FlagsType.tp_init = NULL; FlagsType.tp_new = NULL; - + res = PyDict_DelItemString(FlagsType.tp_dict, "__new__"); + if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) + PyErr_Clear(); #if defined(MS_WINDOWS) /* getwindowsversion */ @@ -1783,6 +1787,9 @@ _PySys_Init(void) /* prevent user from creating new instances */ WindowsVersionType.tp_init = NULL; WindowsVersionType.tp_new = NULL; + res = PyDict_DelItemString(WindowsVersionType.tp_dict, "__new__"); + if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) + PyErr_Clear(); #endif /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */ -- cgit v1.2.1 From 56bb5116b652c71c7de699510a335f9d93161119 Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Mon, 30 Jun 2014 23:31:14 -0700 Subject: Issue #21891: remove extraneous semicolon. --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 2366a8c66f..840b6ee65a 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1546,7 +1546,7 @@ const char *_PySys_ImplName = NAME; #define STRIFY(name) QUOTE(name) #define MAJOR STRIFY(PY_MAJOR_VERSION) #define MINOR STRIFY(PY_MINOR_VERSION) -#define TAG NAME "-" MAJOR MINOR; +#define TAG NAME "-" MAJOR MINOR const char *_PySys_ImplCacheTag = TAG; #undef NAME #undef QUOTE -- cgit v1.2.1 From ab2ad5607f537872c92b3f7ac231866e9c28b6de Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 14 Aug 2014 22:21:18 +0300 Subject: Issue #22193: Added private function _PySys_GetSizeOf() needed to implement some __sizeof__() methods. --- Python/sysmodule.c | 72 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 32 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 840b6ee65a..39fe53fb7e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -863,29 +863,16 @@ sys_mdebug(PyObject *self, PyObject *args) } #endif /* USE_MALLOPT */ -static PyObject * -sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) +size_t +_PySys_GetSizeOf(PyObject *o) { PyObject *res = NULL; - static PyObject *gc_head_size = NULL; - static char *kwlist[] = {"object", "default", 0}; - PyObject *o, *dflt = NULL; PyObject *method; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", - kwlist, &o, &dflt)) - return NULL; - - /* Initialize static variable for GC head size */ - if (gc_head_size == NULL) { - gc_head_size = PyLong_FromSsize_t(sizeof(PyGC_Head)); - if (gc_head_size == NULL) - return NULL; - } + size_t size; /* Make sure the type is initialized. float gets initialized late */ if (PyType_Ready(Py_TYPE(o)) < 0) - return NULL; + return (size_t)-1; method = _PyObject_LookupSpecial(o, &PyId___sizeof__); if (method == NULL) { @@ -899,24 +886,45 @@ sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) Py_DECREF(method); } - /* Has a default value been given */ - if ((res == NULL) && (dflt != NULL) && - PyErr_ExceptionMatches(PyExc_TypeError)) - { - PyErr_Clear(); - Py_INCREF(dflt); - return dflt; - } - else if (res == NULL) - return res; + if (res == NULL) + return (size_t)-1; + + size = PyLong_AsSize_t(res); + Py_DECREF(res); + if (size == (size_t)-1 && PyErr_Occurred()) + return (size_t)-1; /* add gc_head size */ - if (PyObject_IS_GC(o)) { - PyObject *tmp = res; - res = PyNumber_Add(tmp, gc_head_size); - Py_DECREF(tmp); + if (PyObject_IS_GC(o)) + size += sizeof(PyGC_Head); + return size; +} + +static PyObject * +sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"object", "default", 0}; + size_t size; + PyObject *o, *dflt = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", + kwlist, &o, &dflt)) + return NULL; + + size = _PySys_GetSizeOf(o); + + if (size == (size_t)-1 && PyErr_Occurred()) { + /* Has a default value been given */ + if (dflt != NULL && PyErr_ExceptionMatches(PyExc_TypeError)) { + PyErr_Clear(); + Py_INCREF(dflt); + return dflt; + } + else + return NULL; } - return res; + + return PyLong_FromSize_t(size); } PyDoc_STRVAR(getsizeof_doc, -- cgit v1.2.1 From 5da37a6cb2b66e25844e3ee0b410fcdc5f2da4a6 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 15 Nov 2014 13:21:37 +0200 Subject: Issue #22193: Fixed integer overflow error in sys.getsizeof(). Fixed an error in _PySys_GetSizeOf declaration. --- Python/sysmodule.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 39fe53fb7e..106fc84fa9 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -868,7 +868,7 @@ _PySys_GetSizeOf(PyObject *o) { PyObject *res = NULL; PyObject *method; - size_t size; + Py_ssize_t size; /* Make sure the type is initialized. float gets initialized late */ if (PyType_Ready(Py_TYPE(o)) < 0) @@ -889,15 +889,20 @@ _PySys_GetSizeOf(PyObject *o) if (res == NULL) return (size_t)-1; - size = PyLong_AsSize_t(res); + size = PyLong_AsSsize_t(res); Py_DECREF(res); - if (size == (size_t)-1 && PyErr_Occurred()) + if (size == -1 && PyErr_Occurred()) + return (size_t)-1; + + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "__sizeof__() should return >= 0"); return (size_t)-1; + } /* add gc_head size */ if (PyObject_IS_GC(o)) - size += sizeof(PyGC_Head); - return size; + return ((size_t)size) + sizeof(PyGC_Head); + return (size_t)size; } static PyObject * -- cgit v1.2.1 From 50477cc103aa91bbee30c8aa5c3dd1714f9a11d8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 18 Jan 2015 11:28:37 +0200 Subject: Issue #23181: More "codepoint" -> "code point". --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/sysmodule.c') diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 106fc84fa9..290eec1199 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1368,7 +1368,7 @@ hexversion -- version information encoded as a single integer\n\ implementation -- Python implementation information.\n\ int_info -- a struct sequence with information about the int implementation.\n\ maxsize -- the largest supported length of containers.\n\ -maxunicode -- the value of the largest Unicode codepoint\n\ +maxunicode -- the value of the largest Unicode code point\n\ platform -- platform identifier\n\ prefix -- prefix used to find the Python library\n\ thread_info -- a struct sequence with information about the thread implementation.\n\ -- cgit v1.2.1