Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r81460:308cca047a01
Date: 2015-12-28 18:37 +0100
http://bitbucket.org/pypy/pypy/changeset/308cca047a01/

Log:    Make and use NOT_CONSTANT in enforceargs(), not enforcing any
        specific annotation except making sure it is not a constant.

diff --git a/rpython/annotator/signature.py b/rpython/annotator/signature.py
--- a/rpython/annotator/signature.py
+++ b/rpython/annotator/signature.py
@@ -100,6 +100,7 @@
         self.argtypes = argtypes
 
     def __call__(self, funcdesc, inputcells):
+        from rpython.rlib.objectmodel import NOT_CONSTANT
         from rpython.rtyper.lltypesystem import lltype
         args_s = []
         from rpython.annotator import model as annmodel
@@ -115,6 +116,9 @@
                 args_s.append(s_input)
             elif argtype is None:
                 args_s.append(inputcells[i])     # no change
+            elif argtype is NOT_CONSTANT:
+                from rpython.annotator.model import not_const
+                args_s.append(not_const(inputcells[i]))
             else:
                 args_s.append(annotation(argtype, 
bookkeeper=funcdesc.bookkeeper))
         if len(inputcells) != len(args_s):
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -114,6 +114,8 @@
 
 specialize = _Specialize()
 
+NOT_CONSTANT = object()      # to use in enforceargs()
+
 def enforceargs(*types_, **kwds):
     """ Decorate a function with forcing of RPython-level types on arguments.
     None means no enforcing.
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -9,7 +9,7 @@
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rlib.rarithmetic import intmask, widen
 from rpython.rlib.objectmodel import (
-    specialize, enforceargs, register_replacement_for)
+    specialize, enforceargs, register_replacement_for, NOT_CONSTANT)
 from rpython.rlib.signature import signature
 from rpython.rlib import types
 from rpython.annotator.model import s_Str0
@@ -415,7 +415,7 @@
 
 @replace_os_function('open')
 @specialize.argtype(0)
-@enforceargs(None, int, int, typecheck=False)
+@enforceargs(NOT_CONSTANT, int, int, typecheck=False)
 def open(path, flags, mode):
     if _prefer_unicode(path):
         fd = c_wopen(_as_unicode0(path), flags, mode)
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -4,7 +4,7 @@
     r_dict, UnboxedValue, Symbolic, compute_hash, compute_identity_hash,
     compute_unique_id, current_object_addr_as_int, we_are_translated,
     prepare_dict_update, reversed_dict, specialize, enforceargs, newlist_hint,
-    resizelist_hint, is_annotation_constant, always_inline,
+    resizelist_hint, is_annotation_constant, always_inline, NOT_CONSTANT,
     iterkeys_with_hash, iteritems_with_hash, contains_with_hash,
     setitem_with_hash, getitem_with_hash, delitem_with_hash, import_from_mixin)
 from rpython.translator.translator import TranslationContext, graphof
@@ -529,6 +529,18 @@
     TYPES = [v.concretetype for v in graph.getargs()]
     assert TYPES == [lltype.Signed, lltype.Float]
 
+def test_enforceargs_not_constant():
+    from rpython.translator.translator import TranslationContext, graphof
+    @enforceargs(NOT_CONSTANT)
+    def f(a):
+        return a
+    def f42():
+        return f(42)
+    t = TranslationContext()
+    a = t.buildannotator()
+    s = a.build_types(f42, [])
+    assert not hasattr(s, 'const')
+
 
 def getgraph(f, argtypes):
     from rpython.translator.translator import TranslationContext, graphof
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to