[pypy-svn] r45973 - in pypy/branch/pypy-more-rtti-inprogress: module/_curses rpython rpython/module rpython/ootypesystem/test rpython/test translator/js/modules
pedronis at codespeak.net
pedronis at codespeak.net
Sat Aug 25 12:45:19 CEST 2007
Author: pedronis
Date: Sat Aug 25 12:45:17 2007
New Revision: 45973
Modified:
pypy/branch/pypy-more-rtti-inprogress/module/_curses/fficurses.py
pypy/branch/pypy-more-rtti-inprogress/rpython/extfunc.py
pypy/branch/pypy-more-rtti-inprogress/rpython/extfuncregistry.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py
pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py
pypy/branch/pypy-more-rtti-inprogress/rpython/ootypesystem/test/test_bltann.py
pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_extfunc.py
pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/dom.py
pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/mochikit.py
Log:
- given how much is used: make _register_external -> register_external
- fix test_extfunc.py, by making ExtFuncEntry more backward compatible
Modified: pypy/branch/pypy-more-rtti-inprogress/module/_curses/fficurses.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/module/_curses/fficurses.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/module/_curses/fficurses.py Sat Aug 25 12:45:17 2007
@@ -5,7 +5,7 @@
import sys
from pypy.rpython.lltypesystem import rffi
from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.extfunc import _register_external as register_external
+from pypy.rpython.extfunc import register_external
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.module._curses import interp_curses
from pypy.rpython.lltypesystem import llmemory
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfunc.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfunc.py Sat Aug 25 12:45:17 2007
@@ -85,6 +85,27 @@
class ExtFuncEntry(ExtRegistryEntry):
safe_not_sandboxed = False
+ # common case: args is a list of annotation or types
+ def normalize_args(self, *args_s):
+ args = self.signature_args
+ signature_args = [annotation(arg, None) for arg in args]
+ assert len(args_s) == len(signature_args),\
+ "Argument number mismatch"
+ for i, expected in enumerate(signature_args):
+ arg = unionof(args_s[i], expected)
+ if not expected.contains(arg):
+ name = getattr(self, 'name', None)
+ if not name:
+ try:
+ name = self.instance.__name__
+ except AttributeError:
+ name = '?'
+ raise Exception("In call to external function %r:\n"
+ "arg %d must be %s,\n"
+ " got %s" % (
+ name, i+1, expected, args_s[i]))
+ return signature_args
+
def compute_result_annotation(self, *args_s):
if hasattr(self, 'ann_hook'):
self.ann_hook()
@@ -127,7 +148,7 @@
hop.exception_is_here()
return hop.genop('direct_call', vlist, r_result)
-def _register_external(function, args, result=None, export_name=None,
+def register_external(function, args, result=None, export_name=None,
llimpl=None, ooimpl=None,
llfakeimpl=None, oofakeimpl=None,
annotation_hook=None,
@@ -150,31 +171,11 @@
if args is None:
def normalize_args(self, *args_s):
return args_s # accept any argument unmodified
-
elif callable(args):
# custom annotation normalizer (see e.g. os.utime())
normalize_args = staticmethod(args)
-
- else:
- # common case: args is a list of annotation or types
- def normalize_args(self, *args_s):
- signature_args = [annotation(arg, None) for arg in args]
- assert len(args_s) == len(signature_args),\
- "Argument number mismatch"
- for i, expected in enumerate(signature_args):
- arg = unionof(args_s[i], expected)
- if not expected.contains(arg):
- name = getattr(self, 'name', None)
- if not name:
- try:
- name = self.instance.__name__
- except AttributeError:
- name = '?'
- raise Exception("In call to external function %r:\n"
- "arg %d must be %s,\n"
- " got %s" % (
- name, i+1, expected, args_s[i]))
- return signature_args
+ else: # use common case behavior
+ signature_args = args
signature_result = annotation(result, None)
name=export_name
@@ -194,7 +195,7 @@
else:
FunEntry.__name__ = function.func_name
-BaseLazyRegistering.register = staticmethod(_register_external)
+BaseLazyRegistering.register = staticmethod(register_external)
def is_external(func):
if hasattr(func, 'value'):
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfuncregistry.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfuncregistry.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfuncregistry.py Sat Aug 25 12:45:17 2007
@@ -1,7 +1,7 @@
# this registry use the new interface for external functions
# all the above declarations in extfunctable should be moved here at some point.
-from extfunc import _register_external
+from extfunc import register_external
# ___________________________
# math functions
@@ -25,7 +25,8 @@
'floor', 'log', 'log10', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
]
for name in simple_math_functions:
- _register_external(getattr(math, name), [float], float, "ll_math.ll_math_%s" % name,
+ register_external(getattr(math, name), [float], float,
+ "ll_math.ll_math_%s" % name,
sandboxsafe=True)
complex_math_functions = [
@@ -42,9 +43,9 @@
func = getattr(math, name)
llimpl = getattr(ll_math, 'll_math_%s' % name, None)
oofake = getattr(oo_math, 'll_math_%s' % name, None)
- _register_external(func, args, res, 'll_math.ll_math_%s' % name,
- llimpl=llimpl, oofakeimpl=oofake,
- sandboxsafe=True)
+ register_external(func, args, res, 'll_math.ll_math_%s' % name,
+ llimpl=llimpl, oofakeimpl=oofake,
+ sandboxsafe=True)
# ___________________________
@@ -71,5 +72,5 @@
for name, args, res in path_functions:
func = getattr(os.path, name)
llimpl = func_with_new_name(func, name)
- _register_external(func, args, res, 'll_os_path.ll_%s' % name,
- llimpl=llimpl, sandboxsafe=True)
+ register_external(func, args, res, 'll_os_path.ll_%s' % name,
+ llimpl=llimpl, sandboxsafe=True)
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_environ.py Sat Aug 25 12:45:17 2007
@@ -1,7 +1,7 @@
import os
from pypy.annotation import model as annmodel
from pypy.rpython.controllerentry import Controller
-from pypy.rpython.extfunc import _register_external
+from pypy.rpython.extfunc import register_external
from pypy.rpython.lltypesystem import rffi, lltype
# ____________________________________________________________
@@ -63,9 +63,9 @@
rffi.free_charp(l_name)
return result
-_register_external(r_getenv, [str], annmodel.SomeString(can_be_None=True),
- export_name='ll_os.ll_os_getenv',
- llimpl=getenv_lltypeimpl)
+register_external(r_getenv, [str], annmodel.SomeString(can_be_None=True),
+ export_name='ll_os.ll_os_getenv',
+ llimpl=getenv_lltypeimpl)
# ____________________________________________________________
@@ -92,9 +92,9 @@
if l_oldstring:
rffi.free_charp(l_oldstring)
-_register_external(r_putenv, [str, str], annmodel.s_None,
- export_name='ll_os.ll_os_putenv',
- llimpl=putenv_lltypeimpl)
+register_external(r_putenv, [str, str], annmodel.s_None,
+ export_name='ll_os.ll_os_putenv',
+ llimpl=putenv_lltypeimpl)
# ____________________________________________________________
@@ -120,9 +120,9 @@
del envkeepalive.byname[name]
rffi.free_charp(l_oldstring)
- _register_external(r_unsetenv, [str], annmodel.s_None,
- export_name='ll_os.ll_os_unsetenv',
- llimpl=unsetenv_lltypeimpl)
+ register_external(r_unsetenv, [str], annmodel.s_None,
+ export_name='ll_os.ll_os_unsetenv',
+ llimpl=unsetenv_lltypeimpl)
# ____________________________________________________________
# Access to the 'environ' external variable
@@ -154,9 +154,9 @@
i += 1
return result
-_register_external(r_envkeys, [], [str], # returns a list of strings
- export_name='ll_os.ll_os_envkeys',
- llimpl=envkeys_lltypeimpl)
+register_external(r_envkeys, [], [str], # returns a list of strings
+ export_name='ll_os.ll_os_envkeys',
+ llimpl=envkeys_lltypeimpl)
# ____________________________________________________________
@@ -175,6 +175,6 @@
i += 1
return result
-_register_external(r_envitems, [], [(str, str)],
- export_name='ll_os.ll_os_envitems',
- llimpl=envitems_lltypeimpl)
+register_external(r_envitems, [], [(str, str)],
+ export_name='ll_os.ll_os_envitems',
+ llimpl=envitems_lltypeimpl)
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py Sat Aug 25 12:45:17 2007
@@ -6,7 +6,7 @@
from pypy.annotation import model as annmodel
from pypy.tool.sourcetools import func_with_new_name
from pypy.rpython.controllerentry import Controller, SomeControlledInstance
-from pypy.rpython.extfunc import _register_external
+from pypy.rpython.extfunc import register_external
from pypy.rpython.lltypesystem import rffi, lltype
if sys.platform.startswith('win'):
@@ -186,7 +186,7 @@
s_arg = str
else:
s_arg = int
- _register_external(getattr(os, name), [s_arg], s_StatResult,
- "ll_os.ll_os_%s" % (name,),
- llimpl=func_with_new_name(os_mystat_lltypeimpl,
- 'os_%s_lltypeimpl' % (name,)))
+ register_external(getattr(os, name), [s_arg], s_StatResult,
+ "ll_os.ll_os_%s" % (name,),
+ llimpl=func_with_new_name(os_mystat_lltypeimpl,
+ 'os_%s_lltypeimpl' % (name,)))
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py Sat Aug 25 12:45:17 2007
@@ -8,7 +8,7 @@
import termios
from pypy.rpython.lltypesystem import rffi
from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.extfunc import lazy_register, _register_external
+from pypy.rpython.extfunc import lazy_register, register_external
from pypy.rlib.rarithmetic import intmask
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.annotation import model as annmodel
@@ -68,7 +68,7 @@
finally:
lltype.free(c_struct, flavor='raw')
-_register_external(rtermios.tcgetattr, [int], (int, int, int, int, int, int, [str]),
+register_external(rtermios.tcgetattr, [int], (int, int, int, int, int, int, [str]),
llimpl=tcgetattr_llimpl, export_name='termios.tcgetattr')
def tcsetattr_llimpl(fd, when, attributes):
@@ -91,7 +91,7 @@
lltype.free(c_struct, flavor='raw')
r_uint = rffi.r_uint
-_register_external(rtermios.tcsetattr, [int, int, (r_uint, r_uint, r_uint,
+register_external(rtermios.tcsetattr, [int, int, (r_uint, r_uint, r_uint,
r_uint, r_uint, r_uint, [str])], llimpl=tcsetattr_llimpl,
export_name='termios.tcsetattr')
@@ -101,7 +101,7 @@
error = c_tcsendbreak(fd, duration)
if error == -1:
raise termios.error(error, 'tcsendbreak failed')
-_register_external(termios.tcsendbreak, [int, int],
+register_external(termios.tcsendbreak, [int, int],
llimpl=tcsendbreak_llimpl,
export_name='termios.tcsendbreak')
@@ -109,19 +109,19 @@
error = c_tcdrain(fd)
if error == -1:
raise termios.error(error, 'tcdrain failed')
-_register_external(termios.tcdrain, [int], llimpl=tcdrain_llimpl,
+register_external(termios.tcdrain, [int], llimpl=tcdrain_llimpl,
export_name='termios.tcdrain')
def tcflush_llimpl(fd, queue_selector):
error = c_tcflush(fd, queue_selector)
if error == -1:
raise termios.error(error, 'tcflush failed')
-_register_external(termios.tcflush, [int, int], llimpl=tcflush_llimpl,
+register_external(termios.tcflush, [int, int], llimpl=tcflush_llimpl,
export_name='termios.tcflush')
def tcflow_llimpl(fd, action):
error = c_tcflow(fd, action)
if error == -1:
raise termios.error(error, 'tcflow failed')
-_register_external(termios.tcflow, [int, int], llimpl=tcflow_llimpl,
+register_external(termios.tcflow, [int, int], llimpl=tcflow_llimpl,
export_name='termios.tcflow')
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/ootypesystem/test/test_bltann.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/ootypesystem/test/test_bltann.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/ootypesystem/test/test_bltann.py Sat Aug 25 12:45:17 2007
@@ -168,7 +168,7 @@
assert res == 8.3
def test_mixed_classes():
- from pypy.rpython.extfunc import _register_external
+ from pypy.rpython.extfunc import register_external
class One(BasicExternal):
pass
@@ -177,7 +177,7 @@
def g(one):
return 3
- _register_external(g, args=[One], result=int)
+ register_external(g, args=[One], result=int)
def f(x):
if x:
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_extfunc.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/test/test_extfunc.py Sat Aug 25 12:45:17 2007
@@ -1,5 +1,5 @@
-from pypy.rpython.extfunc import ExtFuncEntry, _register_external,\
+from pypy.rpython.extfunc import ExtFuncEntry, register_external,\
is_external, lazy_register
from pypy.annotation import model as annmodel
from pypy.annotation.annrpython import RPythonAnnotator
@@ -79,7 +79,7 @@
def dd():
pass
-_register_external(dd, [int], int)
+register_external(dd, [int], int)
def test_register_external_signature():
def f():
@@ -98,7 +98,7 @@
an argument so that register_external's behavior for tuple-taking functions
can be verified.
"""
-_register_external(function_with_tuple_arg, [(int,)], int)
+register_external(function_with_tuple_arg, [(int,)], int)
def test_register_external_tuple_args():
"""
@@ -118,11 +118,11 @@
def function_with_list():
pass
-_register_external(function_with_list, [[int]], int)
+register_external(function_with_list, [[int]], int)
def function_returning_list():
pass
-_register_external(function_returning_list, [], [int])
+register_external(function_returning_list, [], [int])
def test_register_external_return_goes_back():
"""
@@ -141,7 +141,7 @@
def function_withspecialcase(arg):
return repr(arg)
-_register_external(function_withspecialcase, args=None, result=str)
+register_external(function_withspecialcase, args=None, result=str)
def test_register_external_specialcase():
def f():
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/dom.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/dom.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/dom.py Sat Aug 25 12:45:17 2007
@@ -22,7 +22,7 @@
from pypy.rlib.nonconst import NonConstant
from pypy.rpython.extfunc import genericcallable
-from pypy.rpython.extfunc import _register_external as register_external
+from pypy.rpython.extfunc import register_external
from xml.dom import minidom
from pypy.annotation.signature import annotation
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/mochikit.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/mochikit.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/js/modules/mochikit.py Sat Aug 25 12:45:17 2007
@@ -3,7 +3,7 @@
"""
from pypy.rpython.extfunc import genericcallable
-from pypy.rpython.extfunc import _register_external as register_external
+from pypy.rpython.extfunc import register_external
from pypy.rpython.ootypesystem.bltregistry import BasicExternal, MethodDesc
from pypy.translator.js.modules import dom
More information about the Pypy-commit
mailing list