Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_extractors(): fix possible memory leak #521

Open
wants to merge 4 commits into
base: orm
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions pony/orm/asttranslation.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,25 @@ def create_extractors(code_key, tree, globals, locals, special_functions, const_
for node in pretranslator.externals:
src = node.src = ast2src(node)
if src == '.0':
def extractor(globals, locals):
return locals['.0']
extractor = Extractor('.0')
else:
code = compile(src, src, 'eval')
def extractor(globals, locals, code=code):
return eval(code, globals, locals)
extractor = Extractor(src, code)
extractors[src] = extractor
result = extractors_cache[code_key] = tree, extractors
return result


class Extractor(object):

def __init__(self, src, code=None):
self.src = src
self.code = code

def __call__(self, globals, locals):
if self.src == '.0':
return locals['.0']
return eval(self.code, globals, locals)

def __repr__(self):
return 'Extractor(%s)' % self.src