Kaynağa Gözat

fix thread create bug for freeRTOS

lyon 2 yıl önce
ebeveyn
işleme
0db9ff7c8c

+ 3 - 3
package/_thread/_thread.c

@@ -118,8 +118,6 @@ static void _thread_func(void* arg) {
 #endif
 }
 
-int PikaStdData_Tuple_len(PikaObj* self);
-
 void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
     pika_thread_info* info =
         (pika_thread_info*)pikaMalloc(sizeof(pika_thread_info));
@@ -128,7 +126,8 @@ void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
 
     if (arg_isObject(args_)) {
         PikaObj* tuple = arg_getPtr(args_);
-        size_t tuple_size = PikaStdData_Tuple_len(tuple);
+        size_t tuple_size = objTuple_getSize(tuple);
+        pika_debug("type of args is %d", arg_getType(args_));
         pika_debug("new_thread: args tuple size %d", tuple_size);
         if (tuple_size > 0) {
             info->args = arg_copy(args_);
@@ -146,6 +145,7 @@ void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
     }
 
     info->stack_size = g_thread_stack_size;
+    pika_debug("thread stack size %d", info->stack_size);
     info->thread = pika_platform_thread_init("pika_thread", _thread_func, info,
                                              info->stack_size, PIKA_THREAD_PRIO,
                                              PIKA_THREAD_TICK);

+ 3 - 3
port/linux/package/pikascript/pikascript-lib/_thread/_thread.c

@@ -118,8 +118,6 @@ static void _thread_func(void* arg) {
 #endif
 }
 
-int PikaStdData_Tuple_len(PikaObj* self);
-
 void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
     pika_thread_info* info =
         (pika_thread_info*)pikaMalloc(sizeof(pika_thread_info));
@@ -128,7 +126,8 @@ void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
 
     if (arg_isObject(args_)) {
         PikaObj* tuple = arg_getPtr(args_);
-        size_t tuple_size = PikaStdData_Tuple_len(tuple);
+        size_t tuple_size = objTuple_getSize(tuple);
+        pika_debug("type of args is %d", arg_getType(args_));
         pika_debug("new_thread: args tuple size %d", tuple_size);
         if (tuple_size > 0) {
             info->args = arg_copy(args_);
@@ -146,6 +145,7 @@ void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
     }
 
     info->stack_size = g_thread_stack_size;
+    pika_debug("thread stack size %d", info->stack_size);
     info->thread = pika_platform_thread_init("pika_thread", _thread_func, info,
                                              info->stack_size, PIKA_THREAD_PRIO,
                                              PIKA_THREAD_TICK);

+ 2 - 1
src/PikaObj.c

@@ -897,6 +897,7 @@ static PikaObj* _obj_getObjWithKeepDeepth(PikaObj* self,
     if ('.' == objPath[0] && '\0' == objPath[1]) {
         return self;
     }
+    pika_assert(strGetSize(objPath) < PIKA_PATH_BUFF_SIZE);
     strcpy(objPath_buff, objPath);
     int32_t token_num = strGetTokenNum(objPath, '.');
     PikaObj* obj = self;
@@ -960,6 +961,7 @@ char* methodArg_getTypeList(Arg* method_arg, char* buffs, size_t size) {
     pika_assert(arg_isCallable(method_arg));
     MethodProp* prop = (MethodProp*)arg_getContent(method_arg);
     if (NULL != prop->type_list) {
+        pika_assert(strGetSize(prop->type_list) < size);
         return strcpy(buffs, prop->type_list);
     }
     char* method_dec = methodArg_getDec(method_arg);
@@ -971,7 +973,6 @@ char* methodArg_getTypeList(Arg* method_arg, char* buffs, size_t size) {
         }
     }
     char* res = strCut(buffs, method_dec, '(', ')');
-    pika_assert_msg(NULL != res, "method_dec: %s", method_dec);
     return res;
 }
 

+ 1 - 1
src/PikaPlatform.c

@@ -453,7 +453,7 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
                           thread->thread_stack, &thread->task_buffer);
 #else
     int err =
-        xTaskCreate(entry, name, stack_size, param, priority, thread->thread);
+        xTaskCreate(entry, name, stack_size, param, priority, &thread->thread);
 #endif
 
 #if PIKA_THREAD_MALLOC_STACK_ENABLE

+ 1 - 0
src/PikaVM.c

@@ -1455,6 +1455,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
     /* get method type list */
     f.type_list =
         methodArg_getTypeList(aMethod, buffs1, METHOD_TYPE_LIST_MAX_LEN);
+    pika_assert_msg(NULL != f.type_list, "method: %s", sMethodName);
     if (NULL == f.type_list) {
         pika_platform_printf(
             "OverflowError: type list is too long, please use bigger "