예제 #1
0
def test_ifdef():
    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            post_include_bits = ['/* a C comment */',
                                 '#define XYZZY 42',
                                 'typedef int foo;',
                                 '''
                                 struct s {
                                   int i;
                                   double f;
                                 };
                                 '''])

        s = rffi_platform.Struct('struct s', [('i', rffi.INT)],
                                   ifdef='XYZZY')
        z = rffi_platform.Struct('struct z', [('i', rffi.INT)],
                                   ifdef='FOOBAR')

        foo = rffi_platform.SimpleType('foo', ifdef='XYZZY')
        bar = rffi_platform.SimpleType('bar', ifdef='FOOBAR')

    res = rffi_platform.configure(CConfig)
    assert res['s'] is not None
    assert res['z'] is None
    assert res['foo'] is not None
    assert res['bar'] is None
예제 #2
0
파일: fficurses.py 프로젝트: charred/pypy
def guess_eci():
    for eci in try_eci():
        class CConfig:
            _compilation_info_ = eci
            HAS = rffi_platform.Has("setupterm")
        if rffi_platform.configure(CConfig)['HAS']:
            return eci
    raise ImportError("failed to guess where ncurses is installed. "
                      "You might need to install libncurses5-dev or similar.")
예제 #3
0
def guess_eci():
    for eci in try_eci():
        class CConfig:
            _compilation_info_ = eci
            HAS = rffi_platform.Has("setupterm")
        if rffi_platform.configure(CConfig)['HAS']:
            return eci
    raise ImportError("failed to guess where ncurses is installed. "
                      "You might need to install libncurses5-dev or similar.")
예제 #4
0
def test_integer_function_result():
    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            pre_include_bits=["""int sum(int a, int b){ return a+b;}"""], )
        SUM = rffi_platform.IntegerFunctionResult('sum', [12, 34])
        SUM2 = rffi_platform.IntegerFunctionResult('sum', [-12, -34])

    res = rffi_platform.configure(CConfig)
    assert res['SUM'] == 46
    assert res['SUM2'] == -46
예제 #5
0
def test_integer_function_result():
    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            pre_include_bits = ["""int sum(int a, int b){ return a+b;}"""],
        )
        SUM = rffi_platform.IntegerFunctionResult('sum', [12, 34])
        SUM2 = rffi_platform.IntegerFunctionResult('sum', [-12, -34])


    res = rffi_platform.configure(CConfig)
    assert res['SUM'] == 46
    assert res['SUM2'] == -46
예제 #6
0
def posix_declaration(try_to_add=None):
    global STAT_STRUCT, STATVFS_STRUCT

    LL_STAT_FIELDS = STAT_FIELDS[:]
    if try_to_add:
        LL_STAT_FIELDS.append(try_to_add)

    if TIMESPEC is not None:

        def _expand(lst, originalname, timespecname):
            if _MACOS:  # fields are named e.g. st_atimespec
                timespecname = originalname + "spec"
            else:  # fields are named e.g. st_atim, with no e
                timespecname = originalname[:-1]

            for i, (_name, _TYPE) in enumerate(lst):
                if _name == originalname:
                    # replace the 'st_atime' field of type rffi.DOUBLE
                    # with the corresponding 'struct timespec' field
                    lst[i] = (timespecname, TIMESPEC)
                    break

        _expand(LL_STAT_FIELDS, 'st_atime', 'st_atim')
        _expand(LL_STAT_FIELDS, 'st_mtime', 'st_mtim')
        _expand(LL_STAT_FIELDS, 'st_ctime', 'st_ctim')

        del _expand
    else:
        # Replace float fields with integers
        for name in ('st_atime', 'st_mtime', 'st_ctime', 'st_birthtime'):
            for i, (_name, _TYPE) in enumerate(LL_STAT_FIELDS):
                if _name == name:
                    LL_STAT_FIELDS[i] = (_name, lltype.Signed)
                    break

    class CConfig:
        _compilation_info_ = compilation_info
        STAT_STRUCT = platform.Struct('struct %s' % _name_struct_stat,
                                      LL_STAT_FIELDS)
        STATVFS_STRUCT = platform.Struct('struct statvfs', STATVFS_FIELDS)

    try:
        config = platform.configure(CConfig,
                                    ignore_errors=try_to_add is not None)
    except platform.CompilationError:
        if try_to_add:
            return  # failed to add this field, give up
        raise

    STAT_STRUCT = lltype.Ptr(config['STAT_STRUCT'])
    STATVFS_STRUCT = lltype.Ptr(config['STATVFS_STRUCT'])
    if try_to_add:
        STAT_FIELDS.append(try_to_add)
예제 #7
0
파일: test_lltyped.py 프로젝트: Mu-L/pypy
    def test_padding_in_prebuilt_struct(self):
        from rpython.rtyper.lltypesystem import rffi
        from rpython.rtyper.tool import rffi_platform
        eci = rffi_platform.eci_from_header("""
            typedef struct {
                char c1;        /* followed by one byte of padding */
                short s1;
                char c2;        /* followed by 3 bytes of padding */
                int i2;
                char c3;        /* followed by 3 or 7 bytes of padding */
                Signed l3;
                char c4;        /* followed by 3 or 7 bytes of padding */
                long l4;
                char c5;
            } foobar_t;
        """)

        class CConfig:
            _compilation_info_ = eci
            STRUCT = rffi_platform.Struct("foobar_t", [("c1", Signed),
                                                       ("s1", Signed),
                                                       ("l3", Signed),
                                                       ("l4", Signed)])

        S = rffi_platform.configure(CConfig)['STRUCT']
        assert 'get_padding_drop' in S._hints
        assert 'eci' in S._hints
        s1 = malloc(S, immortal=True)
        s1.c_c1 = rffi.cast(S.c_c1, -12)
        s1.c_s1 = rffi.cast(S.c_s1, -7843)
        s1.c_l3 = -98765432
        s1.c_l4 = rffi.cast(S.c_l4, -91234567)
        s2 = malloc(S, immortal=True)
        s2.c_c1 = rffi.cast(S.c_c1, -123)
        s2.c_s1 = rffi.cast(S.c_s1, -789)
        s2.c_l3 = -9999999
        s2.c_l4 = rffi.cast(S.c_l4, -9111111)

        #
        def f(n):
            if n > 5:
                s = s1
            else:
                s = s2
            return s.c_l3

        #
        fn = self.getcompiled(f, [int])
        res = fn(10)
        assert res == -98765432
        res = fn(1)
        assert res == -9999999
예제 #8
0
파일: extfunc.py 프로젝트: zielmicha/pypy
 def configure(self, CConfig):
     classes_seen = self.__dict__.setdefault('__classes_seen', {})
     if CConfig in classes_seen:
         return
     from rpython.rtyper.tool import rffi_platform as platform
     # copy some stuff
     if self.compilation_info is None:
         self.compilation_info = CConfig._compilation_info_
     else:
         self.compilation_info = self.compilation_info.merge(
             CConfig._compilation_info_)
     self.__dict__.update(platform.configure(CConfig))
     classes_seen[CConfig] = True
예제 #9
0
파일: extfunc.py 프로젝트: pypyjs/pypy
 def configure(self, CConfig):
     classes_seen = self.__dict__.setdefault('__classes_seen', {})
     if CConfig in classes_seen:
         return
     from rpython.rtyper.tool import rffi_platform as platform
     # copy some stuff
     if self.compilation_info is None:
         self.compilation_info = CConfig._compilation_info_
     else:
         self.compilation_info = self.compilation_info.merge(
             CConfig._compilation_info_)
     self.__dict__.update(platform.configure(CConfig))
     classes_seen[CConfig] = True
예제 #10
0
def posix_declaration(try_to_add=None):
    global STAT_STRUCT, STATVFS_STRUCT

    LL_STAT_FIELDS = STAT_FIELDS[:]
    if try_to_add:
        LL_STAT_FIELDS.append(try_to_add)

    if TIMESPEC is not None:

        def _expand(lst, originalname, timespecname):
            for i, (_name, _TYPE) in enumerate(lst):
                if _name == originalname:
                    # replace the 'st_atime' field of type rffi.DOUBLE
                    # with a field 'st_atim' of type 'struct timespec'
                    lst[i] = (timespecname, TIMESPEC.TO)
                    break

        _expand(LL_STAT_FIELDS, "st_atime", "st_atim")
        _expand(LL_STAT_FIELDS, "st_mtime", "st_mtim")
        _expand(LL_STAT_FIELDS, "st_ctime", "st_ctim")

        del _expand
    else:
        # Replace float fields with integers
        for name in ("st_atime", "st_mtime", "st_ctime", "st_birthtime"):
            for i, (_name, _TYPE) in enumerate(LL_STAT_FIELDS):
                if _name == name:
                    LL_STAT_FIELDS[i] = (_name, lltype.Signed)
                    break

    class CConfig:
        _compilation_info_ = compilation_info
        STAT_STRUCT = platform.Struct("struct %s" % _name_struct_stat, LL_STAT_FIELDS)
        STATVFS_STRUCT = platform.Struct("struct statvfs", STATVFS_FIELDS)

    try:
        config = platform.configure(CConfig, ignore_errors=try_to_add is not None)
    except platform.CompilationError:
        if try_to_add:
            return  # failed to add this field, give up
        raise

    STAT_STRUCT = lltype.Ptr(config["STAT_STRUCT"])
    STATVFS_STRUCT = lltype.Ptr(config["STATVFS_STRUCT"])
    if try_to_add:
        STAT_FIELDS.append(try_to_add)
예제 #11
0
def test_configure():
    test_h = udir.join('test_ctypes_platform.h')
    test_h.write('#define XYZZY 42\n')

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(pre_include_bits=[
            "/* a C comment */", "#include <stdio.h>",
            "#include <test_ctypes_platform.h>"
        ],
                                                     include_dirs=[str(udir)])

        FILE = rffi_platform.Struct('FILE', [])
        ushort = rffi_platform.SimpleType('unsigned short')
        XYZZY = rffi_platform.ConstantInteger('XYZZY')

    res = rffi_platform.configure(CConfig)
    assert isinstance(res['FILE'], lltype.Struct)
    assert res == {'FILE': res['FILE'], 'ushort': rffi.USHORT, 'XYZZY': 42}
예제 #12
0
파일: test_lltyped.py 프로젝트: bukzor/pypy
 def test_padding_in_prebuilt_struct(self):
     from rpython.rtyper.lltypesystem import rffi
     from rpython.rtyper.tool import rffi_platform
     eci = rffi_platform.eci_from_header("""
         typedef struct {
             char c1;        /* followed by one byte of padding */
             short s1;
             char c2;        /* followed by 3 bytes of padding */
             int i2;
             char c3;        /* followed by 3 or 7 bytes of padding */
             long l3;
             char c4;
         } foobar_t;
     """)
     class CConfig:
         _compilation_info_ = eci
         STRUCT = rffi_platform.Struct("foobar_t",
                                       [("c1", Signed),
                                        ("s1", Signed),
                                        ("l3", Signed)])
     S = rffi_platform.configure(CConfig)['STRUCT']
     assert 'get_padding_drop' in S._hints
     assert 'eci' in S._hints
     s1 = malloc(S, immortal=True)
     s1.c_c1 = rffi.cast(S.c_c1, -12)
     s1.c_s1 = rffi.cast(S.c_s1, -7843)
     s1.c_l3 = -98765432
     s2 = malloc(S, immortal=True)
     s2.c_c1 = rffi.cast(S.c_c1, -123)
     s2.c_s1 = rffi.cast(S.c_s1, -789)
     s2.c_l3 = -9999999
     #
     def f(n):
         if n > 5:
             s = s1
         else:
             s = s2
         return s.c_l3
     #
     fn = self.getcompiled(f, [int])
     res = fn(10)
     assert res == -98765432
     res = fn(1)
     assert res == -9999999
