mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #9425: Create PyErr_WarnFormat() function
Similar to PyErr_WarnEx() but use PyUnicode_FromFormatV() to format the warning message. Strip also some trailing spaces.
This commit is contained in:
parent
b4b8eb9163
commit
4a2b7a1b14
7 changed files with 74 additions and 34 deletions
|
@ -56,10 +56,6 @@ PyModule_New(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static char api_version_warning[] =
|
||||
"Python C API version mismatch for module %.100s:\
|
||||
This Python has API version %d, module %.100s has version %d.";
|
||||
|
||||
PyObject *
|
||||
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
|
||||
{
|
||||
|
@ -79,12 +75,13 @@ PyModule_Create2(struct PyModuleDef* module, int module_api_version)
|
|||
}
|
||||
name = module->m_name;
|
||||
if (module_api_version != PYTHON_API_VERSION) {
|
||||
char message[512];
|
||||
PyOS_snprintf(message, sizeof(message),
|
||||
api_version_warning, name,
|
||||
PYTHON_API_VERSION, name,
|
||||
module_api_version);
|
||||
if (PyErr_WarnEx(PyExc_RuntimeWarning, message, 1))
|
||||
int err;
|
||||
err = PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
|
||||
"Python C API version mismatch for module %.100s: "
|
||||
"This Python has API version %d, module %.100s has version %d.",
|
||||
name,
|
||||
PYTHON_API_VERSION, name, module_api_version);
|
||||
if (err)
|
||||
return NULL;
|
||||
}
|
||||
/* Make sure name is fully qualified.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue