From 7cbd3d9c0b6d68d7f2112ec1b46ce453a6c75a41 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 17 Mar 2017 15:45:46 +0100 Subject: [PATCH 1/3] Flake8 fixes and do not allow flake8 tests to fail --- .travis.yml | 3 - targettopaz.py | 2 +- tasks/travis.py | 2 + tests/jit/conftest.py | 6 +- tests/modules/ffi/base.py | 1 + tests/modules/ffi/conftest.py | 6 +- tests/modules/ffi/test_abstract_memory.py | 84 +++++++++------- tests/modules/ffi/test_callback.py | 1 - tests/modules/ffi/test_data_converter.py | 20 ++-- tests/modules/ffi/test_dynamic_library.py | 17 +++- tests/modules/ffi/test_ffi.py | 11 ++- tests/modules/ffi/test_function.py | 27 +++--- tests/modules/ffi/test_function_type.py | 2 +- tests/modules/ffi/test_memory_pointer.py | 11 ++- tests/modules/ffi/test_pointer.py | 20 +++- tests/modules/ffi/test_type.py | 28 ++++-- tests/modules/ffi/test_variadic_invoker.py | 5 +- tests/modules/test_marshal.py | 46 ++++----- tests/modules/test_math.py | 8 +- topaz/lexer.py | 2 +- topaz/modules/fcntl.py | 5 +- topaz/modules/ffi/__init__.py | 2 + topaz/modules/ffi/_callback.py | 11 ++- topaz/modules/ffi/abstract_memory.py | 47 +++++---- topaz/modules/ffi/data_converter.py | 6 +- topaz/modules/ffi/dynamic_library.py | 22 +++-- topaz/modules/ffi/ffi.py | 10 +- topaz/modules/ffi/function.py | 7 +- topaz/modules/ffi/function_type.py | 25 +++-- topaz/modules/ffi/memory_pointer.py | 9 +- topaz/modules/ffi/misc.py | 13 ++- topaz/modules/ffi/pointer.py | 3 + topaz/modules/ffi/type.py | 106 +++++++++++---------- topaz/modules/ffi/variadic_invoker.py | 12 +-- topaz/modules/topaz.py | 38 ++++---- topaz/objects/fiberobject.py | 2 + topaz/objects/timeobject.py | 48 ++++++---- topaz/parser.py | 3 +- topaz/utils/regexp.py | 9 +- 39 files changed, 397 insertions(+), 283 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0755bf9b4..6e912a7bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,6 @@ matrix: # This times out because untranslated is so slow :/ - python: pypy-5.3.1 env: TEST_TYPE=rubyspec_untranslated - # We're tracking this, but not failing for it right now :( - - python: pypy-5.3.1 - env: TEST_TYPE=flake8 include: - os: osx language: generic diff --git a/targettopaz.py b/targettopaz.py index 36a45aece..e20e2c07c 100644 --- a/targettopaz.py +++ b/targettopaz.py @@ -15,7 +15,7 @@ def jitpolicy(driver): def handle_config(config, translateconfig): from rpython.translator.platform import host_factory - max_stack_size = 11 << 18 # 2.8 Megs + max_stack_size = 11 << 18 # 2.8 Megs if host_factory.name == 'msvc': host_factory.cflags += ('/DMAX_STACK_SIZE=%d' % max_stack_size,) elif host_factory.name in ('linux', 'darwin'): diff --git a/tasks/travis.py b/tasks/travis.py index e59652282..80cb41e86 100644 --- a/tasks/travis.py +++ b/tasks/travis.py @@ -116,9 +116,11 @@ def run_translate_jit_tests(env): run_specs("`pwd`/bin/topaz") invoke.run("PYTHONPATH={rpython_path}:$PYTHONPATH py.test --topaz=bin/topaz tests/jit/".format(**env)) + def run_translate_jit(env): invoke.run("PYTHONPATH={rpython_path}:$PYTHONPATH python {rpython_path}/rpython/bin/rpython --batch -Ojit targettopaz.py".format(**env)) + def run_specs(binary, prefix=""): invoke.run("{prefix}../mspec/bin/mspec run -G fails -t {binary} --config=topaz.mspec".format( prefix=prefix, diff --git a/tests/jit/conftest.py b/tests/jit/conftest.py index e57ca0d11..696f3050f 100644 --- a/tests/jit/conftest.py +++ b/tests/jit/conftest.py @@ -1,4 +1,3 @@ -import os import py import sys @@ -12,7 +11,8 @@ def __init__(self, trace, expected_ops, exception): self.exception = exception def find_test_file(self): - import traceback, re + import re + import traceback stk = traceback.extract_stack() stk.reverse() for filename, lineno, funcname, text in stk: @@ -21,7 +21,7 @@ def find_test_file(self): return None, None def get_updated_contents(self, filename, lineno): - lno = lineno - 10 # heuristic ;) + lno = lineno - 10 # heuristic ;) with open(filename) as f: contents = f.readlines() newline = "\r\n" if contents[0].endswith("\r\n") else "\n" diff --git a/tests/modules/ffi/base.py b/tests/modules/ffi/base.py index 9c4b6f4ac..7a5aa49ff 100644 --- a/tests/modules/ffi/base.py +++ b/tests/modules/ffi/base.py @@ -1,5 +1,6 @@ from tests.base import BaseTopazTest + class BaseFFITest(BaseTopazTest): def ask(self, space, question): w_answer = space.execute(question) diff --git a/tests/modules/ffi/conftest.py b/tests/modules/ffi/conftest.py index eaa028e86..cff0c4971 100644 --- a/tests/modules/ffi/conftest.py +++ b/tests/modules/ffi/conftest.py @@ -2,10 +2,9 @@ import subprocess import sys -from rpython.rtyper.lltypesystem.ll2ctypes import ALLOCATED def pytest_funcarg__ffis(request, space): - system, _, _, _, cpu = os.uname() # not for windows + system, _, _, _, cpu = os.uname() # not for windows space.execute(""" RUBY_ENGINE = 'topaz' RUBY_PLATFORM = '%s-%s' @@ -13,11 +12,12 @@ def pytest_funcarg__ffis(request, space): """ % (cpu, system.lower())) return space + def pytest_funcarg__libtest_so(): ext = 'dylib' if sys.platform == 'darwin' else 'so' self_dir = os.path.join(os.path.dirname(__file__)) makefile = os.path.join('libtest', 'GNUmakefile') - subprocess.call(["make" , "-f", makefile], cwd=self_dir) + subprocess.call(["make", "-f", makefile], cwd=self_dir) rel_to_libtest_so = os.path.join('build', 'libtest.' + ext) libtest_so = os.path.abspath(os.path.join(self_dir, rel_to_libtest_so)) return libtest_so diff --git a/tests/modules/ffi/test_abstract_memory.py b/tests/modules/ffi/test_abstract_memory.py index e70b282f4..942df8dd8 100644 --- a/tests/modules/ffi/test_abstract_memory.py +++ b/tests/modules/ffi/test_abstract_memory.py @@ -6,7 +6,6 @@ from pypy.module._cffi_backend import misc import sys -import pytest test_types = [ffitype.INT8, ffitype.INT16, ffitype.INT32, ffitype.INT64, ffitype.UINT8, ffitype.UINT16, ffitype.UINT32, ffitype.UINT64, @@ -23,31 +22,36 @@ minval = {} maxval = {} for bits in [8, 16, 32, 64]: - minval['int' + str(bits)] = int(-2**(bits-1)) + minval['int' + str(bits)] = int(-2**(bits - 1)) minval['uint' + str(bits)] = 0 - maxval['int' + str(bits)] = int(2**(bits-1) - 1) + maxval['int' + str(bits)] = int(2**(bits - 1) - 1) # for some reason int(2**64 -1) is not accepted as biggest uint64 - maxval['uint' + str(bits)] = int(2**(bits-1) - 1) -minval['long'] = int(-2**(8*rffi.sizeof(rffi.LONG))) + maxval['uint' + str(bits)] = int(2**(bits - 1) - 1) +minval['long'] = int(-2**(8 * rffi.sizeof(rffi.LONG))) minval['ulong'] = 0 -maxval['long'] = int(2**(8*rffi.sizeof(rffi.LONG)) - 1) -maxval['ulong'] = int(2**(8*rffi.sizeof(rffi.LONG)-1) - 1) +maxval['long'] = int(2**(8 * rffi.sizeof(rffi.LONG)) - 1) +maxval['ulong'] = int(2**(8 * rffi.sizeof(rffi.LONG) - 1) - 1) minval['float32'] = 1.1754943508222875e-38 maxval['float32'] = 3.4028234663852886e+38 minval['float64'] = sys.float_info.min maxval['float64'] = sys.float_info.max + def new_cast_method(typ): ctype = ffitype.lltypes[typ] + def cast_method(memory): return rffi.cast(ffitype.lltype.Ptr(rffi.CArray(ctype)), memory.ptr) return cast_method + def new_numberof_method(typ): csize = ffitype.lltype_sizes[typ] if csize & (csize - 1) == 0: # csize is a power of 2 shift = 0 - while 1 << shift < csize: shift += 1 + while 1 << shift < csize: + shift += 1 + def numberof_method(self): return self.sizeof_memory >> shift else: @@ -55,6 +59,7 @@ def numberof_method(self): return self.sizeof_memory / csize return numberof_method + def put_method_test_code(typename): # For some reason, str(some_float) cuts off a few digits. # Only repr prints the entire float. @@ -66,9 +71,10 @@ def put_method_test_code(typename): mem_ptr.put_TYPE(FFI::Type::UPPER.size, MAX) mem_ptr """.replace('TYPE', typename). - replace('UPPER', typename.upper()). - replace('MIN', strfunc(minval[typename])). - replace('MAX', strfunc(maxval[typename]))) + replace('UPPER', typename.upper()). + replace('MIN', strfunc(minval[typename])). + replace('MAX', strfunc(maxval[typename]))) + def get_method_test_code(typename): strfunc = ((lambda x: repr(x)) if 'float' in typename else @@ -81,9 +87,10 @@ def get_method_test_code(typename): mem_ptr.put_TYPE(pos_4, MAX) [mem_ptr.get_TYPE(pos_3), mem_ptr.get_TYPE(pos_4)] """.replace('TYPE', typename). - replace('UPPER', typename.upper()). - replace('MIN', strfunc(minval[typename])). - replace('MAX', strfunc(maxval[typename]))) + replace('UPPER', typename.upper()). + replace('MIN', strfunc(minval[typename])). + replace('MAX', strfunc(maxval[typename]))) + class TestAbstractMemory_put_methods(BaseFFITest): def test_they_put_a_single_value_into_the_given_offset(self, space): @@ -106,7 +113,7 @@ def test_they_refuse_negative_offsets(self, space): sizeof_t = ffitype.lltype_sizes[t] with self.raises(space, 'IndexError', "Memory access offset=-1 size=%s is out of bounds" - % sizeof_t): + % sizeof_t): space.execute(""" FFI::MemoryPointer.new(:T, 1).put_T(-1, 230) """.replace('T', tn.lower())) @@ -115,13 +122,15 @@ def test_they_refuse_too_large_offsets(self, space): for t in test_types: tn = ffitype.type_names[t] sizeof_t = ffitype.lltype_sizes[t] - with self.raises(space, 'IndexError', - "Memory access offset=1000 size=%s is out of bounds" - % sizeof_t): + with self.raises( + space, 'IndexError', + ("Memory access offset=1000 size=%s is out of bounds" % + sizeof_t)): space.execute(""" FFI::MemoryPointer.new(:T, 3).put_T(1000, 15) """.replace('T', tn.lower())) + class TestAbstractMemory_write_methods(BaseFFITest): def test_they_are_like_calling_put_with_0_as_1st_arg(self, space): for t in test_types: @@ -135,6 +144,7 @@ def test_they_are_like_calling_put_with_0_as_1st_arg(self, space): casted_ptr = cast_method(w_mem_ptr) assert casted_ptr[0] == 'y' if tn == 'INT8' else 121 + class TestAbstractMemory_get_methods(BaseFFITest): def test_they_get_a_single_value_from_the_given_offset(self, space): for tn in [ffitype.type_names[t].lower() @@ -142,10 +152,10 @@ def test_they_get_a_single_value_from_the_given_offset(self, space): w_res = space.execute(get_method_test_code(tn)) assert self.unwrap(space, w_res) == [minval[tn], maxval[tn]] + class TestAbstractMemory_read_methods(BaseFFITest): def test_they_are_like_calling_get_with_0(self, space): - for tn in [ffitype.type_names[t].lower() - for t in test_types]: + for tn in [ffitype.type_names[t].lower() for t in test_types]: w_res = space.execute(""" mem_ptr = FFI::MemoryPointer.new(:T, 1) mem_ptr.write_T(1) @@ -153,6 +163,7 @@ def test_they_are_like_calling_get_with_0(self, space): """.replace('T', tn)) assert self.unwrap(space, w_res) == 1 + class TestAbstractMemory_put_pointer(BaseFFITest): def test_it_puts_a_single_pointer_into_the_given_offset(self, space): w_mem_ptr = space.execute(""" @@ -167,6 +178,7 @@ def test_it_puts_a_single_pointer_into_the_given_offset(self, space): assert w_adr_ptr[0] == 88 assert w_adr_ptr[1] == 55 + class TestAbstractMemory_get_pointer(BaseFFITest): def test_it_gets_a_single_pointer_from_the_given_offset(self, space): assert self.ask(space, """ @@ -196,6 +208,7 @@ def test_it_doesnt_loose_the_content(self, space): """) assert self.unwrap(space, w_res) == 300 + class TestAbstractMemory_write_pointer(BaseFFITest): def test_it_is_like_calling_put_pointer_with_0_as_1st_arg(self, space): w_res = space.execute(""" @@ -205,6 +218,7 @@ def test_it_is_like_calling_put_pointer_with_0_as_1st_arg(self, space): """) assert self.unwrap(space, w_res) == 11 + class TestAbstractMemory_write_uint64(BaseFFITest): def test_it_is_like_calling_put_uint64_with_0_as_1st_arg(self, space): w_res = space.execute(""" @@ -214,6 +228,7 @@ def test_it_is_like_calling_put_uint64_with_0_as_1st_arg(self, space): """) assert self.unwrap(space, w_res) == 14 + class TestAbstractMemory_read_pointer(BaseFFITest): def test_it_is_like_calling_get_pointer_with_0(self, space): w_res = space.execute(""" @@ -223,6 +238,7 @@ def test_it_is_like_calling_get_pointer_with_0(self, space): """) assert self.unwrap(space, w_res) == 13 + class TestAbstractMemory_read_uint64(BaseFFITest): def test_it_is_like_calling_get_uint64_with_0(self, space): w_res = space.execute(""" @@ -232,20 +248,20 @@ def test_it_is_like_calling_get_uint64_with_0(self, space): """) assert self.unwrap(space, w_res) == 12 + class TestAbstractMemory(BaseFFITest): def test_it_defines_the_following_aliases(self, space): for aliases in [ - ('int8', 'char'), - ('uint8', 'uchar'), - ('int16', 'short'), - ('uint16', 'ushort'), - ('int32', 'int'), - ('uint32', 'uint'), - ('int64', 'long_long'), - ('uint64', 'ulong_long'), - ('float32', 'float'), - ('float64', 'double') - ]: + ('int8', 'char'), + ('uint8', 'uchar'), + ('int16', 'short'), + ('uint16', 'ushort'), + ('int32', 'int'), + ('uint32', 'uint'), + ('int64', 'long_long'), + ('uint64', 'ulong_long'), + ('float32', 'float'), + ('float64', 'double')]: assert self.ask(space, """ FFI::AbstractMemory.instance_method(:put_%s) == FFI::AbstractMemory.instance_method(:put_%s) @@ -269,11 +285,11 @@ def test_it_defines_long_methods_in_the_following_way(self, space): FFI::AbstractMemory.instance_method(:PREFIXintSIZEOF_LONG_IN_BITS) """.replace('SIZEOF_LONG_IN_BITS', str(8 * rffi.sizeof(rffi.LONG))) signed_meths = ['put_', 'get_', 'write_', 'read_'] - unsigned_meths = [meth+'u' for meth in signed_meths] + unsigned_meths = [meth + 'u' for meth in signed_meths] for prefix in signed_meths + unsigned_meths: assert self.ask(space, question.replace('PREFIX', prefix)) -#class TestAbstractMemory__put_array_of_int32(BaseFFITest): +# class TestAbstractMemory__put_array_of_int32(BaseFFITest): # def test_it_writes_into_array(self, space): # w_mem_ptr = space.execute(""" # mem_ptr = FFI::MemoryPointer.new(:int32, 10) @@ -316,7 +332,7 @@ def test_it_defines_long_methods_in_the_following_way(self, space): # mem_ptr.put_array_of_int32(0, [1, 2, 3]) # """) # -#class TestAbstractMemory__get_array_of_int32(BaseFFITest): +# class TestAbstractMemory__get_array_of_int32(BaseFFITest): # def test_it_reads_from_array(self, space): # w_res = space.execute(""" # mem_ptr = FFI::MemoryPointer.new(:int32, 10) diff --git a/tests/modules/ffi/test_callback.py b/tests/modules/ffi/test_callback.py index 5634d5a79..a150c1da9 100644 --- a/tests/modules/ffi/test_callback.py +++ b/tests/modules/ffi/test_callback.py @@ -1,4 +1,3 @@ -import os import py from topaz.modules.ffi import _callback diff --git a/tests/modules/ffi/test_data_converter.py b/tests/modules/ffi/test_data_converter.py index 280a56b0a..08348d9e2 100644 --- a/tests/modules/ffi/test_data_converter.py +++ b/tests/modules/ffi/test_data_converter.py @@ -1,6 +1,7 @@ import pytest from tests.modules.ffi.base import BaseFFITest + class TestDataConverter(BaseFFITest): def test_it_is_a_Module(self, space): assert self.ask(space, "FFI::DataConverter.is_a? Module") @@ -30,6 +31,7 @@ def impl_to_native(*args) end """ + class TestDataConverter__native_type(BaseFFITest): @pytest.mark.xfail @@ -42,7 +44,6 @@ def test_it_raises_NotImplementedError_without_args(self, space): DataConverterImplementation.new.impl_native_type """) - def test_it_calls_find_type_if_one_arg_was_given(self, space): space.execute(code_DataConverterImplementation) w_res = space.execute(""" @@ -78,23 +79,26 @@ def test_it_raises_ArgumentError_for_more_than_1_arg(self, space): DataConverterImplementation.new.impl_native_type(:int8, :more) """) + def check_it_takes_two_args_and_returns_the_first(ffitest, space, funcname): space.execute(code_DataConverterImplementation) - w_res = space.execute("%s(1, 2)" %funcname) + w_res = space.execute("%s(1, 2)" % funcname) assert ffitest.unwrap(space, w_res) == 1 with ffitest.raises(space, "ArgumentError"): space.execute(funcname) with ffitest.raises(space, "ArgumentError"): - space.execute("%s(1)" %funcname) + space.execute("%s(1)" % funcname) with ffitest.raises(space, "ArgumentError"): - space.execute("%s(1, 2, 3)" %funcname) + space.execute("%s(1, 2, 3)" % funcname) + class TestDataConverter__to_native(BaseFFITest): def test_it_takes_two_arguments_and_returns_the_first_one(self, space): - check_it_takes_two_args_and_returns_the_first(self, space, - "DataConverterImplementation.new.impl_to_native") + check_it_takes_two_args_and_returns_the_first( + self, space, "DataConverterImplementation.new.impl_to_native") + class TestDataConverter__from_native(BaseFFITest): def test_it_returns_nil_for_now(self, space): - check_it_takes_two_args_and_returns_the_first(self, space, - "DataConverterImplementation.new.impl_from_native") + check_it_takes_two_args_and_returns_the_first( + self, space, "DataConverterImplementation.new.impl_from_native") diff --git a/tests/modules/ffi/test_dynamic_library.py b/tests/modules/ffi/test_dynamic_library.py index 6ca847acc..65fd62052 100644 --- a/tests/modules/ffi/test_dynamic_library.py +++ b/tests/modules/ffi/test_dynamic_library.py @@ -11,13 +11,15 @@ else: libm = 'libm.so' + class TestDynamicLibrary(BaseFFITest): def test_consts(self, space): - consts = {'LAZY':1 , 'NOW':2, 'GLOBAL':257, 'LOCAL':0} + consts = {'LAZY': 1, 'NOW': 2, 'GLOBAL': 257, 'LOCAL': 0} for name in consts: w_res = space.execute('FFI::DynamicLibrary::RTLD_%s' % name) space.int_w(w_res) == consts[name] + class TestDynamicLibrary__new(BaseFFITest): def test_it_opens_a_dynamic_library(self, space): w_res = space.execute("FFI::DynamicLibrary.new('%s', 1)" % libm) @@ -37,14 +39,17 @@ def test_it_accepts_nil_as_library_name(self, space): assert self.unwrap(space, w_name) == '[current process]' def test_it_does_not_accept_anything_else_as_lib_name(self, space): - with self.raises(space, "TypeError", "can't convert Float into String"): + with self.raises( + space, "TypeError", "can't convert Float into String"): space.execute("FFI::DynamicLibrary.new(3.142, 1)") def test_it_only_accepts_an_integer_as_flag_parameter(self, space): # The next error message is different from the one in ruby 1.9.3. # But the meaning is the same. - with self.raises(space, "TypeError", "can't convert String into Integer"): - space.execute("FFI::DynamicLibrary.new('something', 'invalid flag')") + with self.raises( + space, "TypeError", "can't convert String into Integer"): + space.execute( + "FFI::DynamicLibrary.new('something', 'invalid flag')") def test_it_raises_a_LoadError_if_it_can_not_find_the_library(self, space): with self.raises(space, "LoadError", @@ -55,12 +60,14 @@ def test_it_also_known_as_open(self, space): assert self.ask(space, "FFI::DynamicLibrary.method(:new) ==" "FFI::DynamicLibrary.method(:open)") + class TestDynamicLibrary__Symbol(BaseFFITest): def test_its_a_wrapper_around_a_function_symbol(self, space): - exp_ptr = clibffi.CDLL( libm).getaddressindll('exp') + exp_ptr = clibffi.CDLL(libm).getaddressindll('exp') w_dl_sym = W_DL_SymbolObject(space, exp_ptr) assert w_dl_sym.ptr == exp_ptr + class TestDynamicLibrary_find_variable(BaseFFITest): def test_it_returns_a_DynamicLibrary__Symbol(self, space): w_dl_sym = space.execute("FFI::DynamicLibrary::Symbol") diff --git a/tests/modules/ffi/test_ffi.py b/tests/modules/ffi/test_ffi.py index 5e4009aa4..00f994fa2 100644 --- a/tests/modules/ffi/test_ffi.py +++ b/tests/modules/ffi/test_ffi.py @@ -5,14 +5,18 @@ # Most of the stuff is still very vague. # This is because lots of the constants had to be set to something in order to # run some specs but the specs weren't about them. + + class TestTypeDefs(BaseFFITest): def test_it_is_kind_of_a_Hash(self, space): assert self.ask(space, 'FFI::TypeDefs.kind_of? Hash') + class TestTypes(BaseFFITest): def test_it_is_kind_of_a_Hash(self, space): assert self.ask(space, 'FFI::Types.kind_of? Hash') + class TestPlatform(BaseFFITest): def test_it_is_a_Module(self, space): assert self.ask(space, "FFI::Platform.is_a? Module") @@ -35,6 +39,7 @@ def test_it_offers_some_SIZE_constants(self, space): w_res = space.execute('FFI::Platform::ADDRESS_SIZE') assert space.int_w(w_res) == rffi.sizeof(rffi.VOIDP) + class TestStructLayout(BaseFFITest): def test_it_is_a_class(self, space): assert self.ask(space, "FFI::StructLayout.is_a? Class") @@ -42,11 +47,13 @@ def test_it_is_a_class(self, space): def test_has_a_Field_constant(self, space): assert self.ask(space, "defined? FFI::StructLayout::Field") + class TestStructByReference(BaseFFITest): def test_it_is_a_class(self, space): assert self.ask(space, "FFI::StructByReference.is_a? Class") + class TestNullPointerError(BaseFFITest): def test_it_inherits_from_Exception(self, space): - assert self.ask(space, - "FFI::NullPointerError.ancestors.include? Exception") + assert self.ask( + space, "FFI::NullPointerError.ancestors.include? Exception") diff --git a/tests/modules/ffi/test_function.py b/tests/modules/ffi/test_function.py index c6816456f..7b04431de 100644 --- a/tests/modules/ffi/test_function.py +++ b/tests/modules/ffi/test_function.py @@ -19,6 +19,7 @@ for tn in type_names + flat_aliases: substitutions[tn.lower()] = code_ffi_type + tn + def typeformat(rubycode): return (rubycode.replace('\{', 'BRACE_OPEN'). replace('\}', 'BRACE_CLOSE'). @@ -26,23 +27,27 @@ def typeformat(rubycode): replace('BRACE_OPEN', '{'). replace('BRACE_CLOSE', '}')) + class TestFunction(BaseFFITest): def test_it_has_FFI_Pointer_as_ancestor(self, space): assert self.ask(space, "FFI::Function.ancestors.include? FFI::Pointer") + class TestFunction__new(BaseFFITest): def test_it_needs_at_least_a_type_signature(self, space): - space.execute(typeformat("FFI::Function.new({void}, [{int8}, {int16}])")) + space.execute( + typeformat("FFI::Function.new({void}, [{int8}, {int16}])")) def test_it_takes_a_DynamicLibrabry__Symbol_as_3rd_argument(self, space): space.execute(typeformat(""" dlsym = FFI::DynamicLibrary.open('%s').find_function(:sin) FFI::Function.new({void}, [{int8}, {int16}], dlsym) """ % libm)) - with self.raises(space, "TypeError", - "can't convert Fixnum into FFI::DynamicLibrary::Symbol"): + with self.raises( + space, "TypeError", + "can't convert Fixnum into FFI::DynamicLibrary::Symbol"): space.execute(typeformat(""" FFI::Function.new({void}, [{uint8}], 500)""")) @@ -53,7 +58,7 @@ def test_it_takes_a_hash_as_4_argument(self, space): \{\}) """ % libm)) - #def test_it_reacts_to_messy_signature_with_TypeError(self, space): + # def test_it_reacts_to_messy_signature_with_TypeError(self, space): # with self.raises(space, "TypeError", "unable to resolve type '1'"): # space.execute("FFI::Function.new(1, [])") # with self.raises(space, "TypeError", "unable to resolve type '2'"): @@ -73,11 +78,11 @@ def test_it_creates_the_following_low_level_data(self, space): w_float64 = space.execute("FFI::Type::FLOAT64") assert w_function.w_info.arg_types_w == [w_float64] assert w_function.w_info.w_ret_type == w_float64 - tan = clibffi.CDLL(libm).getpointer('tan', - [clibffi.ffi_type_double], - clibffi.ffi_type_double) + tan = clibffi.CDLL(libm).getpointer( + 'tan', [clibffi.ffi_type_double], clibffi.ffi_type_double) assert w_function.ptr == tan.funcsym + class TestFunction_attach(BaseFFITest): def make_mock_library_code(self, libname): @@ -139,9 +144,9 @@ def test_it_works_with_float(self, space, libtest_so): def make_question_code(self, signchar, size, left=1, right=2, with_name=None): - default_T = '%sint%s' %('' if signchar == 's' else 'u', size) + default_T = '%sint%s' % ('' if signchar == 's' else 'u', size) T = default_T if with_name is None else with_name - fn = 'add_%s%s' %(signchar, size) + fn = 'add_%s%s' % (signchar, size) plus_or_minus = '-' if signchar == 's' else '+' return (""" FFI::Function.new({T}, [{T}, {T}], @@ -149,7 +154,7 @@ def make_question_code(self, signchar, size, left=1, right=2, attach(LibraryMock, 'fn') LibraryMock.fn(+|-%s, +|-%s) == +|-%s """.replace('T', T).replace('fn', fn).replace('+|-', plus_or_minus) % - (left, right, left+right)) + (left, right, left + right)) def type_works(self, space, libtest_so, typechar, size, left=1, right=2, with_name=None): @@ -344,7 +349,7 @@ def test_it_can_return_enums(self, ffis, libtest_so): def test_it_raises_ArgumentError_calling_func_with_void_arg(self, space): with self.raises(space, 'ArgumentError', "arguments cannot be of type void"): - w_res = space.execute(typeformat(""" + space.execute(typeformat(""" %s FFI::Function.new({uint32}, [{void}], LibraryMock.find_function(:abs)). diff --git a/tests/modules/ffi/test_function_type.py b/tests/modules/ffi/test_function_type.py index 5d5d0189b..8f43455e2 100644 --- a/tests/modules/ffi/test_function_type.py +++ b/tests/modules/ffi/test_function_type.py @@ -1,7 +1,6 @@ from tests.modules.ffi.base import BaseFFITest from topaz.modules.ffi import type as ffitype -from rpython.rtyper.lltypesystem import rffi, lltype class TestFunctionType(BaseFFITest): def test_it_has_Type_as_a_superclass(self, space): @@ -13,6 +12,7 @@ def test_it_is_also_known_as_FunctionInfo(self, space): def test_it_is_also_known_as_CallbackInfo(self, space): self.ask(space, "FFI::FunctionType.equal? FFI::CallbackInfo") + class TestFunctionType__new(BaseFFITest): def test_it_saves_the_args_and_the_ret_types(self, space): w_function_type = space.execute(""" diff --git a/tests/modules/ffi/test_memory_pointer.py b/tests/modules/ffi/test_memory_pointer.py index 027f1ab94..2867d08f0 100644 --- a/tests/modules/ffi/test_memory_pointer.py +++ b/tests/modules/ffi/test_memory_pointer.py @@ -1,14 +1,15 @@ from tests.modules.ffi.base import BaseFFITest -from rpython.rtyper.lltypesystem import rffi -from rpython.rtyper.lltypesystem.llmemory import (cast_ptr_to_adr as ptr2adr, - cast_adr_to_int as adr2int) +from rpython.rtyper.lltypesystem.llmemory import ( + cast_ptr_to_adr as ptr2adr, cast_adr_to_int as adr2int) + class TestMemoryPointer(BaseFFITest): def test_its_superclass_is_Pointer(self, space): - assert self.ask(space, - "FFI::MemoryPointer.superclass.equal?(FFI::Pointer)") + assert self.ask( + space, "FFI::MemoryPointer.superclass.equal?(FFI::Pointer)") + class TestMemoryPointer__new(BaseFFITest): def test_it_sets_up_a_wrapped_type_object(self, space): diff --git a/tests/modules/ffi/test_pointer.py b/tests/modules/ffi/test_pointer.py index e1767ed61..0bd9f60bf 100644 --- a/tests/modules/ffi/test_pointer.py +++ b/tests/modules/ffi/test_pointer.py @@ -6,6 +6,7 @@ from rpython.rtyper.lltypesystem import rffi, lltype, llmemory from rpython.rtyper.lltypesystem.ll2ctypes import ALLOCATED + class TestPointer__NULL(BaseFFITest): def test_it_is_null(self, space): self.ask(space, "FFI::Pointer::NULL.null?") @@ -21,6 +22,7 @@ def test_it_raises_NullPointerError_on_read_write_methods(self, space): 'read attempt on NULL pointer'): space.execute("FFI::Pointer::NULL.read_something") + class TestPointer__new(BaseFFITest): def test_it_returns_an_object_eq_to_NULL_when_given_0(self, space): assert self.ask(space, "FFI::Pointer.new(0) == FFI::Pointer::NULL") @@ -40,7 +42,7 @@ def test_it_saves_a_pointer_to_whatever_address_was_given(self, space): adr = llmemory.cast_ptr_to_adr(w_ptr_obj.ptr) assert llmemory.cast_adr_to_int(adr, mode='forced') == aint lltype.free(int8_ptr, flavor='raw') - assert not aint in ALLOCATED + assert aint not in ALLOCATED def test_it_also_accepts_negative_values(self, space): for x in range(1, 100): @@ -62,7 +64,8 @@ def test_it_can_also_be_called_with_a_type_size(self, space): adr = llmemory.cast_ptr_to_adr(ptr_obj.ptr) assert llmemory.cast_adr_to_int(adr, mode='forced') == aint lltype.free(int16_ptr, flavor='raw') - assert not aint in ALLOCATED + assert aint not in ALLOCATED + class TestPointer_size(BaseFFITest): def test_it_is_always_2_pow_63(self, space): @@ -70,6 +73,7 @@ def test_it_is_always_2_pow_63(self, space): w_res = space.execute("FFI::Pointer.new(%s).size" % adr) assert self.unwrap(space, w_res) == sys.maxint + class TestPointer_autorelease(BaseFFITest): def test_it(self, space): for question in ["FFI::Pointer.new(0).autorelease=(true)", @@ -86,6 +90,7 @@ def test_it(self, space): """]: assert self.ask(space, question) + class TestPointer_address(BaseFFITest): def test_it_returns_the_address(self, space): w_res = space.execute("FFI::Pointer.new(42).address") @@ -97,6 +102,7 @@ def test_it_is_aliased_by_to_i(self, space): FFI::Pointer::instance_method(:address) """) + class TestPointer_plus(BaseFFITest): def test_it_increases_the_address_by_the_2nd_arg(self, space): w_res = space.execute("(FFI::Pointer.new(3) + 2).address") @@ -108,6 +114,7 @@ def test_it_is_aliased_by_plus(self, space): FFI::Pointer.instance_method(:+) """) + class TestPointer_slice(BaseFFITest): def test_its_1st_arg_is_the_offset(self, space): w_res = space.execute("FFI::Pointer.new(14).slice(6, 0).address") @@ -125,18 +132,20 @@ def test_it_raises_TypeError_on_nonsense_args(self, space): "can't convert Symbol into Integer"): space.execute("FFI::Pointer.new(0).slice(0, :bar)") + class TestPointer_free(BaseFFITest): def test_it_frees_whatever_the_Pointer_is_referencing(self, space): int16_ptr = lltype.malloc(rffi.CArray(rffi.SHORT), 1, flavor='raw') adr = llmemory.cast_ptr_to_adr(int16_ptr) aint = llmemory.cast_adr_to_int(adr, mode='forced') space.execute("FFI::Pointer.new(%s).free" % aint) - assert not aint in ALLOCATED + assert aint not in ALLOCATED + class TestPointer(BaseFFITest): def test_its_superclass_is_AbstractMemory(self, space): - assert self.ask(space, - "FFI::Pointer.superclass.equal?(FFI::AbstractMemory)") + assert self.ask( + space, "FFI::Pointer.superclass.equal?(FFI::AbstractMemory)") def test_it_has_these_methods(self, space): # but they don't do anything yet... @@ -149,6 +158,7 @@ def test_it_has_these_methods(self, space): with self.raises(space, "TypeError", "42 is not a symbol"): space.execute("FFI::Pointer.new(0).order(42)") + class Test_coerce_address(BaseFFITest): def test_it_accepts_ruby_Fixnum_as_address(self, space): assert coerce_address(space, space.newint(2)) == 2 diff --git a/tests/modules/ffi/test_type.py b/tests/modules/ffi/test_type.py index 01ece2bcb..22c1f1585 100644 --- a/tests/modules/ffi/test_type.py +++ b/tests/modules/ffi/test_type.py @@ -3,12 +3,12 @@ W_TypeObject, VOID) from topaz.modules.ffi import type as ffitype -from rpython.rlib import clibffi from rpython.rtyper.lltypesystem import rffi, lltype # XXX maybe move to rlib/jit_libffi from pypy.module._cffi_backend import misc + class TestType(BaseFFITest): def test_it_is_a_class(self, space): assert self.ask(space, "FFI::Type.is_a? Class") @@ -26,15 +26,17 @@ def test_it_delegates_read_and_write_to_rw_strategy(self, space): # only works in Python unit test because of dynamic typing class RWStrategyMock(object): def read(self, space, data): - return "read with data = %s" %data + return "read with data = %s" % data + def write(self, space, data, w_obj): - return "write with data = %s and w_obj = %s" %(data, w_obj) + return "write with data = %s and w_obj = %s" % (data, w_obj) w_type = W_TypeObject(space) w_type.rw_strategy = RWStrategyMock() assert w_type.read(space, "foo") == "read with data = foo" assert (w_type.write(space, "bar", 5) == "write with data = bar and w_obj = 5") + class TestFFI__TestType(BaseFFITest): def test_it_is_a_Module(self, space): assert self.ask(space, "FFI::NativeType.is_a? Module") @@ -43,7 +45,7 @@ def test_it_contains_some_type_constants(self, space): for t in rw_strategies: typename = type_names[t] assert self.ask(space, "FFI::NativeType::%s.is_a? FFI::Type" - %typename) + % typename) def test_it_has_these_instances_defined_as_constants(self, space): for t in rw_strategies: @@ -62,6 +64,7 @@ def test_its_instances_can_be_accessed_in_different_ways(self, space): assert w_t1 == w_t2 assert w_t2 == w_t3 + class TestFFI__Type_size(BaseFFITest): def test_it_returns_the_size_type(self, space): w_res = space.execute("FFI::Type::INT8.size") @@ -71,6 +74,7 @@ def test_it_returns_the_size_type(self, space): w_res = space.execute("FFI::Type::INT32.size") assert self.unwrap(space, w_res) == 4 + class TestFFI__Type_eq(BaseFFITest): def test_it_compares_the_names(self, space): type1 = W_TypeObject(space, VOID) @@ -78,6 +82,7 @@ def test_it_compares_the_names(self, space): w_assertion = space.send(type1, '==', [type2]) assert self.unwrap(space, w_assertion) + class Test_StringRWStrategy(BaseFFITest): def test_it_reads_a_string_from_buffer(self, space): w_string_type = ffitype.StringRWStrategy() @@ -101,6 +106,7 @@ def test_it_writes_a_string_to_buffer(self, space): assert rffi.charp2str(raw_res) == "test" lltype.free(data, flavor='raw') + class Test_PointerRWStrategy(BaseFFITest): def test_it_reads_a_pointer_from_buffer(self, space): w_pointer_type = ffitype.PointerRWStrategy() @@ -124,6 +130,7 @@ def test_it_writes_a_pointer_to_buffer(self, space): assert raw_res == 15 lltype.free(data, flavor='raw') + class Test_BoolRWStrategy(BaseFFITest): def test_it_reads_a_bool_from_buffer(self, space): w_bool_type = ffitype.BoolRWStrategy() @@ -144,6 +151,7 @@ def test_it_writes_a_bool_to_buffer(self, space): assert bool(raw_res) lltype.free(data, flavor='raw') + class Test_FloatRWStrategy(BaseFFITest): def test_it_reads_a_float32_to_buffer(self, space): w_float32_type = ffitype.FloatRWStrategy(ffitype.FLOAT32) @@ -179,6 +187,7 @@ def test_it_writes_a_float64_to_buffer(self, space): assert raw_res == 1e-12 lltype.free(data, flavor='raw') + class Test_SignedRWStrategy(BaseFFITest): def test_it_reads_signed_types_to_buffer(self, space): for t in [ffitype.INT8, @@ -211,6 +220,7 @@ def test_it_writes_signed_types_to_buffer(self, space): assert raw_res == -18 lltype.free(data, flavor='raw') + class Test_UnsignedRWStrategy(BaseFFITest): def test_it_reads_unsigned_types_to_buffer(self, space): for t in [ffitype.UINT8, @@ -243,12 +253,13 @@ def test_it_writes_unsigned_types_to_buffer(self, space): assert raw_res == 16 lltype.free(data, flavor='raw') + class Test_VoidRWStrategy(BaseFFITest): def test_it_reads_nothing_and_returns_nil(self, space): data = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw') w_void_type = ffitype.VoidRWStrategy() w_res = w_void_type.read(space, data) - assert self.unwrap(space, w_res) == None + assert self.unwrap(space, w_res) is None lltype.free(data, flavor='raw') def test_it_writes_nothing_and_returns_None(self, space): @@ -260,10 +271,12 @@ def test_it_writes_nothing_and_returns_None(self, space): assert res is None lltype.free(data, flavor='raw') + class TestFFI__Type__MappedObject(BaseFFITest): def test_its_superclass_is_Type(self, space): assert self.ask(space, "FFI::Type::Mapped.superclass.equal? FFI::Type") + class TestFFI__Type__MappedObject__new(BaseFFITest): def test_it_takes_a_data_converter_as_argument(self, space): with self.raises(space, "NoMethodError", @@ -319,6 +332,7 @@ def from_native; nil; end FFI::Type::Mapped.new(DataConverter.new) """) + class TestFFI__Type__MappedObject_to_native(BaseFFITest): def test_it_delegates_to_the_data_converter(self, space): w_res = space.execute(""" @@ -332,6 +346,7 @@ def from_native; nil; end """) assert self.unwrap(space, w_res) == 'success' + class TestFFI__Type__MappedObject_from_native(BaseFFITest): def test_it_delegates_from_the_data_converter(self, space): w_res = space.execute(""" @@ -345,12 +360,14 @@ def from_native; :success; end """) assert self.unwrap(space, w_res) == 'success' + class TestFFI__Type_MappedObject(BaseFFITest): def test_it_converts_after_reading_and_writing(self, space): class RWStrategyMock(object): def read(self, space, data): return space.newsymbol(data) + def write(self, space, data, w_obj): return data.append(space.str_w(w_obj)) w_mapped = space.execute(""" @@ -366,4 +383,3 @@ def from_native(sym, _); sym.upcase; end data = [] w_mapped.write(space, data, space.newsymbol("BAR")) assert data == ["bar"] - diff --git a/tests/modules/ffi/test_variadic_invoker.py b/tests/modules/ffi/test_variadic_invoker.py index 1d1f4522a..1e7d774dd 100644 --- a/tests/modules/ffi/test_variadic_invoker.py +++ b/tests/modules/ffi/test_variadic_invoker.py @@ -6,6 +6,7 @@ else: libc = 'libc.so.6' + class TestVariadicInvoker(BaseFFITest): def test_it_is_not_a_function(self, space): assert self.ask(space, "! FFI::VariadicInvoker.kind_of? FFI::Function") @@ -34,7 +35,7 @@ def test_it_still_can_be_used_like_a_function(self, ffis): FFI::Type::FLOAT64, 2.0) chars = 0.upto(5).map { |x| result.get_int8(x).chr } chars.inject('') { |str, c| str << c } - """ % {'libname':libc}) + """ % {'libname': libc}) assert self.unwrap(ffis, w_res) == "1, 2.0" w_res = ffis.execute(""" result = FFI::MemoryPointer.new(:int8, 14) @@ -63,5 +64,5 @@ def test_it_also_is_able_to_use_typedefs(self, ffis): :name, "bill", :name, "johanna") chars = 0.upto(24).map { |x| result.get_int8(x).chr } chars.inject('') { |str, c| str << c } - """ % {'libname':libc}) + """ % {'libname': libc}) assert self.unwrap(ffis, w_res) == "bill is father of johanna" diff --git a/tests/modules/test_marshal.py b/tests/modules/test_marshal.py index bbedd5d88..f0bfe1648 100644 --- a/tests/modules/test_marshal.py +++ b/tests/modules/test_marshal.py @@ -71,7 +71,7 @@ def test_load_tiny_integer(self, space): w_res = space.execute("return Marshal.load('\x04\bii')") assert space.int_w(w_res) == 100 - #w_res = space.execute('return Marshal.load("\x04\bi\x00")') + # w_res = space.execute('return Marshal.load("\x04\bi\x00")') w_res = space.execute('return Marshal.load(Marshal.dump(0))') assert space.int_w(w_res) == 0 @@ -104,7 +104,7 @@ def test_dump_array(self, space): assert space.str_w(w_res) == "\x04\b[\a:\bfoo:\bbar" def test_load_array(self, space): - #w_res = space.execute("return Marshal.load('\x04\b[\x00')") + # w_res = space.execute("return Marshal.load('\x04\b[\x00')") w_res = space.execute("return Marshal.load(Marshal.dump([]))") assert self.unwrap(space, w_res) == [] @@ -154,7 +154,7 @@ def test_dump_hash(self, space): assert self.unwrap(space, w_res) == "\x04\b{\ai\x02\xD2\x04{\x06i\x02\xA0[i\x03\x15\xBF4i\ti\n" def test_load_hash(self, space): - #w_res = space.execute("return Marshal.load('\x04\b{\x00')") + # w_res = space.execute("return Marshal.load('\x04\b{\x00')") w_res = space.execute("return Marshal.load(Marshal.dump({}))") assert self.unwrap(space, w_res) == {} @@ -201,7 +201,7 @@ def test_load_integer(self, space): w_res = space.execute("return Marshal.load('\x04\bi\x01\xFF')") assert space.int_w(w_res) == 255 - #w_res = space.execute("return Marshal.load('\x04\bi\x02\x00\x01')") + # w_res = space.execute("return Marshal.load('\x04\bi\x02\x00\x01')") w_res = space.execute("return Marshal.load(Marshal.dump(256))") assert space.int_w(w_res) == 256 @@ -211,11 +211,11 @@ def test_load_integer(self, space): w_res = space.execute("return Marshal.load('\x04\bi\x02\xFF\xFF')") assert space.int_w(w_res) == 2 ** 16 - 1 - #w_res = space.execute("return Marshal.load('\x04\bi\x03\x00\x00\x01')") + # w_res = space.execute("return Marshal.load('\x04\bi\x03\x00\x00\x01')") w_res = space.execute("return Marshal.load(Marshal.dump(2 ** 16))") assert space.int_w(w_res) == 2 ** 16 - #w_res = space.execute("return Marshal.load('\x04\bi\x03\x01\x00\x01')") + # w_res = space.execute("return Marshal.load('\x04\bi\x03\x01\x00\x01')") w_res = space.execute("return Marshal.load(Marshal.dump(2 ** 16 + 1))") assert space.int_w(w_res) == 2 ** 16 + 1 @@ -251,28 +251,28 @@ def test_load_negative_integer(self, space): w_res = space.execute("return Marshal.load('\x04\bi\xFF\x84')") assert space.int_w(w_res) == -124 - #w_res = space.execute("return Marshal.load('\x04\bi\xFF\x00')") + # w_res = space.execute("return Marshal.load('\x04\bi\xFF\x00')") w_res = space.execute("return Marshal.load(Marshal.dump(-256))") assert space.int_w(w_res) == -256 w_res = space.execute("return Marshal.load('\x04\bi\xFE\xFF\xFE')") assert space.int_w(w_res) == -257 - #w_res = space.execute("return Marshal.load('\x04\bi\xFE\x00\x00')") + # w_res = space.execute("return Marshal.load('\x04\bi\xFE\x00\x00')") w_res = space.execute("return Marshal.load(Marshal.dump(-(2 ** 16)))") assert space.int_w(w_res) == -(2 ** 16) w_res = space.execute("return Marshal.load('\x04\bi\xFD\xFF\xFF\xFE')") assert space.int_w(w_res) == -(2 ** 16 + 1) - #w_res = space.execute("return Marshal.load('\x04\bi\xFC\x00\x00\x00')") + # w_res = space.execute("return Marshal.load('\x04\bi\xFC\x00\x00\x00')") w_res = space.execute("return Marshal.load(Marshal.dump(-(2 ** 24)))") assert space.int_w(w_res) == -(2 ** 24) w_res = space.execute("return Marshal.load('\x04\bi\xFC\xFF\xFF\xFF\xFE')") assert space.int_w(w_res) == -(2 ** 24 + 1) - #w_res = space.execute("return Marshal.load('\x04\bi\xFC\x00\x00\x00\xC0')") + # w_res = space.execute("return Marshal.load('\x04\bi\xFC\x00\x00\x00\xC0')") w_res = space.execute("return Marshal.load(Marshal.dump(-(2 ** 30)))") assert space.int_w(w_res) == -(2 ** 30) @@ -292,14 +292,14 @@ def test_dump_float(self, space): w_res = space.execute("return Marshal.dump(1.001)") assert space.str_w(w_res) == "\x04\bf\n1.001" - #w_res = space.execute("return Marshal.dump(123456789.123456789)") - #assert space.str_w(w_res) == "\x04\bf\x17123456789.12345679" + # w_res = space.execute("return Marshal.dump(123456789.123456789)") + # assert space.str_w(w_res) == "\x04\bf\x17123456789.12345679" - #w_res = space.execute("return Marshal.dump(-123456789.123456789)") - #assert space.str_w(w_res) == "\x04\bf\x18-123456789.12345679" + # w_res = space.execute("return Marshal.dump(-123456789.123456789)") + # assert space.str_w(w_res) == "\x04\bf\x18-123456789.12345679" - #w_res = space.execute("return Marshal.dump(-0.0)") - #assert space.str_w(w_res) == "\x04\bf\a-0" + # w_res = space.execute("return Marshal.dump(-0.0)") + # assert space.str_w(w_res) == "\x04\bf\a-0" def test_load_float(self, space): w_res = space.execute("return Marshal.load('\x04\bf\x060')") @@ -317,14 +317,14 @@ def test_load_float(self, space): w_res = space.execute("return Marshal.load('\x04\bf\n1.001')") assert space.float_w(w_res) == 1.001 - #w_res = space.execute("return Marshal.load('\x04\bf\x17123456789.12345679')") - #assert space.float_w(w_res) == 123456789.123456789 + # w_res = space.execute("return Marshal.load('\x04\bf\x17123456789.12345679')") + # assert space.float_w(w_res) == 123456789.123456789 - #w_res = space.execute("return Marshal.load('\x04\bf\x18-123456789.12345679')") - #assert space.float_w(w_res) == -123456789.123456789 + # w_res = space.execute("return Marshal.load('\x04\bf\x18-123456789.12345679')") + # assert space.float_w(w_res) == -123456789.123456789 - #w_res = space.execute("return Marshal.load('\x04\bf\a-0')") - #assert repr(space.float_w(w_res)) == repr(-0.0) + # w_res = space.execute("return Marshal.load('\x04\bf\a-0')") + # assert repr(space.float_w(w_res)) == repr(-0.0) def test_dump_string(self, space): w_res = space.execute("return Marshal.dump('')") @@ -337,7 +337,7 @@ def test_dump_string(self, space): assert space.str_w(w_res) == "\x04\bI\"\x19i am a longer string\x06:\x06ET" def test_load_string(self, space): - #w_res = space.execute("return Marshal.load('\x04\bI\"\x00\x06:\x06ET')") + # w_res = space.execute("return Marshal.load('\x04\bI\"\x00\x06:\x06ET')") w_res = space.execute("return Marshal.load(Marshal.dump(''))") assert space.str_w(w_res) == "" diff --git a/tests/modules/test_math.py b/tests/modules/test_math.py index 9147ef944..7b8ecd48f 100644 --- a/tests/modules/test_math.py +++ b/tests/modules/test_math.py @@ -1,7 +1,5 @@ import math -from rpython.rlib import rfloat - from ..base import BaseTopazTest @@ -228,9 +226,9 @@ def test_type_error(self, space): 'exp', 'frexp', 'log', 'log10', 'log2']: with self.raises(space, "TypeError", "can't convert String into Float"): - space.execute("Math.%s('1.0')" %methodname) + space.execute("Math.%s('1.0')" % methodname) for methodname in ['hypot', 'atan2']: with self.raises(space, "TypeError", "can't convert String into Float"): - space.execute("Math.%s('1', 2)" %methodname) - space.execute("Math.%s(1, '2')" %methodname) + space.execute("Math.%s('1', 2)" % methodname) + space.execute("Math.%s(1, '2')" % methodname) diff --git a/topaz/lexer.py b/topaz/lexer.py index 8be164e14..eb5a08436 100644 --- a/topaz/lexer.py +++ b/topaz/lexer.py @@ -1159,7 +1159,7 @@ def right_paren(self, ch): def left_bracket(self, ch, space_seen): self.paren_nest += 1 - if self.state in [self.EXPR_FNAME, self.EXPR_DOT]: # IS_AFTER_OPERATOR + if self.state in [self.EXPR_FNAME, self.EXPR_DOT]: # IS_AFTER_OPERATOR self.state = self.EXPR_ARG ch2 = self.read() diff --git a/topaz/modules/fcntl.py b/topaz/modules/fcntl.py index a8d61cb78..f6471962d 100644 --- a/topaz/modules/fcntl.py +++ b/topaz/modules/fcntl.py @@ -1,8 +1,6 @@ from __future__ import absolute_import -import os - -from rpython.rlib import jit, rbigint, unroll, rgc, _rsocket_rffi +from rpython.rlib import _rsocket_rffi from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.rtyper.tool import rffi_platform @@ -23,6 +21,7 @@ class CConstants(object): fcntl = _rsocket_rffi.fcntl else: fcntl_constants = {} + def fcntl(fdtype, cmd, arg): raise NotImplementedError diff --git a/topaz/modules/ffi/__init__.py b/topaz/modules/ffi/__init__.py index a4f40cdfd..708077288 100644 --- a/topaz/modules/ffi/__init__.py +++ b/topaz/modules/ffi/__init__.py @@ -1 +1,3 @@ from ffi import FFI + +__all__ = ['FFI'] diff --git a/topaz/modules/ffi/_callback.py b/topaz/modules/ffi/_callback.py index bba549068..7a8a653a4 100644 --- a/topaz/modules/ffi/_callback.py +++ b/topaz/modules/ffi/_callback.py @@ -1,4 +1,3 @@ -from topaz.modules.ffi import type as ffitype from topaz.modules.ffi.type import W_BuiltinType from rpython.rtyper.lltypesystem import rffi, lltype @@ -10,6 +9,7 @@ # This will definitely leak memory registration = {} + class Data(object): def __init__(self, space, w_proc, w_callback_info): self.space = space @@ -24,7 +24,7 @@ def invoke(self, ll_args, ll_res): def _read_args(self, space, ll_adrs): length = len(self.w_callback_info.arg_types_w) - args_w = [None]*length + args_w = [None] * length for i in range(length): w_arg_type = self.w_callback_info.arg_types_w[i] ll_adr = rffi.cast(rffi.CCHARP, ll_adrs[i]) @@ -39,6 +39,7 @@ def _write_res(self, space, w_obj, ll_adr): assert isinstance(w_ret_type, W_BuiltinType) w_ret_type.rw_strategy.write(space, ll_adr, w_obj) + class Closure(object): def __init__(self, callback_data): self.heap = clibffi.closureHeap.alloc() @@ -58,13 +59,15 @@ def __init__(self, callback_data): "libffi failed to build this callback type") def write(self, data): - misc.write_raw_unsigned_data(data, rffi.cast(rffi.CCHARP, self.heap), - rffi.sizeof(clibffi.FFI_CLOSUREP)) + misc.write_raw_unsigned_data( + data, rffi.cast(rffi.CCHARP, self.heap), + rffi.sizeof(clibffi.FFI_CLOSUREP)) def __del__(self): if self.heap: clibffi.closureHeap.free(self.heap) + @jit.jit_callback("block_callback") def invoke(ll_cif, ll_res, ll_args, ll_data): key = rffi.cast(lltype.Signed, ll_data) diff --git a/topaz/modules/ffi/abstract_memory.py b/topaz/modules/ffi/abstract_memory.py index 5976985d6..a137fbb67 100644 --- a/topaz/modules/ffi/abstract_memory.py +++ b/topaz/modules/ffi/abstract_memory.py @@ -1,53 +1,59 @@ from topaz.objects.objectobject import W_Object from topaz.module import ClassDef -from topaz.modules.ffi.type import lltype_for_name, lltypes, UINT64, lltype_sizes from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.rlib.rarithmetic import intmask, r_longlong, r_ulonglong -from rpython.rlib.rbigint import rbigint from topaz.modules.ffi import type as ffitype -import sys def new_put_method(typeindex): rw_strategy = ffitype.rw_strategies[typeindex] sizeof_type = ffitype.lltype_sizes[typeindex] + def put_method(self, space, offset, w_value): offset_ptr = rffi.ptradd(rffi.cast(rffi.CCHARP, self.ptr), offset) raise_if_out_of_bounds(space, offset, self.sizeof_memory, sizeof_type) rw_strategy.write(space, offset_ptr, w_value) return put_method + def new_get_method(typeindex): rw_strategy = ffitype.rw_strategies[typeindex] sizeof_type = ffitype.lltype_sizes[typeindex] + def get_method(self, space, offset): offset_ptr = rffi.ptradd(rffi.cast(rffi.CCHARP, self.ptr), offset) raise_if_out_of_bounds(space, offset, self.sizeof_memory, sizeof_type) return rw_strategy.read(space, offset_ptr) return get_method + def new_write_method(type_str): put_method_name = 'put_' + type_str + def write_method(self, space, w_value): space.send(self, put_method_name, [space.newint(0), w_value]) return write_method + def new_read_method(type_str): get_method_name = 'get_' + type_str + def read_method(self, space): return space.send(self, get_method_name, [space.newint(0)]) return read_method + def raise_if_out_of_bounds(space, offset, size, sizeof_type): if offset < 0 or offset >= size: raise memory_index_error(space, offset, sizeof_type) + def memory_index_error(space, offset, size): return space.error(space.w_IndexError, "Memory access offset=%s size=%s is out of bounds" % (offset, size)) + class W_AbstractMemoryObject(W_Object): classdef = ClassDef('FFI::AbstractMemory', W_Object.classdef) ptr = lltype.nullptr(rffi.VOIDP.TO) @@ -61,19 +67,18 @@ def singleton_method_allocate(self, space): def setup_class(cls, space, w_cls): long_in_bits = 8 * rffi.sizeof(rffi.LONG) for orig, alias in [ - ('int8', 'char'), - ('uint8', 'uchar'), - ('int16', 'short'), - ('uint16', 'ushort'), - ('int32', 'int'), - ('uint32', 'uint'), - ('int64', 'long_long'), - ('uint64', 'ulong_long'), - ('float32', 'float'), - ('float64', 'double'), - ('int' + str(long_in_bits), 'long'), - ('uint' + str(long_in_bits), 'ulong') - ]: + ('int8', 'char'), + ('uint8', 'uchar'), + ('int16', 'short'), + ('uint16', 'ushort'), + ('int32', 'int'), + ('uint32', 'uint'), + ('int64', 'long_long'), + ('uint64', 'ulong_long'), + ('float32', 'float'), + ('float64', 'double'), + ('int' + str(long_in_bits), 'long'), + ('uint' + str(long_in_bits), 'ulong')]: for prefix in ['put_', 'get_', 'write_', 'read_']: space.send(w_cls, 'alias_method', [space.newsymbol(prefix + alias), @@ -87,13 +92,13 @@ def setup_class(cls, space, w_cls): tn = ffitype.type_names[t].lower() setattr(W_AMO, 'method_put_' + tn, W_AMO.classdef.method('put_' + tn, offset='int')( - new_put_method(t))) + new_put_method(t))) setattr(W_AMO, 'method_get_' + tn, W_AMO.classdef.method('get_' + tn, offset='int')( - new_get_method(t))) + new_get_method(t))) setattr(W_AMO, 'method_write_' + tn, W_AMO.classdef.method('write_' + tn)( - new_write_method(tn))) + new_write_method(tn))) setattr(W_AMO, 'method_read_' + tn, W_AMO.classdef.method('read_' + tn)( - new_read_method(tn))) + new_read_method(tn))) diff --git a/topaz/modules/ffi/data_converter.py b/topaz/modules/ffi/data_converter.py index 9998bb153..490cb0b81 100644 --- a/topaz/modules/ffi/data_converter.py +++ b/topaz/modules/ffi/data_converter.py @@ -1,13 +1,15 @@ from topaz.module import ModuleDef from topaz.modules.ffi.type import type_object -# A rather abstract base class + class DataConverter(object): + # A rather abstract base class + moduledef = ModuleDef('FFI::DataConverter') @moduledef.method('native_type') def native_type(self, space, args_w): - #if len(args_w) == 0: + # if len(args_w) == 0: # raise space.error(space.w_NotImplementedError, # "native_type method not overridden and no " # "native_type set") diff --git a/topaz/modules/ffi/dynamic_library.py b/topaz/modules/ffi/dynamic_library.py index 485af2fbf..a5768cb11 100644 --- a/topaz/modules/ffi/dynamic_library.py +++ b/topaz/modules/ffi/dynamic_library.py @@ -4,7 +4,7 @@ from topaz.coerce import Coerce from rpython.rlib import clibffi -from rpython.rtyper.lltypesystem import rffi + class W_DynamicLibraryObject(W_Object): classdef = ClassDef('DynamicLibrary', W_Object.classdef) @@ -26,7 +26,8 @@ def __init__(self, space, name, flags, klass=None): W_Object.__init__(self, space, klass) namestr = '[current process]' if name is None else name # on my os it's libc.so.6, not just libc.so - if name == 'libc.so': name = 'libc.so.6' + if name == 'libc.so': + name = 'libc.so.6' try: self.cdll = clibffi.CDLL(name, flags) except clibffi.DLOpenError: @@ -50,16 +51,19 @@ def singleton_method_new(self, space, w_name, flags=0): @classdef.method('find_variable', name='symbol') def method_find_variable(self, space, name): funcsym = self.cdll.getaddressindll(name) - w_sym = space.find_const(space.getclass(self), 'Symbol') + # w_sym = space.find_const(space.getclass(self), 'Symbol') return W_DL_SymbolObject(space, funcsym) + def coerce_dl_symbol(space, w_name): if isinstance(w_name, W_DL_SymbolObject): return w_name.ptr else: - raise space.error(space.w_TypeError, - "can't convert %s into FFI::DynamicLibrary::Symbol" - % w_name.getclass(space).name) + raise space.error( + space.w_TypeError, + ("can't convert %s into FFI::DynamicLibrary::Symbol" + % w_name.getclass(space).name)) + class W_DL_SymbolObject(W_PointerObject): classdef = ClassDef('Symbol', W_PointerObject.classdef) @@ -71,6 +75,6 @@ def __init__(self, space, funcsym, klass=None): # TODO: new method should be private! # or: should take an int and try to make a voidptr out of it. - #@classdef.singleton_method('allocate') - #def singleton_method_allocate(self, space, args_w): - # return W_DL_SymbolObject(space) + # @classdef.singleton_method('allocate') + # def singleton_method_allocate(self, space, args_w): + # return W_DL_SymbolObject(space) diff --git a/topaz/modules/ffi/ffi.py b/topaz/modules/ffi/ffi.py index 066002540..9d9f99ccc 100644 --- a/topaz/modules/ffi/ffi.py +++ b/topaz/modules/ffi/ffi.py @@ -1,9 +1,7 @@ from __future__ import absolute_import from topaz.error import RubyError -from topaz.module import ModuleDef, ClassDef -from topaz.objects.objectobject import W_Object -from topaz.objects.exceptionobject import W_StandardError, new_exception_allocate +from topaz.module import ModuleDef from topaz.modules.ffi.type import (POINTER, lltype_sizes, W_TypeObject, type_names, W_BuiltinType) from topaz.modules.ffi.function import W_FFIFunctionObject @@ -15,10 +13,9 @@ from topaz.modules.ffi.memory_pointer import W_MemoryPointerObject from topaz.modules.ffi.data_converter import DataConverter -from rpython.rtyper.lltypesystem import rffi - import platform + class FFI(object): moduledef = ModuleDef("FFI") @@ -56,7 +53,8 @@ def setup_module(space, w_mod): space.set_const(w_mod, 'TYPE_' + typename, w_ffi_type) # setup NativeType space.set_const(w_native_type, typename, w_ffi_type) - except RubyError: pass + except RubyError: + pass space.set_const(w_mod, 'NativeType', w_native_type) # setup Platform diff --git a/topaz/modules/ffi/function.py b/topaz/modules/ffi/function.py index af0e056d6..a0c06c9d1 100644 --- a/topaz/modules/ffi/function.py +++ b/topaz/modules/ffi/function.py @@ -1,5 +1,3 @@ -import sys - from topaz.module import ClassDef from topaz.modules.ffi import type as ffitype from topaz.modules.ffi.pointer import W_PointerObject @@ -8,13 +6,11 @@ from topaz.objects.moduleobject import W_FunctionObject from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.rlib import jit -from rpython.rlib.jit_libffi import CIF_DESCRIPTION -from rpython.rlib.jit_libffi import FFI_TYPE_PP for i, name in enumerate(ffitype.type_names): globals()[name] = i + class W_FFIFunctionObject(W_PointerObject): classdef = ClassDef('FFI::Function', W_PointerObject.classdef) _immutable_fields_ = ['ptr'] @@ -46,6 +42,7 @@ def method_call(self, space, args_w, block=None): def method_attach(self, space, w_lib, name): w_lib.attach_method(space, name, W_MethodAdapter(name, self)) + class W_MethodAdapter(W_FunctionObject): _immutable_fields_ = ['name', 'w_ffi_func'] diff --git a/topaz/modules/ffi/function_type.py b/topaz/modules/ffi/function_type.py index 7092d7d6c..4060c4092 100644 --- a/topaz/modules/ffi/function_type.py +++ b/topaz/modules/ffi/function_type.py @@ -1,5 +1,5 @@ import sys -from topaz.modules.ffi.type import W_TypeObject, W_MappedObject +from topaz.modules.ffi.type import W_TypeObject from topaz.modules.ffi import type as ffitype from topaz.modules.ffi import _callback from topaz.module import ClassDef @@ -14,12 +14,14 @@ BIG_ENDIAN = sys.byteorder == 'big' + def raise_TypeError_if_not_TypeObject(space, w_candidate): if not isinstance(w_candidate, W_TypeObject): raise space.error(space.w_TypeError, "Invalid parameter type (%s)" % space.str_w(space.send(w_candidate, 'inspect'))) + class W_FunctionTypeObject(W_TypeObject): classdef = ClassDef('FFI::FunctionType', W_TypeObject.classdef) _immutable_fields_ = ['arg_types_w', 'w_ret_type', 'cif_descr'] @@ -37,7 +39,8 @@ def singleton_method_allocate(self, space, args_w): return W_FunctionTypeObject(space) @classdef.method('initialize', arg_types_w='array') - def method_initialize(self, space, w_ret_type, arg_types_w, w_options=None): + def method_initialize(self, space, w_ret_type, arg_types_w, + w_options=None): if w_options is None: w_options = space.newhash() self.w_options = w_options @@ -66,7 +69,8 @@ def build_cif_descr(self, space): nargs = len(ffi_arg_types) # XXX combine both mallocs with alignment - size = llmemory.raw_malloc_usage(llmemory.sizeof(CIF_DESCRIPTION, nargs)) + size = llmemory.raw_malloc_usage( + llmemory.sizeof(CIF_DESCRIPTION, nargs)) if we_are_translated(): cif_descr = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw') cif_descr = rffi.cast(CIF_DESCRIPTION_P, cif_descr) @@ -112,8 +116,9 @@ def build_cif_descr(self, space): status = jit_ffi_prep_cif(cif_descr) # if status != clibffi.FFI_OK: - raise space.error(space.w_RuntimeError, - "libffi failed to build this function type") + raise space.error( + space.w_RuntimeError, + "libffi failed to build this function type") # return cif_descr @@ -134,14 +139,14 @@ def invoke(self, space, ptr, args_w, block=None): w_obj = args_w[i] self._put_arg(space, data, i, w_obj) - #ec = cerrno.get_errno_container(space) - #cerrno.restore_errno_from(ec) + # ec = cerrno.get_errno_container(space) + # cerrno.restore_errno_from(ec) jit_ffi_call(self.cif_descr, rffi.cast(rffi.VOIDP, ptr), buffer) - #e = cerrno.get_real_errno() - #cerrno.save_errno_into(ec, e) + # e = cerrno.get_real_errno() + # cerrno.save_errno_into(ec, e) resultdata = rffi.ptradd(buffer, self.cif_descr.exchange_result) - w_res = self._get_result(space, resultdata) + w_res = self._get_result(space, resultdata) finally: lltype.free(buffer, flavor='raw') return w_res diff --git a/topaz/modules/ffi/memory_pointer.py b/topaz/modules/ffi/memory_pointer.py index 2693e1aa9..8a8bfe31c 100644 --- a/topaz/modules/ffi/memory_pointer.py +++ b/topaz/modules/ffi/memory_pointer.py @@ -1,10 +1,10 @@ from topaz.modules.ffi.pointer import W_PointerObject from topaz.module import ClassDef -from topaz.modules.ffi.type import W_TypeObject from rpython.rtyper.lltypesystem import rffi from rpython.rtyper.lltypesystem import lltype + class W_MemoryPointerObject(W_PointerObject): classdef = ClassDef('FFI::MemoryPointer', W_PointerObject.classdef) @@ -31,7 +31,8 @@ def method_initialize(self, space, type_hint, size=1): flavor='raw', zero=True) self.ptr = rffi.cast(rffi.VOIDP, memory) - @classdef.method("put_bytes", start='int', string='str', str_offset='int', nbytes='int') + @classdef.method("put_bytes", start='int', string='str', str_offset='int', + nbytes='int') def method_put_bytes(self, space, start, string, str_offset, nbytes): with rffi.scoped_view_charp(string) as cstring: rffi.c_memcpy( @@ -52,5 +53,5 @@ def method_get_bytes(self, space, start, nbytes): @classdef.method("get_string", start='int') def method_get_string(self, space, start): return space.newstr_fromstr( - rffi.charp2str(rffi.cast(rffi.CCHARP, rffi.ptradd(self.ptr, start))) - ) + rffi.charp2str(rffi.cast( + rffi.CCHARP, rffi.ptradd(self.ptr, start)))) diff --git a/topaz/modules/ffi/misc.py b/topaz/modules/ffi/misc.py index 3b368decb..b6ec8b709 100644 --- a/topaz/modules/ffi/misc.py +++ b/topaz/modules/ffi/misc.py @@ -28,6 +28,7 @@ def read_raw_signed_data(target, size): return rffi.cast(lltype.SignedLongLong, rffi.cast(TPP, target)[0]) raise NotImplementedError("bad integer size") + def read_raw_long_data(target, size): for TP, TPP in _prim_signed_types: if size == rffi.sizeof(TP): @@ -35,12 +36,15 @@ def read_raw_long_data(target, size): return rffi.cast(lltype.Signed, rffi.cast(TPP, target)[0]) raise NotImplementedError("bad integer size") + def read_raw_unsigned_data(target, size): for TP, TPP in _prim_unsigned_types: if size == rffi.sizeof(TP): - return rffi.cast(lltype.UnsignedLongLong, rffi.cast(TPP, target)[0]) + return rffi.cast( + lltype.UnsignedLongLong, rffi.cast(TPP, target)[0]) raise NotImplementedError("bad integer size") + def read_raw_ulong_data(target, size): for TP, TPP in _prim_unsigned_types: if size == rffi.sizeof(TP): @@ -48,20 +52,24 @@ def read_raw_ulong_data(target, size): return rffi.cast(lltype.Unsigned, rffi.cast(TPP, target)[0]) raise NotImplementedError("bad integer size") + @specialize.arg(0) def _read_raw_float_data_tp(TPP, target): # in its own function: FLOAT may make the whole function jit-opaque return rffi.cast(lltype.Float, rffi.cast(TPP, target)[0]) + def read_raw_float_data(target, size): for TP, TPP in _prim_float_types: if size == rffi.sizeof(TP): return _read_raw_float_data_tp(TPP, target) raise NotImplementedError("bad float size") + def read_raw_longdouble_data(target): return rffi.cast(rffi.LONGDOUBLEP, target)[0] + @specialize.argtype(1) def write_raw_unsigned_data(target, source, size): for TP, TPP in _prim_unsigned_types: @@ -70,6 +78,7 @@ def write_raw_unsigned_data(target, source, size): return raise NotImplementedError("bad integer size") + @specialize.argtype(1) def write_raw_signed_data(target, source, size): for TP, TPP in _prim_signed_types: @@ -84,6 +93,7 @@ def _write_raw_float_data_tp(TP, TPP, target, source): # in its own function: FLOAT may make the whole function jit-opaque rffi.cast(TPP, target)[0] = rffi.cast(TP, source) + def write_raw_float_data(target, source, size): for TP, TPP in _prim_float_types: if size == rffi.sizeof(TP): @@ -91,5 +101,6 @@ def write_raw_float_data(target, source, size): return raise NotImplementedError("bad float size") + def write_raw_longdouble_data(target, source): rffi.cast(rffi.LONGDOUBLEP, target)[0] = source diff --git a/topaz/modules/ffi/pointer.py b/topaz/modules/ffi/pointer.py index c6c5d39b5..0bb1bb163 100644 --- a/topaz/modules/ffi/pointer.py +++ b/topaz/modules/ffi/pointer.py @@ -9,6 +9,7 @@ NULLPTR = lltype.nullptr(rffi.VOIDP.TO) + def coerce_pointer(space, w_pointer): if isinstance(w_pointer, W_PointerObject): return w_pointer.ptr @@ -19,6 +20,7 @@ def coerce_pointer(space, w_pointer): setattr(Coerce, 'ffi_pointer', staticmethod(coerce_pointer)) + def coerce_address(space, w_addressable): if space.is_kind_of(w_addressable, space.w_bignum): return Coerce.int(space, w_addressable) @@ -35,6 +37,7 @@ def coerce_address(space, w_addressable): setattr(Coerce, 'ffi_address', staticmethod(coerce_address)) + class W_PointerObject(W_AbstractMemoryObject): classdef = ClassDef('FFI::Pointer', W_AbstractMemoryObject.classdef) diff --git a/topaz/modules/ffi/type.py b/topaz/modules/ffi/type.py index c81917737..54d7573e3 100644 --- a/topaz/modules/ffi/type.py +++ b/topaz/modules/ffi/type.py @@ -1,46 +1,44 @@ from topaz.objects.objectobject import W_Object from topaz.module import ClassDef -from topaz.error import RubyError from rpython.rlib.jit_libffi import FFI_TYPE_P from rpython.rlib import clibffi -from rpython.rlib.rbigint import rbigint from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib.rarithmetic import intmask from topaz.coerce import Coerce from topaz.modules.ffi import misc - _native_types = [ - ('VOID', clibffi.ffi_type_void, lltype.Void, []), - ('INT8', clibffi.ffi_type_sint8, rffi.CHAR, ['CHAR', 'SCHAR']), - ('UINT8', clibffi.ffi_type_uint8, rffi.UCHAR, ['UCHAR']), - ('INT16', clibffi.ffi_type_sint16, rffi.SHORT, ['SHORT', 'SSHORT']), - ('UINT16', clibffi.ffi_type_uint16, rffi.USHORT, ['USHORT']), - ('INT32', clibffi.ffi_type_sint32, rffi.INT, ['INT', 'SINT']), - ('UINT32', clibffi.ffi_type_uint32, rffi.UINT, ['UINT']), - ('INT64', clibffi.ffi_type_sint64, rffi.LONGLONG, ['LONG_LONG', 'SLONG_LONG']), - ('UINT64', clibffi.ffi_type_uint64, rffi.ULONGLONG, ['ULONG_LONG']), - ('LONG', clibffi.cast_type_to_ffitype(rffi.LONG), rffi.LONG, ['SLONG']), - ('ULONG', clibffi.cast_type_to_ffitype(rffi.ULONG), rffi.ULONG, []), - ('FLOAT32', clibffi.ffi_type_float, rffi.FLOAT, ['FLOAT']), - ('FLOAT64', clibffi.ffi_type_double, rffi.DOUBLE, ['DOUBLE']), - ('LONGDOUBLE', clibffi.ffi_type_longdouble, rffi.LONGDOUBLE, []), - ('POINTER', clibffi.ffi_type_pointer, rffi.VOIDP, []), - ('CALLBACK', clibffi.ffi_type_pointer, rffi.VOIDP, []), - ('FUNCTION', clibffi.ffi_type_pointer, rffi.VOIDP, []), + ('VOID', clibffi.ffi_type_void, lltype.Void, []), + ('INT8', clibffi.ffi_type_sint8, rffi.CHAR, ['CHAR', 'SCHAR']), + ('UINT8', clibffi.ffi_type_uint8, rffi.UCHAR, ['UCHAR']), + ('INT16', clibffi.ffi_type_sint16, rffi.SHORT, ['SHORT', 'SSHORT']), + ('UINT16', clibffi.ffi_type_uint16, rffi.USHORT, ['USHORT']), + ('INT32', clibffi.ffi_type_sint32, rffi.INT, ['INT', 'SINT']), + ('UINT32', clibffi.ffi_type_uint32, rffi.UINT, ['UINT']), + ('INT64', clibffi.ffi_type_sint64, rffi.LONGLONG, + ['LONG_LONG', 'SLONG_LONG']), + ('UINT64', clibffi.ffi_type_uint64, rffi.ULONGLONG, ['ULONG_LONG']), + ('LONG', clibffi.cast_type_to_ffitype(rffi.LONG), rffi.LONG, ['SLONG']), + ('ULONG', clibffi.cast_type_to_ffitype(rffi.ULONG), rffi.ULONG, []), + ('FLOAT32', clibffi.ffi_type_float, rffi.FLOAT, ['FLOAT']), + ('FLOAT64', clibffi.ffi_type_double, rffi.DOUBLE, ['DOUBLE']), + ('LONGDOUBLE', clibffi.ffi_type_longdouble, rffi.LONGDOUBLE, []), + ('POINTER', clibffi.ffi_type_pointer, rffi.VOIDP, []), + ('CALLBACK', clibffi.ffi_type_pointer, rffi.VOIDP, []), + ('FUNCTION', clibffi.ffi_type_pointer, rffi.VOIDP, []), ('BUFFER_IN',), ('BUFFER_OUT',), ('BUFFER_INOUT',), ('CHAR_ARRAY',), - ('BOOL', clibffi.cast_type_to_ffitype(lltype.Bool), lltype.Bool, []), - ('STRING', clibffi.ffi_type_pointer, rffi.CCHARP, []), - ('VARARGS', clibffi.ffi_type_void, rffi.CHAR, []), + ('BOOL', clibffi.cast_type_to_ffitype(lltype.Bool), lltype.Bool, []), + ('STRING', clibffi.ffi_type_pointer, rffi.CCHARP, []), + ('VARARGS', clibffi.ffi_type_void, rffi.CHAR, []), ('NATIVE_VARARGS',), ('NATIVE_STRUCT',), ('NATIVE_ARRAY',), - ('NATIVE_MAPPED', clibffi.ffi_type_void, rffi.CCHARP, []), + ('NATIVE_MAPPED', clibffi.ffi_type_void, rffi.CCHARP, []), ] ffi_types = [] @@ -67,11 +65,13 @@ del _native_types + def lltype_for_name(name): """NOT_RPYTHON""" # XXX maybe use a dictionary return lltypes[type_names.index(name)] + def size_for_name(name): """NOT_RPYTHON""" # XXX maybe use a dictionary @@ -101,7 +101,7 @@ def setup_class(cls, space, w_cls): @classdef.singleton_method('allocate') def singleton_method_allocate(self, space, args_w): - return W_TypeObject(space, VOID) + return W_TypeObject(space, VOID) # noqa: F821 def __deepcopy__(self, memo): obj = super(W_TypeObject, self).__deepcopy__(memo) @@ -110,7 +110,8 @@ def __deepcopy__(self, memo): return obj def __repr__(self): - return '' % (type_names[self.typeindex], lltype_sizes[self.typeindex]) + return '' % ( + type_names[self.typeindex], lltype_sizes[self.typeindex]) def eq(self, w_other): if not isinstance(w_other, W_TypeObject): @@ -135,6 +136,7 @@ def read(self, space, data): def write(self, space, data, w_arg): return self.rw_strategy.write(space, data, w_arg) + class W_BuiltinType(W_TypeObject): classdef = ClassDef('Builtin', W_TypeObject.classdef) @@ -145,16 +147,18 @@ def __init__(self, space, typeindex, rw_strategy): def singleton_method_allocate(self, space, args_w): raise NotImplementedError + def type_object(space, w_obj): w_ffi_mod = space.find_const(space.w_kernel, 'FFI') w_type = space.send(w_ffi_mod, 'find_type', [w_obj]) if not isinstance(w_type, W_TypeObject): - raise space.error(space.w_TypeError, - "This seems to be a bug. find_type should always" - "return an FFI::Type object, but apparently it did" - "not in this case.") + raise space.error( + space.w_TypeError, + "This seems to be a bug. find_type should always return an" + "FFI::Type object, but apparently it did not in this case.") return w_type + class ReadWriteStrategy(object): def __init__(self, typeindex): self.typesize = lltype_sizes[typeindex] @@ -165,9 +169,10 @@ def read(self, space, data): def write(self, space, data, w_arg): raise NotImplementedError("abstract ReadWriteStrategy") + class StringRWStrategy(ReadWriteStrategy): def __init__(self): - ReadWriteStrategy.__init__(self, STRING) + ReadWriteStrategy.__init__(self, STRING) # noqa: F821 def read(self, space, data): result = misc.read_raw_unsigned_data(data, self.typesize) @@ -181,9 +186,10 @@ def write(self, space, data, w_arg): arg = rffi.cast(lltype.Unsigned, arg) misc.write_raw_unsigned_data(data, arg, self.typesize) + class PointerRWStrategy(ReadWriteStrategy): def __init__(self): - ReadWriteStrategy.__init__(self, POINTER) + ReadWriteStrategy.__init__(self, POINTER) # noqa: F821 def read(self, space, data): result = misc.read_raw_unsigned_data(data, self.typesize) @@ -208,9 +214,10 @@ def _convert_to_NULL_if_nil(space, w_arg): else: return w_arg + class BoolRWStrategy(ReadWriteStrategy): def __init__(self): - ReadWriteStrategy.__init__(self, BOOL) + ReadWriteStrategy.__init__(self, BOOL) # noqa: F821 def read(self, space, data): result = bool(misc.read_raw_signed_data(data, self.typesize)) @@ -220,6 +227,7 @@ def write(self, space, data, w_arg): arg = space.is_true(w_arg) misc.write_raw_unsigned_data(data, arg, self.typesize) + class FloatRWStrategy(ReadWriteStrategy): def read(self, space, data): result = misc.read_raw_float_data(data, self.typesize) @@ -229,6 +237,7 @@ def write(self, space, data, w_arg): arg = space.float_w(w_arg) misc.write_raw_float_data(data, arg, self.typesize) + class SignedRWStrategy(ReadWriteStrategy): def read(self, space, data): result = misc.read_raw_signed_data(data, self.typesize) @@ -238,6 +247,7 @@ def write(self, space, data, w_arg): arg = space.int_w(w_arg) misc.write_raw_signed_data(data, arg, self.typesize) + class UnsignedRWStrategy(ReadWriteStrategy): def read(self, space, data): result = misc.read_raw_unsigned_data(data, self.typesize) @@ -247,44 +257,44 @@ def write(self, space, data, w_arg): arg = space.int_w(w_arg) misc.write_raw_unsigned_data(data, arg, self.typesize) + class VoidRWStrategy(ReadWriteStrategy): def __init__(self): - ReadWriteStrategy.__init__(self, VOID) + ReadWriteStrategy.__init__(self, VOID) # noqa: F821 def read(self, space, data): - return space.w_nil; + return space.w_nil def write(self, space, data, w_arg): pass rw_strategies = {} -rw_strategies[VOID] = VoidRWStrategy() -for ts, tu in [[INT8, UINT8], - [INT16, UINT16], - [INT32, UINT32], - [INT64, UINT64], - [LONG, ULONG]]: +rw_strategies[VOID] = VoidRWStrategy() # noqa: F821 +for ts, tu in [ + [INT8, UINT8], [INT16, UINT16], [INT32, UINT32], # noqa: F821 + [INT64, UINT64], [LONG, ULONG]]: # noqa: F821 rw_strategies[ts] = SignedRWStrategy(ts) rw_strategies[tu] = UnsignedRWStrategy(tu) # LongdoubleRWStrategy is not implemented yet, give LONGDOUBLE a # FloatRWStrategy for now so the ruby part of ffi doesn't crash when it gets # loaded -for t in [FLOAT32, FLOAT64, LONGDOUBLE]: +for t in [FLOAT32, FLOAT64, LONGDOUBLE]: # noqa: F821 rw_strategies[t] = FloatRWStrategy(t) -rw_strategies[POINTER] = PointerRWStrategy() -rw_strategies[BOOL] = BoolRWStrategy() -rw_strategies[STRING] = StringRWStrategy() +rw_strategies[POINTER] = PointerRWStrategy() # noqa: F821 +rw_strategies[BOOL] = BoolRWStrategy() # noqa: F821 +rw_strategies[STRING] = StringRWStrategy() # noqa: F821 # These three are not implemented yet, they just get a pointer strategy for now # to make the ruby part happy -for t in [BUFFER_IN, BUFFER_OUT, BUFFER_INOUT]: +for t in [BUFFER_IN, BUFFER_OUT, BUFFER_INOUT]: # noqa: F821 rw_strategies[t] = PointerRWStrategy() -rw_strategies[VARARGS] = VoidRWStrategy() +rw_strategies[VARARGS] = VoidRWStrategy() # noqa: F821 + class W_MappedObject(W_TypeObject): classdef = ClassDef('MappedObject', W_TypeObject.classdef) def __init__(self, space, klass=None): - W_TypeObject.__init__(self, space, NATIVE_MAPPED) + W_TypeObject.__init__(self, space, NATIVE_MAPPED) # noqa: F821 self.rw_strategy = None @classdef.singleton_method('allocate') diff --git a/topaz/modules/ffi/variadic_invoker.py b/topaz/modules/ffi/variadic_invoker.py index 87703c3e4..c7f523fe1 100644 --- a/topaz/modules/ffi/variadic_invoker.py +++ b/topaz/modules/ffi/variadic_invoker.py @@ -1,13 +1,9 @@ from topaz.module import ClassDef from topaz.objects.objectobject import W_Object -from topaz.modules.ffi.type import type_object, ffi_types, W_TypeObject, VOID -from topaz.modules.ffi.dynamic_library import coerce_dl_symbol -from topaz.modules.ffi.function_type import W_FunctionTypeObject from topaz.modules.ffi.function import W_FFIFunctionObject -from rpython.rlib import clibffi from rpython.rlib import jit -from rpython.rtyper.lltypesystem import lltype, rffi + class W_VariadicInvokerObject(W_Object): classdef = ClassDef('VariadicInvoker', W_Object.classdef) @@ -37,9 +33,9 @@ def method_initialize(self, space, w_handle, w_arg_types, @classdef.method('invoke', arg_values_w='array') def method_invoke(self, space, w_arg_types, arg_values_w): w_func_cls = space.getclassfor(W_FFIFunctionObject) - w_func = space.send(w_func_cls, 'new', - [self.w_ret_type, w_arg_types, - self.w_handle, self.w_options]) + w_func = space.send( + w_func_cls, 'new', + [self.w_ret_type, w_arg_types, self.w_handle, self.w_options]) return self._dli_call(space, w_func, arg_values_w) @jit.dont_look_inside diff --git a/topaz/modules/topaz.py b/topaz/modules/topaz.py index a6b4edee0..7cf5f3437 100644 --- a/topaz/modules/topaz.py +++ b/topaz/modules/topaz.py @@ -31,13 +31,15 @@ def method_intmask(self, space, w_int): @moduledef.function("convert_type", method="symbol") def method_convert_type(self, space, w_obj, w_type, method): if not isinstance(w_type, W_ClassObject): - raise space.error(space.w_TypeError, "type argument must be a class") + raise space.error( + space.w_TypeError, "type argument must be a class") return space.convert_type(w_obj, w_type, method) @moduledef.function("try_convert_type", method="symbol") def method_try_convert_type(self, space, w_obj, w_type, method): if not isinstance(w_type, W_ClassObject): - raise space.error(space.w_TypeError, "type argument must be a class") + raise space.error( + space.w_TypeError, "type argument must be a class") return space.convert_type(w_obj, w_type, method, raise_error=False) @moduledef.function("compare") @@ -45,20 +47,22 @@ def method_compare(self, space, w_a, w_b, block=None): return space.compare(w_a, w_b, block) @moduledef.function("infect", taint="bool", untrust="bool", freeze="bool") - def method_infect(self, space, w_dest, w_src, taint=True, untrust=True, freeze=False): - space.infect(w_dest, w_src, taint=taint, untrust=untrust, freeze=freeze) + def method_infect(self, space, w_dest, w_src, taint=True, untrust=True, + freeze=False): + space.infect( + w_dest, w_src, taint=taint, untrust=untrust, freeze=freeze) return self @moduledef.function("tcsetattr", fd="int", when="int", mode_w="array") def method_tcsetattr(self, space, fd, when, mode_w): cc = [space.str_w(w_char) for w_char in space.listview(mode_w[6])] mode = ( - space.int_w(mode_w[0]), # iflag - space.int_w(mode_w[1]), # oflag - space.int_w(mode_w[2]), # cflag - space.int_w(mode_w[3]), # lflag - space.int_w(mode_w[4]), # ispeed - space.int_w(mode_w[5]), # ospeed + space.int_w(mode_w[0]), # iflag + space.int_w(mode_w[1]), # oflag + space.int_w(mode_w[2]), # cflag + space.int_w(mode_w[3]), # lflag + space.int_w(mode_w[4]), # ispeed + space.int_w(mode_w[5]), # ospeed cc ) try: @@ -68,18 +72,18 @@ def method_tcsetattr(self, space, fd, when, mode_w): return self @moduledef.function("tcgetattr", fd="int") - def method_tcsetattr(self, space, fd): + def method_tcgetattr(self, space, fd): try: mode = tcgetattr(fd) except OSError as e: raise error_for_oserror(space, e) mode_w = [ - space.newint(mode[0]), # iflag - space.newint(mode[1]), # oflag - space.newint(mode[2]), # cflag - space.newint(mode[3]), # lflag - space.newint(mode[4]), # ispeed - space.newint(mode[5]), # ospeed + space.newint(mode[0]), # iflag + space.newint(mode[1]), # oflag + space.newint(mode[2]), # cflag + space.newint(mode[3]), # lflag + space.newint(mode[4]), # ispeed + space.newint(mode[5]), # ospeed space.newarray([space.newstr_fromstr(cc) for cc in mode[6]]) ] return space.newarray(mode_w) diff --git a/topaz/objects/fiberobject.py b/topaz/objects/fiberobject.py index d8792dd8c..f3d33c5e5 100644 --- a/topaz/objects/fiberobject.py +++ b/topaz/objects/fiberobject.py @@ -145,6 +145,8 @@ def clear(self): self.w_result = None self.propagate_exception = None self.space = None + + # This makes me sad. global_state = GlobalState() diff --git a/topaz/objects/timeobject.py b/topaz/objects/timeobject.py index 29d227294..dcf5d9381 100644 --- a/topaz/objects/timeobject.py +++ b/topaz/objects/timeobject.py @@ -1,13 +1,18 @@ import math import time +from rpython.rtyper.lltypesystem import lltype, rffi +from rpython.rlib.rarithmetic import intmask +from pypy.module.time.interp_time import external, TM_P, glob_buf + from topaz.module import ClassDef from topaz.coerce import Coerce from topaz.objects.objectobject import W_Object from topaz.modules.comparable import Comparable -MONTHNAMES = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"] +MONTHNAMES = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", + "oct", "nov", "dec"] class W_TimeObject(W_Object): @@ -28,12 +33,12 @@ def method_now(self, space): return space.send(self, "new") @classdef.singleton_method("new") - def method_now(self, space, args_w): + def method_new(self, space, args_w): if len(args_w) > 7: raise space.error( space.w_ArgumentError, - "wrong number of arguments (given %d, expected 0..7)" % len(args_w) - ) + ("wrong number of arguments (given %d, expected 0..7)" % + len(args_w))) if len(args_w) > 6: utc_offset = Coerce.int(space, args_w.pop()) w_time = space.send(self, "gm", args_w) @@ -109,12 +114,14 @@ def method_gm(self, space, args_w): raise space.error(space.w_ArgumentError, "argument out of range") w_time = space.send(space.getclassfor(W_TimeObject), "new") - w_time._set_epoch_seconds(mktime(year, month, day, hour, minute, sec) + usecfrac) + w_time._set_epoch_seconds( + mktime(year, month, day, hour, minute, sec) + usecfrac) return w_time @staticmethod def month_arg_to_month(space, w_arg): - w_month = space.convert_type(w_arg, space.w_string, "to_str", raise_error=False) + w_month = space.convert_type(w_arg, space.w_string, "to_str", + raise_error=False) if w_month is space.w_nil: month = Coerce.int(space, w_arg) else: @@ -145,17 +152,20 @@ def method_plus(self, space, w_other): if isinstance(w_other, W_TimeObject): raise space.error(space.w_TypeError, "time + time?") w_time = space.send(space.getclassfor(W_TimeObject), "allocate") - w_time._set_epoch_seconds(self.epoch_seconds + Coerce.float(space, w_other)) + w_time._set_epoch_seconds( + self.epoch_seconds + Coerce.float(space, w_other)) w_time._set_offset(self.offset) return w_time @classdef.method("-") def method_sub(self, space, w_other): if isinstance(w_other, W_TimeObject): - return space.newfloat(self.epoch_seconds - Coerce.float(space, w_other)) + return space.newfloat( + self.epoch_seconds - Coerce.float(space, w_other)) else: w_time = space.send(space.getclassfor(W_TimeObject), "allocate") - w_time._set_epoch_seconds(self.epoch_seconds - Coerce.float(space, w_other)) + w_time._set_epoch_seconds( + self.epoch_seconds - Coerce.float(space, w_other)) w_time._set_offset(self.offset) return w_time @@ -187,7 +197,8 @@ def method_to_a(self, space): if self.offset == 0: tp_w.append(space.newstr_fromstr("UTC")) else: - tp_w.append(space.newstr_fromstr(strftime("%Z", self.epoch_seconds))) + tp_w.append(space.newstr_fromstr( + strftime("%Z", self.epoch_seconds))) return space.newarray(tp_w) @classdef.method("utc?") @@ -202,14 +213,13 @@ def _set_offset(self, tzoffset): self.offset = tzoffset -from rpython.rtyper.lltypesystem import lltype, rffi -from rpython.rlib.rarithmetic import intmask -from pypy.module.time.interp_time import external, TM_P, glob_buf - -c_gmtime = external('gmtime', [rffi.TIME_TP], TM_P, save_err=rffi.RFFI_SAVE_ERRNO) -c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P], rffi.SIZE_T) +c_gmtime = external( + 'gmtime', [rffi.TIME_TP], TM_P, save_err=rffi.RFFI_SAVE_ERRNO) +c_strftime = external( + 'strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P], rffi.SIZE_T) c_mktime = external('mktime', [TM_P], rffi.TIME_T) + def strftime(format, seconds): i = 1024 while i < (256 * len(format)): @@ -235,10 +245,10 @@ def gmtime(seconds): rffi.getintfield(t, 'c_tm_min'), rffi.getintfield(t, 'c_tm_hour'), rffi.getintfield(t, 'c_tm_mday'), - rffi.getintfield(t, 'c_tm_mon') + 1, # want january == 1 + rffi.getintfield(t, 'c_tm_mon') + 1, # want january == 1 rffi.getintfield(t, 'c_tm_year') + 1900, - (rffi.getintfield(t, 'c_tm_wday') + 6) % 7, # want monday == 0 - rffi.getintfield(t, 'c_tm_yday') + 1, # want january, 1 == 1 + (rffi.getintfield(t, 'c_tm_wday') + 6) % 7, # want monday == 0 + rffi.getintfield(t, 'c_tm_yday') + 1, # want january, 1 == 1 rffi.getintfield(t, 'c_tm_isdst')] diff --git a/topaz/parser.py b/topaz/parser.py index a927b1529..b2b33d1af 100644 --- a/topaz/parser.py +++ b/topaz/parser.py @@ -813,7 +813,6 @@ def command_asgn_var(self, p): def command_asgn_subscript_op_asgn_command_call(self, p): raise NotImplementedError(p) - @pg.production("command_asgn : primary_value call_op IDENTIFIER OP_ASGN command_rhs") def command_asgn_method_op_asgn_command_call(self, p): raise NotImplementedError(p) @@ -1632,7 +1631,7 @@ def primary_paren_arg(self, p): @pg.production("primary : LPAREN_ARG stmt paren_post_expr rparen") def primary_paren_arg(self, p): stmt = p[1].getast() - if isinstance(stmt, ast.Statement): # simplify here for posterity + if isinstance(stmt, ast.Statement): # simplify here for posterity return BoxAST(stmt.expr) else: return p[1] diff --git a/topaz/utils/regexp.py b/topaz/utils/regexp.py index 4dc92625b..0ac11454f 100644 --- a/topaz/utils/regexp.py +++ b/topaz/utils/regexp.py @@ -12,8 +12,7 @@ ) from rpython.rlib.rsre.rsre_core import ( AT_BEGINNING, AT_BEGINNING_LINE, AT_BEGINNING_STRING, AT_BOUNDARY, - AT_NON_BOUNDARY, AT_END, AT_END_LINE, AT_END_STRING, AT_LOC_BOUNDARY, - AT_LOC_NON_BOUNDARY, AT_UNI_BOUNDARY, AT_UNI_NON_BOUNDARY + AT_NON_BOUNDARY, AT_END_LINE, AT_END_STRING, ) from rpython.rlib.rsre.rsre_char import MAXREPEAT as MAX_REPEAT @@ -283,7 +282,7 @@ def with_flags(self, positive=None, case_insensitive=None, zerowidth=None): zerowidth = zerowidth if zerowidth is not None else self.zerowidth if (positive == self.positive and case_insensitive == self.case_insensitive and - zerowidth == self.zerowidth): + zerowidth == self.zerowidth): return self return self.rebuild(positive, case_insensitive, zerowidth) @@ -892,7 +891,7 @@ def compile(self, ctx): } EXTRA_POSIX_PROPERTIES = { - "print": [Range(32, 255)], # space - ASCII-end + "print": [Range(32, 255)], # space - ASCII-end "blank": [Character(ord(c)) for c in " \t"], "punct": [Character(ord(c)) for c in '~!@#$%^&*()+-\|{}[]:";\'<>?,./'], "alpha": [Range(ord("a"), ord("z")), Range(ord("A"), ord("Z"))], @@ -1159,7 +1158,7 @@ def _parse_set_implicit_union(source, info): def _parse_set_member(source, info): start = _parse_set_item(source, info) if (not isinstance(start, Character) or not start.positive or - not source.match("-")): + not source.match("-")): return start here = source.pos From 2ee855710c1119e070d8bf6ceab9c611ed540de5 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 17 Mar 2017 15:59:10 +0100 Subject: [PATCH 2/3] Fix a few E305 linting errors --- tests/modules/ffi/test_data_converter.py | 1 + topaz/modules/ffi/abstract_memory.py | 1 + topaz/modules/ffi/pointer.py | 2 ++ topaz/modules/ffi/type.py | 1 + topaz/utils/packing/pack.py | 1 + 5 files changed, 6 insertions(+) diff --git a/tests/modules/ffi/test_data_converter.py b/tests/modules/ffi/test_data_converter.py index 08348d9e2..7546af148 100644 --- a/tests/modules/ffi/test_data_converter.py +++ b/tests/modules/ffi/test_data_converter.py @@ -13,6 +13,7 @@ def test_it_has_the_following_instance_methods(self, space): assert 'to_native' in instance_methods assert 'from_native' in instance_methods + code_DataConverterImplementation = """ class DataConverterImplementation include FFI::DataConverter diff --git a/topaz/modules/ffi/abstract_memory.py b/topaz/modules/ffi/abstract_memory.py index a137fbb67..869217ed4 100644 --- a/topaz/modules/ffi/abstract_memory.py +++ b/topaz/modules/ffi/abstract_memory.py @@ -84,6 +84,7 @@ def setup_class(cls, space, w_cls): [space.newsymbol(prefix + alias), space.newsymbol(prefix + orig)]) + W_AMO = W_AbstractMemoryObject for t in [ffitype.INT8, ffitype.INT16, ffitype.INT32, ffitype.INT64, ffitype.UINT8, ffitype.UINT16, ffitype.UINT32, ffitype.UINT64, diff --git a/topaz/modules/ffi/pointer.py b/topaz/modules/ffi/pointer.py index 0bb1bb163..93d1e2331 100644 --- a/topaz/modules/ffi/pointer.py +++ b/topaz/modules/ffi/pointer.py @@ -18,6 +18,7 @@ def coerce_pointer(space, w_pointer): "%s is not an FFI::Pointer." % space.str_w(space.send(w_pointer, 'inspect'))) + setattr(Coerce, 'ffi_pointer', staticmethod(coerce_pointer)) @@ -35,6 +36,7 @@ def coerce_address(space, w_addressable): space.getclass(w_addressable).name) raise space.error(space.w_TypeError, errmsg) + setattr(Coerce, 'ffi_address', staticmethod(coerce_address)) diff --git a/topaz/modules/ffi/type.py b/topaz/modules/ffi/type.py index 54d7573e3..81dd3112f 100644 --- a/topaz/modules/ffi/type.py +++ b/topaz/modules/ffi/type.py @@ -268,6 +268,7 @@ def read(self, space, data): def write(self, space, data, w_arg): pass + rw_strategies = {} rw_strategies[VOID] = VoidRWStrategy() # noqa: F821 for ts, tu in [ diff --git a/topaz/utils/packing/pack.py b/topaz/utils/packing/pack.py index b8c8d3c82..48845f878 100644 --- a/topaz/utils/packing/pack.py +++ b/topaz/utils/packing/pack.py @@ -201,4 +201,5 @@ def make_pack_operators(): return ops + pack_operators = make_pack_operators() From 8e2fe6bd486e7c105ef7cd6f061b41efd3e42b08 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 17 Mar 2017 16:04:38 +0100 Subject: [PATCH 3/3] Use dirty macOS workaround only on OSX on Travis --- tasks/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/base.py b/tasks/base.py index 9ce4e0200..3f5423fcf 100644 --- a/tasks/base.py +++ b/tasks/base.py @@ -2,8 +2,8 @@ import invoke - -invoke.run = os.system +if os.environ.get('TRAVIS_OS_NAME') == 'osx': + invoke.run = os.system class BaseTest(object):