[pypy-svn] r10623 - in pypy/dist/pypy: annotation tool translator/genc
arigo at codespeak.net
arigo at codespeak.net
Thu Apr 14 17:24:04 CEST 2005
Author: arigo
Date: Thu Apr 14 17:24:03 2005
New Revision: 10623
Added:
pypy/dist/pypy/tool/tls.py
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/translator/genc/basetype.py
pypy/dist/pypy/translator/genc/genc.py
Log:
Don't mix the translator's and the annotator's thread-local data with the one
of the application being translated.
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Thu Apr 14 17:24:03 2005
@@ -7,7 +7,7 @@
from pypy.tool.ansi_print import ansi_print
from pypy.annotation.model import *
from pypy.annotation.classdef import ClassDef
-from pypy.interpreter.miscutils import getthreadlocals
+from pypy.tool.tls import tlsobject
from pypy.tool.hack import func_with_new_name
from pypy.interpreter.pycode import CO_VARARGS
from pypy.interpreter.pycode import cpython_code_signature
@@ -29,6 +29,9 @@
self.attrs.update(other.attrs)
+TLS = tlsobject()
+
+
class Bookkeeper:
"""The log of choices that have been made while analysing the operations.
It ensures that the same 'choice objects' will be returned if we ask
@@ -61,11 +64,11 @@
"""Start of an operation.
The operation is uniquely identified by the given key."""
self.position_key = position_key
- getthreadlocals().bookkeeper = self
+ TLS.bookkeeper = self
def leave(self):
"""End of an operation."""
- del getthreadlocals().bookkeeper
+ del TLS.bookkeeper
del self.position_key
def getfactory(self, factorycls):
@@ -393,7 +396,7 @@
"""Get the current Bookkeeper.
Only works during the analysis of an operation."""
try:
- return getthreadlocals().bookkeeper
+ return TLS.bookkeeper
except AttributeError:
return None
Added: pypy/dist/pypy/tool/tls.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/tls.py Thu Apr 14 17:24:03 2005
@@ -0,0 +1,11 @@
+"""Thread-local storage."""
+
+try:
+ from thread import _local as tlsobject
+except ImportError: # Python < 2.4
+
+ # XXX needs a real object whose attributes are visible only in
+ # the thread that reads/writes them.
+
+ class tlsobject(object):
+ pass
Modified: pypy/dist/pypy/translator/genc/basetype.py
==============================================================================
--- pypy/dist/pypy/translator/genc/basetype.py (original)
+++ pypy/dist/pypy/translator/genc/basetype.py Thu Apr 14 17:24:03 2005
@@ -1,6 +1,5 @@
import os
from pypy.objspace.flow.model import SpaceOperation
-from pypy.interpreter.miscutils import getthreadlocals
class CType(object):
@@ -13,7 +12,8 @@
def genc():
"""A hack to get at the currently running GenC instance."""
- return getthreadlocals().genc
+ from pypy.translator.genc.genc import TLS
+ return TLS.genc
genc = staticmethod(genc)
def init_globals(self, genc):
Modified: pypy/dist/pypy/translator/genc/genc.py
==============================================================================
--- pypy/dist/pypy/translator/genc/genc.py (original)
+++ pypy/dist/pypy/translator/genc/genc.py Thu Apr 14 17:24:03 2005
@@ -5,7 +5,7 @@
import autopath, os
from pypy.objspace.flow.model import Variable, Constant
-from pypy.interpreter.miscutils import getthreadlocals
+from pypy.tool.tls import tlsobject
from pypy.translator.gensupp import uniquemodulename
from pypy.translator.genc.funcdef import FunctionDef, USE_CALL_TRACE
@@ -13,10 +13,8 @@
# ____________________________________________________________
-#def go_figure_out_this_name(source):
-# # ahem
-# return 'PyRun_String("%s", Py_eval_input, PyEval_GetGlobals(), NULL)' % (
-# source, )
+TLS = tlsobject() # to store the genc instance temporarily
+
class GenC:
MODNAMES = {}
@@ -35,12 +33,12 @@
self.ctypes_alreadyseen = {}
self.namespace = self.pyobjtype.namespace
- assert not hasattr(getthreadlocals(), 'genc')
- getthreadlocals().genc = self
+ assert not hasattr(TLS, 'genc')
+ TLS.genc = self
try:
self.gen_source()
finally:
- del getthreadlocals().genc
+ del TLS.genc
def nameofconst(self, c, debug=None):
try:
More information about the Pypy-commit
mailing list