youtube / spitfire

A high-performance Python template language
BSD 3-Clause "New" or "Revised" License
404 stars 58 forks source link

With -Xcheetah-cheats, placeholder resolution does not search locals() #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Source code:

#set $a = 'foo'
#set $b = $a

Compiling with -Xcheetah-cheats (no optimization) produces:

    _self_search_list = self.search_list + [_globals]
    _buffer_write(u'\n')
    a = u'foo'
    b = resolve_placeholder(_self_search_list, 'a')

This always fails during runtime with: NotFound: cannot find 'a'

This is probably because locals() is not checked by resolve_placeholder(). 
_self_search_list does not contain locals.

The following two cases compile and run without issues:

1. Compiling without -Xcheetah-cheats produces:

    a = u'foo'
    b = resolve_placeholder('a', template=self, local_vars=locals(), 
global_vars=_globals)

2. Compiling with -Xcheetah-cheats and -O2 produces:

    _self_search_list = self.search_list + [_globals]
    _buffer_write(u'\n')
    a = u'foo'
    b = a

The following case also reproduces the runtime error (compiled with -
Xcheetah-cheats and -O2):

#if True
 #set $a = 'foo'
#end if
#set $b = $a

Summary: If cheetah-cheats is enabled and the optimizer doesn't hit the 
resolve_placeholder node, there is a runtime error.

Original issue reported on code.google.com by shalabh....@gmail.com on 27 Jan 2010 at 10:20