예제 #1
0
    def test_addmodule(self, space, api):
        with rffi.scoped_str2charp("sys") as modname:
            w_sys = api.PyImport_AddModule(modname)
        assert w_sys is space.sys

        with rffi.scoped_str2charp("foobar") as modname:
            w_foobar = api.PyImport_AddModule(modname)
        assert space.str_w(space.getattr(w_foobar,
                                         space.wrap('__name__'))) == 'foobar'
예제 #2
0
    def test_addmodule(self, space, api):
        with rffi.scoped_str2charp("sys") as modname:
            w_sys = api.PyImport_AddModule(modname)
        assert w_sys is space.sys

        with rffi.scoped_str2charp("foobar") as modname:
            w_foobar = api.PyImport_AddModule(modname)
        assert space.str_w(space.getattr(w_foobar,
                                         space.wrap('__name__'))) == 'foobar'
예제 #3
0
 def test_unpack(self, space, api):
     with rffi.scoped_str2charp("\x9a\x99\x99?") as ptr:
         assert abs(api._PyFloat_Unpack4(ptr, 1) - 1.2) < 1e-7
     with rffi.scoped_str2charp("?\x99\x99\x9a") as ptr:
         assert abs(api._PyFloat_Unpack4(ptr, 0) - 1.2) < 1e-7
     with rffi.scoped_str2charp("\x1f\x85\xebQ\xb8\x1e\t@") as ptr:
         assert abs(api._PyFloat_Unpack8(ptr, 1) - 3.14) < 1e-15
     with rffi.scoped_str2charp("@\t\x1e\xb8Q\xeb\x85\x1f") as ptr:
         assert abs(api._PyFloat_Unpack8(ptr, 0) - 3.14) < 1e-15
예제 #4
0
def SetValue(space, w_hkey, w_subkey, typ, value):
    """SetValue(key, sub_key, type, value) - Associates a value with a specified key.

key is an already open key, or any one of the predefined HKEY_* constants.
sub_key is a string that names the subkey with which the value is associated.
type is an integer that specifies the type of the data.  Currently this
 must be REG_SZ, meaning only strings are supported.
value is a string that specifies the new value.

If the key specified by the sub_key parameter does not exist, the SetValue
function creates it.

Value lengths are limited by available memory. Long values (more than
2048 bytes) should be stored as files with the filenames stored in
the configuration registry.  This helps the registry perform efficiently.

The key identified by the key parameter must have been opened with
KEY_SET_VALUE access."""
    if typ != rwinreg.REG_SZ:
        errstring = space.wrap("Type must be _winreg.REG_SZ")
        raise OperationError(space.w_ValueError, errstring)
    hkey = hkey_w(w_hkey, space)
    if space.is_w(w_subkey, space.w_None):
        subkey = None
    else:
        subkey = space.str_w(w_subkey)
    with rffi.scoped_str2charp(value) as dataptr:
        ret = rwinreg.RegSetValue(hkey, subkey, rwinreg.REG_SZ, dataptr, len(value))
        if ret != 0:
            raiseWindowsError(space, ret, 'RegSetValue')
예제 #5
0
def temp_file(vm):
    mod = vm.get_funcs_mod()
    file_class = type_check_class(vm, mod.get_defn(vm, "File"))
    vm.decode_args()
    
    if HAS_MKSTEMP:
        #tmpdir = None
        #if os.environ.has_key("TMPDIR"):
        #    tmpdir = os.environ["TMPDIR"]
        #if tmpdir is None:
        #    tmpdir = "/tmp"
        tmpp = "/tmp/tmp.XXXXXXXXXX"
        with rffi.scoped_str2charp(tmpp) as buf:
            fd = mkstemp(buf)
            tmpp = rffi.charp2str(buf)
           
        if fd == -1:
            _errno_raise(vm, Con_String(vm, tmpp))
        
        f = fdopen(fd, "w+")
        if not f:
            _errno_raise(vm, Con_String(vm, tmpp))
        
        return File(vm, file_class, Con_String(vm, tmpp), f)
    else:
        raise Exception("XXX")
