mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
... ...
This commit is contained in:
parent
649f0d54e7
commit
ed9be6f80e
@ -8,7 +8,7 @@ def memset(ptr: 'void_p', value: int, size: int) -> None: ...
|
|||||||
def memcpy(dst: 'void_p', src: 'void_p', size: int) -> None: ...
|
def memcpy(dst: 'void_p', src: 'void_p', size: int) -> None: ...
|
||||||
|
|
||||||
class _refl:
|
class _refl:
|
||||||
pass
|
def __call__(self) -> 'struct': ...
|
||||||
|
|
||||||
class void_p:
|
class void_p:
|
||||||
def __add__(self, i: int) -> 'void_p': ...
|
def __add__(self, i: int) -> 'void_p': ...
|
||||||
@ -57,6 +57,6 @@ class void_p:
|
|||||||
def set_base_offset(self, offset: str) -> None: ...
|
def set_base_offset(self, offset: str) -> None: ...
|
||||||
|
|
||||||
class struct:
|
class struct:
|
||||||
def address(self) -> 'void_p': ...
|
def addr(self) -> 'void_p': ...
|
||||||
def copy(self) -> 'struct': ...
|
def copy(self) -> 'struct': ...
|
||||||
def size(self) -> int: ...
|
def size(self) -> int: ...
|
||||||
|
10
src/cffi.h
10
src/cffi.h
@ -173,7 +173,7 @@ struct C99Struct{
|
|||||||
C99Struct() { p = _inlined; }
|
C99Struct() { p = _inlined; }
|
||||||
C99Struct(void* p, int size){
|
C99Struct(void* p, int size){
|
||||||
_init(size);
|
_init(size);
|
||||||
memcpy(this->p, p, size);
|
if(p!=nullptr) memcpy(this->p, p, size);
|
||||||
}
|
}
|
||||||
~C99Struct(){ if(p!=_inlined) free(p); }
|
~C99Struct(){ if(p!=_inlined) free(p); }
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ struct C99Struct{
|
|||||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||||
vm->bind_default_constructor<C99Struct>(type);
|
vm->bind_default_constructor<C99Struct>(type);
|
||||||
|
|
||||||
vm->bind_method<0>(type, "address", [](VM* vm, ArgsView args){
|
vm->bind_method<0>(type, "addr", [](VM* vm, ArgsView args){
|
||||||
C99Struct& self = _CAST(C99Struct&, args[0]);
|
C99Struct& self = _CAST(C99Struct&, args[0]);
|
||||||
return VAR_T(VoidP, self.p);
|
return VAR_T(VoidP, self.p);
|
||||||
});
|
});
|
||||||
@ -264,6 +264,12 @@ struct C99ReflType{
|
|||||||
PY_CLASS(C99ReflType, c, "_refl")
|
PY_CLASS(C99ReflType, c, "_refl")
|
||||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||||
vm->bind_constructor<-1>(type, CPP_NOT_IMPLEMENTED());
|
vm->bind_constructor<-1>(type, CPP_NOT_IMPLEMENTED());
|
||||||
|
|
||||||
|
vm->bind_method<0>(type, "__call__", [](VM* vm, ArgsView args){
|
||||||
|
PyObject* self = args[0];
|
||||||
|
i64 size = CAST(i64, self->attr("__size__"));
|
||||||
|
return VAR_T(C99Struct, nullptr, size);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user