add ref_cnt domen for arg

This commit is contained in:
lyon 2022-04-25 13:24:23 +08:00
parent 2eaea345cc
commit 8bc6f64215
4 changed files with 43 additions and 31 deletions

View File

@ -1,32 +1,40 @@
from PikaStdLib import MemChecker as MC
import PikaStdLib
from PikaObj import *
import PikaStdData
import ctypes
import GTestTask
import PikaMath
import PikaStdDevice
import PikaDebug
import ctypes
import PikaStdData
mem = PikaStdLib.MemChecker()
def dcrf32_test():
rlen = ctypes.c_uint(0)
rcvbuf = ctypes.c_wchar_p('')
hdl = ctypes.Test()
i = 0
t = ctypes.Test()
sendbuf = b'\x00\x84\x00\x00\x08'
while i < 50 :
hdl.dc_cpuapdu_hex(5, sendbuf, rlen, rcvbuf)
# hdl.print_rcv(rcvbuf)
# rlen.value
i = 0
while i < 3 :
t.dc_cpuapdu_hex(5, sendbuf, rlen, rcvbuf)
t.print_rcv(rcvbuf)
i += 1
mem.max()
dcrf32_test()
mem = PikaStdLib.MemChecker()
num = 10
c = str(num)
s = "num = " + c
print(s)
cnt = 0
while cnt < 3:
dcrf32_test()
print('----------------------')
log = 'loop '+ str(cnt) + 'mem use max:'
print(log)
mem.max()
print('----------------------')
cnt += 1
print('mem use max:')
mem.max()
mem.max()

View File

@ -463,15 +463,7 @@ static Arg* VM_instruction_handler_BYT(PikaObj* self, VMState* vs, char* data) {
return arg_setBytes(NULL, "", (uint8_t*)data, strGetSize(data));
}
typedef enum {
IS_INIT_OBJ_TRUE,
IS_INIT_OBJ_FALSE,
} is_init_obj_t;
static Arg* __VM_OUT(PikaObj* self,
VMState* vs,
char* data,
is_init_obj_t is_init_obj) {
static Arg* VM_instruction_handler_OUT(PikaObj* self, VMState* vs, char* data) {
Arg* outArg = stack_popArg(&(vs->stack));
ArgType outArg_type = arg_getType(outArg);
PikaObj* hostObj = vs->locals;
@ -499,6 +491,7 @@ static Arg* __VM_OUT(PikaObj* self,
/* set free object to nomal object */
if (ARG_TYPE_FREE_OBJECT == outArg_type) {
arg_setType(outArg, ARG_TYPE_OBJECT);
arg_refCntInc(outArg);
}
/* ouput arg to locals */
obj_setArg_noCopy(hostObj, data, outArg);
@ -512,10 +505,6 @@ static Arg* __VM_OUT(PikaObj* self,
return NULL;
}
static Arg* VM_instruction_handler_OUT(PikaObj* self, VMState* vs, char* data) {
return __VM_OUT(self, vs, data, IS_INIT_OBJ_TRUE);
}
/* run as */
static Arg* VM_instruction_handler_RAS(PikaObj* self, VMState* vs, char* data) {
if (strEqu(data, "$origin")) {

View File

@ -349,3 +349,15 @@ void arg_deinit(Arg* self) {
arg_deinitHeap(self);
arg_freeContent(self);
}
void arg_refCntInc(Arg* self) {
((__arg*)self)->ref_cnt++;
}
void arg_refCntDec(Arg* self) {
((__arg*)self)->ref_cnt--;
}
uint8_t arg_getRefCnt(Arg* self) {
return ((__arg*)self)->ref_cnt;
}

View File

@ -60,7 +60,7 @@ struct __arg {
__arg* next;
uint16_t size;
uint8_t type;
uint8_t __rsvd;
uint8_t ref_cnt;
Hash name_hash;
uint8_t content[];
};
@ -138,5 +138,8 @@ void* arg_getHeapStruct(Arg* self);
void arg_deinitHeap(Arg* self);
Arg* arg_setBytes(Arg* self, char* name, uint8_t* src, size_t size);
void arg_printBytes(Arg* self);
void arg_refCntInc(Arg* self);
void arg_refCntDec(Arg* self);
uint8_t arg_getRefCnt(Arg* self);
#endif