diff options
author | Marc-André Lemburg <mal@egenix.com> | 2001-07-31 13:24:44 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2001-07-31 13:24:44 (GMT) |
commit | e5006ebc9d0618bc500afebfa1e21b6aae2a22e3 (patch) | |
tree | 021cf814e21772f87b22cac30a4aeada787085bc /Python/modsupport.c | |
parent | b9d07b5a8b8b70268ffa520895e7843ab594a486 (diff) | |
download | cpython-e5006ebc9d0618bc500afebfa1e21b6aae2a22e3.zip cpython-e5006ebc9d0618bc500afebfa1e21b6aae2a22e3.tar.gz cpython-e5006ebc9d0618bc500afebfa1e21b6aae2a22e3.tar.bz2 |
This patch turns the Python API mismatch notice into a standard
Python warning which can be catched by means of the Python warning
framework.
It also adds two new APIs which hopefully make it easier for Python
to switch to buffer overflow safe [v]snprintf() APIs for error
reporting et al. The two new APIs are PyOS_snprintf() and
PyOS_vsnprintf() and work just like the standard ones in many
C libs. On platforms which have snprintf(), the native APIs are used,
on all other an emulation with snprintf() tries to do its best.
Diffstat (limited to 'Python/modsupport.c')
-rw-r--r-- | Python/modsupport.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c index 0868589..eb0818c 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -26,8 +26,8 @@ char *_Py_PackageContext = NULL; */ static char api_version_warning[] = -"WARNING: Python C API version mismatch for module %s:\n\ - This Python has API version %d, module %s has version %d.\n"; +"Python C API version mismatch for module %.100s:\ + This Python has API version %d, module %.100s has version %d."; PyObject * Py_InitModule4(char *name, PyMethodDef *methods, char *doc, @@ -37,9 +37,15 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc, PyMethodDef *ml; if (!Py_IsInitialized()) Py_FatalError("Interpreter not initialized (version mismatch?)"); - if (module_api_version != PYTHON_API_VERSION) - fprintf(stderr, api_version_warning, - name, PYTHON_API_VERSION, name, module_api_version); + 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_Warn(PyExc_RuntimeWarning, message)) + return NULL; + } if (_Py_PackageContext != NULL) { char *p = strrchr(_Py_PackageContext, '.'); if (p != NULL && strcmp(name, p+1) == 0) { |