[pypy-svn] pypy improve-unwrap_spec: Simplify unwrap_spec for parser, pyexpat, pypyjit
amauryfa
commits-noreply at bitbucket.org
Wed Feb 16 19:20:14 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: improve-unwrap_spec
Changeset: r42081:4de80533c51b
Date: 2011-02-16 17:55 +0100
http://bitbucket.org/pypy/pypy/changeset/4de80533c51b/
Log: Simplify unwrap_spec for parser, pyexpat, pypyjit
diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -1,7 +1,7 @@
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped
-from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.gateway import NoneNotWrapped
+from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.error import OperationError
from pypy.objspace.descroperation import object_setattr
from pypy.rpython.lltypesystem import rffi, lltype
@@ -357,6 +357,7 @@
global_storage.free_nonmoving_id(
rffi.cast(lltype.Signed, self.itself))
+ @unwrap_spec(flag=int)
def SetParamEntityParsing(self, space, flag):
"""SetParamEntityParsing(flag) -> success
Controls parsing of parameter entities (including the external DTD
@@ -365,7 +366,6 @@
XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag
was successful."""
XML_SetParamEntityParsing(self.itself, flag)
- SetParamEntityParsing.unwrap_spec = ['self', ObjSpace, int]
def UseForeignDTD(self, space, w_flag=True):
"""UseForeignDTD([flag])
@@ -376,7 +376,6 @@
'flag' defaults to True if not provided."""
flag = space.is_true(w_flag)
XML_UseForeignDTD(self.itself, flag)
- UseForeignDTD.unwrap_spec = ['self', ObjSpace, W_Root]
# Handlers management
@@ -499,6 +498,7 @@
return True
+ @unwrap_spec(name=str)
def setattr(self, space, name, w_value):
if name == "namespace_prefixes":
XML_SetReturnNSTriplet(self.itself, space.int_w(w_value))
@@ -513,15 +513,15 @@
return space.call_function(
object_setattr(space),
space.wrap(self), space.wrap(name), w_value)
- setattr.unwrap_spec = ['self', ObjSpace, str, W_Root]
# Parse methods
+ @unwrap_spec(data=str, isfinal=bool)
def Parse(self, space, data, isfinal=False):
"""Parse(data[, isfinal])
Parse XML data. `isfinal' should be true at end of input."""
- res = XML_Parse(self.itself, data, len(data), bool(isfinal))
+ res = XML_Parse(self.itself, data, len(data), isfinal)
if self._exc_info:
e = self._exc_info
self._exc_info = None
@@ -531,7 +531,6 @@
raise exc
self.flush_character_buffer(space)
return space.wrap(res)
- Parse.unwrap_spec = ['self', ObjSpace, str, int]
def ParseFile(self, space, w_file):
"""ParseFile(file)
@@ -540,11 +539,10 @@
w_data = space.call_method(w_file, 'read')
data = space.str_w(w_data)
return self.Parse(space, data, isfinal=True)
- ParseFile.unwrap_spec = ['self', ObjSpace, W_Root]
+ @unwrap_spec(base=str)
def SetBase(self, space, base):
XML_SetBase(self.itself, base)
- SetBase.unwrap_spec = ['self', ObjSpace, str]
def ExternalEntityParserCreate(self, space, w_context, w_encoding=None):
"""ExternalEntityParserCreate(context[, encoding])
@@ -572,7 +570,6 @@
parser.handlers[i] = self.handlers[i]
return space.wrap(parser)
- ExternalEntityParserCreate.unwrap_spec = ['self', ObjSpace, W_Root, W_Root]
def flush_character_buffer(self, space):
if not self.buffer_w:
@@ -676,9 +673,7 @@
CurrentColumnNumber = GetSetProperty(W_XMLParserType.descr_ErrorColumnNumber, cls=W_XMLParserType),
CurrentByteIndex = GetSetProperty(W_XMLParserType.descr_ErrorByteIndex, cls=W_XMLParserType),
- **dict((name, interp2app(getattr(W_XMLParserType, name),
- unwrap_spec=getattr(W_XMLParserType,
- name).unwrap_spec))
+ **dict((name, interp2app(getattr(W_XMLParserType, name)))
for name in XMLParser_methods)
)
@@ -740,11 +735,10 @@
parser.itself, UnknownEncodingHandlerData_callback,
rffi.cast(rffi.VOIDP, parser.id))
return space.wrap(parser)
-ParserCreate.unwrap_spec = [ObjSpace, W_Root, W_Root, W_Root]
+ at unwrap_spec(code=int)
def ErrorString(space, code):
"""ErrorString(errno) -> string
Returns string error for given number."""
return space.wrap(rffi.charp2str(XML_ErrorString(code)))
-ErrorString.unwrap_spec = [ObjSpace, int]
diff --git a/pypy/module/parser/pyparser.py b/pypy/module/parser/pyparser.py
--- a/pypy/module/parser/pyparser.py
+++ b/pypy/module/parser/pyparser.py
@@ -1,7 +1,6 @@
-from pypy.interpreter.baseobjspace import ObjSpace, Wrappable
+from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.argument import Arguments
+from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.error import OperationError
from pypy.interpreter.pyparser import pyparse, pygram, error
from pypy.interpreter.astcompiler.astbuilder import ast_from_node
@@ -36,22 +35,21 @@
def descr_issuite(self, space):
return space.wrap(self.tree.type == pygram.syms.file_input)
- descr_issuite.unwrap_spec = ["self", ObjSpace]
def descr_isexpr(self, space):
return space.wrap(self.tree.type == pygram.syms.eval_input)
- descr_isexpr.unwrap_spec = ["self", ObjSpace]
+ @unwrap_spec(line_info=bool, col_info=bool)
def descr_totuple(self, space, line_info=False, col_info=False):
return self._build_app_tree(space, self.tree, space.newtuple,
line_info, col_info)
- descr_totuple.unwrap_spec = ["self", ObjSpace, bool, bool]
+ @unwrap_spec(line_info=bool, col_info=bool)
def descr_tolist(self, space, line_info=False, col_info=False):
return self._build_app_tree(space, self.tree, space.newlist,
line_info, col_info)
- descr_tolist.unwrap_spec = ["self", ObjSpace, bool, bool]
+ @unwrap_spec(filename=str)
def descr_compile(self, space, filename="<syntax-tree>"):
info = pyparse.CompileInfo(filename, self.mode)
try:
@@ -64,7 +62,6 @@
raise OperationError(space.w_SyntaxError,
e.wrap_info(space))
return space.wrap(result)
- descr_compile.unwrap_spec = ["self", ObjSpace, str]
STType.typedef = TypeDef("parser.st",
issuite=interp2app(STType.descr_issuite),
@@ -89,32 +86,32 @@
return space.wrap(STType(tree, mode))
+ at unwrap_spec(source=str)
def suite(space, source):
return parse_python(space, source, 'exec')
-suite.unwrap_spec = [ObjSpace, str]
+ at unwrap_spec(source=str)
def expr(space, source):
return parse_python(space, source, 'eval')
-expr.unwrap_spec = [ObjSpace, str]
+ at unwrap_spec(st=STType)
def isexpr(space, st):
return space.call_method(st, "isexpr")
-isexpr.unwrap_spec = [ObjSpace, STType]
+ at unwrap_spec(st=STType)
def issuite(space, st):
return space.call_method(st, "issuite")
-issuite.unwrap_spec = [ObjSpace, STType]
+ at unwrap_spec(st=STType)
def st2tuple(space, st, __args__):
return space.call_args(space.getattr(st, space.wrap("totuple")), __args__)
-st2tuple.unwrap_spec = [ObjSpace, STType, Arguments]
+ at unwrap_spec(st=STType)
def st2list(space, st, __args__):
return space.call_args(space.getattr(st, space.wrap("tolist")), __args__)
-st2list.unwrap_spec = [ObjSpace, STType, Arguments]
+ at unwrap_spec(st=STType)
def compilest(space, st, __args__):
return space.call_args(space.getattr(st, space.wrap("compile")), __args__)
-compilest.unwrap_spec = [ObjSpace, STType, Arguments]
diff --git a/pypy/module/pypyjit/interp_jit.py b/pypy/module/pypyjit/interp_jit.py
--- a/pypy/module/pypyjit/interp_jit.py
+++ b/pypy/module/pypyjit/interp_jit.py
@@ -9,7 +9,6 @@
from pypy.rlib.jit import current_trace_length
import pypy.interpreter.pyopcode # for side-effects
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import ObjSpace, Arguments, W_Root
from pypy.interpreter.pycode import PyCode, CO_GENERATOR
from pypy.interpreter.pyframe import PyFrame
from pypy.interpreter.pyopcode import ExitFrame
@@ -119,13 +118,13 @@
#
# Public interface
-def set_param(space, args):
+def set_param(space, __args__):
'''Configure the tunable JIT parameters.
* set_param(name=value, ...) # as keyword arguments
* set_param("name=value,name=value") # as a user-supplied string
'''
# XXXXXXXXX
- args_w, kwds_w = args.unpack()
+ args_w, kwds_w = __args__.unpack()
if len(args_w) > 1:
msg = "set_param() takes at most 1 non-keyword argument, %d given"
raise operationerrfmt(space.w_TypeError, msg, len(args_w))
@@ -144,11 +143,8 @@
raise operationerrfmt(space.w_TypeError,
"no JIT parameter '%s'", key)
-set_param.unwrap_spec = [ObjSpace, Arguments]
-
@dont_look_inside
-def residual_call(space, w_callable, args):
+def residual_call(space, w_callable, __args__):
'''For testing. Invokes callable(...), but without letting
the JIT follow the call.'''
- return space.call_args(w_callable, args)
-residual_call.unwrap_spec = [ObjSpace, W_Root, Arguments]
+ return space.call_args(w_callable, __args__)
More information about the Pypy-commit
mailing list