/home/johnny/projects/merlinux/pypy-dist/pypy/conftest.py:8
import py, sys
from pypy.interpreter.gateway import app2interp_temp
from pypy.interpreter.error import OperationError
from pypy.tool.pytest import appsupport
from pypy.tool.option import make_config, make_objspace
from inspect import isclass, getmro
-> rootdir = py.magic.autopath().dirpath()
#
# PyPy's command line extra options (these are added
# to py.test's standard options)
#
Option = py.test.Config.Option
option = py.test.Config.addoptions("pypy options",
Option('--view', action="store_true", dest="view", default=False,
help="view translation tests' flow graphs with Pygame"),
Option('-A', '--runappdirect', action="store_true",
default=False, dest="runappdirect",
help="run applevel tests directly on python interpreter (not through PyPy)"),
)
_SPACECACHE={}
def gettestobjspace(name=None, **kwds):
""" helper for instantiating and caching space's for testing.
"""
config = make_config(option, objspace=name, **kwds)
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
if option.runappdirect:
return TinyObjSpace(**kwds)
try:
space = make_objspace(config)
except OperationError, e:
check_keyboard_interrupt(e)
if option.verbose:
import traceback
traceback.print_exc()
py.test.fail("fatal: cannot initialize objspace: %r" %(Space,))
_SPACECACHE[key] = space
space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
appsupport.build_pytest_assertion(space))
space.setitem(space.builtin.w_dict, space.wrap('raises'),
space.wrap(appsupport.app_raises))
space.setitem(space.builtin.w_dict, space.wrap('skip'),
space.wrap(appsupport.app_skip))
space.raises_w = appsupport.raises_w.__get__(space)
space.eq_w = appsupport.eq_w.__get__(space)
return space
/home/johnny/projects/merlinux/pypy-dist/pypy/translator/c/database.py:17
from pypy.rpython.lltypesystem.lltype import \
Primitive, Ptr, typeOf, RuntimeTypeInfo, \
Struct, Array, FuncType, PyObject, Void, \
ContainerType, OpaqueType, FixedSizeArray, _uninitialized
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.llmemory import Address
from pypy.rpython.memory.lladdress import NULL
from pypy.tool.sourcetools import valid_identifier
from pypy.translator.c.primitive import PrimitiveName, PrimitiveType
from pypy.translator.c.primitive import PrimitiveErrorValue
from pypy.translator.c.node import StructDefNode, ArrayDefNode
from pypy.translator.c.node import FixedSizeArrayDefNode
from pypy.translator.c.node import ContainerNodeFactory, ExtTypeOpaqueDefNode
from pypy.translator.c.support import cdecl, CNameManager, ErrorValue
from pypy.translator.c.support import log
from pypy.translator.c.extfunc import do_the_getting
-> from pypy import conftest
from pypy.translator.c import gc
# ____________________________________________________________
class LowLevelDatabase(object):
gctransformer = None
def __init__(self, translator=None, standalone=False,
gcpolicyclass=None,
stacklesstransformer=None,
thread_enabled=False):
self.translator = translator
self.standalone = standalone
self.stacklesstransformer = stacklesstransformer
if gcpolicyclass is None:
gcpolicyclass = gc.RefcountingGcPolicy
self.gcpolicy = gcpolicyclass(self, thread_enabled)
self.structdefnodes = {}
self.pendingsetupnodes = []
self.containernodes = {}
self.containerlist = []
self.delayedfunctionnames = {}
self.delayedfunctionptrs = []
self.completedcontainers = 0
self.containerstats = {}
self.externalfuncs = {}
self.helper2ptr = {}
# late_initializations is for when the value you want to
# assign to a constant object is something C doesn't think is
# constant
self.late_initializations = []
self.namespace = CNameManager()
if not standalone:
from pypy.translator.c.pyobj import PyObjMaker
self.pyobjmaker = PyObjMaker(self.namespace, self, translator)
if translator is None or translator.rtyper is None:
self.exctransformer = None
else:
self.exctransformer = translator.getexceptiontransformer()
if translator is not None:
self.gctransformer = self.gcpolicy.transformerclass(translator)
self.completed = False
self.instrument_ncounter = 0
def gettypedefnode(self, T, varlength=1):
if varlength <= 1:
varlength = 1 # it's C after all
key = T
else:
key = T, varlength
try:
node = self.structdefnodes[key]
except KeyError:
if isinstance(T, Struct):
if isinstance(T, FixedSizeArray):
node = FixedSizeArrayDefNode(self, T)
else:
node = StructDefNode(self, T, varlength)
elif isinstance(T, Array):
node = ArrayDefNode(self, T, varlength)
elif isinstance(T, OpaqueType) and hasattr(T, '_exttypeinfo'):
node = ExtTypeOpaqueDefNode(self, T)
else:
raise Exception("don't know about %r" % (T,))
self.structdefnodes[key] = node
self.pendingsetupnodes.append(node)
return node
def gettype(self, T, varlength=1, who_asks=None, argnames=[]):
if isinstance(T, Primitive):
return PrimitiveType[T]
elif isinstance(T, Ptr):
if isinstance(T.TO, FixedSizeArray):
# /me blames C
node = self.gettypedefnode(T.TO)
return node.getptrtype()
else:
typename = self.gettype(T.TO) # who_asks not propagated
return typename.replace('@', '*@')
elif isinstance(T, (Struct, Array)):
node = self.gettypedefnode(T, varlength=varlength)
if who_asks is not None:
who_asks.dependencies[node] = True
return node.gettype()
elif T == PyObject:
return 'PyObject @'
elif isinstance(T, FuncType):
resulttype = self.gettype(T.RESULT)
argtypes = []
for i in range(len(T.ARGS)):
if T.ARGS[i] is not Void:
argtype = self.gettype(T.ARGS[i])
try:
argname = argnames[i]
except IndexError:
argname = ''
argtypes.append(cdecl(argtype, argname))
argtypes = ', '.join(argtypes) or 'void'
return resulttype.replace('@', '(@)(%s)' % argtypes)
elif isinstance(T, OpaqueType):
if T == RuntimeTypeInfo:
return self.gcpolicy.rtti_type()
elif hasattr(T, '_exttypeinfo'):
# for external types (pypy.rpython.extfunctable.declaretype())
node = self.gettypedefnode(T, varlength=varlength)
if who_asks is not None:
who_asks.dependencies[node] = True
return 'struct %s @' % node.name
else:
#raise Exception("don't know about opaque type %r" % (T,))
return 'struct %s @' % (
valid_identifier('pypy_opaque_' + T.tag),)
else:
raise Exception("don't know about type %r" % (T,))
def getcontainernode(self, container, **buildkwds):
try:
node = self.containernodes[container]
except KeyError:
assert not self.completed
T = typeOf(container)
if isinstance(T, (lltype.Array, lltype.Struct)):
if hasattr(self.gctransformer, 'consider_constant'):
self.gctransformer.consider_constant(T, container)
nodefactory = ContainerNodeFactory[T.__class__]
node = nodefactory(self, T, container, **buildkwds)
self.containernodes[container] = node
self.containerlist.append(node)
kind = getattr(node, 'nodekind', '?')
self.containerstats[kind] = self.containerstats.get(kind, 0) + 1
return node
def get(self, obj):
if isinstance(obj, ErrorValue):
T = obj.TYPE
if isinstance(T, Primitive):
return PrimitiveErrorValue[T]
elif isinstance(T, Ptr):
return 'NULL'
else:
raise Exception("don't know about %r" % (T,))
else:
T = typeOf(obj)
if isinstance(T, Primitive):
return PrimitiveName[T](obj, self)
elif isinstance(T, Ptr):
if obj: # test if the ptr is non-NULL
try:
container = obj._obj
except lltype.DelayedPointer:
# hack hack hack
name = obj._obj0
assert name.startswith('delayed!')
n = len('delayed!')
if len(name) == n:
raise
if id(obj) in self.delayedfunctionnames:
return self.delayedfunctionnames[id(obj)][0]
funcname = name[n:]
funcname = self.namespace.uniquename('g_' + funcname)
self.delayedfunctionnames[id(obj)] = funcname, obj
self.delayedfunctionptrs.append(obj)
return funcname
# /hack hack hack
else:
# hack hack hack
if id(obj) in self.delayedfunctionnames:
# this used to be a delayed function,
# make sure we use the same name
forcename = self.delayedfunctionnames[id(obj)][0]
node = self.getcontainernode(container,
forcename=forcename)
assert node.ptrname == forcename
return forcename
# /hack hack hack
if isinstance(container, int):
# special case for tagged odd-valued pointers
return '((%s) %d)' % (cdecl(self.gettype(T), ''),
obj._obj)
node = self.getcontainernode(container)
return node.ptrname
else:
return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
else:
raise Exception("don't know about %r" % (obj,))
def complete(self, show_progress=True):
assert not self.completed
if self.translator and self.translator.rtyper:
do_the_getting(self, self.translator.rtyper)
def dump():
lst = ['%s: %d' % keyvalue
for keyvalue in self.containerstats.items()]
lst.sort()
log.event('%8d nodes [ %s ]' % (i, ' '.join(lst)))
i = self.completedcontainers
if show_progress:
show_i = (i//1000 + 1) * 1000
else:
show_i = -1
# The order of database completion is fragile with stackless and
# gc transformers. Here is what occurs:
#
# 1. follow dependencies recursively from the entry point: data
# structures pointing to other structures or functions, and
# constants in functions pointing to other structures or functions.
# Because of the mixlevelannotator, this might find delayed
# (not-annotated-and-rtyped-yet) function pointers. They are
# not followed at this point. User finalizers (__del__) on the
# other hand are followed during this step too.
#
# 2. gctransformer.finish_helpers() - after this, all functions in
# the program have been rtyped.
#
# 3. follow new dependencies. All previously delayed functions
# should have been resolved by 2 - they are gc helpers, like
# ll_finalize(). New FuncNodes are built for them. No more
# FuncNodes can show up after this step.
#
# 4. stacklesstransform.finish() - freeze the stackless resume point
# table.
#
# 5. follow new dependencies (this should be only the new frozen
# table, which contains only numbers and already-seen function
# pointers).
#
# 6. gctransformer.finish_tables() - freeze the gc types table.
#
# 7. follow new dependencies (this should be only the gc type table,
# which contains only numbers and pointers to ll_finalizer
# functions seen in step 3).
#
# I think that there is no reason left at this point that force
# step 4 to be done before step 6, nor to have a follow-new-
# dependencies step inbetween. It is important though to have step 3
# before steps 4 and 6.
#
# This is implemented by interleaving the follow-new-dependencies
# steps with calls to the next 'finish' function from the following
# list:
finish_callbacks = []
if self.gctransformer:
finish_callbacks.append(self.gctransformer.finish_helpers)
if self.stacklesstransformer:
finish_callbacks.append(self.stacklesstransformer.finish)
if self.gctransformer:
finish_callbacks.append(self.gctransformer.finish_tables)
def add_dependencies(newdependencies):
for value in newdependencies:
#if isinstance(value, _uninitialized):
# continue
if isinstance(typeOf(value), ContainerType):
self.getcontainernode(value)
else:
self.get(value)
while True:
while True:
if hasattr(self, 'pyobjmaker'):
self.pyobjmaker.collect_initcode()
while self.pendingsetupnodes:
lst = self.pendingsetupnodes
self.pendingsetupnodes = []
for nodedef in lst:
nodedef.setup()
if i == len(self.containerlist):
break
node = self.containerlist[i]
add_dependencies(node.enum_dependencies())
i += 1
self.completedcontainers = i
if i == show_i:
dump()
show_i += 1000
if self.delayedfunctionptrs:
lst = self.delayedfunctionptrs
self.delayedfunctionptrs = []
progress = False
for fnptr in lst:
try:
fnptr._obj
except lltype.DelayedPointer: # still not resolved
self.delayedfunctionptrs.append(fnptr)
else:
self.get(fnptr)
progress = True
if progress:
continue # progress - follow all dependencies again
if finish_callbacks:
finish = finish_callbacks.pop(0)
newdependencies = finish()
if newdependencies:
add_dependencies(newdependencies)
continue # progress - follow all dependencies again
break # database is now complete
assert not self.delayedfunctionptrs
self.completed = True
if show_progress:
dump()
def globalcontainers(self):
for node in self.containerlist:
if node.globalcontainer:
yield node
def get_lltype_of_exception_value(self):
if self.translator is not None and self.translator.rtyper is not None:
exceptiondata = self.translator.rtyper.getexceptiondata()
return exceptiondata.lltype_of_exception_value
else:
return Ptr(PyObject)
def getstructdeflist(self):
# return the StructDefNodes sorted according to dependencies
result = []
seen = {}
def produce(node):
if node not in seen:
for othernode in node.dependencies:
produce(othernode)
result.append(node)
seen[node] = True
for node in self.structdefnodes.values():
produce(node)
return result
/home/johnny/projects/merlinux/pypy-dist/pypy/translator/c/genc.py:4
import autopath
import py
from pypy.translator.c.node import PyObjectNode, PyObjHeadNode, FuncNode
-> from pypy.translator.c.database import LowLevelDatabase
from pypy.translator.c.extfunc import pre_include_code_lines
from pypy.translator.gensupp import uniquemodulename, NameManager
from pypy.translator.tool.cbuild import compile_c_module
from pypy.translator.tool.cbuild import build_executable, CCompiler, ProfOpt
from pypy.translator.tool.cbuild import import_module_from_directory
from pypy.translator.tool.cbuild import check_under_under_thread
from pypy.rpython.lltypesystem import lltype
from pypy.tool.udir import udir
from pypy.tool import isolate
from pypy.translator.locality.calltree import CallTree
from pypy.translator.c.support import log, c_string_constant
from pypy.rpython.typesystem import getfunctionptr
from pypy.translator.c import gc
class CBuilder(object):
c_source_filename = None
_compiled = False
symboltable = None
modulename = None
def __init__(self, translator, entrypoint, config, libraries=None,
gcpolicy=None):
self.translator = translator
self.entrypoint = entrypoint
self.originalentrypoint = entrypoint
self.gcpolicy = gcpolicy
if gcpolicy is not None and gcpolicy.requires_stackless:
config.translation.stackless = True
self.config = config
if libraries is None:
libraries = []
self.libraries = libraries
self.exports = {}
def build_database(self, exports=[], pyobj_options=None):
translator = self.translator
gcpolicyclass = self.get_gcpolicyclass()
if self.config.translation.stackless:
if not self.standalone:
raise Exception("stackless: only for stand-alone builds")
from pypy.translator.stackless.transform import StacklessTransformer
stacklesstransformer = StacklessTransformer(
translator, self.originalentrypoint,
stackless_gc=gcpolicyclass.requires_stackless)
self.entrypoint = stacklesstransformer.slp_entry_point
else:
stacklesstransformer = None
db = LowLevelDatabase(translator, standalone=self.standalone,
gcpolicyclass=gcpolicyclass,
stacklesstransformer=stacklesstransformer,
thread_enabled=self.config.translation.thread)
# pass extra options into pyobjmaker
if pyobj_options:
for key, value in pyobj_options.items():
setattr(db.pyobjmaker, key, value)
# we need a concrete gcpolicy to do this
self.libraries += db.gcpolicy.gc_libraries()
# give the gc a chance to register interest in the start-up functions it
# need (we call this for its side-effects of db.get())
list(db.gcpolicy.gc_startup_code())
# build entrypoint and eventually other things to expose
pf = self.getentrypointptr()
pfname = db.get(pf)
self.exports[self.entrypoint.func_name] = pf
for obj in exports:
if type(obj) is tuple:
objname, obj = obj
elif hasattr(obj, '__name__'):
objname = obj.__name__
else:
objname = None
po = self.getentrypointptr(obj)
poname = db.get(po)
objname = objname or poname
if objname in self.exports:
raise NameError, 'duplicate name in export: %s is %s and %s' % (
objname, db.get(self.exports[objname]), poname)
self.exports[objname] = po
db.complete()
# add library dependencies
seen = dict.fromkeys(self.libraries)
for node in db.globalcontainers():
if hasattr(node, 'libraries'):
for library in node.libraries:
if library not in seen:
self.libraries.append(library)
seen[library] = True
return db
have___thread = None
def get_gcpolicyclass(self):
if self.gcpolicy is None:
return gc.name_to_gcpolicy[self.config.translation.gc]
return self.gcpolicy
def generate_source(self, db=None, defines={}):
assert self.c_source_filename is None
translator = self.translator
if db is None:
db = self.build_database()
pf = self.getentrypointptr()
pfname = db.get(pf)
if self.modulename is None:
self.modulename = uniquemodulename('testing')
modulename = self.modulename
targetdir = udir.ensure(modulename, dir=1)
self.targetdir = targetdir
defines = defines.copy()
if self.config.translation.countmallocs:
defines['COUNT_OP_MALLOCS'] = 1
if CBuilder.have___thread is None:
CBuilder.have___thread = check_under_under_thread()
if not self.standalone:
assert not self.config.translation.instrument
from pypy.translator.c.symboltable import SymbolTable
# XXX fix symboltable
#self.symboltable = SymbolTable()
cfile, extra = gen_source(db, modulename, targetdir,
defines = defines,
exports = self.exports,
symboltable = self.symboltable)
else:
if self.config.translation.instrument:
defines['INSTRUMENT'] = 1
if CBuilder.have___thread:
if not self.config.translation.no__thread:
defines['USE___THREAD'] = 1
cfile, extra = gen_source_standalone(db, modulename, targetdir,
entrypointname = pfname,
defines = defines)
self.c_source_filename = py.path.local(cfile)
self.extrafiles = extra
if self.standalone:
self.gen_makefile(targetdir)
return cfile
def generate_graphs_for_llinterp(self, db=None):
# prepare the graphs as when the source is generated, but without
# actually generating the source.
if db is None:
db = self.build_database()
for node in db.containerlist:
if isinstance(node, FuncNode):
for funcgen in node.funcgens:
funcgen.patch_graph(copy_graph=False)
return db
/home/johnny/projects/merlinux/pypy-dist/pypy/translator/stackless/test/test_transform.py:4
import py
import os
from pypy.translator.stackless.transform import StacklessTransformer, FrameTyper
-> from pypy.translator.c.genc import CStandaloneBuilder
from pypy.translator.c import gc
from pypy.translator.unsimplify import varoftype
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython import llinterp
from pypy.rlib import rstack
from pypy.translator.translator import TranslationContext, graphof
from pypy.objspace.flow.model import checkgraph
from pypy.annotation import model as annmodel
from pypy.annotation.listdef import s_list_of_strings
from pypy import conftest
def test_frame_typer():
class TestFrameTyper(FrameTyper):
def saving_function_for_type(self, frame_type):
return None
ft = TestFrameTyper()
ft4vars = lambda types:ft.frame_type_for_vars(types)[0]
signed = varoftype(lltype.Signed)
ptr = varoftype(lltype.Ptr(lltype.GcStruct("S")))
addr = varoftype(llmemory.Address)
float = varoftype(lltype.Float)
longlong = varoftype(lltype.SignedLongLong)
s1_1 = ft4vars([signed])
assert 'header' in s1_1._flds
assert len(s1_1._flds) == 2
s1_2 = ft4vars([signed])
assert s1_1 is s1_2
s2_1 = ft4vars([signed, ptr])
s2_2 = ft4vars([ptr, signed])
assert s2_1 is s2_2
/home/johnny/projects/merlinux/pypy-dist/pypy/translator/js/modules/dom.py:21
"""Document Object Model support
this provides a mock browser API, both the standard DOM level 2 stuff as
the browser-specific additions
note that the API is not and will not be complete: more exotic features
will most probably not behave as expected, or are not implemented at all
->
http://www.w3.org/DOM/ - main standard
http://www.w3schools.com/dhtml/dhtml_dom.asp - more informal stuff
http://developer.mozilla.org/en/docs/Gecko_DOM_Reference - Gecko reference
"""
import time
import re
import urllib
from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc
from pypy.rlib.nonconst import NonConstant
from pypy.translator.stackless.test.test_transform import one
from xml.dom import minidom
# EventTarget is the base class for Nodes and Window
class EventTarget(BasicExternal):
def addEventListener(self, type, listener, useCapture):
if not hasattr(self._original, '_events'):
self._original._events = []
# XXX note that useCapture is ignored...
self._original._events.append((type, listener, useCapture))
def dispatchEvent(self, event):
if event._cancelled:
return
event.currentTarget = self
if event.target is None:
event.target = self
if event.originalTarget is None:
event.originalTarget = self
if hasattr(self._original, '_events'):
for etype, handler, capture in self._original._events:
if etype == event.type:
handler(event)
if event._cancelled or event.cancelBubble:
return
parent = getattr(self, 'parentNode', None)
if parent is not None:
parent.dispatchEvent(event)
def removeEventListener(self, type, listener, useCapture):
if not hasattr(self._original, '_events'):
raise ValueError('no registration for listener')
filtered = []
for data in self._original._events:
if data != (type, listener, useCapture):
filtered.append(data)
if filtered == self._original._events:
raise ValueError('no registration for listener')
self._original._events = filtered
/home/johnny/projects/merlinux/py/dist/py/test/rsession/webjs.py:8
""" javascript source for py.test distributed
"""
import py
-> from py.__.test.rsession.web import exported_methods
try:
from pypy.translator.js.modules import dom
from pypy.translator.js.helper import __show_traceback
from pypy.translator.transformer.debug import traceback_handler
except ImportError:
py.test.skip("PyPy not found")
def create_elem(s):
return dom.get_document().createElement(s)
/home/johnny/projects/merlinux/py/dist/py/misc/testing/test_initpkg.py:69
def check_import(modpath):
print "checking import", modpath
-> assert __import__(modpath)
/home/johnny/projects/merlinux/py/dist/py/test/item.py:79
def execute(self, target, *args):
""" default implementation for calling a test target is to
simply call it.
"""
-> target(*args)
/home/johnny/projects/merlinux/py/dist/py/test/item.py:73
def run(self):
self.state.prepare(self)
-> self.execute(self.obj, *self.args)
/home/johnny/projects/merlinux/py/dist/py/test/rsession/executor.py:22
def execute(self):
try:
-> self.item.run()
outcome = Outcome()
except py.test.Item.Skipped, e:
outcome = Outcome(skipped=str(e))
except (KeyboardInterrupt, SystemExit):
raise
except:
excinfo = py.code.ExceptionInfo()
if isinstance(self.item, py.test.Function):
fun = self.item.obj # hope this is stable
code = py.code.Code(fun)
excinfo.traceback = excinfo.traceback.cut(
path=code.path, firstlineno=code.firstlineno)
outcome = Outcome(excinfo=excinfo, setupfailure=False)
if self.usepdb:
if self.reporter is not None:
self.reporter(report.ImmediateFailure(self.item,
ReprOutcome(outcome.make_repr())))
import pdb
pdb.post_mortem(excinfo._excinfo[2])
# XXX hmm, we probably will not like to continue from that point
# or we do?
raise SystemExit()
outcome.stdout = ""
outcome.stderr = ""
return outcome
/home/johnny/projects/merlinux/py/dist/py/test/rsession/local.py:31
def plain_runner(item, session, reporter):
# box executor is doing stdout/err catching for us, let's do it here
startcapture(session)
r = RunExecutor(item, usepdb=session.config.option.usepdb, reporter=reporter)
-> outcome = r.execute()
outcome = ReprOutcome(outcome.make_repr())
outcome.stdout, outcome.stderr = finishcapture(session)
return outcome
/home/johnny/projects/merlinux/py/dist/py/test/rsession/local.py:47
def apigen_runner(item, session, reporter):
r = RunExecutor(item, reporter=reporter)
session.tracer.start_tracing()
-> retval = plain_runner(item, session, reporter)
session.tracer.end_tracing()
return retval