当前位置: 首页>>代码示例>>Python>>正文


Python lltype.nullptr函数代码示例

本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.nullptr函数的典型用法代码示例。如果您正苦于以下问题:Python nullptr函数的具体用法?Python nullptr怎么用?Python nullptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了nullptr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_carray_to_ll

def test_carray_to_ll():
    A = lltype.Array(lltype.Signed, hints={'nolength': True})
    a = lltype.malloc(A, 10, flavor='raw')
    a2 = lltype.malloc(A, 10, flavor='raw')
    a[0] = 100
    a[1] = 101
    a[2] = 110
    ac = lltype2ctypes(a)
    b = ctypes2lltype(lltype.Ptr(A), ac)
    assert lltype.typeOf(b) == lltype.Ptr(A)
    assert b == a
    assert not (b != a)
    assert a == b
    assert not (a != b)
    assert b != lltype.nullptr(A)
    assert not (b == lltype.nullptr(A))
    assert lltype.nullptr(A) != b
    assert not (lltype.nullptr(A) == b)
    assert b != a2
    assert not (b == a2)
    assert a2 != b
    assert not (a2 == b)
    assert b[2] == 110
    b[2] *= 2
    assert a[2] == 220
    a[2] *= 3
    assert b[2] == 660
    lltype.free(a, flavor='raw')
    lltype.free(a2, flavor='raw')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:test_ll2ctypes.py

示例2: __del__

 def __del__(self):
     if self.lib:
         c_dlclose(self.lib)
         self.lib = lltype.nullptr(rffi.CCHARP.TO)
     if self.ll_libname:
         lltype.free(self.ll_libname, flavor='raw')
         self.ll_libname = lltype.nullptr(rffi.CCHARP.TO)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:libffi.py

示例3: EnumKey

def EnumKey(space, w_hkey, index):
    """string = EnumKey(key, index) - Enumerates subkeys of an open registry key.

key is an already open key, or any one of the predefined HKEY_* constants.
index is an integer that identifies the index of the key to retrieve.

The function retrieves the name of one subkey each time it is called.
It is typically called repeatedly until an EnvironmentError exception is
raised, indicating no more values are available."""
    hkey = hkey_w(w_hkey, space)
    null_dword = lltype.nullptr(rwin32.LPDWORD.TO)

    # max key name length is 255
    buf = lltype.malloc(rffi.CCHARP.TO, 256, flavor="raw")
    try:
        retValueSize = lltype.malloc(rwin32.LPDWORD.TO, 1, flavor="raw")
        try:
            retValueSize[0] = 256  # includes NULL terminator
            ret = rwinreg.RegEnumKeyEx(
                hkey, index, buf, retValueSize, null_dword, None, null_dword, lltype.nullptr(rwin32.PFILETIME.TO)
            )
            if ret != 0:
                raiseWindowsError(space, ret, "RegEnumKeyEx")
            return space.wrap(rffi.charp2str(buf))
        finally:
            lltype.free(retValueSize, flavor="raw")
    finally:
        lltype.free(buf, flavor="raw")
开发者ID:alkorzt,项目名称:pypy,代码行数:28,代码来源:interp_winreg.py

示例4: PyBuffer_FillInfo

def PyBuffer_FillInfo(space, view, obj, buf, length, readonly, flags):
    """
    Fills in a buffer-info structure correctly for an exporter that can only
    share a contiguous chunk of memory of "unsigned bytes" of the given
    length. Returns 0 on success and -1 (with raising an error) on error.

    This is not a complete re-implementation of the CPython API; it only
    provides a subset of CPython's behavior.
    """
    view.c_buf = buf
    view.c_len = length
    view.c_obj = obj
    Py_IncRef(space, obj)
    view.c_itemsize = 1
    if flags & PyBUF_WRITABLE:
        rffi.setintfield(view, "c_readonly", 0)
    else:
        rffi.setintfield(view, "c_readonly", 1)
    rffi.setintfield(view, "c_ndim", 0)
    view.c_format = lltype.nullptr(rffi.CCHARP.TO)
    view.c_shape = lltype.nullptr(Py_ssize_tP.TO)
    view.c_strides = lltype.nullptr(Py_ssize_tP.TO)
    view.c_suboffsets = lltype.nullptr(Py_ssize_tP.TO)
    view.c_internal = lltype.nullptr(rffi.VOIDP.TO)

    return 0
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:26,代码来源:object.py

示例5: test_blit_rect

    def test_blit_rect(self):
        surface = RSDL.CreateRGBSurface(0, 150, 50, 32,
                                        r_uint(0x000000FF),
                                        r_uint(0x0000FF00),
                                        r_uint(0x00FF0000),
                                        r_uint(0xFF000000))
        fmt = surface.c_format
        color = RSDL.MapRGB(fmt, 255, 0, 0)
        RSDL.FillRect(surface, lltype.nullptr(RSDL.Rect), color)
        
        paintrect = RSDL_helper.mallocrect(75, 0, 150, 50)
        dstrect = lltype.malloc(RSDL.Rect, flavor='raw')
        try:
            color = RSDL.MapRGB(fmt, 255, 128, 0)
            RSDL.FillRect(surface, paintrect, color)

            rffi.setintfield(dstrect, 'c_x',  10)
            rffi.setintfield(dstrect, 'c_y',  10)
            rffi.setintfield(dstrect, 'c_w', 150)
            rffi.setintfield(dstrect, 'c_h',  50)
            RSDL.BlitSurface(surface, lltype.nullptr(RSDL.Rect), self.screen, dstrect)
            RSDL.Flip(self.screen)
        finally:
            lltype.free(dstrect, flavor='raw')
            lltype.free(paintrect, flavor='raw')
        RSDL.FreeSurface(surface)
        self.check("Half Red/Orange rectangle(150px * 50px) at the top left, 10 pixels from the border")
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:27,代码来源:test_video.py

示例6: test_AsEncodedObject

    def test_AsEncodedObject(self, space, api):
        ptr = space.wrap('abc')

        errors = rffi.str2charp("strict")

        encoding = rffi.str2charp("hex")
        res = api.PyString_AsEncodedObject(
            ptr, encoding, errors)
        assert space.unwrap(res) == "616263"

        res = api.PyString_AsEncodedObject(
            ptr, encoding, lltype.nullptr(rffi.CCHARP.TO))
        assert space.unwrap(res) == "616263"
        rffi.free_charp(encoding)

        encoding = rffi.str2charp("unknown_encoding")
        self.raises(space, api, LookupError, api.PyString_AsEncodedObject,
                    ptr, encoding, errors)
        rffi.free_charp(encoding)

        rffi.free_charp(errors)

        res = api.PyString_AsEncodedObject(
            ptr, lltype.nullptr(rffi.CCHARP.TO), lltype.nullptr(rffi.CCHARP.TO))
        assert space.unwrap(res) == "abc"

        self.raises(space, api, TypeError, api.PyString_AsEncodedObject,
            space.wrap(2), lltype.nullptr(rffi.CCHARP.TO), lltype.nullptr(rffi.CCHARP.TO)
        )
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:29,代码来源:test_stringobject.py

示例7: test_ascii_codec

    def test_ascii_codec(self, space, api):
        s = 'abcdefg'
        data = rffi.str2charp(s)
        w_u = api.PyUnicode_DecodeASCII(data, len(s), lltype.nullptr(rffi.CCHARP.TO))
        assert space.eq_w(w_u, space.wrap(u"abcdefg"))
        rffi.free_charp(data)

        s = 'abcd\xFF'
        data = rffi.str2charp(s)
        self.raises(space, api, UnicodeDecodeError, api.PyUnicode_DecodeASCII,
                    data, len(s), lltype.nullptr(rffi.CCHARP.TO))
        rffi.free_charp(data)

        uni = u'abcdefg'
        data = rffi.unicode2wcharp(uni)
        w_s = api.PyUnicode_EncodeASCII(data, len(uni), lltype.nullptr(rffi.CCHARP.TO))
        assert space.eq_w(space.wrap("abcdefg"), w_s)
        rffi.free_wcharp(data)

        u = u'äbcdéfg'
        data = rffi.unicode2wcharp(u)
        w_s = api.PyUnicode_EncodeASCII(data, len(u), lltype.nullptr(rffi.CCHARP.TO))
        self.raises(space, api, UnicodeEncodeError, api.PyUnicode_EncodeASCII,
                    data, len(u), lltype.nullptr(rffi.CCHARP.TO))
        rffi.free_wcharp(data)
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_unicodeobject.py

示例8: test_cstruct_to_ll

def test_cstruct_to_ll():
    S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
    s = lltype.malloc(S, flavor='raw')
    s2 = lltype.malloc(S, flavor='raw')
    s.x = 123
    sc = lltype2ctypes(s)
    t = ctypes2lltype(lltype.Ptr(S), sc)
    assert lltype.typeOf(t) == lltype.Ptr(S)
    assert s == t
    assert not (s != t)
    assert t == s
    assert not (t != s)
    assert t != lltype.nullptr(S)
    assert not (t == lltype.nullptr(S))
    assert lltype.nullptr(S) != t
    assert not (lltype.nullptr(S) == t)
    assert t != s2
    assert not (t == s2)
    assert s2 != t
    assert not (s2 == t)
    assert t.x == 123
    t.x += 1
    assert s.x == 124
    s.x += 1
    assert t.x == 125
    lltype.free(s, flavor='raw')
    lltype.free(s2, flavor='raw')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:27,代码来源:test_ll2ctypes.py

示例9: setup

 def setup(self):
     GCBase.setup(self)
     self.heap_usage = 0          # at the end of the latest collection
     self.bytes_malloced = 0      # since the latest collection
     self.bytes_malloced_threshold = self.param_start_heap_size
     self.total_collection_time = 0.0
     self.malloced_objects = lltype.nullptr(self.HDR)
     self.malloced_objects_with_finalizer = lltype.nullptr(self.HDR)
     # these are usually only the small bits of memory that make a
     # weakref object
     self.objects_with_weak_pointers = lltype.nullptr(self.HDR)
     # pools, for x_swap_pool():
     #   'curpool' is the current pool, lazily allocated (i.e. NULL means
     #   the current POOL object is not yet malloc'ed).  POOL objects are
     #   usually at the start of a linked list of objects, via the HDRs.
     #   The exception is 'curpool' whose linked list of objects is in
     #   'self.malloced_objects' instead of in the header of 'curpool'.
     #   POOL objects are never in the middle of a linked list themselves.
     # XXX a likely cause for the current problems with pools is:
     # not all objects live in malloced_objects, some also live in
     # malloced_objects_with_finalizer and objects_with_weak_pointers
     self.curpool = lltype.nullptr(self.POOL)
     #   'poolnodes' is a linked list of all such linked lists.  Each
     #   linked list will usually start with a POOL object, but it can
     #   also contain only normal objects if the POOL object at the head
     #   was already freed.  The objects in 'malloced_objects' are not
     #   found via 'poolnodes'.
     self.poolnodes = lltype.nullptr(self.POOLNODE)
     self.collect_in_progress = False
     self.prev_collect_end_time = 0.0
开发者ID:alkorzt,项目名称:pypy,代码行数:30,代码来源:marksweep.py

示例10: EnumKey

def EnumKey(space, w_hkey, index):
    """string = EnumKey(key, index) - Enumerates subkeys of an open registry key.

key is an already open key, or any one of the predefined HKEY_* constants.
index is an integer that identifies the index of the key to retrieve.

The function retrieves the name of one subkey each time it is called.
It is typically called repeatedly until an EnvironmentError exception is
raised, indicating no more values are available."""
    hkey = hkey_w(w_hkey, space)
    null_dword = lltype.nullptr(rwin32.LPDWORD.TO)

    # The Windows docs claim that the max key name length is 255
    # characters, plus a terminating nul character.  However,
    # empirical testing demonstrates that it is possible to
    # create a 256 character key that is missing the terminating
    # nul.  RegEnumKeyEx requires a 257 character buffer to
    # retrieve such a key name.
    with lltype.scoped_alloc(rffi.CCHARP.TO, 257) as buf:
        with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as retValueSize:
            retValueSize[0] = r_uint(257) # includes NULL terminator
            ret = rwinreg.RegEnumKeyEx(hkey, index, buf, retValueSize,
                                       null_dword, None, null_dword,
                                       lltype.nullptr(rwin32.PFILETIME.TO))
            if ret != 0:
                raiseWindowsError(space, ret, 'RegEnumKeyEx')
            return space.wrap(rffi.charp2str(buf))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:interp_winreg.py

示例11: PyErr_GetExcInfo

def PyErr_GetExcInfo(space, ptype, pvalue, ptraceback):
    """---Cython extension---

    Retrieve the exception info, as known from ``sys.exc_info()``.  This
    refers to an exception that was already caught, not to an exception
    that was freshly raised.  Returns new references for the three
    objects, any of which may be *NULL*.  Does not modify the exception
    info state.

    .. note::

       This function is not normally used by code that wants to handle
       exceptions.  Rather, it can be used when code needs to save and
       restore the exception state temporarily.  Use
       :c:func:`PyErr_SetExcInfo` to restore or clear the exception
       state.
    """
    ec = space.getexecutioncontext()
    operror = ec.sys_exc_info()
    if operror:
        ptype[0] = make_ref(space, operror.w_type)
        pvalue[0] = make_ref(space, operror.get_w_value(space))
        ptraceback[0] = make_ref(space, space.wrap(operror.get_traceback()))
    else:
        ptype[0] = lltype.nullptr(PyObject.TO)
        pvalue[0] = lltype.nullptr(PyObject.TO)
        ptraceback[0] = lltype.nullptr(PyObject.TO)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:pyerrors.py

示例12: init_typeobject

def init_typeobject(space):
    # Probably a hack
    space.model.typeorder[W_PyCTypeObject] = [(W_PyCTypeObject, None),
                                              (W_TypeObject, None),
                                              (W_Root, None)]

    make_typedescr(space.w_type.instancetypedef,
                   basestruct=PyTypeObject,
                   alloc=type_alloc,
                   attach=type_attach,
                   realize=type_realize,
                   dealloc=type_dealloc)

    # some types are difficult to create because of cycles.
    # - object.ob_type = type
    # - type.ob_type   = type
    # - tuple.ob_type  = type
    # - type.tp_base   = object
    # - tuple.tp_base  = object
    # - type.tp_bases is a tuple
    # - object.tp_bases is a tuple
    # - tuple.tp_bases is a tuple

    # insert null placeholders to please create_ref()
    track_reference(space, lltype.nullptr(PyObject.TO), space.w_type)
    track_reference(space, lltype.nullptr(PyObject.TO), space.w_object)
    track_reference(space, lltype.nullptr(PyObject.TO), space.w_tuple)
    track_reference(space, lltype.nullptr(PyObject.TO), space.w_str)

    # create the objects
    py_type = create_ref(space, space.w_type)
    py_object = create_ref(space, space.w_object)
    py_tuple = create_ref(space, space.w_tuple)
    py_str = create_ref(space, space.w_str)

    # form cycles
    pto_type = rffi.cast(PyTypeObjectPtr, py_type)
    py_type.c_ob_type = pto_type
    py_object.c_ob_type = pto_type
    py_tuple.c_ob_type = pto_type

    pto_object = rffi.cast(PyTypeObjectPtr, py_object)
    pto_type.c_tp_base = pto_object
    pto_tuple = rffi.cast(PyTypeObjectPtr, py_tuple)
    pto_tuple.c_tp_base = pto_object

    pto_type.c_tp_bases.c_ob_type = pto_tuple
    pto_object.c_tp_bases.c_ob_type = pto_tuple
    pto_tuple.c_tp_bases.c_ob_type = pto_tuple

    for typ in (py_type, py_object, py_tuple, py_str):
        heaptype = rffi.cast(PyHeapTypeObject, typ)
        heaptype.c_ht_name.c_ob_type = pto_type

    # Restore the mapping
    track_reference(space, py_type, space.w_type, replace=True)
    track_reference(space, py_object, space.w_object, replace=True)
    track_reference(space, py_tuple, space.w_tuple, replace=True)
    track_reference(space, py_str, space.w_str, replace=True)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:typeobject.py

