[pypy-svn] r39850 - pypy/dist/pypy/translator/c

xoraxax at codespeak.net xoraxax at codespeak.net
Sun Mar 4 10:59:17 CET 2007


Author: xoraxax
Date: Sun Mar  4 10:59:16 2007
New Revision: 39850

Modified:
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/c/support.py
Log:
Add the possiblity of having __thread globals in genc. Note that the code doesnt actually use the result of the __thread check that is done before code generation.

Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Sun Mar  4 10:59:16 2007
@@ -406,15 +406,18 @@
             self.ptrname = '((%s)(void*)%s)' % (cdecl(ptrtypename, ''),
                                                 self.ptrname)
 
+    def is_thread_local(self):
+        return hasattr(self.T, "_hints") and self.T._hints.get('thread_local')
+
     def forward_declaration(self):
         yield '%s;' % (
             forward_cdecl(self.implementationtypename,
-                self.name, self.db.standalone))
+                self.name, self.db.standalone, self.is_thread_local()))
 
     def implementation(self):
         lines = list(self.initializationexpr())
         lines[0] = '%s = %s' % (
-            cdecl(self.implementationtypename, self.name),
+            cdecl(self.implementationtypename, self.name, self.is_thread_local()),
             lines[0])
         lines[-1] += ';'
         return lines

Modified: pypy/dist/pypy/translator/c/support.py
==============================================================================
--- pypy/dist/pypy/translator/c/support.py	(original)
+++ pypy/dist/pypy/translator/c/support.py	Sun Mar  4 10:59:16 2007
@@ -18,7 +18,7 @@
 #
 # helpers
 #
-def cdecl(ctype, cname):
+def cdecl(ctype, cname, is_thread_local=False):
     """
     Produce a C declaration from a 'type template' and an identifier.
     The type template must contain a '@' sign at the place where the
@@ -26,10 +26,17 @@
     """
     # the (@) case is for functions, where if there is a plain (@) around
     # the function name, we don't need the very confusing parenthesis
-    return ctype.replace('(@)', '@').replace('@', cname).strip()
+    __thread = ""
+    if is_thread_local:
+        __thread = "__thread "
+    return __thread + ctype.replace('(@)', '@').replace('@', cname).strip()
+
+def forward_cdecl(ctype, cname, standalone, is_thread_local=False):
+    __thread = ""
+    if is_thread_local:
+        __thread = "__thread "
 
-def forward_cdecl(ctype, cname, standalone):
-    cdecl_str = cdecl(ctype, cname)
+    cdecl_str = __thread + cdecl(ctype, cname)
     if standalone:
         return 'extern ' + cdecl_str
     else:



More information about the Pypy-commit mailing list