@@ -97,7 +97,7 @@ char* fast_itoa(char* buf, uint32_t val) {
9797 return & p [val < 10 ];
9898}
9999
100- int32_t obj_deinit (PikaObj * self ) {
100+ static int32_t obj_deinit_no_del (PikaObj * self ) {
101101 /* free the list */
102102 args_deinit (self -> list );
103103 /* free the pointer */
@@ -106,6 +106,22 @@ int32_t obj_deinit(PikaObj* self) {
106106 return 0 ;
107107}
108108
109+ int32_t obj_deinit (PikaObj * self ) {
110+ Arg * del = obj_getMethodArg (self , "__del__" );
111+ if (NULL != del ) {
112+ const uint8_t bytes [] = {
113+ 0x04 , 0x00 , /* instruct array size */
114+ 0x00 , 0x82 , 0x01 , 0x00 , /* instruct array */
115+ 0x09 , 0x00 , /* const pool size */
116+ 0x00 , 0x5f , 0x5f , 0x64 , 0x65 ,
117+ 0x6c , 0x5f , 0x5f , 0x00 , /* const pool */
118+ };
119+ pikaVM_runByteCode (self , (uint8_t * )bytes );
120+ arg_deinit (del );
121+ }
122+ return obj_deinit_no_del (self );
123+ }
124+
109125int32_t obj_enable (PikaObj * self ) {
110126 obj_setInt (self , "isEnable" , 1 );
111127 return 0 ;
@@ -327,14 +343,21 @@ Arg* obj_getMethodArg(PikaObj* obj, char* methodPath) {
327343 goto exit ;
328344 }
329345 methodHostClass = obj_getClassObj (obj );
346+ if (NULL == methodHostClass ) {
347+ method = NULL ;
348+ goto exit ;
349+ }
330350 method = arg_copy (obj_getArg (methodHostClass , methodName ));
331- obj_deinit (methodHostClass );
351+ obj_deinit_no_del (methodHostClass );
332352exit :
333353 return method ;
334354}
335355
336356PikaObj * obj_getClassObj (PikaObj * obj ) {
337357 NewFun classPtr = (NewFun )obj_getPtr (obj , "_clsptr" );
358+ if (NULL == classPtr ) {
359+ return NULL ;
360+ }
338361 PikaObj * classObj = obj_getClassObjByNewFun (obj , "" , classPtr );
339362 return classObj ;
340363}
0 commit comments