[pypy-commit] pypy default: Fix: don't hard-code in the translated pypy the value for

arigo noreply at buildbot.pypy.org
Mon Mar 30 13:32:10 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r76634:180f86a2e1fb
Date: 2015-03-30 13:32 +0200
http://bitbucket.org/pypy/pypy/changeset/180f86a2e1fb/

Log:	Fix: don't hard-code in the translated pypy the value for
	'openssl_md_meth_names'.

diff --git a/pypy/module/_hashlib/__init__.py b/pypy/module/_hashlib/__init__.py
--- a/pypy/module/_hashlib/__init__.py
+++ b/pypy/module/_hashlib/__init__.py
@@ -1,11 +1,10 @@
 from pypy.interpreter.mixedmodule import MixedModule
-from pypy.module._hashlib.interp_hashlib import algorithms
+from pypy.module._hashlib.interp_hashlib import algorithms, fetch_names
 
 
 class Module(MixedModule):
     interpleveldefs = {
         'new' : 'interp_hashlib.new',
-        'openssl_md_meth_names': 'interp_hashlib.get(space).w_meth_names'
         }
 
     appleveldefs = {
@@ -15,5 +14,5 @@
         interpleveldefs['openssl_' + name] = 'interp_hashlib.new_' + name
 
     def startup(self, space):
-        from rpython.rlib.ropenssl import init_digests
-        init_digests()
+        w_meth_names = fetch_names(space)
+        space.setattr(self, space.wrap('openssl_md_meth_names'), w_meth_names)
diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py
--- a/pypy/module/_hashlib/interp_hashlib.py
+++ b/pypy/module/_hashlib/interp_hashlib.py
@@ -16,8 +16,6 @@
 algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
 
 def hash_name_mapper_callback(obj_name, userdata):
-    state = global_state[0]
-    assert state is not None
     if not obj_name:
         return
     # Ignore aliased names, they pollute the list and OpenSSL appears
@@ -27,36 +25,31 @@
     if obj_name[0].c_alias:
         return
     try:
-        w_name = state.space.wrap(rffi.charp2str(obj_name[0].c_name))
-        state.space.call_method(state.w_meth_names, "add", w_name)
+        space = global_name_fetcher.space
+        w_name = space.wrap(rffi.charp2str(obj_name[0].c_name))
+        space.call_method(global_name_fetcher.w_meth_names, "add", w_name)
     except OperationError, e:
-        state.w_error = e
+        global_name_fetcher.w_error = e
 
-# XXX make it threadlocal?
-global_state = [None]
+class NameFetcher:
+    def setup(self, space):
+        self.space = space
+        self.w_meth_names = space.call_function(space.w_set)
+        self.w_error = None
+    def _cleanup_(self):
+        del self.space
+        del self.w_meth_names
+        del self.w_error
+global_name_fetcher = NameFetcher()
 
-class State:
-    def __init__(self, space):
-        self.space = space
-        self.generate_method_names(space)
-
-    def generate_method_names(self, space):
-        if not we_are_translated():
-            ropenssl.init_digests()
-        self.w_error = None
-        try:
-            global_state[0] = self
-            self.w_meth_names = space.call_function(space.w_set)
-            ropenssl.OBJ_NAME_do_all(
-                ropenssl.OBJ_NAME_TYPE_MD_METH,
-                hash_name_mapper_callback, None)
-        finally:
-            global_state[0] = None
-        if self.w_error:
-            raise self.w_error
-
-def get(space):
-    return space.fromcache(State)
+def fetch_names(space):
+    global_name_fetcher.setup(space)
+    ropenssl.init_digests()
+    ropenssl.OBJ_NAME_do_all(ropenssl.OBJ_NAME_TYPE_MD_METH,
+                             hash_name_mapper_callback, None)
+    if global_name_fetcher.w_error:
+        raise global_name_fetcher.w_error
+    return global_name_fetcher.w_meth_names
 
 class W_Hash(W_Root):
     NULL_CTX = lltype.nullptr(ropenssl.EVP_MD_CTX.TO)


More information about the pypy-commit mailing list