[Python-bugs-list] [ python-Bugs-663074 ] codec registry and Python embedding problem
SourceForge.net
noreply@sourceforge.net
Sat, 01 Mar 2003 00:07:50 -0800
Bugs item #663074, was opened at 2003-01-06 12:17
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=663074&group_id=5470
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: M.-A. Lemburg (lemburg)
Assigned to: Gustavo Niemeyer (niemeyer)
Summary: codec registry and Python embedding problem
Initial Comment:
Found by Hartmut Ring:
#include <Python.h>
int main() {
for (int i=0; i<2; i++) {
Py_Initialize();
PyRun_SimpleString("a = u'\xe4'.encode('Latin-1')");
Py_Finalize();
}
return 0;
}
First try runs fine, second try gives:
Traceback (most recent call last):
File "<string>", line 1, in ?
LookupError: no codec search functions registered:
can't find encoding
----------------------------------------------------------------------
>Comment By: Gustavo Niemeyer (niemeyer)
Date: 2003-03-01 08:07
Message:
Logged In: YES
user_id=7887
Here is a proposed solution.
It has been tested with the standard regression tests, and
in an environment with multiple interpreters.
----------------------------------------------------------------------
Comment By: Gustavo Niemeyer (niemeyer)
Date: 2003-02-12 13:13
Message:
Logged In: YES
user_id=7887
As discussed in python-dev, I'll work on that.
----------------------------------------------------------------------
Comment By: M.-A. Lemburg (lemburg)
Date: 2003-01-22 12:12
Message:
Logged In: YES
user_id=38388
Good suggestion. Do you have time to cook up a patch ?
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2003-01-22 10:07
Message:
Logged In: YES
user_id=21627
I think the various global variables maintained in codecs.c
(_PyCodec_SearchCache, import_encodings_called, ...) need to
become part of the interpreter state. Otherwise, a codec
registered in one interpreter will be found in another.
Also, it appears that import_encodings_called can be
eliminated. Instead, a NULL value of _PyCodec_SearchPath
could be used to indicate whether initialization has taken
place.
----------------------------------------------------------------------
Comment By: M.-A. Lemburg (lemburg)
Date: 2003-01-06 12:18
Message:
Logged In: YES
user_id=38388
This is due to a flag used in codecs.c:
/* Flag used for lazy import of the standard encodings
package */
static int import_encodings_called = 0;
The solution is to reset this flag in Py_Finalize().
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=663074&group_id=5470