示例13: do_poll

    def do_poll(self, space, timeout):
        from pypy.module._multiprocessing.interp_win32 import (
            _PeekNamedPipe, _GetTickCount, _Sleep)
        from pypy.rlib import rwin32
        from pypy.interpreter.error import wrap_windowserror
        bytes_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
                                 flavor='raw')
        try:
            if not _PeekNamedPipe(self.handle, rffi.NULL, 0,
                                  lltype.nullptr(rwin32.LPDWORD.TO),
                                  bytes_ptr,
                                  lltype.nullptr(rwin32.LPDWORD.TO)):
                raise wrap_windowserror(space, rwin32.lastWindowsError())
            bytes = bytes_ptr[0]
        finally:
            lltype.free(bytes_ptr, flavor='raw')

        if timeout == 0.0:
            return bytes > 0

        block = timeout < 0
        if not block:
            # XXX does not check for overflow
            deadline = intmask(_GetTickCount()) + int(1000 * timeout + 0.5)
        else:
            deadline = 0

        _Sleep(0)

        delay = 1
        while True:
            bytes_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
                                     flavor='raw')
            try:
                if not _PeekNamedPipe(self.handle, rffi.NULL, 0,
                                      lltype.nullptr(rwin32.LPDWORD.TO),
                                      bytes_ptr,
                                      lltype.nullptr(rwin32.LPDWORD.TO)):
                    raise wrap_windowserror(space, rwin32.lastWindowsError())
                bytes = bytes_ptr[0]
            finally:
                lltype.free(bytes_ptr, flavor='raw')

            if bytes > 0:
                return True

            if not block:
                now = intmask(_GetTickCount())
                if now > deadline:
                    return False
                diff = deadline - now
                if delay > diff:
                    delay = diff
            else:
                delay += 1

            if delay >= 20:
                delay = 20
            _Sleep(delay)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:interp_connection.py

示例14: select

def select(inl, outl, excl, timeout=-1.0):
    nfds = 0
    if inl:
        ll_inl = lltype.malloc(_c.fd_set.TO, flavor="raw")
        _c.FD_ZERO(ll_inl)
        for i in inl:
            _c.FD_SET(i, ll_inl)
            if i > nfds:
                nfds = i
    else:
        ll_inl = lltype.nullptr(_c.fd_set.TO)
    if outl:
        ll_outl = lltype.malloc(_c.fd_set.TO, flavor="raw")
        _c.FD_ZERO(ll_outl)
        for i in outl:
            _c.FD_SET(i, ll_outl)
            if i > nfds:
                nfds = i
    else:
        ll_outl = lltype.nullptr(_c.fd_set.TO)
    if excl:
        ll_excl = lltype.malloc(_c.fd_set.TO, flavor="raw")
        _c.FD_ZERO(ll_excl)
        for i in excl:
            _c.FD_SET(i, ll_excl)
            if i > nfds:
                nfds = i
    else:
        ll_excl = lltype.nullptr(_c.fd_set.TO)
    if timeout != -1.0:
        ll_timeval = lltype.malloc(_c.timeval, flavor="raw")
        frac = math.fmod(timeout, 1.0)
        ll_timeval.c_tv_sec = int(timeout)
        ll_timeval.c_tv_usec = int((timeout - int(timeout)) * 1000000.0)
    else:
        ll_timeval = lltype.nullptr(_c.timeval)
    try:
        res = _c.select(nfds + 1, ll_inl, ll_outl, ll_excl, ll_timeval)
        if res == -1:
            raise SelectError(_c.geterrno())
        if res == 0:
            return ([], [], [])
        else:
            return (
                [i for i in inl if _c.FD_ISSET(i, ll_inl)],
                [i for i in outl if _c.FD_ISSET(i, ll_outl)],
                [i for i in excl if _c.FD_ISSET(i, ll_excl)],
            )
    finally:
        if ll_inl:
            lltype.free(ll_inl, flavor="raw")
        if ll_outl:
            lltype.free(ll_outl, flavor="raw")
        if ll_excl:
            lltype.free(ll_excl, flavor="raw")
        if ll_timeval:
            lltype.free(ll_timeval, flavor="raw")
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:57,代码来源:rpoll.py

示例15: main

 def main(a, b, x):
     pq = lltype.malloc(PQ)
     pq.vable_access = lltype.nullptr(PQ_ACCESS)
     pq.p = lltype.nullptr(S)
     pq.q = pq.p
     e = lltype.malloc(E3)
     e.pq = pq
     f(e, a, b)
     return e.w
开发者ID:camillobruni,项目名称:pygirl,代码行数:9,代码来源:test_virtualizable.py


注:本文中的pypy.rpython.lltypesystem.lltype.nullptr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。