Browse Source

minor fix

blueloveTH 1 month ago
parent
commit
b4ba0d91d5

+ 2 - 2
include/pocketpy/objects/codeobject.h

@@ -107,8 +107,8 @@ typedef struct FuncDecl {
     RefCounted rc;
     CodeObject code;  // strong ref
 
-    c11_vector /*T=int*/ args;      // indices in co->varnames
-    c11_vector /*T=KwArg*/ kwargs;  // indices in co->varnames
+    c11_vector /*T=int32_t*/ args;          // indices in co->varnames
+    c11_vector /*T=FuncDeclKwArg*/ kwargs;  // indices in co->varnames
 
     int starred_arg;    // index in co->varnames, -1 if no *arg
     int starred_kwarg;  // index in co->varnames, -1 if no **kwarg

+ 2 - 2
src/common/sourcedata.c

@@ -89,9 +89,9 @@ void SourceData__snapshot(const struct SourceData* self,
         c11_sbuf__write_cstr(ss, name);
     }
 
-    c11_sbuf__write_char(ss, '\n');
     const char *st = NULL, *ed;
     if(SourceData__get_line(self, lineno, &st, &ed)) {
+        c11_sbuf__write_char(ss, '\n');
         while(st < ed && isblank(*st))
             ++st;
         if(st < ed) {
@@ -108,5 +108,5 @@ void SourceData__snapshot(const struct SourceData* self,
         }
     }
 
-    if(!st) { c11_sbuf__write_cstr(ss, "    <?>"); }
+    // if(!st) { c11_sbuf__write_cstr(ss, "    <?>"); }
 }

+ 1 - 0
src/common/vector.c

@@ -78,6 +78,7 @@ int c11_vector__nextcap(c11_vector* self) {
 }
 
 void c11_vector__extend(c11_vector* self, const void* p, int size) {
+    if (size <= 0) return;
     int min_capacity = self->length + size;
     if(self->capacity < min_capacity) {
         int nextcap = c11_vector__nextcap(self);

+ 1 - 2
src/objects/codeobject_ser.c

@@ -19,7 +19,6 @@ static void CodeObject__serialize(c11_serializer* s,
 static CodeObject CodeObject__deserialize(c11_deserializer* d, const char* filename, SourceData_ embedded_src);
 
 // Serialize a py_TValue constant
-// Supported types: None, int, float, bool, str, bytes, tuple, Ellipsis
 static void TValue__serialize(c11_serializer* s, py_Ref val) {
     c11_serializer__write_type(s, val->type);
     // 1. co_consts: int | float | str
@@ -285,7 +284,7 @@ static void FuncDecl__serialize(c11_serializer* s,
 
 // Deserialize FuncDecl
 static FuncDecl_ FuncDecl__deserialize(c11_deserializer* d, SourceData_ embedded_src) {
-    FuncDecl* self = PK_MALLOC(sizeof(FuncDecl));
+    FuncDecl_ self = PK_MALLOC(sizeof(FuncDecl));
     self->rc.count = 1;
     self->rc.dtor = (void (*)(void*))FuncDecl__dtor;