示例#1
0
def test_has():
    assert rffi_platform.has("x", "int x = 3;")
    assert not rffi_platform.has("x", "")
    # has() should also not crash if it is given an invalid #include
    assert not rffi_platform.has("x", "#include <some/path/which/cannot/exist>")
示例#2
0
# IN THE SOFTWARE.


import sys
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rpython.tool import rffi_platform as platform
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from Builtins import *



eci             = ExternalCompilationInfo(includes=["curses.h", "term.h", "unistd.h"], \
                    libraries=["curses"])


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"]
示例#3
0
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.


import os
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rpython.tool import rffi_platform as platform
from pypy.rlib import rarithmetic, rposix
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from Builtins import *
import Stdlib_Modules



separate_module_files = []
if not platform.has("fgetln", "#include <stdio.h>"):
    separate_module_files.append(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../platform/fgetln.c"))
    extra_includes = [os.path.join(os.path.split(os.path.abspath(__file__))[0], "../platform/fgetln.h")]
else:
    extra_includes = []

eci         = ExternalCompilationInfo(includes=["limits.h", "stdio.h", "stdlib.h", "string.h",
                "unistd.h"] + extra_includes, separate_module_files=separate_module_files)

FILEP       = rffi.COpaquePtr("FILE")
fclose      = rffi.llexternal("fclose", [FILEP], rffi.INT, compilation_info=eci)
fdopen      = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], FILEP, compilation_info=eci)
feof        = rffi.llexternal("feof", [FILEP], rffi.INT, compilation_info=eci)
ferror      = rffi.llexternal("ferror", [FILEP], rffi.INT, compilation_info=eci)
fflush      = rffi.llexternal("fflush", [FILEP], rffi.INT, compilation_info=eci)
fgetln      = rffi.llexternal("fgetln", [FILEP, rffi.SIZE_TP], rffi.CCHARP, compilation_info=eci)
示例#4
0
eci            = ExternalCompilationInfo(includes=["stdlib.h", "time.h", "sys/time.h"])

class CConfig:
    _compilation_info_ = eci
    TIMEVAL            = platform.Struct("struct timeval", [("tv_sec", rffi.LONG), ("tv_usec", rffi.LONG)])
    TIMEZONE           = platform.Struct("struct timezone", [])

cconfig        = platform.configure(CConfig)

TIMEVAL        = cconfig["TIMEVAL"]
TIMEVALP       = lltype.Ptr(TIMEVAL)
TIMEZONE       = cconfig["TIMEZONE"]
TIMEZONEP      = lltype.Ptr(TIMEZONE)

gettimeofday   = rffi.llexternal('gettimeofday', [TIMEVALP, TIMEZONEP], rffi.INT, compilation_info=eci)
if platform.has("random", "#include <stdlib.h>"):
    HAS_RANDOM = True
    random     = rffi.llexternal("random", [], rffi.LONG, compilation_info=eci)
    srandom    = rffi.llexternal("srandom", [rffi.INT], lltype.Void, compilation_info=eci)
else:
    HAS_RANDOM = False
    rand       = rffi.llexternal("rand", [], rffi.LONG, compilation_info=eci)
    srand      = rffi.llexternal("srand", [rffi.INT], lltype.Void, compilation_info=eci)

if platform.has("srandomdev", "#include <stdlib.h>"):
    HAS_SRANDOMDEV = True
    srandomdev = rffi.llexternal("srandomdev", [], lltype.Void, compilation_info=eci)
else:
    HAS_SRANDOMDEV = False

示例#5
0
    TIMEZONE           = platform.Struct("struct timezone", [])
    TIMESPEC           = platform.Struct("struct timespec", [("tv_sec", rffi.TIME_T), ("tv_nsec", rffi.LONG)])
    CLOCK_MONOTONIC    = platform.DefinedConstantInteger("CLOCK_MONOTONIC")

cconfig         = platform.configure(CConfig)

TIMEVAL         = cconfig["TIMEVAL"]
TIMEVALP        = lltype.Ptr(TIMEVAL)
TIMEZONE        = cconfig["TIMEZONE"]
TIMEZONEP       = lltype.Ptr(TIMEZONE)
TIMESPEC        = cconfig["TIMESPEC"]
TIMESPECP       = lltype.Ptr(TIMESPEC)
CLOCK_MONOTONIC = cconfig["CLOCK_MONOTONIC"]

gettimeofday    = rffi.llexternal('gettimeofday', [TIMEVALP, TIMEZONEP], rffi.INT, compilation_info=eci)
if platform.has("clock_gettime", "#include <sys/time.h>"):
    HAS_CLOCK_GETTIME = True
    clock_gettime   = rffi.llexternal('clock_gettime', [rffi.INT, TIMESPECP], rffi.INT, compilation_info=eci)
else:
    HAS_CLOCK_GETTIME = False


def init(vm):
    return new_c_con_module(vm, "C_Time", "C_Time", __file__, import_, \
      ["current", "current_mono"])


@con_object_proc
def import_(vm):
    (mod,),_ = vm.decode_args("O")
    
示例#6
0
def test_has():
    assert rffi_platform.has("x", "int x = 3;")
    assert not rffi_platform.has("x", "")
    # has() should also not crash if it is given an invalid #include
    assert not rffi_platform.has("x",
                                 "#include <some/path/which/cannot/exist>")