예제 #6
0
    def test_getmoduledict(self, space, api):
        testmod = "binascii"
        w_pre_dict = api.PyImport_GetModuleDict()
        assert not space.is_true(space.contains(w_pre_dict, space.wrap(testmod)))

        with rffi.scoped_str2charp(testmod) as modname:
            w_module = api.PyImport_ImportModule(modname)
            print w_module
            assert w_module

        w_dict = api.PyImport_GetModuleDict()
        assert space.is_true(space.contains(w_dict, space.wrap(testmod)))
예제 #7
0
파일: libffi.py 프로젝트: njues/Sypy
 def __init__(self, libname, mode=-1):
     """Load the library, or raises DLOpenError."""
     self.lib = rffi.cast(DLLHANDLE, 0)
     with rffi.scoped_str2charp(libname) as ll_libname:
         self.lib = dlopen(ll_libname, mode)
예제 #8
0
def LoadWAV(filename_ccharp):
    with rffi.scoped_str2charp('rb') as mode:
        return LoadWAV_RW(RSDL.RWFromFile(filename_ccharp, mode), 1)
예제 #9
0
 def __init__(self, libname):
     """Load the library, or raises DLOpenError."""
     RawCDLL.__init__(self, rffi.cast(DLLHANDLE, -1))
     with rffi.scoped_str2charp(libname) as ll_libname:
         self.lib = dlopen(ll_libname)
예제 #10
0
파일: RMix.py 프로젝트: purepython/pypy
def LoadWAV(filename_ccharp):
    with rffi.scoped_str2charp('rb') as mode:
        return LoadWAV_RW(RSDL.RWFromFile(filename_ccharp, mode), 1)
예제 #11
0
 def func(l):
     s = StringBuilder()
     with rffi.scoped_str2charp("hello world") as x:
         s.append_charpsize(x, l)
     return s.build()
예제 #12
0
 def test_file_name(self, space, api):
     name = str(udir / "_test_file")
     with rffi.scoped_str2charp(name) as filename:
         with rffi.scoped_str2charp("wb") as mode:
             w_file = api.PyFile_FromString(filename, mode)
     assert space.str_w(api.PyFile_Name(w_file)) == name
예제 #13
0
    rootincpath = []
    rootlibpath = []

def identify():
    return 'CINT'

ts_reflect = False
ts_call    = False
ts_memory  = 'auto'
ts_helper  = 'auto'

# force loading in global mode of core libraries, rather than linking with
# them as PyPy uses various version of dlopen in various places; note that
# this isn't going to fly on Windows (note that locking them in objects and
# calling dlclose in __del__ seems to come too late, so this'll do for now)
with rffi.scoped_str2charp('libCint.so') as ll_libname:
    _cintdll = rdynload.dlopen(ll_libname, rdynload.RTLD_GLOBAL | rdynload.RTLD_NOW)
with rffi.scoped_str2charp('libCore.so') as ll_libname:
    _coredll = rdynload.dlopen(ll_libname, rdynload.RTLD_GLOBAL | rdynload.RTLD_NOW)

eci = ExternalCompilationInfo(
    separate_module_files=[srcpath.join("cintcwrapper.cxx")],
    include_dirs=[incpath] + rootincpath,
    includes=["cintcwrapper.h"],
    library_dirs=rootlibpath,
    link_extra=["-lCore", "-lCint"],
    use_cpp_linker=True,
)

_c_load_dictionary = rffi.llexternal(
    "cppyy_load_dictionary",
예제 #14
0
 def test_file_name(self, space, api):
     name = str(udir / "_test_file")
     with rffi.scoped_str2charp(name) as filename:
         with rffi.scoped_str2charp("wb") as mode:
             w_file = api.PyFile_FromString(filename, mode)
     assert space.str_w(api.PyFile_Name(w_file)) == name
예제 #15
0
 def func(l):
     s = StringBuilder()
     with rffi.scoped_str2charp("hello world") as x:
         s.append_charpsize(x, l)
     return s.build()