def get_version(self): if not self.version: space = self.space w_version = space.sys.get('version') version = space.str_w(w_version) self.version = rffi.str2charp(version) lltype.render_immortal(self.version) return self.version
def setup_buffer_buffer_procs(space, pto): c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True) lltype.render_immortal(c_buf) c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype, str_segcount.api_func.get_wrapper(space)) c_buf.c_bf_getreadbuffer = llhelper(buf_getreadbuffer.api_func.functype, buf_getreadbuffer.api_func.get_wrapper(space)) pto.c_tp_as_buffer = c_buf
def setup_string_buffer_procs(space, pto): c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True) lltype.render_immortal(c_buf) c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype, str_segcount.api_func.get_wrapper(space)) c_buf.c_bf_getreadbuffer = llhelper(str_getreadbuffer.api_func.functype, str_getreadbuffer.api_func.get_wrapper(space)) c_buf.c_bf_getcharbuffer = llhelper(str_getcharbuffer.api_func.functype, str_getcharbuffer.api_func.get_wrapper(space)) pto.c_tp_as_buffer = c_buf pto.c_tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER
def get_programname(self): if not self.programname: space = self.space argv = space.sys.get('argv') if space.len_w(argv): argv0 = space.getitem(argv, space.wrap(0)) progname = space.str_w(argv0) else: progname = "pypy" self.programname = rffi.str2charp(progname) lltype.render_immortal(self.programname) return self.programname
def get_new_method_def(space): state = space.fromcache(State) if state.new_method_def: return state.new_method_def from pypy.module.cpyext.modsupport import PyMethodDef ptr = lltype.malloc(PyMethodDef, flavor="raw", zero=True, immortal=True) ptr.c_ml_name = rffi.str2charp("__new__") lltype.render_immortal(ptr.c_ml_name) rffi.setintfield(ptr, 'c_ml_flags', METH_VARARGS | METH_KEYWORDS) ptr.c_ml_doc = rffi.str2charp( "T.__new__(S, ...) -> a new object with type S, a subtype of T") lltype.render_immortal(ptr.c_ml_doc) state.new_method_def = ptr return ptr
elif os.name == 'posix': READ_MAX = (sys.maxint//4) + 1 # upper bound on reads to avoid surprises raw_os_open = rffi.llexternal('open', [rffi.CCHARP, rffi.INT, rffi.MODE_T], rffi.INT, sandboxsafe=True, _nowrapper=True) raw_os_read = rffi.llexternal('read', [rffi.INT, llmemory.Address, rffi.SIZE_T], rffi.SIZE_T, sandboxsafe=True, _nowrapper=True) raw_os_close = rffi.llexternal('close', [rffi.INT], rffi.INT, sandboxsafe=True, _nowrapper=True) _dev_zero = rffi.str2charp('/dev/zero') # prebuilt lltype.render_immortal(_dev_zero) def clear_large_memory_chunk(baseaddr, size): # on some Unixy platforms, reading from /dev/zero is the fastest way # to clear arenas, because the kernel knows that it doesn't # need to even allocate the pages before they are used. # NB.: careful, don't do anything that could malloc here! # this code is called during GC initialization. fd = raw_os_open(_dev_zero, rffi.cast(rffi.INT, os.O_RDONLY), rffi.cast(rffi.MODE_T, 0644)) if rffi.cast(lltype.Signed, fd) != -1: while size > 0: size1 = rffi.cast(rffi.SIZE_T, min(READ_MAX, size)) count = raw_os_read(fd, baseaddr, size1)
READ_MAX = (sys.maxint // 4) + 1 # upper bound on reads to avoid surprises raw_os_open = rffi.llexternal('open', [rffi.CCHARP, rffi.INT, rffi.MODE_T], rffi.INT, sandboxsafe=True, _nowrapper=True) raw_os_read = rffi.llexternal('read', [rffi.INT, llmemory.Address, rffi.SIZE_T], rffi.SIZE_T, sandboxsafe=True, _nowrapper=True) raw_os_close = rffi.llexternal('close', [rffi.INT], rffi.INT, sandboxsafe=True, _nowrapper=True) _dev_zero = rffi.str2charp('/dev/zero') # prebuilt lltype.render_immortal(_dev_zero) def clear_large_memory_chunk(baseaddr, size): # on some Unixy platforms, reading from /dev/zero is the fastest way # to clear arenas, because the kernel knows that it doesn't # need to even allocate the pages before they are used. # NB.: careful, don't do anything that could malloc here! # this code is called during GC initialization. fd = raw_os_open(_dev_zero, rffi.cast(rffi.INT, os.O_RDONLY), rffi.cast(rffi.MODE_T, 0644)) if rffi.cast(lltype.Signed, fd) != -1: while size > 0: size1 = rffi.cast(rffi.SIZE_T, min(READ_MAX, size)) count = raw_os_read(fd, baseaddr, size1) count = rffi.cast(lltype.Signed, count)