Sfoglia il codice sorgente

fix attr.XX.YY cause mem lack

lyon1998 2 anni fa
parent
commit
c52e180975

+ 1 - 1
port/linux/.vscode/launch.json

@@ -19,7 +19,7 @@
                 // "--gtest_filter=vm.run_file"
                 // "--gtest_filter=stddata.encode_decode"
                 // "--gtest_filter=packtool.packfiles_txt"
-                "--gtest_filter=parser.rshift_equ"
+                "--gtest_filter=cmodule.class_attr_obj"
             ],
             "stopAtEntry": false,
             "cwd": "${workspaceFolder}",

+ 13 - 1
port/linux/package/pikascript/GTestTask.pyi

@@ -22,5 +22,17 @@ class ProxyTest:
     def __getattribute__(self, __name: str) -> any: ...
     def __setattr__(self, __name: str, __value: any): ...
 
+
 class _test:
-    def __init__(self):...
+    def __init__(self): ...
+
+
+class ATTR_TYPE:
+    b: int
+    def __init__(self): ...
+
+
+class ClassAttr:
+    A: int
+    B: ATTR_TYPE
+    def __init__(self, a: int): ...

+ 23 - 0
port/linux/package/pikascript/pikascript-lib/GTestTask/GTestTask.c

@@ -1,4 +1,5 @@
 #include "GTestTask.h"
+#include "GTestTask_ATTR_TYPE.h"
 #include "GTestTask_ProxyTest.h"
 #include "GTestTask_Task.h"
 #include "PikaStdData_Dict.h"
@@ -67,3 +68,25 @@ void GTestTask_test_raise(PikaObj* self) {
 void GTestTask__test___init__(PikaObj* self) {
     obj_setStr(self, "a", NULL);
 }
+
+/*
+class ATTR_TYPE:
+    b: int
+    def __init__(self): ...
+
+
+class ClassAttr:
+    A: int
+    B: ATTR_TYPE
+    def __init__(self, a: int): ...
+*/
+
+void GTestTask_ATTR_TYPE___init__(PikaObj* self) {
+    obj_setInt(self, "b", 0);
+}
+
+void GTestTask_ClassAttr___init__(PikaObj* self, int a) {
+    obj_setInt(self, "A", a);
+    obj_newDirectObj(self, "B", New_GTestTask_ATTR_TYPE);
+    obj_runMethod0(obj_getObj(self, "B"), "__init__");
+}

+ 33 - 19
src/PikaObj.c

@@ -868,40 +868,42 @@ static PikaObj* _obj_getObjDirect(PikaObj* self,
         return NULL;
     }
     /* finded object, check type*/
-    Arg* arg_obj = args_getArg(self->list, name);
+    Arg* aObj = args_getArg(self->list, name);
     ArgType type = ARG_TYPE_NONE;
-    if (NULL == arg_obj) {
-        arg_obj = _obj_getPropArg(self, name);
+    if (NULL == aObj) {
+        aObj = _obj_getPropArg(self, name);
     }
-    if (NULL == arg_obj) {
+    if (NULL == aObj) {
         return NULL;
     }
-    type = arg_getType(arg_obj);
+    type = arg_getType(aObj);
     /* found meta Object */
     if (type == ARG_TYPE_OBJECT_META) {
         return _obj_initMetaObj(self, name);
     }
     /* found Objcet */
     if (argType_isObject(type)) {
-        return arg_getPtr(arg_obj);
+        return arg_getPtr(aObj);
     }
 #if !PIKA_NANO_ENABLE
     /* found class */
     if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
         type == ARG_TYPE_METHOD_CONSTRUCTOR) {
         *pIsTemp = pika_true;
-        PikaObj* method_args_obj = New_TinyObj(NULL);
-        Arg* cls_obj_arg = obj_runMethodArg(self, method_args_obj, arg_obj);
-        obj_deinit(method_args_obj);
+        PikaObj* oMethodArgs = New_TinyObj(NULL);
+        Arg* aClsObj = obj_runMethodArg(self, oMethodArgs, aObj);
+        obj_deinit(oMethodArgs);
+        Args* args = New_args(NULL);
         if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR) {
-            obj_runNativeMethod(arg_getPtr(cls_obj_arg), "__init__", NULL);
+            obj_runNativeMethod(arg_getPtr(aClsObj), "__init__", args);
         }
-        PikaObj* res = arg_getPtr(cls_obj_arg);
-        arg_deinit(cls_obj_arg);
+        PikaObj* res = arg_getPtr(aClsObj);
+        arg_deinit(aClsObj);
+        args_deinit(args);
         return res;
     }
 #endif
-    return _arg_to_obj(arg_obj, pIsTemp);
+    return _arg_to_obj(aObj, pIsTemp);
 }
 
 static PikaObj* _obj_getObjWithKeepDeepth(PikaObj* self,
@@ -917,20 +919,32 @@ static PikaObj* _obj_getObjWithKeepDeepth(PikaObj* self,
     pika_assert(strGetSize(objPath) < PIKA_PATH_BUFF_SIZE);
     strcpy(objPath_buff, objPath);
     int32_t token_num = strGetTokenNum(objPath, '.');
-    PikaObj* obj = self;
+    PikaObj* objThis = self;
+    PikaObj* objNext = NULL;
+    pika_bool bThisIsTemp = pika_false;
     for (int32_t i = 0; i < token_num - keepDeepth; i++) {
         char* token = strPopFirstToken(&objPath_ptr, '.');
-        obj = _obj_getObjDirect(obj, token, pIsTemp);
-        if (obj == NULL) {
+        objNext = _obj_getObjDirect(objThis, token, pIsTemp);
+        if (objNext == NULL) {
+            objThis = NULL;
             goto __exit;
         }
+        if (bThisIsTemp) {
+            if (*pIsTemp == pika_false) {
+                obj_refcntInc(objNext);
+                *pIsTemp = pika_true;
+            }
+            obj_deinit(objThis);
+        }
+        objThis = objNext;
+        bThisIsTemp = *pIsTemp;
     }
     goto __exit;
 __exit:
-    if (NULL != obj) {
-        pika_assert(obj_checkAlive(obj));
+    if (NULL != objThis) {
+        pika_assert(obj_checkAlive(objThis));
     }
-    return obj;
+    return objThis;
 }
 
 PikaObj* obj_getObj(PikaObj* self, char* objPath) {

+ 1 - 1
src/PikaPlatform.c

@@ -34,7 +34,7 @@
 #endif
 
 #if defined(_WIN32)
-#include <dirent.h>
+#include <direct.h>
 #endif
 
 #if defined(__linux) || PIKA_LINUX_COMPATIBLE

+ 1 - 1
src/PikaVersion.h

@@ -2,4 +2,4 @@
 #define PIKA_VERSION_MINOR 13
 #define PIKA_VERSION_MICRO 1
 
-#define PIKA_EDIT_TIME "2023/12/28 14:29:51"
+#define PIKA_EDIT_TIME "2024/01/01 19:22:12"

BIN
tools/pikaCompiler/rust-msc-latest-win10.exe