| 1 |
from rpython.rlib import _rffi_stacklet as _c |
| 2 |
from rpython.rlib import debug |
| 3 |
from rpython.rlib.objectmodel import we_are_translated, specialize |
| 4 |
from rpython.rtyper.annlowlevel import llhelper |
| 5 |
|
| 6 |
|
| 7 |
class StackletGcRootFinder(object): |
| 8 |
@staticmethod |
| 9 |
@specialize.arg(1) |
| 10 |
def new(thrd, callback, arg): |
| 11 |
h = _c.new(thrd._thrd, llhelper(_c.run_fn, callback), arg) |
| 12 |
if not h: |
| 13 |
raise MemoryError |
| 14 |
return h |
| 15 |
|
| 16 |
@staticmethod |
| 17 |
def switch(h): |
| 18 |
h = _c.switch(h) |
| 19 |
if not h: |
| 20 |
raise MemoryError |
| 21 |
return h |
| 22 |
|
| 23 |
@staticmethod |
| 24 |
def destroy(thrd, h): |
| 25 |
_c.destroy(thrd._thrd, h) |
| 26 |
if we_are_translated(): |
| 27 |
debug.debug_print("not using a framework GC: " |
| 28 |
"stacklet_destroy() may leak") |
| 29 |
|
| 30 |
is_empty_handle = staticmethod(_c.is_empty_handle) |
| 31 |
|
| 32 |
@staticmethod |
| 33 |
def get_null_handle(): |
| 34 |
return _c.null_handle |
| 35 |
|
| 36 |
|
| 37 |
gcrootfinder = StackletGcRootFinder |