from pypy.interpreter.error import oefmt, wrap_oserror
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import GetSetProperty, TypeDef

RECURSIVE_MUTEX, SEMAPHORE = range(2)
sys_platform = sys.platform

if sys.platform == 'win32':
    from rpython.rlib import rwin32
    from pypy.module._multiprocessing.interp_win32_py3 import (_GetTickCount,
                                                               handle_w)

    SEM_VALUE_MAX = int(2**31 - 1)  # max rffi.LONG

    _CreateSemaphore = rwin32.winexternal(
        'CreateSemaphoreA', [rffi.VOIDP, rffi.LONG, rffi.LONG, rwin32.LPCSTR],
        rwin32.HANDLE,
        save_err=rffi.RFFI_FULL_LASTERROR)
    _CloseHandle_no_errno = rwin32.winexternal('CloseHandle', [rwin32.HANDLE],
                                               rwin32.BOOL,
                                               releasegil=False)
    _ReleaseSemaphore = rwin32.winexternal(
        'ReleaseSemaphore', [rwin32.HANDLE, rffi.LONG, rffi.LONGP],
        rwin32.BOOL,
        save_err=rffi.RFFI_SAVE_LASTERROR,
        releasegil=False)

    def sem_unlink(name):
        return None
else:
    from rpython.rlib import rposix
Exemplo n.º 2
0
    for name in CONSTANTS:
        locals()[name] = rffi_platform.ConstantInteger(name)


config = rffi_platform.configure(CConfig)
globals().update(config)


def handle_w(space, w_handle):
    return rffi.cast(rwin32.HANDLE, space.int_w(w_handle))


_CreateNamedPipe = rwin32.winexternal('CreateNamedPipeA', [
    rwin32.LPCSTR, rwin32.DWORD, rwin32.DWORD, rwin32.DWORD, rwin32.DWORD,
    rwin32.DWORD, rwin32.DWORD, rffi.VOIDP
],
                                      rwin32.HANDLE,
                                      save_err=rffi.RFFI_SAVE_LASTERROR)

_ConnectNamedPipe = rwin32.winexternal('ConnectNamedPipe',
                                       [rwin32.HANDLE, rffi.VOIDP],
                                       rwin32.BOOL,
                                       save_err=rffi.RFFI_SAVE_LASTERROR)

_SetNamedPipeHandleState = rwin32.winexternal(
    'SetNamedPipeHandleState',
    [rwin32.HANDLE, rwin32.LPDWORD, rwin32.LPDWORD, rwin32.LPDWORD],
    rwin32.BOOL,
    save_err=rffi.RFFI_SAVE_LASTERROR)

_WaitNamedPipe = rwin32.winexternal('WaitNamedPipeA',
Exemplo n.º 3
0
    if res != 0:
        raise getWindowsError(space)


@unwrap_spec(handle=int, buffersize=int)
def multiprocessing_recv(space, handle, buffersize):
    with rffi.scoped_alloc_buffer(buffersize) as buf:
        read_bytes = socketrecv(handle, buf.raw, buffersize, 0)
        if read_bytes >= 0:
            return space.newtext(buf.str(read_bytes))
    raise getWindowsError(space)


@unwrap_spec(handle=int, data='bufferstr')
def multiprocessing_send(space, handle, data):
    if data is None:
        raise OperationError(space.w_ValueError, 'data cannot be None')
    with rffi.scoped_nonmovingbuffer(data) as dataptr:
        # rsocket checks for writability of socket with wait_for_data, cpython does check
        res = send(handle, dataptr, len(data), 0)
        if res < 0:
            raise getWindowsError(space)
    return space.newint(res)


def handle_w(space, w_handle):
    return rffi.cast(rwin32.HANDLE, space.int_w(w_handle))


_GetTickCount = rwin32.winexternal('GetTickCount', [], rwin32.DWORD)
Exemplo n.º 4
0
from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import GetSetProperty, TypeDef
from pypy.module._multiprocessing.interp_connection import w_handle

RECURSIVE_MUTEX, SEMAPHORE = range(2)

if sys.platform == 'win32':
    from rpython.rlib import rwin32
    from pypy.module._multiprocessing.interp_win32 import (
        _GetTickCount, handle_w)

    SEM_VALUE_MAX = sys.maxint

    _CreateSemaphore = rwin32.winexternal(
        'CreateSemaphoreA', [rffi.VOIDP, rffi.LONG, rffi.LONG, rwin32.LPCSTR],
        rwin32.HANDLE,
        save_err=rffi.RFFI_FULL_LASTERROR)
    _CloseHandle_no_errno = rwin32.winexternal('CloseHandle', [rwin32.HANDLE],
        rwin32.BOOL, releasegil=False)
    _ReleaseSemaphore = rwin32.winexternal(
        'ReleaseSemaphore', [rwin32.HANDLE, rffi.LONG, rffi.LONGP],
        rwin32.BOOL,
        save_err=rffi.RFFI_SAVE_LASTERROR)

else:
    from rpython.rlib import rposix

    if sys.platform == 'darwin':
        libraries = []
    else:
        libraries = ['rt']
Exemplo n.º 5
0
        libraries = ['kernel32'],
        )

    for name in CONSTANTS:
        locals()[name] = rffi_platform.ConstantInteger(name)

config = rffi_platform.configure(CConfig)
globals().update(config)

