Author: Manuel Jacob <m...@manueljacob.de> Branch: Changeset: r82342:dd1e021c36b6 Date: 2016-02-20 12:55 +0100 http://bitbucket.org/pypy/pypy/changeset/dd1e021c36b6/
Log: Move StringTraits and UnicodeTraits classes from rpython/rtyper/module/support.py to rpython/rlib/rposix.py. diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -3,7 +3,6 @@ import errno from rpython.rtyper.lltypesystem.rffi import CConstant, CExternVariable, INT from rpython.rtyper.lltypesystem import lltype, ll2ctypes, rffi -from rpython.rtyper.module.support import StringTraits, UnicodeTraits from rpython.rtyper.tool import rffi_platform from rpython.tool.sourcetools import func_renamer from rpython.translator.tool.cbuild import ExternalCompilationInfo @@ -12,7 +11,7 @@ specialize, enforceargs, register_replacement_for, NOT_CONSTANT) from rpython.rlib.signature import signature from rpython.rlib import types -from rpython.annotator.model import s_Str0 +from rpython.annotator.model import s_Str0, s_Unicode0 from rpython.rlib import jit from rpython.translator.platform import platform from rpython.rlib import rstring @@ -342,6 +341,87 @@ rstring.check_str0(res) return res + +class StringTraits: + str = str + str0 = s_Str0 + CHAR = rffi.CHAR + CCHARP = rffi.CCHARP + charp2str = staticmethod(rffi.charp2str) + charpsize2str = staticmethod(rffi.charpsize2str) + scoped_str2charp = staticmethod(rffi.scoped_str2charp) + str2charp = staticmethod(rffi.str2charp) + free_charp = staticmethod(rffi.free_charp) + scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_buffer) + + @staticmethod + def posix_function_name(name): + return UNDERSCORE_ON_WIN32 + name + + @staticmethod + def ll_os_name(name): + return 'll_os.ll_os_' + name + + @staticmethod + @specialize.argtype(0) + def as_str(path): + assert path is not None + if isinstance(path, str): + return path + elif isinstance(path, unicode): + # This never happens in PyPy's Python interpreter! + # Only in raw RPython code that uses unicode strings. + # We implement python2 behavior: silently convert to ascii. + return path.encode('ascii') + else: + return path.as_bytes() + + @staticmethod + @specialize.argtype(0) + def as_str0(path): + res = StringTraits.as_str(path) + rstring.check_str0(res) + return res + + +class UnicodeTraits: + str = unicode + str0 = s_Unicode0 + CHAR = rffi.WCHAR_T + CCHARP = rffi.CWCHARP + charp2str = staticmethod(rffi.wcharp2unicode) + charpsize2str = staticmethod(rffi.wcharpsize2unicode) + str2charp = staticmethod(rffi.unicode2wcharp) + scoped_str2charp = staticmethod(rffi.scoped_unicode2wcharp) + free_charp = staticmethod(rffi.free_wcharp) + scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_unicodebuffer) + + @staticmethod + def posix_function_name(name): + return UNDERSCORE_ON_WIN32 + 'w' + name + + @staticmethod + @specialize.argtype(0) + def ll_os_name(name): + return 'll_os.ll_os_w' + name + + @staticmethod + @specialize.argtype(0) + def as_str(path): + assert path is not None + if isinstance(path, unicode): + return path + else: + return path.as_unicode() + + @staticmethod + @specialize.argtype(0) + def as_str0(path): + res = UnicodeTraits.as_str(path) + rstring.check_str0(res) + return res + + # Returns True when the unicode function should be called: # - on Windows # - if the path is Unicode. diff --git a/rpython/rlib/rposix_environ.py b/rpython/rlib/rposix_environ.py --- a/rpython/rlib/rposix_environ.py +++ b/rpython/rlib/rposix_environ.py @@ -2,10 +2,10 @@ import sys from rpython.annotator import model as annmodel from rpython.rlib.objectmodel import enforceargs +from rpython.rlib.rposix import _WIN32, StringTraits, UnicodeTraits from rpython.rtyper.controllerentry import Controller from rpython.rtyper.extfunc import register_external from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.rtyper.module.support import _WIN32, StringTraits, UnicodeTraits from rpython.translator.tool.cbuild import ExternalCompilationInfo str0 = annmodel.s_Str0 diff --git a/rpython/rtyper/module/support.py b/rpython/rtyper/module/support.py --- a/rpython/rtyper/module/support.py +++ b/rpython/rtyper/module/support.py @@ -1,6 +1,5 @@ import sys -from rpython.annotator import model as annmodel from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.objectmodel import specialize from rpython.rlib import rstring @@ -8,85 +7,6 @@ _WIN32 = sys.platform.startswith('win') UNDERSCORE_ON_WIN32 = '_' if _WIN32 else '' - -class StringTraits: - str = str - str0 = annmodel.s_Str0 - CHAR = rffi.CHAR - CCHARP = rffi.CCHARP - charp2str = staticmethod(rffi.charp2str) - charpsize2str = staticmethod(rffi.charpsize2str) - scoped_str2charp = staticmethod(rffi.scoped_str2charp) - str2charp = staticmethod(rffi.str2charp) - free_charp = staticmethod(rffi.free_charp) - scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_buffer) - - @staticmethod - def posix_function_name(name): - return UNDERSCORE_ON_WIN32 + name - - @staticmethod - def ll_os_name(name): - return 'll_os.ll_os_' + name - - @staticmethod - @specialize.argtype(0) - def as_str(path): - assert path is not None - if isinstance(path, str): - return path - elif isinstance(path, unicode): - # This never happens in PyPy's Python interpreter! - # Only in raw RPython code that uses unicode strings. - # We implement python2 behavior: silently convert to ascii. - return path.encode('ascii') - else: - return path.as_bytes() - - @staticmethod - @specialize.argtype(0) - def as_str0(path): - res = StringTraits.as_str(path) - rstring.check_str0(res) - return res - -class UnicodeTraits: - str = unicode - str0 = annmodel.s_Unicode0 - CHAR = rffi.WCHAR_T - CCHARP = rffi.CWCHARP - charp2str = staticmethod(rffi.wcharp2unicode) - charpsize2str = staticmethod(rffi.wcharpsize2unicode) - str2charp = staticmethod(rffi.unicode2wcharp) - scoped_str2charp = staticmethod(rffi.scoped_unicode2wcharp) - free_charp = staticmethod(rffi.free_wcharp) - scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_unicodebuffer) - - @staticmethod - def posix_function_name(name): - return UNDERSCORE_ON_WIN32 + 'w' + name - - @staticmethod - @specialize.argtype(0) - def ll_os_name(name): - return 'll_os.ll_os_w' + name - - @staticmethod - @specialize.argtype(0) - def as_str(path): - assert path is not None - if isinstance(path, unicode): - return path - else: - return path.as_unicode() - - @staticmethod - @specialize.argtype(0) - def as_str0(path): - res = UnicodeTraits.as_str(path) - rstring.check_str0(res) - return res - def ll_strcpy(dst_s, src_s, n): dstchars = dst_s.chars srcchars = src_s.chars _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit