mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Fix Access to be reloaded if the python interpreter is restarted when embedded. Fixes #2268.
This commit is contained in:
parent
f5a74e1862
commit
878881b1b9
|
@ -7,7 +7,7 @@ except ImportError:
|
|||
pass
|
||||
|
||||
from PIL import Image
|
||||
|
||||
import sys
|
||||
|
||||
class AccessTest(PillowTestCase):
|
||||
# initial value
|
||||
|
@ -249,5 +249,37 @@ class TestCffi(AccessTest):
|
|||
self.assertEqual(px[i, 0], 0)
|
||||
|
||||
|
||||
class TestEmbeddable(unittest.TestCase):
|
||||
@unittest.skipIf(not sys.platform.startswith('win32'), "requires Windows")
|
||||
def test_embeddable(self):
|
||||
import subprocess
|
||||
from distutils import ccompiler
|
||||
|
||||
with open('embed_pil.c', 'w') as fh:
|
||||
fh.write("""
|
||||
#include "Python.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Py_SetPythonHome( "%s" );
|
||||
|
||||
Py_InitializeEx( 0 );
|
||||
Py_DECREF(PyImport_ImportModule( "PIL.Image" ));
|
||||
Py_Finalize();
|
||||
|
||||
Py_InitializeEx( 0 );
|
||||
Py_DECREF(PyImport_ImportModule( "PIL.Image" ));
|
||||
Py_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
""" % sys.prefix.replace('\\', '\\\\'))
|
||||
|
||||
compiler = ccompiler.new_compiler()
|
||||
objects = compiler.compile(['embed_pil.c'])
|
||||
compiler.link_executable(objects, 'embed_pil')
|
||||
|
||||
subprocess.call(['embed_pil.exe'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -32,7 +32,7 @@ add_item(const char* mode)
|
|||
{
|
||||
UINT32 i = hash(mode);
|
||||
/* printf("hash %s => %d\n", mode, i); */
|
||||
if (access_table[i].mode) {
|
||||
if (access_table[i].mode && strcmp(access_table[i].mode, mode) != 0) {
|
||||
fprintf(stderr, "AccessInit: hash collision: %d for both %s and %s\n",
|
||||
i, mode, access_table[i].mode);
|
||||
exit(1);
|
||||
|
|
Loading…
Reference in New Issue
Block a user