Debian Codegraph @

lib_pypy/_pypy_util_cffi.py

raw symbols SCIP
1 import __pypy__
2 from _pypy_util_cffi_inner import ffi, lib
3
4 class StackNew(object):
5 def __init__(self, tp, size=None):
6 if size is None:
7 total_size = ffi.sizeof(tp)
8 else:
9 if tp.endswith("[]"):
10 total_size = ffi.sizeof(tp[:-2] + "[1]") * size
11 else:
12 total_size = ffi.sizeof(tp) * size
13 if tp.endswith("[]"):
14 tp = tp[:-2] + "*" # XXX dodgu?
15 self._p = ffi.cast(tp, lib.malloc(total_size))
16 __pypy__.add_memory_pressure(total_size)
17
18 def __enter__(self):
19 return self._p
20
21 def __exit__(self, tp, val, tb):
22 lib.free(ffi.cast("void*", self._p))