summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-04-19 02:28:06 (GMT)
committerSteven Knight <knight@baldmt.com>2010-04-19 02:28:06 (GMT)
commitf1049d9db2e71842802f89b708ba825df304e774 (patch)
tree17b7ed783aafcd8fdb28147b1bbe621bf4d3f9a4 /src/engine/SCons
parent391aabed467e2b5d88c13462851fef981cd8c44d (diff)
downloadSCons-f1049d9db2e71842802f89b708ba825df304e774.zip
SCons-f1049d9db2e71842802f89b708ba825df304e774.tar.gz
SCons-f1049d9db2e71842802f89b708ba825df304e774.tar.bz2
Remove use of the "new" module from --debug=memoizer support.
Diffstat (limited to 'src/engine/SCons')
-rw-r--r--src/engine/SCons/Memoize.py90
-rw-r--r--src/engine/SCons/MemoizeTests.py16
2 files changed, 25 insertions, 81 deletions
diff --git a/src/engine/SCons/Memoize.py b/src/engine/SCons/Memoize.py
index 30e7d9f..98e3809 100644
--- a/src/engine/SCons/Memoize.py
+++ b/src/engine/SCons/Memoize.py
@@ -119,7 +119,7 @@ This collected caching logic nicely, but had two drawbacks:
to figure out how to optimize the underlying methods.
"""
-import new
+import types
# A flag controlling whether or not we actually use memoization.
use_memoizer = None
@@ -213,77 +213,29 @@ class Memoizer:
def __init__(self):
pass
-# Find out if we support metaclasses (Python 2.2 and later).
+def Dump(title=None):
+ if title:
+ print title
+ CounterList.sort()
+ for counter in CounterList:
+ counter.display()
-class M:
+class Memoized_Metaclass(type):
def __init__(cls, name, bases, cls_dict):
- cls.use_metaclass = 1
- def fake_method(self):
- pass
- new.instancemethod(fake_method, None, cls)
-
-try:
- class A:
- __metaclass__ = M
-
- use_metaclass = A.use_metaclass
-except AttributeError:
- use_metaclass = None
- reason = 'no metaclasses'
-except TypeError:
- use_metaclass = None
- reason = 'new.instancemethod() bug'
-else:
- del A
-
-del M
-
-if not use_metaclass:
-
- def Dump(title):
- pass
+ super(Memoized_Metaclass, cls).__init__(name, bases, cls_dict)
+
+ for counter in cls_dict.get('memoizer_counters', []):
+ method_name = counter.method_name
+
+ counter.name = cls.__name__ + '.' + method_name
+ counter.underlying_method = cls_dict[method_name]
+
+ replacement_method = types.MethodType(counter, None, cls)
+ setattr(cls, method_name, replacement_method)
- try:
- class Memoized_Metaclass(type):
- # Just a place-holder so pre-metaclass Python versions don't
- # have to have special code for the Memoized classes.
- pass
- except TypeError:
- class Memoized_Metaclass:
- # A place-holder so pre-metaclass Python versions don't
- # have to have special code for the Memoized classes.
- pass
-
- def EnableMemoization():
- import SCons.Warnings
- msg = 'memoization is not supported in this version of Python (%s)'
- raise SCons.Warnings.NoMetaclassSupportWarning(msg % reason)
-
-else:
-
- def Dump(title=None):
- if title:
- print title
- CounterList.sort()
- for counter in CounterList:
- counter.display()
-
- class Memoized_Metaclass(type):
- def __init__(cls, name, bases, cls_dict):
- super(Memoized_Metaclass, cls).__init__(name, bases, cls_dict)
-
- for counter in cls_dict.get('memoizer_counters', []):
- method_name = counter.method_name
-
- counter.name = cls.__name__ + '.' + method_name
- counter.underlying_method = cls_dict[method_name]
-
- replacement_method = new.instancemethod(counter, None, cls)
- setattr(cls, method_name, replacement_method)
-
- def EnableMemoization():
- global use_memoizer
- use_memoizer = 1
+def EnableMemoization():
+ global use_memoizer
+ use_memoizer = 1
# Local Variables:
# tab-width:4
diff --git a/src/engine/SCons/MemoizeTests.py b/src/engine/SCons/MemoizeTests.py
index b3edf01..ea2096c 100644
--- a/src/engine/SCons/MemoizeTests.py
+++ b/src/engine/SCons/MemoizeTests.py
@@ -132,12 +132,8 @@ class CountDictTestCase(unittest.TestCase):
c = obj.get_memoizer_counter('dict')
- if SCons.Memoize.use_metaclass:
- assert c.hit == 3, c.hit
- assert c.miss == 2, c.miss
- else:
- assert c.hit == 0, c.hit
- assert c.miss == 0, c.miss
+ assert c.hit == 3, c.hit
+ assert c.miss == 2, c.miss
class CountValueTestCase(unittest.TestCase):
@@ -171,12 +167,8 @@ class CountValueTestCase(unittest.TestCase):
c = obj.get_memoizer_counter('value')
- if SCons.Memoize.use_metaclass:
- assert c.hit == 3, c.hit
- assert c.miss == 1, c.miss
- else:
- assert c.hit == 0, c.hit
- assert c.miss == 0, c.miss
+ assert c.hit == 3, c.hit
+ assert c.miss == 1, c.miss
if __name__ == "__main__":