Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: exctrans
Changeset: r81770:ae4115e11c00
Date: 2016-01-13 00:09 +0000
http://bitbucket.org/pypy/pypy/changeset/ae4115e11c00/

Log:    Extract name computation out of FuncNode.__init__

diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -818,17 +818,10 @@
         self.globalcontainer = True
         self.T = T
         self.obj = obj
-        callable = getattr(obj, '_callable', None)
-        if (callable is not None and
-            getattr(callable, 'c_name', None) is not None):
-            self.name = forcename or obj._callable.c_name
-        elif (getattr(obj, 'external', None) == 'C' and
-              (not db.sandbox or not need_sandboxing(obj))):
-            self.name = forcename or self.basename()
+        if forcename:
+            self.name = forcename
         else:
-            self.name = (forcename or
-                         db.namespace.uniquename('g_' + self.basename()))
-
+            self.name = _select_name(db, obj)
         self.funcgen = select_function_code_generators(obj, db, self.name)
         if self.funcgen:
             argnames = self.funcgen.argnames()
@@ -958,6 +951,17 @@
     else:
         raise ValueError("don't know how to generate code for %r" % (fnobj,))
 
+def _select_name(db, obj):
+    try:
+        return obj._callable.c_name
+    except AttributeError:
+        pass
+    if (getattr(obj, 'external', None) == 'C' and
+            (not db.sandbox or not need_sandboxing(obj))):
+        return obj._name
+    return db.namespace.uniquename('g_' + obj._name)
+
+
 class ExtType_OpaqueNode(ContainerNode):
     nodekind = 'rpyopaque'
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to