[Zope-Checkins] CVS: Zope2 - VSExec.py:1.7 code_editor.py:1.3
evan@serenade.digicool.com
evan@serenade.digicool.com
Wed, 11 Apr 2001 11:52:11 -0400
Update of /cvs-repository/Zope2/lib/python/Products/PythonScripts/zbytecodehacks
In directory serenade.digicool.com:/home/evan/Zope/Zope2/lib/python/Products/PythonScripts/zbytecodehacks
Modified Files:
VSExec.py code_editor.py
Log Message:
Merge to evan-script_fix-merge-3
--- Updated File VSExec.py in package Zope2 --
--- VSExec.py 2001/02/26 19:47:30 1.6
+++ VSExec.py 2001/04/11 15:51:40 1.7
@@ -166,6 +166,15 @@
self.munge_data = {}
self.munge(f.func_code)
+ stack = []
+ max_stack = 0
+ for op in f.func_code.co_code.opcodes:
+ try: op.execute(stack)
+ except: stack = []
+ max_stack = max(max_stack, len(stack))
+ if max_stack > f.func_code.co_stacksize:
+ f.func_code.set_stacksize(max_stack)
+
if not self.errors: self.t = f.as_tuple()
def munge(self, fc, depth=0):
@@ -198,7 +207,7 @@
window.do_op()
elif op and forbid.get(op.op, 0):
errors.append(self.forbidden % (opname, line))
- window.do_op() #???
+ window.do_op() # This is necessary to track stack usage.
else:
for m in mungers:
handler = getattr(m, opname, None)
@@ -217,6 +226,7 @@
break
else:
window.do_op()
+
def __call__(self, *args, **kargs):
F = code_editor.Function(self.t)
F.func_globals = self.globals
@@ -417,13 +427,10 @@
def _wrap(w):
load_guard = ((ops.LOAD_FAST,), ((guard,),))
# Load the guard function before the guarded object, call after.
- w.insert_code(load_guard, w.before_code_for(spos))
- if spos == 0:
- w.set_code(0, cf1)
- else:
- iops = w.insert_code(cf1, w.after_code_for(spos))
- # Fix the execution stack.
- if w.use_stack: w.stack[spos] = (w.stack[spos][0], iops[0])
+ iops1 = w.insert_code(load_guard, w.before_code_for(spos))
+ iops2 = w.insert_code(cf1, w.after_code_for(spos))
+ # Fix the execution stack.
+ if w.use_stack: w.stack[spos] = (iops1[0], iops2[0])
def _WriteGuardWrapper():
def model_handler(self, *args):
--- Updated File code_editor.py in package Zope2 --
--- code_editor.py 2000/12/11 20:01:19 1.2
+++ code_editor.py 2001/04/11 15:51:40 1.3
@@ -252,6 +252,8 @@
self.co_name = name
def set_filename(self, filename):
self.co_filename = filename
+ def set_stacksize(self, stacksize):
+ self.co_stacksize = stacksize
def as_tuple(self):
# the assembling might change co_names or co_varnames - so
# make sure it's done *before* we start gathering them.