Beispiel #1
0
 def func():
     from pypy.rlib import rgc
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Beispiel #2
0
 def func():
     from pypy.rlib import rgc
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Beispiel #3
0
 def func():
     #try:
     a = rgc.malloc_nonmovable(TP, 3, zero=True)
     rgc.collect()
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Beispiel #4
0
 def alloc_gcref_list(self, n):
     # Important: the GRREF_LISTs allocated are *non-movable*.  This
     # requires support in the gc (only the hybrid GC supports it so far).
     if we_are_translated():
         list = rgc.malloc_nonmovable(self.GCREF_LIST, n)
         assert list, "malloc_nonmovable failed!"
     else:
         list = lltype.malloc(self.GCREF_LIST, n)  # for tests only
     return list
Beispiel #5
0
 def alloc_gcref_list(self, n):
     # Important: the GRREF_LISTs allocated are *non-movable*.  This
     # requires support in the gc (only the hybrid GC supports it so far).
     if we_are_translated():
         list = rgc.malloc_nonmovable(self.GCREF_LIST, n)
         assert list, "malloc_nonmovable failed!"
     else:
         list = lltype.malloc(self.GCREF_LIST, n)     # for tests only
     return list
Beispiel #6
0
 def _grow(self):
     # XXX workaround for a fact that rgc.malloc_nonmovable always
     #     returns nullptr when run on top of python
     if we_are_translated():
         new_item = rgc.malloc_nonmovable(ATP, CHUNK_SIZE, zero=True)
     else:
         new_item = lltype.malloc(ATP, CHUNK_SIZE, zero=True)
     self.chunks.append(new_item)
     self.lgt += 1
Beispiel #7
0
 def _grow(self):
     # XXX workaround for a fact that rgc.malloc_nonmovable always
     #     returns nullptr when run on top of python
     if we_are_translated():
         new_item = rgc.malloc_nonmovable(ATP, CHUNK_SIZE, zero=True)
     else:
         new_item = lltype.malloc(ATP, CHUNK_SIZE, zero=True)
     self.chunks.append(new_item)
     self.lgt += 1
Beispiel #8
0
 def func():
     try:
         a = rgc.malloc_nonmovable(TP)
         rgc.collect()
         if a:
             assert not rgc.can_move(a)
             return 0
         return 1
     except Exception, e:
         return 2
Beispiel #9
0
 def func():
     try:
         from pypy.rlib import rgc
         a = rgc.malloc_nonmovable(TP, 3)
         rgc.collect()
         if a:
             assert not rgc.can_move(a)
             return 0
         return 1
     except Exception, e:
         return 2
Beispiel #10
0
 def func():
     try:
         from pypy.rlib import rgc
         a = rgc.malloc_nonmovable(TP, 3)
         rgc.collect()
         if a:
             assert not rgc.can_move(a)
             return 0
         return 1
     except Exception, e:
         return 2
Beispiel #11
0
 def alloc_buffer(count):
     """
     Returns a (raw_buffer, gc_buffer) pair, allocated with count bytes.
     The raw_buffer can be safely passed to a native function which expects
     it to not move. Call str_from_buffer with the returned values to get a
     safe high-level string. When the garbage collector cooperates, this
     allows for the process to be performed without an extra copy.
     Make sure to call keep_buffer_alive_until_here on the returned values.
     """
     str_chars_offset = offsetof(STRTYPE, "chars") + itemoffsetof(STRTYPE.chars, 0)
     gc_buf = rgc.malloc_nonmovable(STRTYPE, count)
     if gc_buf:
         realbuf = cast_ptr_to_adr(gc_buf) + str_chars_offset
         raw_buf = cast(TYPEP, realbuf)
         return raw_buf, gc_buf
     else:
         raw_buf = lltype.malloc(TYPEP.TO, count, flavor="raw")
         return raw_buf, lltype.nullptr(STRTYPE)
Beispiel #12
0
 def alloc_buffer(count):
     """
     Returns a (raw_buffer, gc_buffer) pair, allocated with count bytes.
     The raw_buffer can be safely passed to a native function which expects
     it to not move. Call str_from_buffer with the returned values to get a
     safe high-level string. When the garbage collector cooperates, this
     allows for the process to be performed without an extra copy.
     Make sure to call keep_buffer_alive_until_here on the returned values.
     """
     str_chars_offset = (offsetof(STRTYPE, 'chars') + \
                         itemoffsetof(STRTYPE.chars, 0))
     gc_buf = rgc.malloc_nonmovable(STRTYPE, count)
     if gc_buf:
         realbuf = cast_ptr_to_adr(gc_buf) + str_chars_offset
         raw_buf = cast(TYPEP, realbuf)
         return raw_buf, gc_buf
     else:
         raw_buf = lltype.malloc(TYPEP.TO, count, flavor='raw')
         return raw_buf, lltype.nullptr(STRTYPE)
Beispiel #13
0
 def func():
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1
Beispiel #14
0
 def func():
     a = rgc.malloc_nonmovable(TP, 3)
     if a:
         assert not rgc.can_move(a)
         return 0
     return 1