示例#1
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

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

if not platform.has("fgetln", "#include <stdio.h>"):
    # This should use separate_module_files, but that appears to be broken, hence
    # this horrible hack.
    f = open(
        os.path.join(
            os.path.split(os.path.abspath(__file__))[0],
            "../platform/fgetln.c"))
    d = f.read()
    separate_module_sources = [d]
    extra_includes = [
        os.path.join(
            os.path.split(os.path.abspath(__file__))[0],
            "../platform/fgetln.h")
    ]
else:
    separate_module_sources = []
示例#2
0
def test_has_0006():
    """missing include"""
    assert not rffi_platform.has("pow", "", libraries=["m"])
示例#3
0
GENERAL_NAMES = rffi.COpaquePtr('GENERAL_NAMES')
GENERAL_NAME.TO.become(GENERAL_NAME_st)
OBJ_NAME = rffi.CArrayPtr(OBJ_NAME_st)
COMP_METHOD = rffi.CArrayPtr(COMP_METHOD_st)
ACCESS_DESCRIPTION = rffi.CArrayPtr(ACCESS_DESCRIPTION_st)

HAVE_OPENSSL_RAND = OPENSSL_VERSION_NUMBER >= 0x0090500f
HAVE_OPENSSL_FINISHED = OPENSSL_VERSION_NUMBER >= 0x0090500f
HAVE_SSL_CTX_CLEAR_OPTIONS = OPENSSL_VERSION_NUMBER >= 0x009080df and \
                             OPENSSL_VERSION_NUMBER != 0x00909000
if OPENSSL_VERSION_NUMBER < 0x0090800f and not OPENSSL_NO_ECDH:
    OPENSSL_NO_ECDH = True
HAS_ALPN = OPENSSL_VERSION_NUMBER >= 0x1000200fL and not OPENSSL_NO_TLSEXT

HAVE_OPENSSL_RAND_EGD = rffi_platform.has('RAND_egd("/")',
                                          '#include <openssl/rand.h>',
                                          libraries=['ssl', 'crypto'])

def external(name, argtypes, restype, **kw):
    kw['compilation_info'] = eci
    return rffi.llexternal(
        name, argtypes, restype, **kw)

def ssl_external(name, argtypes, restype, **kw):
    globals()['libssl_' + name] = external(
        name, argtypes, restype, **kw)

ssl_external('SSL_load_error_strings', [], lltype.Void)
ssl_external('SSL_library_init', [], rffi.INT)
ssl_external('CRYPTO_num_locks', [], rffi.INT)
ssl_external('CRYPTO_set_locking_callback',
示例#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
def test_has_0005():
    """bogus symbol name and lib name"""
    assert not rffi_platform.has(
        "bogus_symbol_name", "#include <math.h>", libraries=["boguslibname"])
示例#6
0

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):
示例#7
0
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.


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



