Example #1
0
    def _unwrap_object(self, space, w_value):
        utf8, length = space.utf8_len_w(space.unicode_from_object(w_value))
        if length != 1:
            raise oefmt(space.w_ValueError,
                        "wchar_t expected, got string of size %d", length)

        with rffi.scoped_utf82wcharp(utf8, length) as u:
            value = rffi.cast(self.c_type, u[0])
        return value
Example #2
0
def ExpandEnvironmentStrings(source, unicode_len):
    with rffi.scoped_utf82wcharp(source, unicode_len) as src_buf:
        size = _ExpandEnvironmentStringsW(src_buf,
                                          lltype.nullptr(rffi.CWCHARP.TO), 0)
        if size == 0:
            raise rwin32.lastSavedWindowsError("ExpandEnvironmentStrings")
        size = intmask(size)
        with rffi.scoped_alloc_unicodebuffer(size) as dest_buf:
            if _ExpandEnvironmentStringsW(src_buf, dest_buf.raw, size) == 0:
                raise rwin32.lastSavedWindowsError("ExpandEnvironmentStrings")
            res = dest_buf.str(size - 1)  # remove trailing \0
            return res.encode('utf8'), len(res)
Example #3
0
def dlopen_w(space, w_filename, flags):
    from pypy.module._cffi_backend.cdataobj import W_CData
    from pypy.module._cffi_backend import ctypeptr

    autoclose = True
    if isinstance(w_filename, W_CData):
        # 'flags' ignored in this case
        w_ctype = w_filename.ctype
        if (not isinstance(w_ctype, ctypeptr.W_CTypePointer)
                or not w_ctype.is_void_ptr):
            raise oefmt(
                space.w_TypeError,
                "dlopen() takes a file name or 'void *' handle, not '%s'",
                w_ctype.name)
        handle = w_filename.unsafe_escaping_ptr()
        if not handle:
            raise oefmt(space.w_RuntimeError, "cannot call dlopen(NULL)")
        fname = w_ctype.extra_repr(handle)
        handle = rffi.cast(DLLHANDLE, handle)
        autoclose = False
        #
    elif WIN32 and space.isinstance_w(w_filename, space.w_unicode):
        fname = space.text_w(space.repr(w_filename))
        utf8_name = space.utf8_w(w_filename)
        uni_len = space.len_w(w_filename)
        with rffi.scoped_utf82wcharp(utf8_name, uni_len) as ll_libname:
            try:
                handle = dlopenU(ll_libname, flags)
            except DLOpenError as e:
                raise wrap_dlopenerror(space, e, fname)
    else:
        if space.is_none(w_filename):
            fname = None
        else:
            fname = space.fsencode_w(w_filename)
        with rffi.scoped_str2charp(fname) as ll_libname:
            if fname is None:
                fname = "<None>"
            try:
                handle = dlopen(ll_libname, flags)
            except DLOpenError as e:
                raise wrap_dlopenerror(space, e, fname)
    return fname, handle, autoclose
Example #4
0
 def opendir(path, lgt):
     if lgt == 0:
         path = '.'
     if path[-1] not in ('\\', '/', ':'):
         mask = path + '\\*.*'
         lgt += 4
     else:
         mask = path + '*.*'
         lgt += 3
     dirp = lltype.malloc(SCANDIRP.TO, flavor='raw')
     with rffi.scoped_utf82wcharp(mask, lgt) as src_buf:
         hFindFile = win32traits.FindFirstFile(src_buf, dirp.filedata)
     if hFindFile == rwin32.INVALID_HANDLE_VALUE:
         error = rwin32.GetLastError_saved()
         lltype.free(dirp, flavor='raw')
         raise WindowsError(error, "FindFirstFileW failed")
     dirp.hFindFile = hFindFile
     dirp.first_time = True
     return dirp
Example #5
0
File: misc.py Project: xen0n/pypy
def dlopen_w(space, w_filename, flags):
    if WIN32 and space.isinstance_w(w_filename, space.w_unicode):
        fname = space.text_w(space.repr(w_filename))
        utf8_name = space.utf8_w(w_filename)
        uni_len = space.len_w(w_filename)
        with rffi.scoped_utf82wcharp(utf8_name, uni_len) as ll_libname:
            try:
                handle = dlopenU(ll_libname, flags)
            except DLOpenError as e:
                raise wrap_dlopenerror(space, e, fname)
    else:
        if space.is_none(w_filename):
            fname = None
        else:
            fname = space.fsencode_w(w_filename)
        with rffi.scoped_str2charp(fname) as ll_libname:
            if fname is None:
                fname = "<None>"
            try:
                handle = dlopen(ll_libname, flags)
            except DLOpenError as e:
                raise wrap_dlopenerror(space, e, fname)
    return fname, handle
Example #6
0
File: rwin32.py Project: Mu-L/pypy
 def AddDllDirectory(path, length):
     with rffi.scoped_utf82wcharp(path, length) as pathW:
         return _AddDllDirectory(pathW)