def method_put_bytes(self, space, start, string, str_offset, nbytes): with rffi.scoped_view_charp(string) as cstring: rffi.c_memcpy( rffi.ptradd(self.ptr, start), rffi.cast(rffi.VOIDP, rffi.ptradd(cstring, str_offset)), nbytes )
def do_send_string(self, space, buf, offset, size): from pypy.module._multiprocessing.interp_win32 import ( _WriteFile, ERROR_NO_SYSTEM_RESOURCES) from rpython.rlib import rwin32 with rffi.scoped_view_charp(buf) as charp: written_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1, flavor='raw') try: result = _WriteFile(self.handle, rffi.ptradd(charp, offset), size, written_ptr, rffi.NULL) if (result == 0 and rwin32.GetLastError_saved() == ERROR_NO_SYSTEM_RESOURCES): raise oefmt(space.w_ValueError, "Cannot send %d bytes over connection", size) finally: lltype.free(written_ptr, flavor='raw')
def do_send_string(self, space, buf, offset, size): from pypy.module._multiprocessing.interp_win32 import ( _WriteFile, ERROR_NO_SYSTEM_RESOURCES) from rpython.rlib import rwin32 with rffi.scoped_view_charp(buf) as charp: written_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1, flavor='raw') try: result = _WriteFile( self.handle, rffi.ptradd(charp, offset), size, written_ptr, rffi.NULL) if (result == 0 and rwin32.GetLastError_saved() == ERROR_NO_SYSTEM_RESOURCES): raise oefmt(space.w_ValueError, "Cannot send %d bytes over connection", size) finally: lltype.free(written_ptr, flavor='raw')
def initialize_from_env(): # This uses the same algorithms as CPython 3.5. The environment # variable we read also defaults to "PYTHONHASHSEED". If needed, # a different RPython interpreter can patch the value of the # global variable 'env_var_name', or just patch the whole # initialize_from_env() function. value = os.environ.get(env_var_name) if value and value != "random": with rffi.scoped_view_charp(value) as ptr: with lltype.scoped_alloc(rffi.CCHARPP.TO, 1) as endptr: endptr[0] = ptr seed = strtoul(ptr, endptr, 10) full = endptr[0][0] == '\x00' seed = lltype.cast_primitive(lltype.Unsigned, seed) if not full or seed > r_uint(4294967295) or ( rposix.get_saved_errno() == errno.ERANGE and seed == lltype.cast_primitive(lltype.Unsigned, rffi.cast(rffi.ULONG, -1))): os.write( 2, "%s must be \"random\" or an integer " "in range [0; 4294967295]\n" % (env_var_name, )) os._exit(1) if not seed: # disable the randomized hash s = '\x00' * 16 else: s = lcg_urandom(seed) else: try: s = rurandom.urandom(random_ctx, 16) except Exception as e: os.write( 2, "%s: failed to get random numbers to initialize Python\n" % (str(e), )) os._exit(1) raise # makes the annotator happy select_random_seed(s)
def parse_c_type(info, input): with rffi.scoped_view_charp(input) as p_input: res = ll_parse_c_type(info, p_input) return rffi.cast(lltype.Signed, res)
def search_in_struct_unions(ctx, name): with rffi.scoped_view_charp(name) as c_name: result = ll_search_in_struct_unions(ctx, c_name, rffi.cast(rffi.SIZE_T, len(name))) return rffi.cast(lltype.Signed, result)
def c_charp2stdstring(space, pystr, sz): with rffi.scoped_view_charp(pystr) as cstr: cppstr = _c_charp2stdstring(cstr, sz) return cppstr
def ask_question(string): with rffi.scoped_view_charp(string) as charp: res = __llask_question(charp) return res == 1 return True
def method_put_bytes(self, space, start, string, str_offset, nbytes): with rffi.scoped_view_charp(string) as cstring: rffi.c_memcpy( rffi.ptradd(self.ptr, start), rffi.cast(rffi.VOIDP, rffi.ptradd(cstring, str_offset)), nbytes)