Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r79892:f5b2758482a2 Date: 2015-09-29 11:32 +0200 http://bitbucket.org/pypy/pypy/changeset/f5b2758482a2/
Log: Fix: r_wchar_t.SIGN is not useful to know if that type is originally signed or not diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py --- a/pypy/module/_cffi_backend/ctypeprim.py +++ b/pypy/module/_cffi_backend/ctypeprim.py @@ -7,6 +7,7 @@ from rpython.rlib.rarithmetic import r_uint, r_ulonglong, intmask from rpython.rlib import jit from rpython.rtyper.lltypesystem import lltype, rffi +from rpython.rtyper.tool import rfficache from pypy.interpreter.error import oefmt from pypy.module._cffi_backend import cdataobj, misc @@ -130,7 +131,8 @@ # though it may be signed when 'wchar_t' is written to C). WCHAR_INT = {(2, False): rffi.USHORT, (4, False): rffi.UINT, - (4, True): rffi.INT}[rffi.sizeof(lltype.UniChar), rffi.r_wchar_t.SIGN] + (4, True): rffi.INT}[rffi.sizeof(lltype.UniChar), + rfficache.signof_c_type('wchar_t')] WCHAR_INTP = rffi.CArrayPtr(WCHAR_INT) class W_CTypePrimitiveUniChar(W_CTypePrimitiveCharOrUniChar): diff --git a/rpython/rtyper/tool/rfficache.py b/rpython/rtyper/tool/rfficache.py --- a/rpython/rtyper/tool/rfficache.py +++ b/rpython/rtyper/tool/rfficache.py @@ -52,6 +52,17 @@ result.append(int(answer[1])) return result +def signof_c_type(c_typename, **kwds): + question = 'printf("sign %s=%%d\\n", ((%s) -1) <= 0);' % (c_typename, + c_typename) + answer = ask_gcc(question, **kwds).strip() + if answer == 'sign %s=0' % (c_typename,): + return False + if answer == 'sign %s=1' % (c_typename,): + return True + raise ValueError(answer) + + class Platform: def __init__(self): self.types = {} diff --git a/rpython/rtyper/tool/test/test_rfficache.py b/rpython/rtyper/tool/test/test_rfficache.py --- a/rpython/rtyper/tool/test/test_rfficache.py +++ b/rpython/rtyper/tool/test/test_rfficache.py @@ -15,3 +15,13 @@ assert hasattr(rffi, 'r_' + name) assert hasattr(rffi, name.upper()) +def test_signof_c_type(): + assert signof_c_type('signed char') == True + assert signof_c_type('unsigned char') == False + assert signof_c_type('long long') == True + assert signof_c_type('unsigned long long') == False + # + assert (sizeof_c_type('wchar_t'), signof_c_type('wchar_t')) in [ + (2, False), + (4, False), + (4, True)] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit