Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3k Changeset: r52118:4c6488c2ca14 Date: 2012-02-05 19:52 +0100 http://bitbucket.org/pypy/pypy/changeset/4c6488c2ca14/
Log: hg merge default diff --git a/pypy/annotation/annrpython.py b/pypy/annotation/annrpython.py --- a/pypy/annotation/annrpython.py +++ b/pypy/annotation/annrpython.py @@ -93,6 +93,10 @@ # make input arguments and set their type args_s = [self.typeannotation(t) for t in input_arg_types] + # XXX hack + annmodel.TLS.check_str_without_nul = ( + self.translator.config.translation.check_str_without_nul) + flowgraph, inputcells = self.get_call_parameters(function, args_s, policy) if not isinstance(flowgraph, FunctionGraph): assert isinstance(flowgraph, annmodel.SomeObject) diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py --- a/pypy/annotation/model.py +++ b/pypy/annotation/model.py @@ -39,7 +39,9 @@ DEBUG = False # set to False to disable recording of debugging information class State(object): - pass + # A global attribute :-( Patch it with 'True' to enable checking of + # the no_nul attribute... + check_str_without_nul = False TLS = State() class SomeObject(object): @@ -225,9 +227,7 @@ def __init__(self): pass -class SomeString(SomeObject): - "Stands for an object which is known to be a string." - knowntype = str +class SomeStringOrUnicode(SomeObject): immutable = True can_be_None=False no_nul = False # No NUL character in the string. @@ -241,27 +241,29 @@ def can_be_none(self): return self.can_be_None + def __eq__(self, other): + if self.__class__ is not other.__class__: + return False + d1 = self.__dict__ + d2 = other.__dict__ + if not TLS.check_str_without_nul: + d1 = d1.copy(); d1['no_nul'] = 0 # ignored + d2 = d2.copy(); d2['no_nul'] = 0 # ignored + return d1 == d2 + +class SomeString(SomeStringOrUnicode): + "Stands for an object which is known to be a string." + knowntype = str + def nonnoneify(self): return SomeString(can_be_None=False, no_nul=self.no_nul) -class SomeUnicodeString(SomeObject): +class SomeUnicodeString(SomeStringOrUnicode): "Stands for an object which is known to be an unicode string" knowntype = unicode - immutable = True - can_be_None=False - no_nul = False - - def __init__(self, can_be_None=False, no_nul=False): - if can_be_None: - self.can_be_None = True - if no_nul: - self.no_nul = True - - def can_be_none(self): - return self.can_be_None def nonnoneify(self): - return SomeUnicodeString(can_be_None=False) + return SomeUnicodeString(can_be_None=False, no_nul=self.no_nul) class SomeChar(SomeString): "Stands for an object known to be a string of length 1." @@ -740,15 +742,6 @@ s_obj = new_s_obj return s_obj -def remove_no_nul(s_obj): - if not getattr(s_obj, 'no_nul', False): - return s_obj - new_s_obj = SomeObject.__new__(s_obj.__class__) - new_s_obj.__dict__ = s_obj.__dict__.copy() - del new_s_obj.no_nul - return new_s_obj - - # ____________________________________________________________ # internal diff --git a/pypy/rpython/extfunc.py b/pypy/rpython/extfunc.py --- a/pypy/rpython/extfunc.py +++ b/pypy/rpython/extfunc.py @@ -152,15 +152,7 @@ assert len(args_s) == len(signature_args),\ "Argument number mismatch" - check_no_nul = False - if hasattr(self, 'bookkeeper'): - config = self.bookkeeper.annotator.translator.config - if config.translation.check_str_without_nul: - check_no_nul = True - for i, expected in enumerate(signature_args): - if not check_no_nul: - expected = annmodel.remove_no_nul(expected) arg = annmodel.unionof(args_s[i], expected) if not expected.contains(arg): name = getattr(self, 'name', None) diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py b/pypy/rpython/lltypesystem/ll2ctypes.py --- a/pypy/rpython/lltypesystem/ll2ctypes.py +++ b/pypy/rpython/lltypesystem/ll2ctypes.py @@ -1036,13 +1036,8 @@ libraries = eci.testonly_libraries + eci.libraries + eci.frameworks FUNCTYPE = lltype.typeOf(funcptr).TO - if not libraries: - cfunc = get_on_lib(standard_c_lib, funcname) - # XXX magic: on Windows try to load the function from 'kernel32' too - if cfunc is None and hasattr(ctypes, 'windll'): - cfunc = get_on_lib(ctypes.windll.kernel32, funcname) - else: - cfunc = None + cfunc = None + if libraries: not_found = [] for libname in libraries: libpath = None @@ -1075,6 +1070,12 @@ not_found.append(libname) if cfunc is None: + cfunc = get_on_lib(standard_c_lib, funcname) + # XXX magic: on Windows try to load the function from 'kernel32' too + if cfunc is None and hasattr(ctypes, 'windll'): + cfunc = get_on_lib(ctypes.windll.kernel32, funcname) + + if cfunc is None: # function name not found in any of the libraries if not libraries: place = 'the standard C library (missing libraries=...?)' diff --git a/pypy/rpython/test/test_extfunc.py b/pypy/rpython/test/test_extfunc.py --- a/pypy/rpython/test/test_extfunc.py +++ b/pypy/rpython/test/test_extfunc.py @@ -187,3 +187,23 @@ raises(Exception, a.build_types, g, [str]) a.build_types(g, [str0]) # Does not raise + def test_list_of_str0(self): + str0 = annmodel.SomeString(no_nul=True) + def os_execve(l): + pass + register_external(os_execve, [[str0]], None) + def f(l): + return os_execve(l) + policy = AnnotatorPolicy() + policy.allow_someobjects = False + a = RPythonAnnotator(policy=policy) + a.build_types(f, [[str]]) # Does not raise + assert a.translator.config.translation.check_str_without_nul == False + # Now enable the str0 check, and try again with a similar function + a.translator.config.translation.check_str_without_nul=True + def g(l): + return os_execve(l) + raises(Exception, a.build_types, g, [[str]]) + a.build_types(g, [[str0]]) # Does not raise + + _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit