예제 #1
0
    class ComplexCConfig:
        _compilation_info_ = CConfig._compilation_info_

        SYSINFO_STRUCT = rffi.CStruct(
            'SYSINFO_STRUCT',
            ("wProcessorArchitecture", WORD),
            ("wReserved", WORD),
        )

        SYSINFO_UNION = rffi.CStruct(
            'union SYSINFO_UNION',
            ("dwOemId", DWORD),
            ("_struct_", SYSINFO_STRUCT),
        )
        # sorry, I can't find a way to insert the above
        # because the union field has no name
        SYSTEM_INFO = rffi_platform.Struct(
            'SYSTEM_INFO',
            [
                ## ("_union_", SYSINFO_UNION),
                ## instead, we put the smaller fields, here
                ("wProcessorArchitecture", WORD),
                ("wReserved", WORD),
                ## should be a union. dwOemId is obsolete, anyway
                ("dwPageSize", DWORD),
                ("lpMinimumApplicationAddress", LPVOID),
                ("lpMaximumApplicationAddress", LPVOID),
                ("dwActiveProcessorMask", DWORD_PTR),
                ("dwNumberOfProcessors", DWORD),
                ("dwProcessorType", DWORD),
                ("dwAllocationGranularity", DWORD),
                ("wProcessorLevel", WORD),
                ("wProcessorRevision", WORD),
            ])
예제 #2
0
    def build_result(self, info, config_result):
        if self.ifdef is not None:
            if not info['defined']:
                return None
        layout = [None] * info['size']
        for fieldname, fieldtype in self.interesting_fields:
            if isinstance(fieldtype, Struct):
                offset = info['fldofs ' + fieldname]
                size = info['fldsize ' + fieldname]
                c_fieldtype = config_result.get_entry_result(fieldtype)
                layout_addfield(layout, offset, c_fieldtype, fieldname)
            else:
                offset = info['fldofs ' + fieldname]
                size = info['fldsize ' + fieldname]
                sign = info.get('fldunsigned ' + fieldname, False)
                if (size, sign) != rffi.size_and_sign(fieldtype):
                    fieldtype = fixup_ctype(fieldtype, fieldname, (size, sign))
                layout_addfield(layout, offset, fieldtype, fieldname)

        n = 0
        padfields = []
        for i, cell in enumerate(layout):
            if cell is not None:
                continue
            name = '_pad%d' % (n, )
            layout_addfield(layout, i, rffi.UCHAR, name)
            padfields.append('c_' + name)
            n += 1

        # build the lltype Structure
        seen = {}
        fields = []
        fieldoffsets = []
        for offset, cell in enumerate(layout):
            if cell in seen:
                continue
            fields.append((cell.name, cell.ctype))
            fieldoffsets.append(offset)
            seen[cell] = True

        allfields = tuple(['c_' + name for name, _ in fields])
        padfields = tuple(padfields)
        name = self.name
        eci = config_result.CConfig._compilation_info_
        padding_drop = PaddingDrop(name, allfields, padfields, eci)
        hints = {
            'align': info['align'],
            'size': info['size'],
            'fieldoffsets': tuple(fieldoffsets),
            'padding': padfields,
            'get_padding_drop': padding_drop,
            'eci': eci
        }
        if name.startswith('struct '):
            name = name[7:]
        else:
            hints['typedef'] = True
        kwds = {'hints': hints}
        return rffi.CStruct(name, *fields, **kwds)
예제 #3
0
파일: cintf.py 프로젝트: soIu/rpython
    def __init__(self, namespace):
        for k, v in namespace.iteritems():
            setattr(self, k, v)

    def _freeze_(self):
        return True


# --- copy a few declarations from src/vmprof_stack.h ---

VMPROF_CODE_TAG = 1

VMPROFSTACK = lltype.ForwardReference()
PVMPROFSTACK = lltype.Ptr(VMPROFSTACK)
VMPROFSTACK.become(
    rffi.CStruct("vmprof_stack_s", ('next', PVMPROFSTACK),
                 ('value', lltype.Signed), ('kind', lltype.Signed)))
# ----------

vmprof_tl_stack = rthread.ThreadLocalField(PVMPROFSTACK, "vmprof_tl_stack")
do_use_eci = rffi.llexternal_use_eci(
    ExternalCompilationInfo(includes=['vmprof_stack.h'], include_dirs=[SRC]))


def enter_code(unique_id):
    do_use_eci()
    s = lltype.malloc(VMPROFSTACK, flavor='raw')
    s.c_next = vmprof_tl_stack.get_or_make_raw()
    s.c_value = unique_id
    s.c_kind = VMPROF_CODE_TAG
    vmprof_tl_stack.setraw(s)
    return s
예제 #4
0
    pre_include_bits=['#define _CFFI_INTERNAL'],
)


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


_CFFI_OPCODE_T = rffi.VOIDP
GLOBAL_S = rffi.CStruct('_cffi_global_s', ('name', rffi.CCHARP),
                        ('address', rffi.VOIDP), ('type_op', _CFFI_OPCODE_T),
                        ('size_or_direct_fn', rffi.CCHARP))
CDL_INTCONST_S = lltype.Struct('cdl_intconst_s', ('value', rffi.ULONGLONG),
                               ('neg', rffi.INT))
STRUCT_UNION_S = rffi.CStruct('_cffi_struct_union_s', ('name', rffi.CCHARP),
                              ('type_index', rffi.INT), ('flags', rffi.INT),
                              ('size', rffi.SIZE_T), ('alignment', rffi.INT),
                              ('first_field_index', rffi.INT),
                              ('num_fields', rffi.INT))
FIELD_S = rffi.CStruct('_cffi_field_s', ('name', rffi.CCHARP),
                       ('field_offset', rffi.SIZE_T),
                       ('field_size', rffi.SIZE_T),
                       ('field_type_op', _CFFI_OPCODE_T))
ENUM_S = rffi.CStruct('_cffi_enum_s', ('name', rffi.CCHARP),
                      ('type_index', rffi.INT), ('type_prim', rffi.INT),
                      ('enumerators', rffi.CCHARP))
예제 #5
0
파일: _pcre.py 프로젝트: netyum/hippyvm
    '''.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))

pcre_exec = llexternal('pcre_exec', [
    lltype.Ptr(pcre),
    lltype.Ptr(pcre_extra), rffi.CCHARP, rffi.INT, rffi.INT, rffi.INT,
    rffi.INTP, rffi.INT
], rffi.INT)

pcre_fullinfo = llexternal(
    'pcre_fullinfo',
    [lltype.Ptr(pcre),
예제 #6
0
eci = ExternalCompilationInfo(libraries=['testlib'],
                              library_dirs=[os.path.abspath('.')],#/testlib.so')],
                              includes=[os.path.abspath('./stdlib.h')])

external_function = rffi.llexternal('myprint', [], lltype.Void,
                                    compilation_info=eci)

# Note to self: UUID4 has some fixed bits
# struct.unpack('>qq', uuid.UUID(int=uuid.UUID(bytes=os.urandom(16)).int | (1 << 127)).bytes)
INTEGER = (-6855051840143784798, -7880198636693933229)
STRING = (-5744892467500213749, 739713154171887357)
DOUBLE = (-5419088552942547567, 806613043255133199)

TYPE_BFG_OBJECT = rffi.CStruct('bfg_object',
                               # ('GUID_high', rffi.ULONGLONG), # unneeded?
                               # ('GUID_low', rffi.ULONGLONG), # unneeded?
                               ('metadata', rffi.ULONGLONG),
                               ('data', rffi.VOIDP))

SIZE_BFG_OBJECT = rffi.cast(rffi.UINT, rffi.sizeof(TYPE_BFG_OBJECT))

TYPE_BFG_OBJECT_PTR = lltype.Ptr(TYPE_BFG_OBJECT)
TYPE_BFG_OBJECT_ARRAY = rffi.CArray(TYPE_BFG_OBJECT)
TYPE_BFG_OBJECT_ARRAY_PTR = lltype.Ptr(TYPE_BFG_OBJECT_ARRAY)

TYPE_BFG_TYPE_SPACE = rffi.CStruct('bfg_type_space',
                                   ('GUID_high', rffi.ULONGLONG),
                                   ('GUID_low', rffi.ULONGLONG),
                                   ('index', rffi.ULONGLONG),
                                   ('length', rffi.ULONGLONG),
                                   ('alloc_length', rffi.ULONGLONG),
예제 #7
0
파일: capi.py 프로젝트: soIu/rpython
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rtyper.tool import rffi_platform as platform
from rpython.translator.platform import platform as trans_plaform

ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rutf8')
SRC = ROOT.join('src')

if sys.platform.startswith('linux'):
    _libs = ['dl']
else:
    _libs = []

IDXTAB = lltype.ForwardReference()
IDXTAB.become(
    rffi.CStruct("fu8_idxtab", ('character_step', rffi.INT),
                 ('byte_positions', rffi.SIZE_TP),
                 ('bytepos_table_length', rffi.SIZE_T)))
IDXTABP = lltype.Ptr(IDXTAB)


def setup():
    compile_extra = ['-DRPYTHON_LL2CTYPES', '-DALLOW_SURROGATES=0', '-fPIC']
    eci_kwds = dict(include_dirs=[SRC],
                    includes=['utf8.h'],
                    libraries=_libs,
                    compile_extra=compile_extra)
    # compile the SSE4.1 and AVX version
    compile_extra.append('-msse4.1')
    ofile_eci = ExternalCompilationInfo(**eci_kwds)
    sse4_o, = trans_plaform._compile_o_files([SRC.join('utf8-sse4.c')],
                                             ofile_eci)
예제 #8
0
import os
import sys

from sota.constants import LIBDIR, PYPYDIR, CLIDIR
sys.path.insert(0, PYPYDIR)

from rpython.rtyper.lltypesystem import rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo

cli_eci = ExternalCompilationInfo(include_dirs=[CLIDIR],
                                  includes=['cli.h'],
                                  library_dirs=[LIBDIR],
                                  libraries=['cli'],
                                  use_cpp_linker=True)
CliToken = rffi.CStruct('CliToken', ('name', rffi.CCHARP),
                        ('value', rffi.CCHARP))
CliTokenPtr = rffi.CArrayPtr(CliToken)
CliTokensPtr = rffi.CStructPtr('CliTokens', ('count', rffi.LONG),
                               ('tokens', CliTokenPtr))
c_parse = rffi.llexternal('parse', [rffi.LONG, rffi.CCHARPP],
                          CliTokensPtr,
                          compilation_info=cli_eci)
c_clean = rffi.llexternal('clean', [CliTokensPtr],
                          rffi.LONG,
                          compilation_info=cli_eci)

#class CliParseError(Exception):
#    '''
#    CliParseError
#    '''
#    def __init__(self, result):
예제 #9
0
    DIRENT_DIR:u"dir",
    DIRENT_LINK:u"link",
    DIRENT_FIFO:u"fifo",
    DIRENT_SOCKET:u"socket",
    DIRENT_CHAR:u"char",
    DIRENT_BLOCK:u"block"
}

#setup_args = llexternal("uv_setup_args", [rffi.INT, rffi.CCHARPP], rffi.CCHARPP)
#get_process_title = llexternal("uv_get_process_title", [rffi.CCHARP, rffi.SIZE_T], rffi.INT)
#set_process_title = llexternal("uv_set_process_title", [rffi.CCHARP], rffi.INT)
#resident_set_memory = llexternal("uv_resident_set_memory", [rffi.SIZE_TP], rffi.INT)
#uptime = llexternal("uv_uptime", [rffi.CArrayPtr(rffi.DOUBLE)], rffi.INT)
 
timeval_t = rffi.CStruct("uv_timeval_t",
    ("tv_sec",  rffi.LONG),
    ("tv_usec", rffi.LONG))
 

rusage_t = rffi.CStruct("uv_rusage_t",
    ("ru_utime",     timeval_t), # user CPU time used
    ("ru_stime",     timeval_t), # system CPU time used
    ("ru_maxrss",    uint64_t), # maximum resident set size
    ("ru_ixrss",     uint64_t), # integral shared memory size
    ("ru_idrss",     uint64_t), # integral unshared data size
    ("ru_isrss",     uint64_t), # integral unshared stack size
    ("ru_minflt",    uint64_t), # page reclaims (soft page faults)
    ("ru_majflt",    uint64_t), # page faults (hard page faults)
    ("ru_nswap",     uint64_t), # swaps
    ("ru_inblock",   uint64_t), # block input operations
    ("ru_oublock",   uint64_t), # block output operations
예제 #10
0
파일: rmqueue.py 프로젝트: zarutian/typhon
import os

from rpython.rlib.rposix import get_saved_errno
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo

eci = ExternalCompilationInfo(includes=["mqueue.h"], libraries=["rt"])

mqd_t = rffi.platform.inttype("mqd_t",
                              "mqd_t",
                              True,
                              add_source="#include <mqueue.h>")

mq_attr = rffi.CStruct("mq_attr", ("mq_flags", rffi.LONG),
                       ("mq_maxmsg", rffi.LONG), ("mq_msgsize", rffi.LONG),
                       ("mq_curmsgs", rffi.LONG))
mq_attrp = rffi.lltype.Ptr(mq_attr)

mq_open = rffi.llexternal("mq_open",
                          [rffi.CCHARP, rffi.INT, rffi.MODE_T, mq_attrp],
                          mqd_t,
                          compilation_info=eci,
                          save_err=rffi.RFFI_SAVE_ERRNO)

mq_close = rffi.llexternal("mq_close", [mqd_t],
                           rffi.INT,
                           compilation_info=eci,
                           save_err=rffi.RFFI_SAVE_ERRNO)

mq_unlink = rffi.llexternal("mq_unlink", [rffi.CCHARP],
예제 #11
0
from rpython.rtyper.lltypesystem import lltype, rffi
from pypy.module.cpyext.api import (PyObjectFields, bootstrap_function,
                                    cpython_api, cpython_struct, PyObject,
                                    build_type_checkers)
from pypy.module.cpyext.pyobject import (make_typedescr, track_reference,
                                         from_ref)
from pypy.module.cpyext.floatobject import PyFloat_AsDouble
from pypy.objspace.std.complexobject import W_ComplexObject
from pypy.interpreter.error import oefmt

PyComplex_Check, PyComplex_CheckExact = build_type_checkers("Complex")

Py_complex_t = rffi.CStruct('Py_complex_t', ('real', rffi.DOUBLE),
                            ('imag', rffi.DOUBLE),
                            hints={'size': 2 * rffi.sizeof(rffi.DOUBLE)})
Py_complex_ptr = lltype.Ptr(Py_complex_t)

PyComplexObjectStruct = lltype.ForwardReference()
PyComplexObject = lltype.Ptr(PyComplexObjectStruct)
PyComplexObjectFields = PyObjectFields + \
    (("cval", Py_complex_t),)
cpython_struct("PyComplexObject", PyComplexObjectFields, PyComplexObjectStruct)


@bootstrap_function
def init_complexobject(space):
    "Type description of PyComplexObject"
    make_typedescr(space.w_complex.layout.typedef,
                   basestruct=PyComplexObject.TO,
                   attach=complex_attach,
                   realize=complex_realize)
예제 #12
0
파일: timelib.py 프로젝트: netyum/hippyvm
LIBDIR = py.path.local(__file__).join('..', 'lib/')
subprocess.check_call(['make', '-C', str(LIBDIR)])

eci = ExternalCompilationInfo(includes=['timelib.h', 'sys/time.h', 'time.h'],
                              include_dirs=[LIBDIR],
                              libraries=['timelib1'],
                              testonly_libraries=['timelib'],
                              library_dirs=[str(LIBDIR)])


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


timelib_error_message = rffi.CStruct('timelib_error_message',
                                     ('position', rffi.INT),
                                     ('character', lltype.Char),
                                     ('message', rffi.CCHARP))


class CConfig(object):
    ttinfo = platform.Struct('ttinfo', [
        ('offset', rffi.INT),
        ('isdst', rffi.INT),
        ('abbr_idx', lltype.Unsigned),
        ('isstdcnt', lltype.Unsigned),
        ('isgmtcnt', lltype.Unsigned),
    ])

    tm = platform.Struct("struct tm", [("tm_sec", rffi.INT),
                                       ("tm_min", rffi.INT),
                                       ("tm_hour", rffi.INT),
예제 #13
0
파일: lexer.py 프로젝트: sota/old-lang
import os
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.translator.tool.cbuild import ExternalCompilationInfo

from sast.tokens import Token

#pylint: disable=invalid-name

CTOKEN = rffi.CStruct('CToken', ('start', rffi.LONG), ('end', rffi.LONG),
                      ('kind', rffi.LONG), ('line', rffi.LONG),
                      ('pos', rffi.LONG), ('skip', rffi.LONG))

CTOKENP = rffi.CArrayPtr(CTOKEN)
CTOKENPP = rffi.CArrayPtr(CTOKENP)


def deref(obj):
    return obj[0]


def escape(old):
    new = ''
    for char in old:
        if char == '\n':
            new += '\\'
            new += 'n'
        else:
            new += char
    return new