mirror of
https://github.com/pocketpy/pocketpy
synced 2026-05-06 10:13:37 +00:00
fix stdc.memcpy
This commit is contained in:
parent
9a57b281e8
commit
6e3ed84a9e
@ -5,7 +5,7 @@ intptr = int
|
|||||||
def malloc(size: int) -> intptr: ...
|
def malloc(size: int) -> intptr: ...
|
||||||
def free(ptr: intptr) -> None: ...
|
def free(ptr: intptr) -> None: ...
|
||||||
|
|
||||||
def memcpy(dst: intptr, src: intptr, n: int) -> None: ...
|
def memcpy(dst: intptr, src: intptr | bytes, n: int) -> None: ...
|
||||||
def memset(s: intptr, c: int, n: int) -> None: ...
|
def memset(s: intptr, c: int, n: int) -> None: ...
|
||||||
def memcmp(s1: intptr, s2: intptr, n: int) -> int: ...
|
def memcmp(s1: intptr, s2: intptr, n: int) -> int: ...
|
||||||
|
|
||||||
|
|||||||
@ -124,12 +124,19 @@ static bool stdc_free(int argc, py_Ref argv) {
|
|||||||
|
|
||||||
static bool stdc_memcpy(int argc, py_Ref argv) {
|
static bool stdc_memcpy(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(3);
|
PY_CHECK_ARGC(3);
|
||||||
PY_CHECK_ARG_TYPE(0, tp_int);
|
PY_CHECK_ARG_TYPE(0, tp_int); // dst
|
||||||
PY_CHECK_ARG_TYPE(1, tp_int);
|
|
||||||
PY_CHECK_ARG_TYPE(2, tp_int);
|
|
||||||
void* dst = (void*)(intptr_t)py_toint(&argv[0]);
|
void* dst = (void*)(intptr_t)py_toint(&argv[0]);
|
||||||
void* src = (void*)(intptr_t)py_toint(&argv[1]);
|
PY_CHECK_ARG_TYPE(2, tp_int); // n
|
||||||
py_i64 n = py_toint(&argv[2]);
|
py_i64 n = py_toint(&argv[2]);
|
||||||
|
void* src;
|
||||||
|
if(py_istype(&argv[1], tp_bytes)) {
|
||||||
|
int size;
|
||||||
|
src = py_tobytes(&argv[1], &size);
|
||||||
|
if(size < n) n = size;
|
||||||
|
} else {
|
||||||
|
PY_CHECK_ARG_TYPE(1, tp_int); // src
|
||||||
|
src = (void*)(intptr_t)py_toint(&argv[1]);
|
||||||
|
}
|
||||||
memcpy(dst, src, (size_t)n);
|
memcpy(dst, src, (size_t)n);
|
||||||
py_newnone(py_retval());
|
py_newnone(py_retval());
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user