if not platform.has("fgetln", "#include <stdio.h>"):
    # This should use separate_module_files, but that appears to be broken, hence
    # this horrible hack.
    f = open(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../platform/fgetln.c"))
    d = f.read()
    separate_module_sources = [d]
    extra_includes = [os.path.join(os.path.split(os.path.abspath(__file__))[0], "../platform/fgetln.h")]
else:
    separate_module_sources = []
    extra_includes = []

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

FILEP       = rffi.COpaquePtr("FILE")
fclose      = rffi.llexternal("fclose", [FILEP], rffi.INT, compilation_info=eci, releasegil=False)
示例#8
0
def test_has_0005():
    """bogus symbol name and lib name"""
    assert not rffi_platform.has("bogus_symbol_name", "#include <math.h>",
                                 libraries=["boguslibname"])
示例#9
0
def test_has_0006():
    """missing include"""
    assert not rffi_platform.has("pow", "", libraries=["m"])
示例#10
0
def test_has_0002():
    if platform.name == 'msvc':
        py.test.skip('no m.lib in msvc')
    assert rffi_platform.has("pow", "#include <math.h>", libraries=["m"])
示例#11
0
def test_has_0003():
    """multiple libraries"""
    if platform.name == 'msvc':
        py.test.skip('no m.lib in msvc')
    assert rffi_platform.has("pow", "#include <math.h>", libraries=["m", "c"])
示例#12
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")
    
def test_has_0003():
    """multiple libraries"""
    assert rffi_platform.has("pow", "#include <math.h>", libraries=["m", "c"])
def test_has_0002():
    assert rffi_platform.has("pow", "#include <math.h>", libraries=["m"])
示例#15
0
文件: ropenssl.py 项目: sota/pypy-old
GENERAL_NAMES = rffi.COpaquePtr('GENERAL_NAMES')
GENERAL_NAME.TO.become(GENERAL_NAME_st)
OBJ_NAME = rffi.CArrayPtr(OBJ_NAME_st)
COMP_METHOD = rffi.CArrayPtr(COMP_METHOD_st)
ACCESS_DESCRIPTION = rffi.CArrayPtr(ACCESS_DESCRIPTION_st)

HAVE_OPENSSL_RAND = OPENSSL_VERSION_NUMBER >= 0x0090500f
HAVE_OPENSSL_FINISHED = OPENSSL_VERSION_NUMBER >= 0x0090500f
HAVE_SSL_CTX_CLEAR_OPTIONS = OPENSSL_VERSION_NUMBER >= 0x009080df and \
                             OPENSSL_VERSION_NUMBER != 0x00909000
if OPENSSL_VERSION_NUMBER < 0x0090800f and not OPENSSL_NO_ECDH:
    OPENSSL_NO_ECDH = True
HAS_ALPN = OPENSSL_VERSION_NUMBER >= 0x1000200fL and not OPENSSL_NO_TLSEXT

HAVE_OPENSSL_RAND_EGD = rffi_platform.has('RAND_egd("/")',
                                          '#include <openssl/rand.h>',
                                          libraries=['ssl', 'crypto'])


def external(name, argtypes, restype, **kw):
    kw['compilation_info'] = eci
    return rffi.llexternal(name, argtypes, restype, **kw)


def ssl_external(name, argtypes, restype, **kw):
    globals()['libssl_' + name] = external(name, argtypes, restype, **kw)


ssl_external('SSL_load_error_strings', [], lltype.Void)
ssl_external('SSL_library_init', [], rffi.INT)
ssl_external('CRYPTO_num_locks', [], rffi.INT)
示例#16
0
def test_has_0001():
    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>")
示例#17
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>")
示例#18
0
def test_has_0002():
    if platform.name == 'msvc':
        py.test.skip('no m.lib in msvc')
    assert rffi_platform.has("pow", "#include <math.h>", libraries=["m"])
示例#19
0
ASN1_TIME = rffi.COpaquePtr("ASN1_TIME")
ASN1_INTEGER = rffi.COpaquePtr("ASN1_INTEGER")
GENERAL_NAMES = rffi.COpaquePtr("GENERAL_NAMES")
GENERAL_NAME.TO.become(GENERAL_NAME_st)
OBJ_NAME = rffi.CArrayPtr(OBJ_NAME_st)
ACCESS_DESCRIPTION = rffi.CArrayPtr(ACCESS_DESCRIPTION_st)


HAVE_OPENSSL_RAND = OPENSSL_VERSION_NUMBER >= 0x0090500F
HAVE_OPENSSL_FINISHED = OPENSSL_VERSION_NUMBER >= 0x0090500F
HAVE_SSL_CTX_CLEAR_OPTIONS = OPENSSL_VERSION_NUMBER >= 0x009080DF and OPENSSL_VERSION_NUMBER != 0x00909000
if OPENSSL_VERSION_NUMBER < 0x0090800F and not OPENSSL_NO_ECDH:
    OPENSSL_NO_ECDH = True
HAS_ALPN = OPENSSL_VERSION_NUMBER >= 0x1000200FL and not OPENSSL_NO_TLSEXT

HAVE_OPENSSL_RAND_EGD = rffi_platform.has('RAND_egd("/")', "#include <openssl/rand.h>", libraries=["ssl", "crypto"])


def external(name, argtypes, restype, **kw):
    kw["compilation_info"] = eci
    return rffi.llexternal(name, argtypes, restype, **kw)


def ssl_external(name, argtypes, restype, **kw):
    globals()["libssl_" + name] = external(name, argtypes, restype, **kw)


ssl_external("SSL_load_error_strings", [], lltype.Void, macro=OPENSSL_1_1 or None)
ssl_external("SSL_library_init", [], rffi.INT, macro=OPENSSL_1_1 or None)
ssl_external("CRYPTO_num_locks", [], rffi.INT)
ssl_external(
示例#20
0
def test_has_0003():
    """multiple libraries"""
    if platform.name == 'msvc':
        py.test.skip('no m.lib in msvc')
    assert rffi_platform.has("pow", "#include <math.h>", libraries=["m", "c"])
示例#21
0
# IN THE SOFTWARE.


import sys
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rtyper.tool import rffi_platform as platform
from rpython.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"]
示例#22
0
    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", [],