예제 #13
0
def test_configure():
    test_h = udir.join('test_ctypes_platform.h')
    test_h.write('#define XYZZY 42\n')

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            pre_include_bits = ["/* a C comment */",
                                "#include <stdio.h>",
                                "#include <test_ctypes_platform.h>"],
            include_dirs = [str(udir)]
        )

        FILE = rffi_platform.Struct('FILE', [])
        ushort = rffi_platform.SimpleType('unsigned short')
        XYZZY = rffi_platform.ConstantInteger('XYZZY')

    res = rffi_platform.configure(CConfig)
    assert isinstance(res['FILE'], lltype.Struct)
    assert res == {'FILE': res['FILE'],
                   'ushort': rffi.USHORT,
                   'XYZZY': 42}
예제 #14
0
파일: gc.py 프로젝트: weijiwei/pypy
    def configure_boehm_once(cls):
        """ Configure boehm only once, since we don't cache failures
        """
        if hasattr(cls, 'malloc_fn_ptr'):
            return cls.malloc_fn_ptr
        from rpython.rtyper.tool import rffi_platform
        compilation_info = rffi_platform.configure_boehm()

        # on some platform GC_init is required before any other
        # GC_* functions, call it here for the benefit of tests
        # XXX move this to tests
        init_fn_ptr = rffi.llexternal("GC_init", [],
                                      lltype.Void,
                                      compilation_info=compilation_info,
                                      sandboxsafe=True,
                                      _nowrapper=True)
        init_fn_ptr()

        # Versions 6.x of libgc needs to use GC_local_malloc().
        # Versions 7.x of libgc removed this function; GC_malloc() has
        # the same behavior if libgc was compiled with
        # THREAD_LOCAL_ALLOC.
        class CConfig:
            _compilation_info_ = compilation_info
            HAS_LOCAL_MALLOC = rffi_platform.Has("GC_local_malloc")

        config = rffi_platform.configure(CConfig)
        if config['HAS_LOCAL_MALLOC']:
            GC_MALLOC = "GC_local_malloc"
        else:
            GC_MALLOC = "GC_malloc"
        malloc_fn_ptr = rffi.llexternal(
            GC_MALLOC,
            [lltype.Signed],  # size_t, but good enough
            llmemory.GCREF,
            compilation_info=compilation_info,
            sandboxsafe=True,
            _nowrapper=True)
        cls.malloc_fn_ptr = malloc_fn_ptr
        return malloc_fn_ptr
예제 #15
0
def test_ifdef():
    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(post_include_bits=[
            '/* a C comment */', '#define XYZZY 42', 'typedef int foo;', '''
                                 struct s {
                                   int i;
                                   double f;
                                 };
                                 '''
        ])

        s = rffi_platform.Struct('struct s', [('i', rffi.INT)], ifdef='XYZZY')
        z = rffi_platform.Struct('struct z', [('i', rffi.INT)], ifdef='FOOBAR')

        foo = rffi_platform.SimpleType('foo', ifdef='XYZZY')
        bar = rffi_platform.SimpleType('bar', ifdef='FOOBAR')

    res = rffi_platform.configure(CConfig)
    assert res['s'] is not None
    assert res['z'] is None
    assert res['foo'] is not None
    assert res['bar'] is None
예제 #16
0
def test_nested_structs_in_the_opposite_order():
    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            post_include_bits=["""
            struct y {
            int foo;
            unsigned long bar;
            };
            struct x {
            char c;
            struct y y;
            };
            """])
        y = rffi_platform.Struct("struct y", [("bar", rffi.SHORT)])
        x = rffi_platform.Struct("struct x", [("y", y)])

    res = rffi_platform.configure(CConfig)
    c_x = res["x"]
    c_y = res["y"]
    assert isinstance(c_x, lltype.Struct)
    assert isinstance(c_y, lltype.Struct)
    assert c_x.c_y is c_y
예제 #17
0
파일: gc.py 프로젝트: mozillazg/pypy
    def configure_boehm_once(cls):
        """ Configure boehm only once, since we don't cache failures
        """
        if hasattr(cls, 'malloc_fn_ptr'):
            return cls.malloc_fn_ptr
        from rpython.rtyper.tool import rffi_platform
        compilation_info = rffi_platform.configure_boehm()

        # on some platform GC_init is required before any other
        # GC_* functions, call it here for the benefit of tests
        # XXX move this to tests
        init_fn_ptr = rffi.llexternal("GC_init",
                                      [], lltype.Void,
                                      compilation_info=compilation_info,
                                      sandboxsafe=True,
                                      _nowrapper=True)
        init_fn_ptr()

        # Versions 6.x of libgc needs to use GC_local_malloc().
        # Versions 7.x of libgc removed this function; GC_malloc() has
        # the same behavior if libgc was compiled with
        # THREAD_LOCAL_ALLOC.
        class CConfig:
            _compilation_info_ = compilation_info
            HAS_LOCAL_MALLOC = rffi_platform.Has("GC_local_malloc")
        config = rffi_platform.configure(CConfig)
        if config['HAS_LOCAL_MALLOC']:
            GC_MALLOC = "GC_local_malloc"
        else:
            GC_MALLOC = "GC_malloc"
        malloc_fn_ptr = rffi.llexternal(GC_MALLOC,
                                        [lltype.Signed], # size_t, but good enough
                                        llmemory.GCREF,
                                        compilation_info=compilation_info,
                                        sandboxsafe=True,
                                        _nowrapper=True)
        cls.malloc_fn_ptr = malloc_fn_ptr
        return malloc_fn_ptr
예제 #18
0
def test_nested_structs_in_the_opposite_order():
    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(post_include_bits=[
            """
            struct y {
            int foo;
            unsigned long bar;
            };
            struct x {
            char c;
            struct y y;
            };
            """
        ])
        y = rffi_platform.Struct("struct y", [("bar", rffi.SHORT)])
        x = rffi_platform.Struct("struct x", [("y", y)])

    res = rffi_platform.configure(CConfig)
    c_x = res["x"]
    c_y = res["y"]
    assert isinstance(c_x, lltype.Struct)
    assert isinstance(c_y, lltype.Struct)
    assert c_x.c_y is c_y
예제 #19
0
def make_utime_impl(traits):
    from rpython.rlib import rwin32
    win32traits = make_win32_traits(traits)
    from rpython.rtyper.module.ll_os_stat import time_t_to_FILE_TIME

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            includes = ['windows.h'],
            )

        FILE_WRITE_ATTRIBUTES = platform.ConstantInteger(
            'FILE_WRITE_ATTRIBUTES')
        OPEN_EXISTING = platform.ConstantInteger(
            'OPEN_EXISTING')
        FILE_FLAG_BACKUP_SEMANTICS = platform.ConstantInteger(
            'FILE_FLAG_BACKUP_SEMANTICS')
    globals().update(platform.configure(CConfig))

    CreateFile = rffi.llexternal(
        'CreateFile' + win32traits.apisuffix,
        [traits.CCHARP, rwin32.DWORD, rwin32.DWORD,
         rwin32.LPSECURITY_ATTRIBUTES, rwin32.DWORD, rwin32.DWORD,
         rwin32.HANDLE],
        rwin32.HANDLE,
        calling_conv='win')

    GetSystemTime = rffi.llexternal(
        'GetSystemTime',
        [lltype.Ptr(rwin32.SYSTEMTIME)],
        lltype.Void,
        calling_conv='win')

    SystemTimeToFileTime = rffi.llexternal(
        'SystemTimeToFileTime',
        [lltype.Ptr(rwin32.SYSTEMTIME),
         lltype.Ptr(rwin32.FILETIME)],
        rwin32.BOOL,
        calling_conv='win')

    SetFileTime = rffi.llexternal(
        'SetFileTime',
        [rwin32.HANDLE,
         lltype.Ptr(rwin32.FILETIME),
         lltype.Ptr(rwin32.FILETIME),
         lltype.Ptr(rwin32.FILETIME)],
        rwin32.BOOL,
        calling_conv = 'win')

    @specialize.argtype(1)
    def os_utime_llimpl(path, tp):
        hFile = CreateFile(path,
                           FILE_WRITE_ATTRIBUTES, 0,
                           None, OPEN_EXISTING,
                           FILE_FLAG_BACKUP_SEMANTICS,
                           rwin32.NULL_HANDLE)
        if hFile == rwin32.INVALID_HANDLE_VALUE:
            raise rwin32.lastWindowsError()
        ctime = lltype.nullptr(rwin32.FILETIME)
        atime = lltype.malloc(rwin32.FILETIME, flavor='raw')
        mtime = lltype.malloc(rwin32.FILETIME, flavor='raw')
        try:
            if tp is None:
                now = lltype.malloc(rwin32.SYSTEMTIME, flavor='raw')
                try:
                    GetSystemTime(now)
                    if (not SystemTimeToFileTime(now, atime) or
                        not SystemTimeToFileTime(now, mtime)):
                        raise rwin32.lastWindowsError()
                finally:
                    lltype.free(now, flavor='raw')
            else:
                actime, modtime = tp
                time_t_to_FILE_TIME(actime, atime)
                time_t_to_FILE_TIME(modtime, mtime)
            if not SetFileTime(hFile, ctime, atime, mtime):
                raise rwin32.lastWindowsError()
        finally:
            rwin32.CloseHandle(hFile)
            lltype.free(atime, flavor='raw')
            lltype.free(mtime, flavor='raw')

    return os_utime_llimpl
예제 #20
0
파일: ll_os_stat.py 프로젝트: charred/pypy
    _name_struct_stat = 'stat'
    INCLUDES = ['sys/types.h', 'sys/stat.h', 'sys/statvfs.h', 'unistd.h']

compilation_info = ExternalCompilationInfo(
    # This must be set to 64 on some systems to enable large file support.
    #pre_include_bits = ['#define _FILE_OFFSET_BITS 64'],
    # ^^^ nowadays it's always set in all C files we produce.
    includes=INCLUDES
)

if TIMESPEC is not None:
    class CConfig_for_timespec:
        _compilation_info_ = compilation_info
        TIMESPEC = TIMESPEC
    TIMESPEC = lltype.Ptr(
        platform.configure(CConfig_for_timespec)['TIMESPEC'])


def posix_declaration(try_to_add=None):
    global STAT_STRUCT, STATVFS_STRUCT

    LL_STAT_FIELDS = STAT_FIELDS[:]
    if try_to_add:
        LL_STAT_FIELDS.append(try_to_add)

    if TIMESPEC is not None:

        def _expand(lst, originalname, timespecname):
            for i, (_name, _TYPE) in enumerate(lst):
                if _name == originalname:
                    # replace the 'st_atime' field of type rffi.DOUBLE
예제 #21
0

if platform.has("setupterm", "#include <curses.h>\n#include <term.h>"):
    HAVE_CURSES = True
    setupterm   = rffi.llexternal("setupterm", [rffi.CCHARP, rffi.INT, rffi.INTP], rffi.INT, \
                    compilation_info=eci)
    tigetstr    = rffi.llexternal("tigetstr", [rffi.CCHARP], rffi.CCHARP, compilation_info=eci)
else:
    HAVE_CURSES = False

class CConfig:
    _compilation_info_ = eci
    OK                 = platform.DefinedConstantInteger("OK")
    STDOUT_FILENO      = platform.DefinedConstantInteger("STDOUT_FILENO")

cconfig = platform.configure(CConfig)

OK                     = cconfig["OK"]
STDOUT_FILENO          = cconfig["STDOUT_FILENO"]



def init(vm):
    return new_c_con_module(vm, "Curses", "Curses", __file__, import_, \
      ["Curses_Exception", "setupterm", "tigetstr"])


@con_object_proc
def import_(vm):
    (mod,),_ = vm.decode_args("O")
    
