コード例 #1
0
def test_has_weakref_support():
    assert has_weakref_support()

    res = interpret(lambda: has_weakref_support(), [],
                    **{'translation.rweakref': True})
    assert res == True

    res = interpret(lambda: has_weakref_support(), [],
                    **{'translation.rweakref': False})
    assert res == False
コード例 #2
0
ファイル: newtype.py プロジェクト: stjordanis/pypy
def _new_array_type(space, w_ctptr, length):
    _setup_wref(rweakref.has_weakref_support())
    if not isinstance(w_ctptr, ctypeptr.W_CTypePointer):
        raise oefmt(space.w_TypeError, "first arg must be a pointer ctype")
    arrays = w_ctptr._array_types
    if arrays is None:
        arrays = rweakref.RWeakValueDictionary(int, ctypearray.W_CTypeArray)
        w_ctptr._array_types = arrays
    else:
        ctype = arrays.get(length)
        if ctype is not None:
            return ctype
    #
    ctitem = w_ctptr.ctitem
    if ctitem.size < 0:
        raise oefmt(space.w_ValueError, "array item of unknown size: '%s'",
                    ctitem.name)
    if length < 0:
        assert length == -1
        arraysize = -1
        extra = '[]'
    else:
        try:
            arraysize = ovfcheck(length * ctitem.size)
        except OverflowError:
            raise oefmt(space.w_OverflowError,
                        "array size would overflow a ssize_t")
        extra = '[%d]' % length
    #
    ctype = ctypearray.W_CTypeArray(space, w_ctptr, length, arraysize, extra)
    arrays.set(length, ctype)
    return ctype
コード例 #3
0
ファイル: newtype.py プロジェクト: stjordanis/pypy
def _new_pointer_type(space, w_ctype):
    _setup_wref(rweakref.has_weakref_support())
    ctptr = w_ctype._pointer_type()
    if ctptr is None:
        ctptr = ctypeptr.W_CTypePointer(space, w_ctype)
        w_ctype._pointer_type = rweakref.ref(ctptr)
    return ctptr
コード例 #4
0
ファイル: newtype.py プロジェクト: mozillazg/pypy
def _new_array_type(space, w_ctptr, length):
    _setup_wref(rweakref.has_weakref_support())
    if not isinstance(w_ctptr, ctypeptr.W_CTypePointer):
        raise oefmt(space.w_TypeError, "first arg must be a pointer ctype")
    arrays = w_ctptr._array_types
    if arrays is None:
        arrays = rweakref.RWeakValueDictionary(int, ctypearray.W_CTypeArray)
        w_ctptr._array_types = arrays
    else:
        ctype = arrays.get(length)
        if ctype is not None:
            return ctype
    #
    ctitem = w_ctptr.ctitem
    if ctitem.size < 0:
        raise oefmt(space.w_ValueError, "array item of unknown size: '%s'",
                    ctitem.name)
    if length < 0:
        assert length == -1
        arraysize = -1
        extra = '[]'
    else:
        try:
            arraysize = ovfcheck(length * ctitem.size)
        except OverflowError:
            raise oefmt(space.w_OverflowError,
                        "array size would overflow a ssize_t")
        extra = '[%d]' % length
    #
    ctype = ctypearray.W_CTypeArray(space, w_ctptr, length, arraysize, extra)
    arrays.set(length, ctype)
    return ctype
コード例 #5
0
ファイル: newtype.py プロジェクト: mozillazg/pypy
def _new_pointer_type(space, w_ctype):
    _setup_wref(rweakref.has_weakref_support())
    ctptr = w_ctype._pointer_type()
    if ctptr is None:
        ctptr = ctypeptr.W_CTypePointer(space, w_ctype)
        w_ctype._pointer_type = rweakref.ref(ctptr)
    return ctptr
コード例 #6
0
ファイル: interp_iobase.py プロジェクト: kipras/pypy
 def add(self, w_iobase):
     if rweakref.has_weakref_support():
         self.add_handle(w_iobase)
コード例 #7
0
ファイル: interp_iobase.py プロジェクト: juokaz/pypy
 def add(self, w_iobase):
     if rweakref.has_weakref_support():
         self.add_handle(w_iobase)
コード例 #8
0
ファイル: interp_iobase.py プロジェクト: charred/pypy
 def add(self, w_iobase):
     assert w_iobase.streamholder is None
     if rweakref.has_weakref_support():
         holder = StreamHolder(w_iobase)
         w_iobase.streamholder = holder
         self.streams[holder] = None