[Python-checkins] python/dist/src/Python codecs.c,2.13.26.2,2.13.26.3 pystate.c,2.20.16.2,2.20.16.3 pythonrun.c,2.153.6.4,2.153.6.5
loewis@users.sourceforge.net
loewis@users.sourceforge.net
Sun, 30 Mar 2003 12:57:33 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv31662/Python
Modified Files:
Tag: release22-maint
codecs.c pystate.c pythonrun.c
Log Message:
Patch #710576: Implement per-interpreter-state codec registries.
Index: codecs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/codecs.c,v
retrieving revision 2.13.26.2
retrieving revision 2.13.26.3
diff -C2 -d -r2.13.26.2 -r2.13.26.3
*** codecs.c 30 Sep 2002 10:52:21 -0000 2.13.26.2
--- codecs.c 30 Mar 2003 20:57:31 -0000 2.13.26.3
***************
*** 12,23 ****
#include <ctype.h>
- /* --- Globals ------------------------------------------------------------ */
-
- static PyObject *_PyCodec_SearchPath;
- static PyObject *_PyCodec_SearchCache;
-
- /* Flag used for lazy import of the standard encodings package */
- static int import_encodings_called = 0;
-
/* --- Codec Registry ----------------------------------------------------- */
--- 12,15 ----
***************
*** 33,65 ****
*/
! static
! int import_encodings(void)
! {
! PyObject *mod;
!
! import_encodings_called = 1;
! mod = PyImport_ImportModule("encodings");
! if (mod == NULL) {
! if (PyErr_ExceptionMatches(PyExc_ImportError)) {
! /* Ignore ImportErrors... this is done so that
! distributions can disable the encodings package. Note
! that other errors are not masked, e.g. SystemErrors
! raised to inform the user of an error in the Python
! configuration are still reported back to the user. */
! PyErr_Clear();
! return 0;
! }
! return -1;
! }
! Py_DECREF(mod);
! return 0;
! }
int PyCodec_Register(PyObject *search_function)
{
! if (!import_encodings_called) {
! if (import_encodings())
! goto onError;
! }
if (search_function == NULL) {
PyErr_BadArgument();
--- 25,35 ----
*/
! static int _PyCodecRegistry_Init(void); /* Forward */
int PyCodec_Register(PyObject *search_function)
{
! PyInterpreterState *interp = PyThreadState_Get()->interp;
! if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
! goto onError;
if (search_function == NULL) {
PyErr_BadArgument();
***************
*** 71,75 ****
goto onError;
}
! return PyList_Append(_PyCodec_SearchPath, search_function);
onError:
--- 41,45 ----
goto onError;
}
! return PyList_Append(interp->codec_search_path, search_function);
onError:
***************
*** 125,128 ****
--- 95,99 ----
PyObject *_PyCodec_Lookup(const char *encoding)
{
+ PyInterpreterState *interp;
PyObject *result, *args = NULL, *v;
int i, len;
***************
*** 132,145 ****
goto onError;
}
! if (_PyCodec_SearchCache == NULL ||
! _PyCodec_SearchPath == NULL) {
! PyErr_SetString(PyExc_SystemError,
! "codec module not properly initialized");
goto onError;
- }
- if (!import_encodings_called) {
- if (import_encodings())
- goto onError;
- }
/* Convert the encoding to a normalized Python string: all
--- 103,110 ----
goto onError;
}
!
! interp = PyThreadState_Get()->interp;
! if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
goto onError;
/* Convert the encoding to a normalized Python string: all
***************
*** 152,156 ****
/* First, try to lookup the name in the registry dictionary */
! result = PyDict_GetItem(_PyCodec_SearchCache, v);
if (result != NULL) {
Py_INCREF(result);
--- 117,121 ----
/* First, try to lookup the name in the registry dictionary */
! result = PyDict_GetItem(interp->codec_search_cache, v);
if (result != NULL) {
Py_INCREF(result);
***************
*** 165,169 ****
PyTuple_SET_ITEM(args,0,v);
! len = PyList_Size(_PyCodec_SearchPath);
if (len < 0)
goto onError;
--- 130,134 ----
PyTuple_SET_ITEM(args,0,v);
! len = PyList_Size(interp->codec_search_path);
if (len < 0)
goto onError;
***************
*** 178,182 ****
PyObject *func;
! func = PyList_GetItem(_PyCodec_SearchPath, i);
if (func == NULL)
goto onError;
--- 143,147 ----
PyObject *func;
! func = PyList_GetItem(interp->codec_search_path, i);
if (func == NULL)
goto onError;
***************
*** 204,208 ****
/* Cache and return the result */
! PyDict_SetItem(_PyCodec_SearchCache, v, result);
Py_DECREF(args);
return result;
--- 169,173 ----
/* Cache and return the result */
! PyDict_SetItem(interp->codec_search_cache, v, result);
Py_DECREF(args);
return result;
***************
*** 423,442 ****
}
! void _PyCodecRegistry_Init(void)
{
! if (_PyCodec_SearchPath == NULL)
! _PyCodec_SearchPath = PyList_New(0);
! if (_PyCodec_SearchCache == NULL)
! _PyCodec_SearchCache = PyDict_New();
! if (_PyCodec_SearchPath == NULL ||
! _PyCodec_SearchCache == NULL)
Py_FatalError("can't initialize codec registry");
- }
! void _PyCodecRegistry_Fini(void)
! {
! Py_XDECREF(_PyCodec_SearchPath);
! _PyCodec_SearchPath = NULL;
! Py_XDECREF(_PyCodec_SearchCache);
! _PyCodec_SearchCache = NULL;
}
--- 388,420 ----
}
! static int _PyCodecRegistry_Init(void)
{
! PyInterpreterState *interp = PyThreadState_Get()->interp;
! PyObject *mod;
!
! if (interp->codec_search_path != NULL)
! return 0;
!
! interp->codec_search_path = PyList_New(0);
! interp->codec_search_cache = PyDict_New();
!
! if (interp->codec_search_path == NULL ||
! interp->codec_search_cache == NULL)
Py_FatalError("can't initialize codec registry");
! mod = PyImport_ImportModuleEx("encodings", NULL, NULL, NULL);
! if (mod == NULL) {
! if (PyErr_ExceptionMatches(PyExc_ImportError)) {
! /* Ignore ImportErrors... this is done so that
! distributions can disable the encodings package. Note
! that other errors are not masked, e.g. SystemErrors
! raised to inform the user of an error in the Python
! configuration are still reported back to the user. */
! PyErr_Clear();
! return 0;
! }
! return -1;
! }
! Py_DECREF(mod);
! return 0;
}
Index: pystate.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pystate.c,v
retrieving revision 2.20.16.2
retrieving revision 2.20.16.3
diff -C2 -d -r2.20.16.2 -r2.20.16.3
*** pystate.c 8 Oct 2002 14:50:55 -0000 2.20.16.2
--- pystate.c 30 Mar 2003 20:57:31 -0000 2.20.16.3
***************
*** 51,54 ****
--- 51,56 ----
interp->checkinterval = 10;
interp->tstate_head = NULL;
+ interp->codec_search_path = NULL;
+ interp->codec_search_cache = NULL;
#ifdef HAVE_DLOPEN
#ifdef RTLD_NOW
***************
*** 77,80 ****
--- 79,84 ----
PyThreadState_Clear(p);
HEAD_UNLOCK();
+ ZAP(interp->codec_search_path);
+ ZAP(interp->codec_search_cache);
ZAP(interp->modules);
ZAP(interp->sysdict);
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.153.6.4
retrieving revision 2.153.6.5
diff -C2 -d -r2.153.6.4 -r2.153.6.5
*** pythonrun.c 20 Nov 2002 02:38:10 -0000 2.153.6.4
--- pythonrun.c 30 Mar 2003 20:57:31 -0000 2.153.6.5
***************
*** 50,55 ****
extern void _PyUnicode_Init(void);
extern void _PyUnicode_Fini(void);
- extern void _PyCodecRegistry_Init(void);
- extern void _PyCodecRegistry_Fini(void);
int Py_DebugFlag; /* Needed by parser.c */
--- 50,53 ----
***************
*** 134,140 ****
Py_FatalError("Py_Initialize: can't make modules dictionary");
- /* Init codec registry */
- _PyCodecRegistry_Init();
-
#ifdef Py_USING_UNICODE
/* Init Unicode implementation; relies on the codec registry */
--- 132,135 ----
***************
*** 219,225 ****
/* Disable signal handling */
PyOS_FiniInterrupts();
-
- /* Cleanup Codec registry */
- _PyCodecRegistry_Fini();
/* Destroy all modules */
--- 214,217 ----