예제 #22
0
if sys.platform != 'win32':
    for name in """ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF""".split():
        setattr(CConfig, name, rffi_platform.DefinedConstantInteger(name))

    CConfig.timeval = rffi_platform.Struct(
        'struct timeval',
        [('tv_sec', rffi.LONG),
         ('tv_usec', rffi.LONG)])

    CConfig.itimerval = rffi_platform.Struct(
        'struct itimerval',
        [('it_value', CConfig.timeval),
         ('it_interval', CConfig.timeval)])

for k, v in rffi_platform.configure(CConfig).items():
    globals()[k] = v

def external(name, args, result, **kwds):
    return rffi.llexternal(name, args, result, compilation_info=eci,
                           sandboxsafe=True, **kwds)

pypysig_ignore = external('pypysig_ignore', [rffi.INT], lltype.Void)
pypysig_default = external('pypysig_default', [rffi.INT], lltype.Void)
pypysig_setflag = external('pypysig_setflag', [rffi.INT], lltype.Void)
pypysig_reinstall = external('pypysig_reinstall', [rffi.INT], lltype.Void)
pypysig_set_wakeup_fd = external('pypysig_set_wakeup_fd', [rffi.INT], rffi.INT)
pypysig_poll = external('pypysig_poll', [], rffi.INT, releasegil=False)
# don't bother releasing the GIL around a call to pypysig_poll: it's
# pointless and a performance issue
pypysig_pushback = external('pypysig_pushback', [rffi.INT], lltype.Void,
예제 #23
0
        locals()[name] = rffi_platform.ConstantInteger(name)
    for name in xml_model_list:
        locals()[name] = rffi_platform.ConstantInteger(name)
    for name in xml_model_list:
        locals()[name] = rffi_platform.ConstantInteger(name)
    for name in xml_model_list:
        locals()[name] = rffi_platform.ConstantInteger(name)
    for name in xml_model_list:
        locals()[name] = rffi_platform.ConstantInteger(name)
    for name in xml_model_list:
        locals()[name] = rffi_platform.ConstantInteger(name)
    for name in xml_model_list:
        locals()[name] = rffi_platform.ConstantInteger(name)
    XML_Parser_SIZE = rffi_platform.SizeOf("XML_Parser")

for k, v in rffi_platform.configure(CConfigure).items():
    globals()[k] = v

XML_COMBINED_VERSION = 10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION

XML_Content_Ptr.TO.become(rffi.CArray(XML_Content))
XML_Encoding_Ptr = lltype.Ptr(XML_Encoding)


def expat_external(*a, **kw):
    kw['compilation_info'] = eci
    return rffi.llexternal(*a, **kw)

INTERNED_CCHARP = "INTERNED"

HANDLERS = dict(
예제 #24
0
파일: rwin32file.py 프로젝트: Mu-L/pypy
def make_win32_traits(traits):
    from rpython.rlib import rwin32
    global config_global

    if traits.str is unicode:
        suffix = 'W'
    else:
        suffix = 'A'

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            includes = ['windows.h', 'winbase.h', 'sys/stat.h'],
        )
        WIN32_FIND_DATA = platform.Struct(
            'struct _WIN32_FIND_DATA' + suffix,
            # Only interesting fields
            [('dwFileAttributes', rwin32.DWORD),
             ('ftCreationTime', rwin32.FILETIME),
             ('ftLastAccessTime', rwin32.FILETIME),
             ('ftLastWriteTime', rwin32.FILETIME),
             ('nFileSizeHigh', rwin32.DWORD),
             ('nFileSizeLow', rwin32.DWORD),
             ('dwReserved0', rwin32.DWORD),
             ('dwReserved1', rwin32.DWORD),
             ('cFileName', lltype.FixedSizeArray(traits.CHAR, 250))])

    if config_global is None:
        config_global = platform.configure(GetCConfigGlobal())
    config = config_global.copy()
    config.update(platform.configure(CConfig))

    def external(*args, **kwargs):
        kwargs['compilation_info'] = CConfig._compilation_info_
        llfunc = rffi.llexternal(calling_conv='win', *args, **kwargs)
        return staticmethod(llfunc)

    class Win32Traits:
        apisuffix = suffix

        for name in '''WIN32_FIND_DATA WIN32_FILE_ATTRIBUTE_DATA
                       BY_HANDLE_FILE_INFORMATION
                       FILE_ATTRIBUTE_TAG_INFO
                       GetFileExInfoStandard
                       FILE_ATTRIBUTE_DIRECTORY FILE_ATTRIBUTE_READONLY
                       INVALID_FILE_ATTRIBUTES
                       _S_IFDIR _S_IFREG _S_IFCHR _S_IFIFO
                       FILE_TYPE_UNKNOWN FILE_TYPE_CHAR FILE_TYPE_PIPE
                       ERROR_INVALID_PARAMETER FILE_TYPE_DISK GENERIC_READ
                       FILE_SHARE_READ FILE_SHARE_WRITE ERROR_NOT_SUPPORTED
                       FILE_FLAG_OPEN_REPARSE_POINT FileAttributeTagInfo
                       FILE_READ_ATTRIBUTES FILE_ATTRIBUTE_NORMAL
                       FILE_WRITE_ATTRIBUTES OPEN_EXISTING
                       VOLUME_NAME_DOS VOLUME_NAME_NT
                       ERROR_FILE_NOT_FOUND ERROR_NO_MORE_FILES
                       ERROR_SHARING_VIOLATION MOVEFILE_REPLACE_EXISTING
                       ERROR_ACCESS_DENIED ERROR_CANT_ACCESS_FILE
                       ERROR_INVALID_FUNCTION FILE_FLAG_BACKUP_SEMANTICS
                       FILE_ATTRIBUTE_REPARSE_POINT
                       _O_RDONLY _O_WRONLY _O_BINARY
                    '''.split():
            locals()[name] = config[name]
        LPWIN32_FIND_DATA    = lltype.Ptr(WIN32_FIND_DATA)
        GET_FILEEX_INFO_LEVELS = rffi.ULONG # an enumeration

        FindFirstFile = external('FindFirstFile' + suffix,
                                 [traits.CCHARP, LPWIN32_FIND_DATA],
                                 rwin32.HANDLE,
                                 save_err=rffi.RFFI_SAVE_LASTERROR)
        FindNextFile = external('FindNextFile' + suffix,
                                [rwin32.HANDLE, LPWIN32_FIND_DATA],
                                rwin32.BOOL,
                                save_err=rffi.RFFI_SAVE_LASTERROR)
        FindClose = external('FindClose',
                             [rwin32.HANDLE],
                             rwin32.BOOL, releasegil=False)

        GetFileAttributes = external(
            'GetFileAttributes' + suffix,
            [traits.CCHARP],
            rwin32.DWORD,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        SetFileAttributes = external(
            'SetFileAttributes' + suffix,
            [traits.CCHARP, rwin32.DWORD],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        GetFileAttributesEx = external(
            'GetFileAttributesEx' + suffix,
            [traits.CCHARP, GET_FILEEX_INFO_LEVELS,
             lltype.Ptr(WIN32_FILE_ATTRIBUTE_DATA)],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        GetFileInformationByHandleEx = external(
            'GetFileInformationByHandleEx',
            [rwin32.HANDLE, rffi.INT, rffi.VOIDP, rwin32.DWORD],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        GetFileInformationByHandle = external(
            'GetFileInformationByHandle',
            [rwin32.HANDLE, lltype.Ptr(BY_HANDLE_FILE_INFORMATION)],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        GetFileType = external(
            'GetFileType',
            [rwin32.HANDLE],
            rwin32.DWORD,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        LPSTRP = rffi.CArrayPtr(traits.CCHARP)

        GetFullPathName = external(
            'GetFullPathName' + suffix,
            [traits.CCHARP, rwin32.DWORD,
             traits.CCHARP, LPSTRP],
            rwin32.DWORD,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        GetCurrentDirectory = external(
            'GetCurrentDirectory' + suffix,
            [rwin32.DWORD, traits.CCHARP],
            rwin32.DWORD,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        SetCurrentDirectory = external(
            'SetCurrentDirectory' + suffix,
            [traits.CCHARP],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        CreateDirectory = external(
            'CreateDirectory' + suffix,
            [traits.CCHARP, rffi.VOIDP],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        SetEnvironmentVariable = external(
            'SetEnvironmentVariable' + suffix,
            [traits.CCHARP, traits.CCHARP],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        CreateFile = external(
            'CreateFile' + apisuffix,
            [traits.CCHARP, rwin32.DWORD, rwin32.DWORD,
             rwin32.LPSECURITY_ATTRIBUTES, rwin32.DWORD, rwin32.DWORD,
             rwin32.HANDLE],
            rwin32.HANDLE,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        DeleteFile = external(
            'DeleteFile' + suffix,
            [traits.CCHARP],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        MoveFileEx = external(
            'MoveFileEx' + suffix,
            [traits.CCHARP, traits.CCHARP, rwin32.DWORD],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        CreateHardLink = external(
            'CreateHardLink' + suffix,
            [traits.CCHARP, traits.CCHARP, rwin32.LPSECURITY_ATTRIBUTES],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        TagInfoSize = 2 * rffi.sizeof(rwin32.DWORD)

    return Win32Traits
예제 #25
0
파일: rurandom.py 프로젝트: mozillazg/pypy
if sys.platform == 'win32':
    from rpython.rlib import rwin32

    eci = ExternalCompilationInfo(
        includes = ['windows.h', 'wincrypt.h'],
        libraries = ['advapi32'],
        )

    class CConfig:
        _compilation_info_ = eci
        PROV_RSA_FULL = rffi_platform.ConstantInteger(
            "PROV_RSA_FULL")
        CRYPT_VERIFYCONTEXT = rffi_platform.ConstantInteger(
            "CRYPT_VERIFYCONTEXT")

    globals().update(rffi_platform.configure(CConfig))

    HCRYPTPROV = rwin32.ULONG_PTR

    CryptAcquireContext = rffi.llexternal(
        'CryptAcquireContextA',
        [rffi.CArrayPtr(HCRYPTPROV),
         rwin32.LPCSTR, rwin32.LPCSTR, rwin32.DWORD, rwin32.DWORD],
        rwin32.BOOL,
        calling_conv='win',
        compilation_info=eci,
        save_err=rffi.RFFI_SAVE_LASTERROR)

    CryptGenRandom = rffi.llexternal(
        'CryptGenRandom',
        [HCRYPTPROV, rwin32.DWORD, rffi.CArrayPtr(rwin32.BYTE)],
예제 #26
0
from rpython.translator.tool.cbuild import ExternalCompilationInfo
# rffi-based pwd module

eci = ExternalCompilationInfo(includes=['sys/types.h', 'pwd.h', 'grp.h'])


class CConfig(object):
    _compilation_info_ = eci

    passwd = platform.Struct('struct passwd', [('pw_name', rffi.CCHARP),
                                               ('pw_passwd', rffi.CCHARP),
                                               ('pw_uid', lltype.Signed),
                                               ('pw_gid', lltype.Signed),
                                               ('pw_gecos', rffi.CCHARP),
                                               ('pw_dir', rffi.CCHARP),
                                               ('pw_shell', rffi.CCHARP)])


PASSWD = platform.configure(CConfig)['passwd']
PASSWDPTR = lltype.Ptr(PASSWD)

getpwnam = rffi.llexternal('getpwnam', [rffi.CCHARP],
                           PASSWDPTR,
                           compilation_info=eci)
getpwuid = rffi.llexternal('getpwuid', [lltype.Signed],
                           PASSWDPTR,
                           compilation_info=eci)
initgroups = rffi.llexternal('initgroups', [rffi.CCHARP, lltype.Signed],
                             rffi.INT,
                             compilation_info=eci)
예제 #27
0
def setup():
    INSPECT = {
        'b': 'signed char',
        'h': 'signed short',
        'i': 'signed int',
        'l': 'signed long',
        'q': 'signed long long',
        'n': 'ssize_t',
        'B': 'unsigned char',
        'H': 'unsigned short',
        'I': 'unsigned int',
        'L': 'unsigned long',
        'Q': 'unsigned long long',
        'N': 'size_t',
        'P': 'char *',
        'f': 'float',
        'd': 'double',
        '?': '_Bool',
    }

    pre_include_bits = [
        """
        #include <sys/types.h>
        #ifdef _MSC_VER
        #define _Bool char
        typedef int ssize_t; /* XXX fixme for 64 bit*/
        typedef unsigned int size_t; /* XXX fixme for 64 bit*/
        #endif"""
    ]
    field_names = dict.fromkeys(INSPECT)
    for fmtchar, ctype in INSPECT.iteritems():
        field_name = ctype.replace(" ", "_").replace("*", "star")
        field_names[fmtchar] = field_name
        pre_include_bits.append("""
            struct about_%s {
                char pad;
                %s field;
            };
        """ % (field_name, ctype))

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            pre_include_bits=pre_include_bits)

    for fmtchar, ctype in INSPECT.items():
        setattr(
            CConfig, field_names[fmtchar],
            rffi_platform.Struct(
                "struct about_%s" % (field_names[fmtchar], ),
                [('field', lltype.FixedSizeArray(rffi.CHAR, 1))]))

    cConfig = rffi_platform.configure(CConfig)

    for fmtchar, ctype in INSPECT.items():
        S = cConfig[field_names[fmtchar]]
        alignment = rffi.offsetof(S, 'c_field')
        size = rffi.sizeof(S.c_field)
        signed = 'a' <= fmtchar <= 'z'

        if fmtchar == 'f':
            pack = pack_float
            unpack = std.unpack_float
        elif fmtchar == 'd':
            pack = pack_double
            unpack = std.unpack_double
        elif fmtchar == '?':
            pack = std.pack_bool
            unpack = std.unpack_bool
        else:
            pack = std.make_int_packer(size, signed)
            unpack = std.make_int_unpacker(size, signed)

        native_fmttable[fmtchar] = {
            'size': size,
            'alignment': alignment,
            'pack': pack,
            'unpack': unpack
        }
예제 #28
0
def make_win32_traits(traits):
    from rpython.rlib import rwin32

    if traits.str is unicode:
        suffix = 'W'
    else:
        suffix = 'A'

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            includes=['windows.h', 'winbase.h', 'sys/stat.h'], )
        WIN32_FIND_DATA = platform.Struct(
            'struct _WIN32_FIND_DATA' + suffix,
            # Only interesting fields
            [('dwFileAttributes', rwin32.DWORD),
             ('nFileSizeHigh', rwin32.DWORD), ('nFileSizeLow', rwin32.DWORD),
             ('ftCreationTime', rwin32.FILETIME),
             ('ftLastAccessTime', rwin32.FILETIME),
             ('ftLastWriteTime', rwin32.FILETIME),
             ('cFileName', lltype.FixedSizeArray(traits.CHAR, 250))])
        ERROR_FILE_NOT_FOUND = platform.ConstantInteger('ERROR_FILE_NOT_FOUND')
        ERROR_NO_MORE_FILES = platform.ConstantInteger('ERROR_NO_MORE_FILES')

        GetFileExInfoStandard = platform.ConstantInteger(
            'GetFileExInfoStandard')
        FILE_ATTRIBUTE_DIRECTORY = platform.ConstantInteger(
            'FILE_ATTRIBUTE_DIRECTORY')
        FILE_ATTRIBUTE_READONLY = platform.ConstantInteger(
            'FILE_ATTRIBUTE_READONLY')
        INVALID_FILE_ATTRIBUTES = platform.ConstantInteger(
            'INVALID_FILE_ATTRIBUTES')
        ERROR_SHARING_VIOLATION = platform.ConstantInteger(
            'ERROR_SHARING_VIOLATION')
        MOVEFILE_REPLACE_EXISTING = platform.ConstantInteger(
            'MOVEFILE_REPLACE_EXISTING')
        _S_IFDIR = platform.ConstantInteger('_S_IFDIR')
        _S_IFREG = platform.ConstantInteger('_S_IFREG')
        _S_IFCHR = platform.ConstantInteger('_S_IFCHR')
        _S_IFIFO = platform.ConstantInteger('_S_IFIFO')
        FILE_TYPE_UNKNOWN = platform.ConstantInteger('FILE_TYPE_UNKNOWN')
        FILE_TYPE_CHAR = platform.ConstantInteger('FILE_TYPE_CHAR')
        FILE_TYPE_PIPE = platform.ConstantInteger('FILE_TYPE_PIPE')

        FILE_WRITE_ATTRIBUTES = platform.ConstantInteger(
            'FILE_WRITE_ATTRIBUTES')
        OPEN_EXISTING = platform.ConstantInteger('OPEN_EXISTING')
        FILE_FLAG_BACKUP_SEMANTICS = platform.ConstantInteger(
            'FILE_FLAG_BACKUP_SEMANTICS')
        VOLUME_NAME_DOS = platform.ConstantInteger('VOLUME_NAME_DOS')
        VOLUME_NAME_NT = platform.ConstantInteger('VOLUME_NAME_NT')

        WIN32_FILE_ATTRIBUTE_DATA = platform.Struct(
            'WIN32_FILE_ATTRIBUTE_DATA',
            [('dwFileAttributes', rwin32.DWORD),
             ('nFileSizeHigh', rwin32.DWORD), ('nFileSizeLow', rwin32.DWORD),
             ('ftCreationTime', rwin32.FILETIME),
             ('ftLastAccessTime', rwin32.FILETIME),
             ('ftLastWriteTime', rwin32.FILETIME)])

        BY_HANDLE_FILE_INFORMATION = platform.Struct(
            'BY_HANDLE_FILE_INFORMATION',
            [('dwFileAttributes', rwin32.DWORD),
             ('ftCreationTime', rwin32.FILETIME),
             ('ftLastAccessTime', rwin32.FILETIME),
             ('ftLastWriteTime', rwin32.FILETIME),
             ('dwVolumeSerialNumber', rwin32.DWORD),
             ('nFileSizeHigh', rwin32.DWORD), ('nFileSizeLow', rwin32.DWORD),
             ('nNumberOfLinks', rwin32.DWORD),
             ('nFileIndexHigh', rwin32.DWORD),
             ('nFileIndexLow', rwin32.DWORD)])

    config = platform.configure(CConfig)

    def external(*args, **kwargs):
        kwargs['compilation_info'] = CConfig._compilation_info_
        llfunc = rffi.llexternal(calling_conv='win', *args, **kwargs)
        return staticmethod(llfunc)

    class Win32Traits:
        apisuffix = suffix

        for name in '''WIN32_FIND_DATA WIN32_FILE_ATTRIBUTE_DATA BY_HANDLE_FILE_INFORMATION
                       GetFileExInfoStandard
                       FILE_ATTRIBUTE_DIRECTORY FILE_ATTRIBUTE_READONLY
                       INVALID_FILE_ATTRIBUTES
                       _S_IFDIR _S_IFREG _S_IFCHR _S_IFIFO
                       FILE_TYPE_UNKNOWN FILE_TYPE_CHAR FILE_TYPE_PIPE
                       FILE_WRITE_ATTRIBUTES OPEN_EXISTING FILE_FLAG_BACKUP_SEMANTICS
                       VOLUME_NAME_DOS VOLUME_NAME_NT
                       ERROR_FILE_NOT_FOUND ERROR_NO_MORE_FILES
                       ERROR_SHARING_VIOLATION MOVEFILE_REPLACE_EXISTING
                    '''.split():
            locals()[name] = config[name]
        LPWIN32_FIND_DATA = lltype.Ptr(WIN32_FIND_DATA)
        GET_FILEEX_INFO_LEVELS = rffi.ULONG  # an enumeration

        FindFirstFile = external('FindFirstFile' + suffix,
                                 [traits.CCHARP, LPWIN32_FIND_DATA],
                                 rwin32.HANDLE,
                                 save_err=rffi.RFFI_SAVE_LASTERROR)
        FindNextFile = external('FindNextFile' + suffix,
                                [rwin32.HANDLE, LPWIN32_FIND_DATA],
                                rwin32.BOOL,
                                save_err=rffi.RFFI_SAVE_LASTERROR)
        FindClose = external('FindClose', [rwin32.HANDLE], rwin32.BOOL)

        GetFileAttributes = external('GetFileAttributes' + suffix,
                                     [traits.CCHARP],
                                     rwin32.DWORD,
                                     save_err=rffi.RFFI_SAVE_LASTERROR)

        SetFileAttributes = external('SetFileAttributes' + suffix,
                                     [traits.CCHARP, rwin32.DWORD],
                                     rwin32.BOOL,
                                     save_err=rffi.RFFI_SAVE_LASTERROR)

        GetFileAttributesEx = external('GetFileAttributesEx' + suffix, [
            traits.CCHARP, GET_FILEEX_INFO_LEVELS,
            lltype.Ptr(WIN32_FILE_ATTRIBUTE_DATA)
        ],
                                       rwin32.BOOL,
                                       save_err=rffi.RFFI_SAVE_LASTERROR)

        GetFileInformationByHandle = external(
            'GetFileInformationByHandle',
            [rwin32.HANDLE,
             lltype.Ptr(BY_HANDLE_FILE_INFORMATION)],
            rwin32.BOOL,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        GetFileType = external('GetFileType', [rwin32.HANDLE],
                               rwin32.DWORD,
                               save_err=rffi.RFFI_SAVE_LASTERROR)

        LPSTRP = rffi.CArrayPtr(traits.CCHARP)

        GetFullPathName = external(
            'GetFullPathName' + suffix,
            [traits.CCHARP, rwin32.DWORD, traits.CCHARP, LPSTRP],
            rwin32.DWORD,
            save_err=rffi.RFFI_SAVE_LASTERROR)

        GetCurrentDirectory = external('GetCurrentDirectory' + suffix,
                                       [rwin32.DWORD, traits.CCHARP],
                                       rwin32.DWORD,
                                       save_err=rffi.RFFI_SAVE_LASTERROR)

        SetCurrentDirectory = external('SetCurrentDirectory' + suffix,
                                       [traits.CCHARP],
                                       rwin32.BOOL,
                                       save_err=rffi.RFFI_SAVE_LASTERROR)

        CreateDirectory = external('CreateDirectory' + suffix,
                                   [traits.CCHARP, rffi.VOIDP],
                                   rwin32.BOOL,
                                   save_err=rffi.RFFI_SAVE_LASTERROR)

        SetEnvironmentVariable = external('SetEnvironmentVariable' + suffix,
                                          [traits.CCHARP, traits.CCHARP],
                                          rwin32.BOOL,
                                          save_err=rffi.RFFI_SAVE_LASTERROR)

        CreateFile = external('CreateFile' + apisuffix, [
            traits.CCHARP, rwin32.DWORD, rwin32.DWORD,
            rwin32.LPSECURITY_ATTRIBUTES, rwin32.DWORD, rwin32.DWORD,
            rwin32.HANDLE
        ],
                              rwin32.HANDLE,
                              save_err=rffi.RFFI_SAVE_LASTERROR)

        DeleteFile = external('DeleteFile' + suffix, [traits.CCHARP],
                              rwin32.BOOL,
                              save_err=rffi.RFFI_SAVE_LASTERROR)

        MoveFileEx = external('MoveFileEx' + suffix,
                              [traits.CCHARP, traits.CCHARP, rwin32.DWORD],
                              rwin32.BOOL,
                              save_err=rffi.RFFI_SAVE_LASTERROR)

    return Win32Traits
예제 #29
0
파일: rzlib.py 프로젝트: sota/pypy-old
    _compilation_info_ = eci

    # XXX If Z_PREFIX was defined for the libz build, then these types are
    # named z_uInt, z_uLong, and z_Bytef instead.
    uInt = rffi_platform.SimpleType('uInt', rffi.UINT)
    uLong = rffi_platform.SimpleType('uLong', rffi.ULONG)
    Bytef = rffi_platform.SimpleType('Bytef', rffi.UCHAR)
    voidpf = rffi_platform.SimpleType('voidpf', rffi.VOIDP)

    ZLIB_VERSION = rffi_platform.DefinedConstantString('ZLIB_VERSION')


for _name in constantnames:
    setattr(SimpleCConfig, _name, rffi_platform.ConstantInteger(_name))

config = rffi_platform.configure(SimpleCConfig)
voidpf = config['voidpf']
uInt = config['uInt']
uLong = config['uLong']
Bytef = config['Bytef']
Bytefp = lltype.Ptr(lltype.Array(Bytef, hints={'nolength': True}))

ZLIB_VERSION = config['ZLIB_VERSION']

for _name in constantnames:
    globals()[_name] = config[_name]

# The following parameter is copied from zutil.h, version 0.95,
# according to CPython's zlibmodule.c
DEFLATED = Z_DEFLATED
if MAX_MEM_LEVEL >= 8:
예제 #30
0
파일: ropenssl.py 프로젝트: sota/pypy-old
stack_st_DIST_POINT = rffi.COpaquePtr('STACK_OF(X509_OBJECT)')
DH = rffi.COpaquePtr('DH')
EC_KEY = rffi.COpaquePtr('EC_KEY')
AUTHORITY_INFO_ACCESS = rffi.COpaquePtr('AUTHORITY_INFO_ACCESS')
GENERAL_NAME = lltype.Ptr(lltype.ForwardReference())


class CConfigBootstrap:
    _compilation_info_ = eci
    OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
        "OPENSSL_EXPORT_VAR_AS_FUNCTION")
    OPENSSL_VERSION_NUMBER = rffi_platform.ConstantInteger(
        "OPENSSL_VERSION_NUMBER")


cconfig = rffi_platform.configure(CConfigBootstrap)
if cconfig["OPENSSL_EXPORT_VAR_AS_FUNCTION"]:
    ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
else:
    ASN1_ITEM_EXP = ASN1_ITEM
OPENSSL_VERSION_NUMBER = cconfig["OPENSSL_VERSION_NUMBER"]
HAVE_TLSv1_2 = OPENSSL_VERSION_NUMBER >= 0x10001000


class CConfig:
    _compilation_info_ = eci

    SSLEAY_VERSION = rffi_platform.DefinedConstantString(
        "SSLEAY_VERSION", "SSLeay_version(SSLEAY_VERSION)")
    OPENSSL_NO_SSL2 = rffi_platform.Defined("OPENSSL_NO_SSL2")
    OPENSSL_NO_SSL3 = rffi_platform.Defined("OPENSSL_NO_SSL3")
예제 #31
0
파일: fcntl.py 프로젝트: fniephaus/topaz
from topaz.system import IS_WINDOWS

if not IS_WINDOWS:

    class CConstants(object):
        _compilation_info_ = ExternalCompilationInfo(includes=['fcntl.h'])

    for const in [
            "F_DUPFD", "F_GETFD", "F_GETLK", "F_SETFD", "F_GETFL", "F_SETFL",
            "F_SETLK", "F_SETLKW", "FD_CLOEXEC", "F_RDLCK", "F_UNLCK",
            "F_WRLCK", "O_CREAT", "O_EXCL", "O_NOCTTY", "O_TRUNC", "O_APPEND",
            "O_NONBLOCK", "O_NDELAY", "O_RDONLY", "O_RDWR", "O_WRONLY",
            "O_ACCMODE"
    ]:
        setattr(CConstants, const, rffi_platform.ConstantInteger(const))
    fcntl_constants = rffi_platform.configure(CConstants)
    fcntl = _rsocket_rffi.fcntl
else:
    fcntl_constants = {}

    def fcntl(fdtype, cmd, arg):
        raise NotImplementedError


class Fcntl(object):
    moduledef = ModuleDef("Fcntl")

    @moduledef.setup_module
    def setup_module(space, w_mod):
        if not IS_WINDOWS:
            for key, value in fcntl_constants.items():
예제 #32
0
파일: rposix_stat.py 프로젝트: xulukai/pypy
        _name_struct_stat = 'stat'
    INCLUDES = ['sys/types.h', 'sys/stat.h', 'sys/statvfs.h', 'unistd.h']

compilation_info = ExternalCompilationInfo(
    # This must be set to 64 on some systems to enable large file support.
    #pre_include_bits = ['#define _FILE_OFFSET_BITS 64'],
    # ^^^ nowadays it's always set in all C files we produce.
    includes=INCLUDES)

if TIMESPEC is not None:

    class CConfig_for_timespec:
        _compilation_info_ = compilation_info
        TIMESPEC = TIMESPEC

    TIMESPEC = lltype.Ptr(platform.configure(CConfig_for_timespec)['TIMESPEC'])


def posix_declaration(try_to_add=None):
    global STAT_STRUCT, STATVFS_STRUCT

    LL_STAT_FIELDS = STAT_FIELDS[:]
    if try_to_add:
        LL_STAT_FIELDS.append(try_to_add)

    if TIMESPEC is not None:

        def _expand(lst, originalname, timespecname):
            for i, (_name, _TYPE) in enumerate(lst):
                if _name == originalname:
                    # replace the 'st_atime' field of type rffi.DOUBLE
예제 #33
0
파일: rpwd.py 프로젝트: youaani/hippyvm
    passwd = platform.Struct('struct passwd', [('pw_name', rffi.CCHARP),
                                               ('pw_passwd', rffi.CCHARP),
                                               ('pw_uid', lltype.Signed),
                                               ('pw_gid', lltype.Signed),
                                               ('pw_gecos', rffi.CCHARP),
                                               ('pw_dir', rffi.CCHARP),
                                               ('pw_shell', rffi.CCHARP)])

    group = platform.Struct('struct group', [('gr_name', rffi.CCHARP),
                                             ('gr_passwd', rffi.CCHARP),
                                             ('gr_gid', lltype.Signed),
                                             ('gr_mem', rffi.CCHARPP)])


PASSWD = platform.configure(CConfig)['passwd']
PASSWDPTR = lltype.Ptr(PASSWD)
GROUP = platform.configure(CConfig)['group']
GROUPPTR = lltype.Ptr(GROUP)

getpwnam = rffi.llexternal('getpwnam', [rffi.CCHARP],
                           PASSWDPTR,
                           compilation_info=eci)
getpwuid = rffi.llexternal('getpwuid', [lltype.Signed],
                           PASSWDPTR,
                           compilation_info=eci)
initgroups = rffi.llexternal('initgroups', [rffi.CCHARP, lltype.Signed],
                             rffi.INT,
                             compilation_info=eci)
getgrgid = rffi.llexternal('getgrgid', [lltype.Signed],
                           GROUPPTR,
예제 #34
0
파일: timelib.py 프로젝트: netyum/hippyvm
                                       ("tm_mday", rffi.INT),
                                       ("tm_mon", rffi.INT),
                                       ("tm_year", rffi.INT),
                                       ("tm_wday", rffi.INT),
                                       ("tm_yday", rffi.INT),
                                       ("tm_isdst", rffi.INT),
                                       ("tm_gmtoff", rffi.LONG),
                                       ("tm_zone", rffi.CCHARP)])

    timeval = platform.Struct("struct timeval", [("tv_sec", rffi.INT),
                                                 ("tv_usec", rffi.INT)])

    _compilation_info_ = eci


conf = platform.configure(CConfig)

tzinfo = rffi.CArrayPtr(conf['ttinfo'])
tm = conf['tm']
tmP = lltype.Ptr(tm)
timeval = conf['timeval']
timevalP = lltype.Ptr(timeval)

c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, tmP],
                      rffi.SIZE_T)

c_gettimeofday = external('gettimeofday', [rffi.VOIDP, rffi.VOIDP], rffi.INT)


class CConfig(object):
    timelib_special = platform.Struct('timelib_special', [
예제 #35
0
REG_NO_LAZY_FLUSH REG_NOTIFY_CHANGE_NAME REG_NOTIFY_CHANGE_ATTRIBUTES
REG_NOTIFY_CHANGE_LAST_SET REG_NOTIFY_CHANGE_SECURITY REG_LEGAL_CHANGE_FILTER
REG_NONE REG_SZ REG_EXPAND_SZ REG_BINARY REG_DWORD REG_DWORD_LITTLE_ENDIAN
REG_DWORD_BIG_ENDIAN REG_LINK REG_MULTI_SZ REG_RESOURCE_LIST
REG_FULL_RESOURCE_DESCRIPTOR REG_RESOURCE_REQUIREMENTS_LIST

HKEY_LOCAL_MACHINE HKEY_CLASSES_ROOT HKEY_CURRENT_CONFIG HKEY_CURRENT_USER
HKEY_DYN_DATA HKEY_LOCAL_MACHINE HKEY_PERFORMANCE_DATA HKEY_USERS

ERROR_MORE_DATA
'''.split()
for name in constant_names:
    setattr(CConfig, name, platform.DefinedConstantInteger(name))

constants = {}
cConfig = platform.configure(CConfig)
constants.update(cConfig)
globals().update(cConfig)


def external(name, args, result, **kwds):
    return rffi.llexternal(name,
                           args,
                           result,
                           compilation_info=eci,
                           calling_conv='win',
                           **kwds)


HKEY = rwin32.HANDLE
PHKEY = rffi.CArrayPtr(HKEY)
예제 #36
0
파일: api.py 프로젝트: charred/pypy
def configure_types():
    for config in (CConfig, CConfig2):
        for name, TYPE in rffi_platform.configure(config).iteritems():
            if name in TYPES:
                TYPES[name].become(TYPE)
예제 #37
0
파일: api.py 프로젝트: charred/pypy
    validate_fd(fileno(fp))
    return _feof(fp)


constant_names = """
Py_TPFLAGS_READY Py_TPFLAGS_READYING Py_TPFLAGS_HAVE_GETCHARBUFFER
METH_COEXIST METH_STATIC METH_CLASS
METH_NOARGS METH_VARARGS METH_KEYWORDS METH_O
Py_TPFLAGS_HEAPTYPE Py_TPFLAGS_HAVE_CLASS
Py_LT Py_LE Py_EQ Py_NE Py_GT Py_GE
""".split()
for name in constant_names:
    setattr(CConfig_constants, name, rffi_platform.ConstantInteger(name))
udir.join('pypy_decl.h').write("/* Will be filled later */\n")
udir.join('pypy_macros.h').write("/* Will be filled later */\n")
globals().update(rffi_platform.configure(CConfig_constants))

def copy_header_files(dstdir):
    assert dstdir.check(dir=True)
    headers = include_dir.listdir('*.h') + include_dir.listdir('*.inl')
    for name in ("pypy_decl.h", "pypy_macros.h"):
        headers.append(udir.join(name))
    for header in headers:
        target = dstdir.join(header.basename)
        try:
            header.copy(dstdir)
        except py.error.EACCES:
            target.remove()   # maybe it was a read-only file
            header.copy(dstdir)
        target.chmod(0444) # make the file read-only, to make sure that nobody
                           # edits it by mistake
예제 #38
0
파일: api.py 프로젝트: juokaz/pypy
def configure_types():
    for config in (CConfig, CConfig2):
        for name, TYPE in rffi_platform.configure(config).iteritems():
            if name in TYPES:
                TYPES[name].become(TYPE)
예제 #39
0
파일: timelib.py 프로젝트: LewisGet/hippyvm
        ("tm_mon", rffi.INT),
        ("tm_year", rffi.INT),
        ("tm_wday", rffi.INT),
        ("tm_yday", rffi.INT),
        ("tm_isdst", rffi.INT),
        ("tm_gmtoff", rffi.LONG),
        ("tm_zone", rffi.CCHARP)])

    timeval = platform.Struct("struct timeval", [
        ("tv_sec", rffi.INT),
        ("tv_usec", rffi.INT)
    ])

    _compilation_info_ = eci

conf = platform.configure(CConfig)

tzinfo = rffi.CArrayPtr(conf['ttinfo'])
tm = conf['tm']
tmP = lltype.Ptr(tm)
timeval = conf['timeval']
timevalP = lltype.Ptr(timeval)

c_strftime = external('strftime',
                      [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, tmP],
                      rffi.SIZE_T)

c_gettimeofday = external('gettimeofday', [rffi.VOIDP, rffi.VOIDP], rffi.INT)

class CConfig(object):
    timelib_special = platform.Struct('timelib_special', [
예제 #40
0
파일: api.py 프로젝트: juokaz/pypy
def is_valid_fp(fp):
    return is_valid_fd(fileno(fp))

constant_names = """
Py_TPFLAGS_READY Py_TPFLAGS_READYING Py_TPFLAGS_HAVE_GETCHARBUFFER
METH_COEXIST METH_STATIC METH_CLASS
METH_NOARGS METH_VARARGS METH_KEYWORDS METH_O
Py_TPFLAGS_HEAPTYPE Py_TPFLAGS_HAVE_CLASS
Py_LT Py_LE Py_EQ Py_NE Py_GT Py_GE
""".split()
for name in constant_names:
    setattr(CConfig_constants, name, rffi_platform.ConstantInteger(name))
udir.join('pypy_decl.h').write("/* Will be filled later */\n")
udir.join('pypy_macros.h').write("/* Will be filled later */\n")
globals().update(rffi_platform.configure(CConfig_constants))

def _copy_header_files(headers, dstdir):
    for header in headers:
        target = dstdir.join(header.basename)
        try:
            header.copy(dstdir)
        except py.error.EACCES:
            target.remove()   # maybe it was a read-only file
            header.copy(dstdir)
        target.chmod(0444) # make the file read-only, to make sure that nobody
                           # edits it by mistake

def copy_header_files(dstdir):
    # XXX: 20 lines of code to recursively copy a directory, really??
    assert dstdir.check(dir=True)
예제 #41
0
파일: rtime.py 프로젝트: sczfaker/pypy
    return rffi.llexternal(name,
                           args,
                           result,
                           compilation_info=compilation_info,
                           **kwds)


def replace_time_function(name):
    func = getattr(pytime, name, None)
    if func is None:
        return lambda f: f
    return register_replacement_for(func,
                                    sandboxed_name='ll_time.ll_time_%s' % name)


config = rffi_platform.configure(CConfig)
globals().update(config)

# Note: time.time() is used by the framework GC during collect(),
# which means that we have to be very careful about not allocating
# GC memory here.  This is the reason for the _nowrapper=True.
if HAVE_GETTIMEOFDAY:
    if GETTIMEOFDAY_NO_TZ:
        c_gettimeofday = external('gettimeofday', [lltype.Ptr(TIMEVAL)],
                                  rffi.INT,
                                  _nowrapper=True,
                                  releasegil=False)
    else:
        c_gettimeofday = external('gettimeofday',
                                  [lltype.Ptr(TIMEVAL), rffi.VOIDP],
                                  rffi.INT,
예제 #42
0
translator_c_dir = py.path.local(cdir)

eci = ExternalCompilationInfo(
    includes = ['src/thread.h'],
    separate_module_files = [translator_c_dir / 'src' / 'thread.c'],
    include_dirs = [translator_c_dir],
)

class CConfig:
    _compilation_info_ = eci
    RPYTHREAD_NAME = rffi_platform.DefinedConstantString('RPYTHREAD_NAME')
    USE_SEMAPHORES = rffi_platform.Defined('USE_SEMAPHORES')
    CS_GNU_LIBPTHREAD_VERSION = rffi_platform.DefinedConstantInteger(
        '_CS_GNU_LIBPTHREAD_VERSION')
cconfig = rffi_platform.configure(CConfig)
globals().update(cconfig)


def llexternal(name, args, result, **kwds):
    kwds.setdefault('sandboxsafe', True)
    return rffi.llexternal(name, args, result, compilation_info=eci,
                           **kwds)

@not_rpython
def _emulated_start_new_thread(func):
    import thread
    try:
        ident = thread.start_new_thread(func, ())
    except thread.error:
        ident = -1
예제 #43
0
파일: ropenssl.py 프로젝트: GaussDing/pypy
stack_st_X509_OBJECT = rffi.COpaquePtr("STACK_OF(X509_OBJECT)")
DIST_POINT = rffi.COpaquePtr("DIST_POINT")
stack_st_DIST_POINT = rffi.COpaquePtr("STACK_OF(X509_OBJECT)")
DH = rffi.COpaquePtr("DH")
EC_KEY = rffi.COpaquePtr("EC_KEY")
AUTHORITY_INFO_ACCESS = rffi.COpaquePtr("AUTHORITY_INFO_ACCESS")
GENERAL_NAME = lltype.Ptr(lltype.ForwardReference())


class CConfigBootstrap:
    _compilation_info_ = eci
    OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined("OPENSSL_EXPORT_VAR_AS_FUNCTION")
    OPENSSL_VERSION_NUMBER = rffi_platform.ConstantInteger("OPENSSL_VERSION_NUMBER")


cconfig = rffi_platform.configure(CConfigBootstrap)
if cconfig["OPENSSL_EXPORT_VAR_AS_FUNCTION"]:
    ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
else:
    ASN1_ITEM_EXP = ASN1_ITEM
OPENSSL_VERSION_NUMBER = cconfig["OPENSSL_VERSION_NUMBER"]


class CConfig:
    _compilation_info_ = eci

    SSLEAY_VERSION = rffi_platform.DefinedConstantString("SSLEAY_VERSION", "SSLeay_version(SSLEAY_VERSION)")
    OPENSSL_NO_SSL2 = rffi_platform.Defined("OPENSSL_NO_SSL2")
    OPENSSL_NO_SSL3 = rffi_platform.Defined("OPENSSL_NO_SSL3")
    OPENSSL_NO_ECDH = rffi_platform.Defined("OPENSSL_NO_ECDH")
    OPENSSL_NPN_NEGOTIATED = rffi_platform.Defined("OPENSSL_NPN_NEGOTIATED")
예제 #44
0
            ('iMaxSockets', rffi.USHORT),
            ('iMaxUdpDg', rffi.USHORT),
            ('lpVendorInfo', CCHARP)
        ])

    CConfig.tcp_keepalive = platform.Struct(
        'struct tcp_keepalive', [('onoff', rffi.ULONG),
                                 ('keepalivetime', rffi.ULONG),
                                 ('keepaliveinterval', rffi.ULONG)])


class cConfig:
    pass


cConfig.__dict__.update(platform.configure(CConfig))

sockaddr_ptr.TO.become(cConfig.sockaddr)
addrinfo_ptr.TO.become(cConfig.addrinfo)

# fill in missing constants with reasonable defaults
cConfig.NI_MAXHOST = cConfig.NI_MAXHOST or 1025
cConfig.NI_MAXSERV = cConfig.NI_MAXSERV or 32
cConfig.INET_ADDRSTRLEN = cConfig.INET_ADDRSTRLEN or 16

for name in constant_names:
    value = getattr(cConfig, name)
    if value is not None:
        constants[name] = value
for name, default in constants_w_defaults:
    value = getattr(cConfig, name)
예제 #45
0
eci = rffi_platform.configure_external_library('openssl', eci, [
    dict(prefix='openssl-', include_dir='inc32', library_dir='out32'),
])

ASN1_STRING = lltype.Ptr(lltype.ForwardReference())
ASN1_ITEM = rffi.COpaquePtr('ASN1_ITEM')
X509_NAME = rffi.COpaquePtr('X509_NAME')


class CConfigBootstrap:
    _compilation_info_ = eci
    OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
        "OPENSSL_EXPORT_VAR_AS_FUNCTION")


if rffi_platform.configure(CConfigBootstrap)["OPENSSL_EXPORT_VAR_AS_FUNCTION"]:
    ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
else:
    ASN1_ITEM_EXP = ASN1_ITEM


class CConfig:
    _compilation_info_ = eci

    OPENSSL_VERSION_NUMBER = rffi_platform.ConstantInteger(
        "OPENSSL_VERSION_NUMBER")
    SSLEAY_VERSION = rffi_platform.DefinedConstantString(
        "SSLEAY_VERSION", "SSLeay_version(SSLEAY_VERSION)")
    OPENSSL_NO_SSL2 = rffi_platform.Defined("OPENSSL_NO_SSL2")
    OPENSSL_NO_SSL3 = rffi_platform.Defined("OPENSSL_NO_SSL3")
    SSL_FILETYPE_PEM = rffi_platform.ConstantInteger("SSL_FILETYPE_PEM")
예제 #46
0
파일: rzlib.py 프로젝트: charred/pypy
    """
    _compilation_info_ = eci

    # XXX If Z_PREFIX was defined for the libz build, then these types are
    # named z_uInt, z_uLong, and z_Bytef instead.
    uInt = rffi_platform.SimpleType('uInt', rffi.UINT)
    uLong = rffi_platform.SimpleType('uLong', rffi.ULONG)
    Bytef = rffi_platform.SimpleType('Bytef', rffi.UCHAR)
    voidpf = rffi_platform.SimpleType('voidpf', rffi.VOIDP)

    ZLIB_VERSION = rffi_platform.DefinedConstantString('ZLIB_VERSION')

for _name in constantnames:
    setattr(SimpleCConfig, _name, rffi_platform.ConstantInteger(_name))

config = rffi_platform.configure(SimpleCConfig)
voidpf = config['voidpf']
uInt = config['uInt']
uLong = config['uLong']
Bytef = config['Bytef']
Bytefp = lltype.Ptr(lltype.Array(Bytef, hints={'nolength': True}))

ZLIB_VERSION = config['ZLIB_VERSION']

for _name in constantnames:
    globals()[_name] = config[_name]

# The following parameter is copied from zutil.h, version 0.95,
# according to CPython's zlibmodule.c
DEFLATED = Z_DEFLATED
if MAX_MEM_LEVEL >= 8:
예제 #47
0
    "ERPCMISMATCH",
    "ESHLIBVERS"
]

includes = ['errno.h']
if sys.platform == 'win32':
    includes.append('winsock2.h')


class CConfig:
    _compilation_info_ = ExternalCompilationInfo(includes=includes)


for err_name in errors + win_errors + more_errors:
    setattr(CConfig, err_name, DefinedConstantInteger(err_name))
config = configure(CConfig)

errorcode = {}
name2code = {}
for err_name in errors:
    # Note: later names take precedence over earlier ones, if they have the
    # same value
    code = config[err_name]
    if code is not None:
        errorcode[code] = err_name
        name2code[err_name] = code
for name in win_errors:
    assert name.startswith('WSA')
    code = config[name]
    if code is not None:
        if name[3:] in errors and name[3:] not in name2code:
예제 #48
0
파일: rtime.py 프로젝트: mozillazg/pypy
            float(rffi.getintfield(t, 'c_tv_usec')) * 0.000001)


def external(name, args, result, compilation_info=eci, **kwds):
    return rffi.llexternal(name, args, result,
                           compilation_info=compilation_info, **kwds)

def replace_time_function(name):
    func = getattr(pytime, name, None)
    if func is None:
        return lambda f: f
    return register_replacement_for(
        func,
        sandboxed_name='ll_time.ll_time_%s' % name)

config = rffi_platform.configure(CConfig)
globals().update(config)

# Note: time.time() is used by the framework GC during collect(),
# which means that we have to be very careful about not allocating
# GC memory here.  This is the reason for the _nowrapper=True.
if HAVE_GETTIMEOFDAY:
    if GETTIMEOFDAY_NO_TZ:
        c_gettimeofday = external('gettimeofday',
                                  [lltype.Ptr(TIMEVAL)], rffi.INT,
                                  _nowrapper=True, releasegil=False)
    else:
        c_gettimeofday = external('gettimeofday',
                                  [lltype.Ptr(TIMEVAL), rffi.VOIDP], rffi.INT,
                                  _nowrapper=True, releasegil=False)
if HAVE_FTIME:
예제 #49
0
def make_win32_traits(traits):
    from rpython.rlib import rwin32

    if traits.str is unicode:
        suffix = 'W'
    else:
        suffix = 'A'

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            includes = ['windows.h', 'winbase.h', 'sys/stat.h'],
        )
        WIN32_FIND_DATA = platform.Struct(
            'struct _WIN32_FIND_DATA' + suffix,
            # Only interesting fields
            [('dwFileAttributes', rwin32.DWORD),
             ('nFileSizeHigh', rwin32.DWORD),
             ('nFileSizeLow', rwin32.DWORD),
             ('ftCreationTime', rwin32.FILETIME),
             ('ftLastAccessTime', rwin32.FILETIME),
             ('ftLastWriteTime', rwin32.FILETIME),
             ('cFileName', lltype.FixedSizeArray(traits.CHAR, 250))])
        ERROR_FILE_NOT_FOUND = platform.ConstantInteger(
            'ERROR_FILE_NOT_FOUND')
        ERROR_NO_MORE_FILES = platform.ConstantInteger(
            'ERROR_NO_MORE_FILES')

        GetFileExInfoStandard = platform.ConstantInteger(
            'GetFileExInfoStandard')
        FILE_ATTRIBUTE_DIRECTORY = platform.ConstantInteger(
            'FILE_ATTRIBUTE_DIRECTORY')
        FILE_ATTRIBUTE_READONLY = platform.ConstantInteger(
            'FILE_ATTRIBUTE_READONLY')
        INVALID_FILE_ATTRIBUTES = platform.ConstantInteger(
            'INVALID_FILE_ATTRIBUTES')
        ERROR_SHARING_VIOLATION = platform.ConstantInteger(
            'ERROR_SHARING_VIOLATION')
        _S_IFDIR = platform.ConstantInteger('_S_IFDIR')
        _S_IFREG = platform.ConstantInteger('_S_IFREG')
        _S_IFCHR = platform.ConstantInteger('_S_IFCHR')
        _S_IFIFO = platform.ConstantInteger('_S_IFIFO')
        FILE_TYPE_UNKNOWN = platform.ConstantInteger('FILE_TYPE_UNKNOWN')
        FILE_TYPE_CHAR = platform.ConstantInteger('FILE_TYPE_CHAR')
        FILE_TYPE_PIPE = platform.ConstantInteger('FILE_TYPE_PIPE')

        WIN32_FILE_ATTRIBUTE_DATA = platform.Struct(
            'WIN32_FILE_ATTRIBUTE_DATA',
            [('dwFileAttributes', rwin32.DWORD),
             ('nFileSizeHigh', rwin32.DWORD),
             ('nFileSizeLow', rwin32.DWORD),
             ('ftCreationTime', rwin32.FILETIME),
             ('ftLastAccessTime', rwin32.FILETIME),
             ('ftLastWriteTime', rwin32.FILETIME)])

        BY_HANDLE_FILE_INFORMATION = platform.Struct(
            'BY_HANDLE_FILE_INFORMATION',
            [('dwFileAttributes', rwin32.DWORD),
             ('nFileSizeHigh', rwin32.DWORD),
             ('nFileSizeLow', rwin32.DWORD),
             ('nNumberOfLinks', rwin32.DWORD),
             ('nFileIndexHigh', rwin32.DWORD),
             ('nFileIndexLow', rwin32.DWORD),
             ('ftCreationTime', rwin32.FILETIME),
             ('ftLastAccessTime', rwin32.FILETIME),
             ('ftLastWriteTime', rwin32.FILETIME)])

    config = platform.configure(CConfig)

    def external(*args, **kwargs):
        kwargs['compilation_info'] = CConfig._compilation_info_
        llfunc = rffi.llexternal(calling_conv='win', *args, **kwargs)
        return staticmethod(llfunc)

    class Win32Traits:
        apisuffix = suffix

        for name in '''WIN32_FIND_DATA WIN32_FILE_ATTRIBUTE_DATA BY_HANDLE_FILE_INFORMATION
                       GetFileExInfoStandard
                       FILE_ATTRIBUTE_DIRECTORY FILE_ATTRIBUTE_READONLY
                       INVALID_FILE_ATTRIBUTES
                       _S_IFDIR _S_IFREG _S_IFCHR _S_IFIFO
                       FILE_TYPE_UNKNOWN FILE_TYPE_CHAR FILE_TYPE_PIPE
                       ERROR_FILE_NOT_FOUND ERROR_NO_MORE_FILES
                       ERROR_SHARING_VIOLATION
                    '''.split():
            locals()[name] = config[name]
        LPWIN32_FIND_DATA    = lltype.Ptr(WIN32_FIND_DATA)
        GET_FILEEX_INFO_LEVELS = rffi.ULONG # an enumeration

        FindFirstFile = external('FindFirstFile' + suffix,
                                 [traits.CCHARP, LPWIN32_FIND_DATA],
                                 rwin32.HANDLE)
        FindNextFile = external('FindNextFile' + suffix,
                                [rwin32.HANDLE, LPWIN32_FIND_DATA],
                                rwin32.BOOL)
        FindClose = external('FindClose',
                             [rwin32.HANDLE],
                             rwin32.BOOL)

        GetFileAttributes = external(
            'GetFileAttributes' + suffix,
            [traits.CCHARP],
            rwin32.DWORD)

        SetFileAttributes = external(
            'SetFileAttributes' + suffix,
            [traits.CCHARP, rwin32.DWORD],
            rwin32.BOOL)

        GetFileAttributesEx = external(
            'GetFileAttributesEx' + suffix,
            [traits.CCHARP, GET_FILEEX_INFO_LEVELS,
             lltype.Ptr(WIN32_FILE_ATTRIBUTE_DATA)],
            rwin32.BOOL)

        GetFileInformationByHandle = external(
            'GetFileInformationByHandle',
            [rwin32.HANDLE, lltype.Ptr(BY_HANDLE_FILE_INFORMATION)],
            rwin32.BOOL)

        GetFileType = external(
            'GetFileType',
            [rwin32.HANDLE],
            rwin32.DWORD)

        LPSTRP = rffi.CArrayPtr(traits.CCHARP)

        GetFullPathName = external(
            'GetFullPathName' + suffix,
            [traits.CCHARP, rwin32.DWORD,
             traits.CCHARP, LPSTRP],
            rwin32.DWORD)

        GetCurrentDirectory = external(
            'GetCurrentDirectory' + suffix,
            [rwin32.DWORD, traits.CCHARP],
            rwin32.DWORD)

        SetCurrentDirectory = external(
            'SetCurrentDirectory' + suffix,
            [traits.CCHARP],
            rwin32.BOOL)

        CreateDirectory = external(
            'CreateDirectory' + suffix,
            [traits.CCHARP, rffi.VOIDP],
            rwin32.BOOL)

        SetEnvironmentVariable = external(
            'SetEnvironmentVariable' + suffix,
            [traits.CCHARP, traits.CCHARP],
            rwin32.BOOL)

        DeleteFile = external(
            'DeleteFile' + suffix,
            [traits.CCHARP],
            rwin32.BOOL)

        MoveFile = external(
            'MoveFile' + suffix,
            [traits.CCHARP, traits.CCHARP],
            rwin32.BOOL)

    return Win32Traits
예제 #50
0
                                      ('szDescription', rffi.CFixedArray(lltype.Char, 1)), # (WSADESCRIPTION_LEN+1)
                                      ('szSystemStatus', rffi.CFixedArray(lltype.Char, 1)), # (WSASYS_STATUS_LEN+1)
                                      ('iMaxSockets', rffi.USHORT),
                                      ('iMaxUdpDg', rffi.USHORT),
                                      ('lpVendorInfo', CCHARP)])

    CConfig.tcp_keepalive = platform.Struct(
        'struct tcp_keepalive',
        [('onoff', rffi.ULONG),
         ('keepalivetime', rffi.ULONG),
         ('keepaliveinterval', rffi.ULONG)])


class cConfig:
    pass
cConfig.__dict__.update(platform.configure(CConfig))

sockaddr_ptr.TO.become(cConfig.sockaddr)
addrinfo_ptr.TO.become(cConfig.addrinfo)

# fill in missing constants with reasonable defaults
cConfig.NI_MAXHOST = cConfig.NI_MAXHOST or 1025
cConfig.NI_MAXSERV = cConfig.NI_MAXSERV or 32
cConfig.INET_ADDRSTRLEN = cConfig.INET_ADDRSTRLEN or 16

for name in constant_names:
    value = getattr(cConfig, name)
    if value is not None:
        constants[name] = value
for name, default in constants_w_defaults:
    value = getattr(cConfig, name)
예제 #51
0
    INCLUDES = ["sys/types.h", "sys/stat.h", "sys/statvfs.h", "unistd.h"]

compilation_info = ExternalCompilationInfo(
    # This must be set to 64 on some systems to enable large file support.
    # pre_include_bits = ['#define _FILE_OFFSET_BITS 64'],
    # ^^^ nowadays it's always set in all C files we produce.
    includes=INCLUDES
)

if TIMESPEC is not None:

    class CConfig_for_timespec:
        _compilation_info_ = compilation_info
        TIMESPEC = TIMESPEC

    TIMESPEC = lltype.Ptr(platform.configure(CConfig_for_timespec)["TIMESPEC"])


def posix_declaration(try_to_add=None):
    global STAT_STRUCT, STATVFS_STRUCT

    LL_STAT_FIELDS = STAT_FIELDS[:]
    if try_to_add:
        LL_STAT_FIELDS.append(try_to_add)

    if TIMESPEC is not None:

        def _expand(lst, originalname, timespecname):
            for i, (_name, _TYPE) in enumerate(lst):
                if _name == originalname:
                    # replace the 'st_atime' field of type rffi.DOUBLE
예제 #52
0
파일: ropenssl.py 프로젝트: yuyichao/pypy
# WinSock does not use a bitmask in select, and uses
# socket handles greater than FD_SETSIZE
if sys.platform == 'win32':
    MAX_FD_SIZE = None
else:
    from rpython.rlib._rsocket_rffi import FD_SETSIZE as MAX_FD_SIZE

ASN1_STRING = lltype.Ptr(lltype.ForwardReference())
ASN1_ITEM = rffi.COpaquePtr('ASN1_ITEM')
X509_NAME = rffi.COpaquePtr('X509_NAME')

class CConfigBootstrap:
    _compilation_info_ = eci
    OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
            "OPENSSL_EXPORT_VAR_AS_FUNCTION")
if rffi_platform.configure(CConfigBootstrap)["OPENSSL_EXPORT_VAR_AS_FUNCTION"]:
    ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
else:
    ASN1_ITEM_EXP = ASN1_ITEM

class CConfig:
    _compilation_info_ = eci

    OPENSSL_VERSION_NUMBER = rffi_platform.ConstantInteger(
        "OPENSSL_VERSION_NUMBER")
    SSLEAY_VERSION = rffi_platform.DefinedConstantString(
        "SSLEAY_VERSION", "SSLeay_version(SSLEAY_VERSION)")
    OPENSSL_NO_SSL2 = rffi_platform.Defined("OPENSSL_NO_SSL2")
    SSL_FILETYPE_PEM = rffi_platform.ConstantInteger("SSL_FILETYPE_PEM")
    SSL_OP_ALL = rffi_platform.ConstantInteger("SSL_OP_ALL")
    SSL_OP_NO_SSLv2 = rffi_platform.ConstantInteger("SSL_OP_NO_SSLv2")
예제 #53
0
파일: rpwd.py 프로젝트: cklein/hippyvm
    passwd = platform.Struct('struct passwd',
                             [('pw_name', rffi.CCHARP),
                              ('pw_passwd', rffi.CCHARP),
                              ('pw_uid', lltype.Signed),
                              ('pw_gid', lltype.Signed),
                              ('pw_gecos', rffi.CCHARP),
                              ('pw_dir', rffi.CCHARP),
                              ('pw_shell', rffi.CCHARP)])

    group = platform.Struct('struct group',
                            [('gr_name', rffi.CCHARP),
                             ('gr_passwd', rffi.CCHARP),
                             ('gr_gid', lltype.Signed),
                             ('gr_mem', rffi.CCHARPP)])

PASSWD = platform.configure(CConfig)['passwd']
PASSWDPTR = lltype.Ptr(PASSWD)
GROUP =  platform.configure(CConfig)['group']
GROUPPTR = lltype.Ptr(GROUP)

getpwnam = rffi.llexternal('getpwnam', [rffi.CCHARP], PASSWDPTR,
                           compilation_info=eci)
getpwuid = rffi.llexternal('getpwuid', [lltype.Signed], PASSWDPTR,
                           compilation_info=eci)
initgroups = rffi.llexternal('initgroups', [rffi.CCHARP, lltype.Signed],
                             rffi.INT, compilation_info=eci)
getgrgid = rffi.llexternal('getgrgid', [lltype.Signed], GROUPPTR,
                           compilation_info=eci)
getgrnam = rffi.llexternal('getgrnam', [rffi.CCHARP], GROUPPTR,
                           compilation_info=eci)
예제 #54
0
파일: rtermios.py 프로젝트: cimarieta/usp
       TIOCGSERIAL TIOCGSOFTCAR TIOCGWINSZ TIOCINQ TIOCLINUX TIOCMBIC
       TIOCMBIS TIOCMGET TIOCMIWAIT TIOCMSET TIOCM_CAR TIOCM_CD TIOCM_CTS 
       TIOCM_DSR TIOCM_DTR TIOCM_LE TIOCM_RI TIOCM_RNG TIOCM_RTS TIOCM_SR
       TIOCM_ST TIOCNOTTY TIOCNXCL TIOCOUTQ TIOCPKT TIOCPKT_DATA
       TIOCPKT_DOSTOP TIOCPKT_FLUSHREAD TIOCPKT_FLUSHWRITE TIOCPKT_NOSTOP
       TIOCPKT_START TIOCPKT_STOP TIOCSCTTY TIOCSERCONFIG TIOCSERGETLSR 
       TIOCSERGETMULTI TIOCSERGSTRUCT TIOCSERGWILD TIOCSERSETMULTI
       TIOCSERSWILD TIOCSER_TEMT TIOCSETD TIOCSLCKTRMIOS TIOCSPGRP
       TIOCSSERIAL TIOCSSOFTCAR TIOCSTI TIOCSWINSZ TIOCTTYGSTRUCT
    """
).split()

for name in CONSTANT_NAMES:
    setattr(CConfig, name, rffi_platform.DefinedConstantInteger(name))

c_config = rffi_platform.configure(CConfig)

# Copy VSWTCH to VSWTC and vice-versa
if c_config["VSWTC"] is None:
    c_config["VSWTC"] = c_config["VSWTCH"]
if c_config["VSWTCH"] is None:
    c_config["VSWTCH"] = c_config["VSWTC"]

all_constants = {}
for name in CONSTANT_NAMES:
    value = c_config[name]
    if value is not None:
        if value < -sys.maxsize - 1 or value >= 2 * (sys.maxsize + 1):
            raise AssertionError("termios: %r has value %r, too large" % (name, value))
        value = intmask(value)  # wrap unsigned long numbers to signed longs
        globals()[name] = value
예제 #55
0
파일: _pcre.py 프로젝트: LegendZhu/hippyvm
PCRE_NO_UTF8_CHECK
PCRE_ERROR_NOMATCH PCRE_ERROR_MATCHLIMIT PCRE_ERROR_RECURSIONLIMIT
PCRE_ERROR_BADUTF8 PCRE_ERROR_BADUTF8_OFFSET
PCRE_INFO_CAPTURECOUNT PCRE_INFO_NAMECOUNT PCRE_INFO_NAMETABLE
PCRE_INFO_NAMEENTRYSIZE
'''.split():
    setattr(CConfig, _name, platform.ConstantInteger(_name))

# list of all integer constants that are optional

for _name in '''
PCRE_UCP
'''.split():
    setattr(CConfig, _name, platform.DefinedConstantInteger(_name))

globals().update(platform.configure(CConfig))

# ____________________________________________________________

CCHARPPP = lltype.Ptr(lltype.Array(rffi.CCHARPP, hints={'nolength': True}))

pcre = rffi.CStruct('pcre')

pcre_compile = llexternal('pcre_compile',
                          [rffi.CCHARP, rffi.INT,
                           rffi.CCHARPP, rffi.INTP,
                           rffi.CCHARP],
                          lltype.Ptr(pcre), releasegil=False)

pcre_exec = llexternal('pcre_exec',
                       [lltype.Ptr(pcre), lltype.Ptr(pcre_extra),
예제 #56
0
])

RegexList = rffi_platform.Struct('RegexList', [
    ('count', rffi.ULONGLONG),
    ('regex', rffi.VOIDP),
])


class Config:
    _compilation_info_ = eci
    regex_transition = RegexTransition
    regex = Regex
    regex_list = RegexList


config = rffi_platform.configure(Config())


def run_machine(machine, input_data):
    token_id, init_state, transitions = machine
    current_state = init_state

    for char in input_data:
        places_to_go_next = transitions.get(current_state, {})
        if char not in places_to_go_next:
            return RESULT_FAIL
        current_state = places_to_go_next[char]

    what_left = transitions.get(current_state, {})

    next_state = what_left.get(chr(0), INVALID_NEXT_STATE)
예제 #57
0
파일: c_bzip2.py 프로젝트: youaani/hippyvm
    'bzlib.h',
],
                              include_dirs=['/usr/include/'],
                              library_dirs=[
                                  '/usr/lib/x86_64-linux-gnu/',
                              ],
                              libraries=['bz2'])


class CConfig:
    _compilation_info_ = eci
    BZ_OK = platform.DefinedConstantInteger('BZ_OK')
    BZ_STREAM_END = platform.DefinedConstantInteger('BZ_STREAM_END')


globals().update(platform.configure(CConfig))


def external(name, args, result):
    return rffi.llexternal(name, args, result, compilation_info=eci)


BZFILEPTR = rffi.VOIDP
FILEP = rffi.COpaquePtr('FILE')

c_bz_read_open = external(
    'BZ2_bzReadOpen',
    [rffi.INTP, FILEP, rffi.INT, rffi.INT, rffi.VOIDP, rffi.INT], BZFILEPTR)

c_bz_read_close = external('BZ2_bzReadClose', [rffi.INTP, BZFILEPTR],
                           lltype.Void)
예제 #58
0
def setup():
    INSPECT = {'b': 'signed char',
               'h': 'signed short',
               'i': 'signed int',
               'l': 'signed long',
               'q': 'signed long long',
               'B': 'unsigned char',
               'H': 'unsigned short',
               'I': 'unsigned int',
               'L': 'unsigned long',
               'Q': 'unsigned long long',
               'P': 'char *',
               'f': 'float',
               'd': 'double',
               '?': '_Bool',
               }

    pre_include_bits = ["""
        #ifdef _MSC_VER
        #define _Bool char
        #endif"""]
    field_names = dict.fromkeys(INSPECT)
    for fmtchar, ctype in INSPECT.iteritems():
        field_name = ctype.replace(" ", "_").replace("*", "star")
        field_names[fmtchar] = field_name
        pre_include_bits.append("""
            struct about_%s {
                char pad;
                %s field;
            };
        """ % (field_name, ctype))

    class CConfig:
        _compilation_info_ = ExternalCompilationInfo(
            pre_include_bits = pre_include_bits
        )

    for fmtchar, ctype in INSPECT.items():
        setattr(CConfig, field_names[fmtchar], rffi_platform.Struct(
            "struct about_%s" % (field_names[fmtchar],),
            [('field', lltype.FixedSizeArray(rffi.CHAR, 1))]))

    cConfig = rffi_platform.configure(CConfig)

    for fmtchar, ctype in INSPECT.items():
        S = cConfig[field_names[fmtchar]]
        alignment = rffi.offsetof(S, 'c_field')
        size = rffi.sizeof(S.c_field)
        signed = 'a' <= fmtchar <= 'z'

        if fmtchar == 'f':
            pack = pack_float
            unpack = unpack_float
        elif fmtchar == 'd':
            pack = pack_double
            unpack = unpack_double
        elif fmtchar == '?':
            pack = std.pack_bool
            unpack = std.unpack_bool
        else:
            pack = std.make_int_packer(size, signed, True)
            unpack = std.make_int_unpacker(size, signed)

        native_fmttable[fmtchar] = {'size': size,
                                    'alignment': alignment,
                                    'pack': pack,
                                    'unpack': unpack}
예제 #59
0
FILE = rffi.COpaquePtr('FILE')
BZFILE = rffi.COpaquePtr('BZFILE')


constants = {}
constant_names = ['BZ_RUN', 'BZ_FLUSH', 'BZ_FINISH', 'BZ_OK',
    'BZ_RUN_OK', 'BZ_FLUSH_OK', 'BZ_FINISH_OK', 'BZ_STREAM_END',
    'BZ_SEQUENCE_ERROR', 'BZ_PARAM_ERROR', 'BZ_MEM_ERROR', 'BZ_DATA_ERROR',
    'BZ_DATA_ERROR_MAGIC', 'BZ_IO_ERROR', 'BZ_UNEXPECTED_EOF',
    'BZ_OUTBUFF_FULL', 'BZ_CONFIG_ERROR']
for name in constant_names:
    setattr(CConfig, name, platform.DefinedConstantInteger(name))

class cConfig(object):
    pass
for k, v in platform.configure(CConfig).items():
    setattr(cConfig, k, v)
if not cConfig.CHECK_LIBRARY:
    raise ImportError("Invalid bz2 library")

for name in constant_names:
    value = getattr(cConfig, name)
    if value is not None:
        constants[name] = value
locals().update(constants)

off_t = cConfig.off_t
bz_stream = lltype.Ptr(cConfig.bz_stream)
BUFSIZ = cConfig.BUFSIZ
SEEK_SET = cConfig.SEEK_SET
BZ_OK = cConfig.BZ_OK
예제 #60
0
파일: fcntl.py 프로젝트: topazproject/topaz
from rpython.rtyper.tool import rffi_platform

from topaz.module import ModuleDef
from topaz.system import IS_WINDOWS


if not IS_WINDOWS:
    class CConstants(object):
        _compilation_info_ = ExternalCompilationInfo(includes=['fcntl.h'])
    for const in ["F_DUPFD", "F_GETFD", "F_GETLK", "F_SETFD", "F_GETFL",
                  "F_SETFL", "F_SETLK", "F_SETLKW", "FD_CLOEXEC", "F_RDLCK",
                  "F_UNLCK", "F_WRLCK", "O_CREAT", "O_EXCL", "O_NOCTTY",
                  "O_TRUNC", "O_APPEND", "O_NONBLOCK", "O_NDELAY", "O_RDONLY",
                  "O_RDWR", "O_WRONLY", "O_ACCMODE"]:
        setattr(CConstants, const, rffi_platform.ConstantInteger(const))
    fcntl_constants = rffi_platform.configure(CConstants)
    fcntl = _rsocket_rffi.fcntl
else:
    fcntl_constants = {}

    def fcntl(fdtype, cmd, arg):
        raise NotImplementedError


class Fcntl(object):
    moduledef = ModuleDef("Fcntl")

    @moduledef.setup_module
    def setup_module(space, w_mod):
        if not IS_WINDOWS:
            for key, value in fcntl_constants.items():