def handle_w(space, w_handle):
    return rffi.cast(rwin32.HANDLE, space.int_w(w_handle))

_CreateNamedPipe = rwin32.winexternal(
    'CreateNamedPipeA', [
        rwin32.LPCSTR,
        rwin32.DWORD, rwin32.DWORD, rwin32.DWORD,
        rwin32.DWORD, rwin32.DWORD, rwin32.DWORD,
        rffi.VOIDP],
    rwin32.HANDLE,
    save_err=rffi.RFFI_SAVE_LASTERROR)

_ConnectNamedPipe = rwin32.winexternal(
    'ConnectNamedPipe', [rwin32.HANDLE, rffi.VOIDP], rwin32.BOOL,
    save_err=rffi.RFFI_SAVE_LASTERROR)

_SetNamedPipeHandleState = rwin32.winexternal(
    'SetNamedPipeHandleState', [
        rwin32.HANDLE,
        rwin32.LPDWORD, rwin32.LPDWORD, rwin32.LPDWORD],
    rwin32.BOOL,
    save_err=rffi.RFFI_SAVE_LASTERROR)
Exemplo n.º 6
0
    for name in CONSTANTS:
        locals()[name] = rffi_platform.ConstantInteger(name)


config = rffi_platform.configure(CConfig)
globals().update(config)


def handle_w(space, w_handle):
    return rffi.cast(rwin32.HANDLE, space.int_w(w_handle))


_CreateNamedPipe = rwin32.winexternal(
    "CreateNamedPipeA",
    [rwin32.LPCSTR, rwin32.DWORD, rwin32.DWORD, rwin32.DWORD, rwin32.DWORD, rwin32.DWORD, rwin32.DWORD, rffi.VOIDP],
    rwin32.HANDLE,
    save_err=rffi.RFFI_SAVE_LASTERROR,
)

_ConnectNamedPipe = rwin32.winexternal(
    "ConnectNamedPipe", [rwin32.HANDLE, rffi.VOIDP], rwin32.BOOL, save_err=rffi.RFFI_SAVE_LASTERROR
)

_SetNamedPipeHandleState = rwin32.winexternal(
    "SetNamedPipeHandleState",
    [rwin32.HANDLE, rwin32.LPDWORD, rwin32.LPDWORD, rwin32.LPDWORD],
    rwin32.BOOL,
    save_err=rffi.RFFI_SAVE_LASTERROR,
)

_WaitNamedPipe = rwin32.winexternal(
Exemplo n.º 7
0
from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import GetSetProperty, TypeDef
from pypy.module._multiprocessing.interp_connection import w_handle

RECURSIVE_MUTEX, SEMAPHORE = range(2)

if sys.platform == 'win32':
    from rpython.rlib import rwin32
    from pypy.module._multiprocessing.interp_win32 import (
        _GetTickCount, handle_w)

    SEM_VALUE_MAX = sys.maxint

    _CreateSemaphore = rwin32.winexternal(
        'CreateSemaphoreA', [rffi.VOIDP, rffi.LONG, rffi.LONG, rwin32.LPCSTR],
        rwin32.HANDLE)
    _CloseHandle = rwin32.winexternal('CloseHandle', [rwin32.HANDLE],
        rwin32.BOOL, releasegil=False)
    _ReleaseSemaphore = rwin32.winexternal(
        'ReleaseSemaphore', [rwin32.HANDLE, rffi.LONG, rffi.LONGP],
        rwin32.BOOL)

else:
    from rpython.rlib import rposix

    if sys.platform == 'darwin':
        libraries = []
    else:
        libraries = ['rt']
Exemplo n.º 8
0
if _POSIX:
    cConfig.timeval.__name__ = "_timeval"
    timeval = cConfig.timeval

CLOCKS_PER_SEC = cConfig.CLOCKS_PER_SEC
HAS_CLOCK_GETTIME = rtime.HAS_CLOCK_GETTIME
HAS_CLOCK_HIGHRES = rtime.CLOCK_HIGHRES is not None
HAS_CLOCK_MONOTONIC = rtime.CLOCK_MONOTONIC is not None
HAS_MONOTONIC = (_WIN or _MACOSX
                 or (HAS_CLOCK_GETTIME and
                     (HAS_CLOCK_HIGHRES or HAS_CLOCK_MONOTONIC)))
tm = cConfig.tm
glob_buf = lltype.malloc(tm, flavor='raw', zero=True, immortal=True)

if _WIN:
    _GetSystemTimeAsFileTime = rwin32.winexternal(
        'GetSystemTimeAsFileTime', [lltype.Ptr(rwin32.FILETIME)], lltype.Void)
    LPDWORD = rwin32.LPDWORD
    _GetSystemTimeAdjustment = rwin32.winexternal(
        'GetSystemTimeAdjustment', [LPDWORD, LPDWORD, rwin32.LPBOOL], rffi.INT)

    def gettimeofday(space, w_info=None):
        with lltype.scoped_alloc(rwin32.FILETIME) as system_time:
            _GetSystemTimeAsFileTime(system_time)
            quad_part = (system_time.c_dwLowDateTime |
                         (r_ulonglong(system_time.c_dwHighDateTime) << 32))
            # 11,644,473,600,000,000: number of microseconds between
            # the 1st january 1601 and the 1st january 1970 (369 years + 80 leap
            # days).

            # We can't use that big number when translating for
            # 32-bit system (which windows always is currently)