From d1d013c01c268d869597b35cbcd8b5d7c5baf2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Wed, 28 Sep 2011 07:41:54 +0200 Subject: Implement PEP 393. --- Python/errors.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 5a9a624279..149151ebfa 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -395,7 +395,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) /* remove trailing cr/lf and dots */ while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.')) s_buf[--len] = L'\0'; - message = PyUnicode_FromUnicode(s_buf, len); + message = PyUnicode_FromWideChar(s_buf, len); } } } @@ -487,7 +487,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( /* remove trailing cr/lf and dots */ while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.')) s_buf[--len] = L'\0'; - message = PyUnicode_FromUnicode(s_buf, len); + message = PyUnicode_FromWideChar(s_buf, len); } if (message == NULL) -- cgit v1.2.1 From c3eb93fe1ce5f5ff2666fb9f34a6fd7c46279554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 10 Oct 2011 18:11:30 +0200 Subject: Use identifier API for PyObject_GetAttrString. --- Python/errors.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 149151ebfa..02f84b46ac 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -707,6 +707,7 @@ PyErr_NewExceptionWithDoc(const char *name, const char *doc, void PyErr_WriteUnraisable(PyObject *obj) { + _Py_identifier(__module__); PyObject *f, *t, *v, *tb; PyErr_Fetch(&t, &v, &tb); f = PySys_GetObject("stderr"); @@ -723,7 +724,7 @@ PyErr_WriteUnraisable(PyObject *obj) className = dot+1; } - moduleName = PyObject_GetAttrString(t, "__module__"); + moduleName = _PyObject_GetAttrId(t, &PyId___module__); if (moduleName == NULL) PyFile_WriteString("", f); else { -- cgit v1.2.1 From f52a051081e30c3421e009d1369e4f6be081fd93 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 12 Oct 2011 02:54:14 +0200 Subject: PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy. --- Python/errors.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 02f84b46ac..6e69d23c30 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -496,10 +496,11 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( return NULL; } - if (filenameObject != NULL) - v = Py_BuildValue("(iOO)", err, message, filenameObject); - else - v = Py_BuildValue("(iO)", err, message); + if (filenameObject == NULL) + filenameObject = Py_None; + /* This is the constructor signature for passing a Windows error code. + The POSIX translation will be figured out by the constructor. */ + v = Py_BuildValue("(iOOi)", 0, message, filenameObject, err); Py_DECREF(message); if (v != NULL) { -- cgit v1.2.1 From edb19b80f00cf42741fa66efdcab2f25a9fb3f08 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 12 Oct 2011 19:39:57 +0200 Subject: Instantiate the OS-related exception as soon as we raise it, so that "except" works properly. --- Python/errors.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 6e69d23c30..5988e1bf89 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -341,7 +341,7 @@ PyObject * PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) { PyObject *message; - PyObject *v; + PyObject *v, *args; int i = errno; #ifndef MS_WINDOWS char *s; @@ -410,14 +410,18 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) } if (filenameObject != NULL) - v = Py_BuildValue("(iOO)", i, message, filenameObject); + args = Py_BuildValue("(iOO)", i, message, filenameObject); else - v = Py_BuildValue("(iO)", i, message); + args = Py_BuildValue("(iO)", i, message); Py_DECREF(message); - if (v != NULL) { - PyErr_SetObject(exc, v); - Py_DECREF(v); + if (args != NULL) { + v = PyObject_Call(exc, args, NULL); + Py_DECREF(args); + if (v != NULL) { + PyErr_SetObject((PyObject *) Py_TYPE(v), v); + Py_DECREF(v); + } } #ifdef MS_WINDOWS LocalFree(s_buf); -- cgit v1.2.1 From f5ad3b280b43227eb0e3fa63d89490a58ba9c28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 14 Oct 2011 10:20:37 +0200 Subject: Rename _Py_identifier to _Py_IDENTIFIER. --- Python/errors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 5988e1bf89..998bef6a67 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -712,7 +712,7 @@ PyErr_NewExceptionWithDoc(const char *name, const char *doc, void PyErr_WriteUnraisable(PyObject *obj) { - _Py_identifier(__module__); + _Py_IDENTIFIER(__module__); PyObject *f, *t, *v, *tb; PyErr_Fetch(&t, &v, &tb); f = PySys_GetObject("stderr"); -- cgit v1.2.1 From 406e4d8f1d3d003e8754d9e65607a697e7f5c865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 14 Oct 2011 15:16:45 +0200 Subject: Port SetAttrString/HasAttrString to SetAttrId/GetAttrId. --- Python/errors.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 998bef6a67..d62648ba3a 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -780,6 +780,12 @@ void PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) { PyObject *exc, *v, *tb, *tmp; + _Py_IDENTIFIER(filename); + _Py_IDENTIFIER(lineno); + _Py_IDENTIFIER(msg); + _Py_IDENTIFIER(offset); + _Py_IDENTIFIER(print_file_and_line); + _Py_IDENTIFIER(text); /* add attributes for the line number and filename for the error */ PyErr_Fetch(&exc, &v, &tb); @@ -790,7 +796,7 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) if (tmp == NULL) PyErr_Clear(); else { - if (PyObject_SetAttrString(v, "lineno", tmp)) + if (_PyObject_SetAttrId(v, &PyId_lineno, tmp)) PyErr_Clear(); Py_DECREF(tmp); } @@ -799,7 +805,7 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) if (tmp == NULL) PyErr_Clear(); else { - if (PyObject_SetAttrString(v, "offset", tmp)) + if (_PyObject_SetAttrId(v, &PyId_offset, tmp)) PyErr_Clear(); Py_DECREF(tmp); } @@ -809,35 +815,35 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset) if (tmp == NULL) PyErr_Clear(); else { - if (PyObject_SetAttrString(v, "filename", tmp)) + if (_PyObject_SetAttrId(v, &PyId_filename, tmp)) PyErr_Clear(); Py_DECREF(tmp); } tmp = PyErr_ProgramText(filename, lineno); if (tmp) { - if (PyObject_SetAttrString(v, "text", tmp)) + if (_PyObject_SetAttrId(v, &PyId_text, tmp)) PyErr_Clear(); Py_DECREF(tmp); } } - if (PyObject_SetAttrString(v, "offset", Py_None)) { + if (_PyObject_SetAttrId(v, &PyId_offset, Py_None)) { PyErr_Clear(); } if (exc != PyExc_SyntaxError) { - if (!PyObject_HasAttrString(v, "msg")) { + if (!_PyObject_HasAttrId(v, &PyId_msg)) { tmp = PyObject_Str(v); if (tmp) { - if (PyObject_SetAttrString(v, "msg", tmp)) + if (_PyObject_SetAttrId(v, &PyId_msg, tmp)) PyErr_Clear(); Py_DECREF(tmp); } else { PyErr_Clear(); } } - if (!PyObject_HasAttrString(v, "print_file_and_line")) { - if (PyObject_SetAttrString(v, "print_file_and_line", - Py_None)) + if (!_PyObject_HasAttrId(v, &PyId_print_file_and_line)) { + if (_PyObject_SetAttrId(v, &PyId_print_file_and_line, + Py_None)) PyErr_Clear(); } } -- cgit v1.2.1 From f8ba1a5cbeb56fe6ac204f3bdef184156b20aa4d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 17 Oct 2011 20:18:58 +0200 Subject: Instantiate the OS-related exception as soon as we raise it, so that "except" works properly. PyErr_SetFromErrnoWithFilenameObject() was already fixed by the changeset 793c75177d28. This commit fixes PyErr_SetExcFromWindowsErrWithFilenameObject(), used on Windows. --- Python/errors.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index d62648ba3a..cd0f68dff4 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -468,7 +468,7 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( int len; WCHAR *s_buf = NULL; /* Free via LocalFree */ PyObject *message; - PyObject *v; + PyObject *args, *v; DWORD err = (DWORD)ierr; if (err==0) err = GetLastError(); len = FormatMessageW( @@ -504,12 +504,16 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( filenameObject = Py_None; /* This is the constructor signature for passing a Windows error code. The POSIX translation will be figured out by the constructor. */ - v = Py_BuildValue("(iOOi)", 0, message, filenameObject, err); + args = Py_BuildValue("(iOOi)", 0, message, filenameObject, err); Py_DECREF(message); - if (v != NULL) { - PyErr_SetObject(exc, v); - Py_DECREF(v); + if (args != NULL) { + v = PyObject_Call(exc, args, NULL); + Py_DECREF(args); + if (v != NULL) { + PyErr_SetObject((PyObject *) Py_TYPE(v), v); + Py_DECREF(v); + } } LocalFree(s_buf); return NULL; -- cgit v1.2.1 From b15cf649f348f5af9bd8f38405377c5be866a6d8 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Mon, 12 Dec 2011 18:54:29 +0100 Subject: Issue #13575: there is only one class type. --- Python/errors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index cd0f68dff4..36b8c545ac 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -665,7 +665,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) if (bases == NULL) goto failure; } - /* Create a real new-style class. */ + /* Create a real class. */ result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO", dot+1, bases, dict); failure: -- cgit v1.2.1 From 6e12c9c2963cfe7327fcdf99f151c05f5cdaf240 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 17 Dec 2011 04:45:09 +0100 Subject: Issue #13560: os.strerror() now uses the current locale encoding instead of UTF-8 --- Python/errors.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 36b8c545ac..122e444b82 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -343,9 +343,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) PyObject *message; PyObject *v, *args; int i = errno; -#ifndef MS_WINDOWS - char *s; -#else +#ifdef MS_WINDOWS WCHAR *s_buf = NULL; #endif /* Unix/Windows */ @@ -355,11 +353,14 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) #endif #ifndef MS_WINDOWS - if (i == 0) - s = "Error"; /* Sometimes errno didn't get set */ - else - s = strerror(i); - message = PyUnicode_DecodeUTF8(s, strlen(s), "ignore"); + if (i != 0) { + char *s = strerror(i); + message = PyUnicode_DecodeLocale(s, 1); + } + else { + /* Sometimes errno didn't get set */ + message = PyUnicode_FromString("Error"); + } #else if (i == 0) message = PyUnicode_FromString("Error"); /* Sometimes errno didn't get set */ -- cgit v1.2.1 From d7170a94c2cd4e21a5c81fb30344839b63bbe313 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 17 Dec 2011 05:47:23 +0100 Subject: Issue #13560: Locale codec functions use the classic "errors" parameter, instead of surrogateescape So it would be possible to support more error handlers later. --- Python/errors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 122e444b82..31fa9e2955 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -355,7 +355,7 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) #ifndef MS_WINDOWS if (i != 0) { char *s = strerror(i); - message = PyUnicode_DecodeLocale(s, 1); + message = PyUnicode_DecodeLocale(s, "surrogateescape"); } else { /* Sometimes errno didn't get set */ -- cgit v1.2.1 From 6c2c39a063041c5df28659a9766a9d67b629fd23 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Thu, 12 Apr 2012 20:24:54 -0400 Subject: Issue #1559549: Add 'name' and 'path' attributes to ImportError. Currently import does not use these attributes as they are planned for use by importlib (which will be another commit). Thanks to Filip Gruszczy?ski for the initial patch and Brian Curtin for refining it. --- Python/errors.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 31fa9e2955..345a345afe 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -585,6 +585,53 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( } #endif /* MS_WINDOWS */ +PyObject * +PyErr_SetExcWithArgsKwargs(PyObject *exc, PyObject *args, PyObject *kwargs) +{ + PyObject *val; + + /* args must at least be an empty tuple */ + if (args == NULL) + args = PyTuple_New(0); + + val = PyObject_Call(exc, args, kwargs); + if (val != NULL) { + PyErr_SetObject((PyObject *) Py_TYPE(val), val); + Py_DECREF(val); + } + + return NULL; +} + +PyObject * +PyErr_SetFromImportErrorWithNameAndPath(PyObject *msg, + PyObject *name, PyObject *path) +{ + PyObject *args = PyTuple_New(1); + PyObject *kwargs = PyDict_New(); + PyObject *result; + + if (path == NULL) + path = Py_None; + + PyTuple_SetItem(args, 0, msg); + PyDict_SetItemString(kwargs, "name", name); + PyDict_SetItemString(kwargs, "path", path); + + result = PyErr_SetExcWithArgsKwargs(PyExc_ImportError, args, kwargs); + + Py_DECREF(args); + Py_DECREF(kwargs); + + return result; +} + +PyObject * +PyErr_SetFromImportErrorWithName(PyObject *msg, PyObject *name) +{ + return PyErr_SetFromImportErrorWithNameAndPath(msg, name, NULL); +} + void _PyErr_BadInternalCall(const char *filename, int lineno) { -- cgit v1.2.1 From 5d8520121e1ea38bcfe37258449a946ee328cac1 Mon Sep 17 00:00:00 2001 From: Brian Curtin Date: Tue, 17 Apr 2012 16:57:09 -0500 Subject: Fix #14600. Correct reference handling and naming of ImportError convenience function --- Python/errors.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 345a345afe..a49cde6247 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -586,50 +586,43 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( #endif /* MS_WINDOWS */ PyObject * -PyErr_SetExcWithArgsKwargs(PyObject *exc, PyObject *args, PyObject *kwargs) +PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) { - PyObject *val; + PyObject *args, *kwargs, *error; - /* args must at least be an empty tuple */ + args = PyTuple_New(1); if (args == NULL) - args = PyTuple_New(0); - - val = PyObject_Call(exc, args, kwargs); - if (val != NULL) { - PyErr_SetObject((PyObject *) Py_TYPE(val), val); - Py_DECREF(val); - } + return NULL; - return NULL; -} + kwargs = PyDict_New(); + if (args == NULL) + return NULL; -PyObject * -PyErr_SetFromImportErrorWithNameAndPath(PyObject *msg, - PyObject *name, PyObject *path) -{ - PyObject *args = PyTuple_New(1); - PyObject *kwargs = PyDict_New(); - PyObject *result; + if (name == NULL) + name = Py_None; if (path == NULL) path = Py_None; + Py_INCREF(msg); PyTuple_SetItem(args, 0, msg); PyDict_SetItemString(kwargs, "name", name); PyDict_SetItemString(kwargs, "path", path); - result = PyErr_SetExcWithArgsKwargs(PyExc_ImportError, args, kwargs); + /* args must at least be an empty tuple */ + if (args == NULL) + args = PyTuple_New(0); + + error = PyObject_Call(PyExc_ImportError, args, kwargs); + if (error!= NULL) { + PyErr_SetObject((PyObject *) Py_TYPE(error), error); + Py_DECREF(error); + } Py_DECREF(args); Py_DECREF(kwargs); - return result; -} - -PyObject * -PyErr_SetFromImportErrorWithName(PyObject *msg, PyObject *name) -{ - return PyErr_SetFromImportErrorWithNameAndPath(msg, name, NULL); + return NULL; } void -- cgit v1.2.1 From 013a85ff656fa0156dbfe26ec30698ebb9bfdf70 Mon Sep 17 00:00:00 2001 From: Brian Curtin Date: Wed, 18 Apr 2012 08:30:51 -0500 Subject: Fix email post-commit review comments. Add INCREFs, fix args->kwargs, and a second args==NULL check was removed, left over from a merger with another function. Instead, checking msg==NULL does what that used to do in a roundabout way. --- Python/errors.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index a49cde6247..63eebe2e77 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -590,29 +590,32 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) { PyObject *args, *kwargs, *error; + if (msg == NULL) + return NULL; + args = PyTuple_New(1); if (args == NULL) return NULL; kwargs = PyDict_New(); - if (args == NULL) + if (kwargs == NULL) return NULL; - if (name == NULL) + if (name == NULL) { + Py_INCREF(Py_None); name = Py_None; + } - if (path == NULL) + if (path == NULL) { + Py_INCREF(Py_None); path = Py_None; + } Py_INCREF(msg); - PyTuple_SetItem(args, 0, msg); + PyTuple_SetItem(args, 0, NULL);//msg); PyDict_SetItemString(kwargs, "name", name); PyDict_SetItemString(kwargs, "path", path); - /* args must at least be an empty tuple */ - if (args == NULL) - args = PyTuple_New(0); - error = PyObject_Call(PyExc_ImportError, args, kwargs); if (error!= NULL) { PyErr_SetObject((PyObject *) Py_TYPE(error), error); -- cgit v1.2.1 From f67d48c67432fafbe397e581a419ac8408bd9463 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 18 Apr 2012 10:48:00 -0400 Subject: fix refcnt/style/debuging oversights --- Python/errors.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 63eebe2e77..558404a1ee 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -593,13 +593,15 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) if (msg == NULL) return NULL; - args = PyTuple_New(1); + args = PyTuple_New(0); if (args == NULL) return NULL; kwargs = PyDict_New(); - if (kwargs == NULL) + if (kwargs == NULL) { + Py_DECREF(args); return NULL; + } if (name == NULL) { Py_INCREF(Py_None); @@ -612,13 +614,13 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) } Py_INCREF(msg); - PyTuple_SetItem(args, 0, NULL);//msg); + PyTuple_SET_ITEM(args, 0, msg); PyDict_SetItemString(kwargs, "name", name); PyDict_SetItemString(kwargs, "path", path); error = PyObject_Call(PyExc_ImportError, args, kwargs); - if (error!= NULL) { - PyErr_SetObject((PyObject *) Py_TYPE(error), error); + if (error != NULL) { + PyErr_SetObject((PyObject *)Py_TYPE(error), error); Py_DECREF(error); } -- cgit v1.2.1 From cfbf44cab972e0e29602d100e7f5b97595c522b5 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 18 Apr 2012 16:57:54 +0200 Subject: Fix it for good :-) --- Python/errors.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 558404a1ee..36ab3d87fe 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -593,7 +593,7 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) if (msg == NULL) return NULL; - args = PyTuple_New(0); + args = PyTuple_New(1); if (args == NULL) return NULL; @@ -604,12 +604,10 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) } if (name == NULL) { - Py_INCREF(Py_None); name = Py_None; } if (path == NULL) { - Py_INCREF(Py_None); path = Py_None; } -- cgit v1.2.1 From 0d2fbd15924e7def207b34fc325422aec4519757 Mon Sep 17 00:00:00 2001 From: "Martin v. L?wis" Date: Thu, 19 Apr 2012 14:33:43 +0200 Subject: Issue #14098: New functions PyErr_GetExcInfo and PyErr_SetExcInfo. Patch by Stefan Behnel. --- Python/errors.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 36ab3d87fe..626b16e46f 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -320,6 +320,39 @@ PyErr_Clear(void) PyErr_Restore(NULL, NULL, NULL); } +void +PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) +{ + PyThreadState *tstate = PyThreadState_GET(); + + *p_type = tstate->exc_type; + *p_value = tstate->exc_value; + *p_traceback = tstate->exc_traceback; + + Py_XINCREF(*p_type); + Py_XINCREF(*p_value); + Py_XINCREF(*p_traceback); +} + +void +PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback) +{ + PyObject *oldtype, *oldvalue, *oldtraceback; + PyThreadState *tstate = PyThreadState_GET(); + + oldtype = tstate->exc_type; + oldvalue = tstate->exc_value; + oldtraceback = tstate->exc_traceback; + + tstate->exc_type = p_type; + tstate->exc_value = p_value; + tstate->exc_traceback = p_traceback; + + Py_XDECREF(oldtype); + Py_XDECREF(oldvalue); + Py_XDECREF(oldtraceback); +} + /* Convenience functions to set a type error exception and return 0 */ int -- cgit v1.2.1