Procházet zdrojové kódy

replace all `free`

blueloveTH před 1 rokem
rodič
revize
6d2547723f

+ 1 - 1
include/pocketpy/common/utils.h

@@ -45,6 +45,6 @@ typedef struct RefCounted {
     do {                                                                                           \
         if(--(obj)->rc.count == 0) {                                                               \
             (obj)->rc.dtor(obj);                                                                   \
-            free(obj);                                                                             \
+            PK_FREE(obj);                                                                             \
         }                                                                                          \
     } while(0)

+ 1 - 1
include/pocketpy/xmacros/smallmap.h

@@ -66,7 +66,7 @@ NAME* METHOD(new)() {
 
 void METHOD(delete)(NAME* self) {
     METHOD(dtor)(self);
-    free(self);
+    PK_FREE(self);
 }
 
 void METHOD(set)(NAME* self, K key, V value) {

+ 2 - 2
src/common/algorithm.c

@@ -46,12 +46,12 @@ bool c11__stable_sort(void* ptr_,
             if(b_end > ptr + length * elem_size) b_end = ptr + length * elem_size;
             bool ok = merge(a, a_end, b, b_end, tmp, elem_size, f_lt, extra);
             if(!ok) {
-                free(tmp);
+                PK_FREE(tmp);
                 return false;
             }
             memcpy(a, tmp, b_end - a);
         }
     }
-    free(tmp);
+    PK_FREE(tmp);
     return true;
 }

+ 6 - 6
src/common/memorypool.c

@@ -169,14 +169,14 @@ static void MemoryPool__shrink_to_fit(MemoryPool* self) {
             MemoryPoolArena* arena = (MemoryPoolArena*)node;
             if(MemoryPoolArena__full(arena)) {
                 LinkedList__erase(&self->_arenas, node);
-                free(arena);
+                PK_FREE(arena);
             });
 }
 
 
 static void MemoryPool__dtor(MemoryPool* self) {
-    LinkedList__apply(&self->_arenas, free(node););
-    LinkedList__apply(&self->_empty_arenas, free(node););
+    LinkedList__apply(&self->_arenas, PK_FREE(node););
+    LinkedList__apply(&self->_empty_arenas, PK_FREE(node););
 }
 
 typedef struct FixedMemoryPool {
@@ -205,8 +205,8 @@ static void FixedMemoryPool__ctor(FixedMemoryPool* self, int BlockSize, int Bloc
 }
 
 static void FixedMemoryPool__dtor(FixedMemoryPool* self) {
-    free(self->_free_list);
-    free(self->data);
+    PK_FREE(self->_free_list);
+    PK_FREE(self->data);
 }
 
 static void* FixedMemoryPool__alloc(FixedMemoryPool* self) {
@@ -226,7 +226,7 @@ static void FixedMemoryPool__dealloc(FixedMemoryPool* self, void* p) {
         self->_free_list_end++;
     } else {
         self->exceeded_bytes -= self->BlockSize;
-        free(p);
+        PK_FREE(p);
     }
 }
 

+ 1 - 1
src/common/str.c

@@ -51,7 +51,7 @@ c11_string* c11_string__copy(c11_string* self) {
     return retval;
 }
 
-void c11_string__delete(c11_string* self) { free(self); }
+void c11_string__delete(c11_string* self) { PK_FREE(self); }
 
 c11_sv c11_string__sv(c11_string* self) { return (c11_sv){self->data, self->size}; }
 

+ 2 - 2
src/common/strname.c

@@ -13,7 +13,7 @@ static c11_vector /*T=char* */ _r_interned;
 void py_Name__initialize() {
     c11_smallmap_s2n__ctor(&_interned);
     for(int i = 0; i < _r_interned.length; i++) {
-        free(c11__at(char*, &_r_interned, i));
+        PK_FREE(c11__at(char*, &_r_interned, i));
     }
     c11_vector__ctor(&_r_interned, sizeof(c11_sv));
 
@@ -26,7 +26,7 @@ void py_Name__initialize() {
 void py_Name__finalize() {
     // free all char*
     for(int i = 0; i < _r_interned.length; i++) {
-        free(c11__getitem(char*, &_r_interned, i));
+        PK_FREE(c11__getitem(char*, &_r_interned, i));
     }
     c11_smallmap_s2n__dtor(&_interned);
     c11_vector__dtor(&_r_interned);

+ 2 - 1
src/common/vector.c

@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "pocketpy/common/utils.h"
+#include "pocketpy/config.h"
 
 void c11_vector__ctor(c11_vector* self, int elem_size) {
     self->data = NULL;
@@ -12,7 +13,7 @@ void c11_vector__ctor(c11_vector* self, int elem_size) {
 }
 
 void c11_vector__dtor(c11_vector* self) {
-    if(self->data) free(self->data);
+    if(self->data) PK_FREE(self->data);
     self->data = NULL;
     self->length = 0;
     self->capacity = 0;

+ 3 - 3
src/compiler/compiler.c

@@ -464,7 +464,7 @@ void SequenceExpr__dtor(Expr* self_) {
     for(int i = 0; i < self->itemCount; i++) {
         vtdelete(self->items[i]);
     }
-    free(self->items);
+    PK_FREE(self->items);
 }
 
 bool TupleExpr__emit_store(Expr* self_, Ctx* ctx) {
@@ -1318,11 +1318,11 @@ static void Compiler__dtor(Compiler* self) {
     // free tokens
     for(int i = 0; i < self->tokens_length; i++) {
         if(self->tokens[i].value.index == TokenValue_STR) {
-            // free internal string
+            // PK_FREE internal string
             c11_string__delete(self->tokens[i].value._str);
         }
     }
-    free(self->tokens);
+    PK_FREE(self->tokens);
     // free contexts
     c11__foreach(Ctx, &self->contexts, ctx) Ctx__dtor(ctx);
     c11_vector__dtor(&self->contexts);

+ 1 - 1
src/interpreter/frame.c

@@ -35,7 +35,7 @@ UnwindTarget* UnwindTarget__new(UnwindTarget* next, int iblock, int offset) {
     return self;
 }
 
-void UnwindTarget__delete(UnwindTarget* self) { free(self); }
+void UnwindTarget__delete(UnwindTarget* self) { PK_FREE(self); }
 
 Frame* Frame__new(const CodeObject* co,
                   py_GlobalRef module,

+ 1 - 1
src/interpreter/typeinfo.c

@@ -10,7 +10,7 @@ void TypeList__ctor(TypeList* self) {
 
 void TypeList__dtor(TypeList* self) {
     for (int i = 0; i < self->length; i++) {
-        if(self->chunks[i]) free(self->chunks[i]);
+        if(self->chunks[i]) PK_FREE(self->chunks[i]);
     }
 }
 

+ 1 - 1
src/interpreter/vm.c

@@ -572,7 +572,7 @@ void PyObject__delete(PyObject* self) {
     if(ti->dtor) ti->dtor(PyObject__userdata(self));
     if(self->slots == -1) NameDict__dtor(PyObject__dict(self));
     if(self->gc_is_large) {
-        free(self);
+        PK_FREE(self);
     } else {
         PoolObject_dealloc(self);
     }

+ 1 - 1
src/modules/os.c

@@ -160,7 +160,7 @@ static bool io_FileIO_read(int argc, py_Ref argv) {
         void* dst = PK_MALLOC(size);
         int actual_size = fread(dst, 1, size, ud->file);
         py_newstrv(py_retval(), (c11_sv){dst, actual_size});
-        free(dst);
+        PK_FREE(dst);
     }
     return true;
 }

+ 1 - 1
src/modules/pickle.c

@@ -48,7 +48,7 @@ static void PickleObject__ctor(PickleObject* self) {
 }
 
 static void PickleObject__dtor(PickleObject* self) {
-    free(self->used_types);
+    PK_FREE(self->used_types);
     c11_smallmap_p2i__dtor(&self->memo);
     c11_vector__dtor(&self->codes);
 }

+ 6 - 6
src/modules/random.c

@@ -233,21 +233,21 @@ static bool Random_choices(int argc, py_Ref argv) {
         py_TValue* w;
         int wlen = pk_arrayview(weights, &w);
         if(wlen == -1) {
-            free(cum_weights);
+            PK_FREE(cum_weights);
             return TypeError("choices(): weights must be a list or tuple");
         }
         if(wlen != length) {
-            free(cum_weights);
+            PK_FREE(cum_weights);
             return ValueError("len(weights) != len(population)");
         }
         if(!py_castfloat(&w[0], &cum_weights[0])) {
-            free(cum_weights);
+            PK_FREE(cum_weights);
             return false;
         }
         for(int i = 1; i < length; i++) {
             py_f64 tmp;
             if(!py_castfloat(&w[i], &tmp)) {
-                free(cum_weights);
+                PK_FREE(cum_weights);
                 return false;
             }
             cum_weights[i] = cum_weights[i - 1] + tmp;
@@ -256,7 +256,7 @@ static bool Random_choices(int argc, py_Ref argv) {
 
     py_f64 total = cum_weights[length - 1];
     if(total <= 0) {
-        free(cum_weights);
+        PK_FREE(cum_weights);
         return ValueError("total of weights must be greater than zero");
     }
 
@@ -269,7 +269,7 @@ static bool Random_choices(int argc, py_Ref argv) {
         py_list_setitem(py_retval(), i, p + index);
     }
 
-    free(cum_weights);
+    PK_FREE(cum_weights);
     return true;
 }
 

+ 1 - 1
src/modules/traceback.c

@@ -8,7 +8,7 @@ static bool traceback_format_exc(int argc, py_Ref argv) {
         py_newnone(py_retval());
     } else {
         py_newstr(py_retval(), s);
-        free(s);
+        PK_FREE(s);
     }
     return true;
 }

+ 2 - 2
src/objects/namedict.c

@@ -17,11 +17,11 @@ void ModuleDict__ctor(ModuleDict* self, const char* path, py_TValue module) {
 void ModuleDict__dtor(ModuleDict* self) {
     if(self->left) {
         ModuleDict__dtor(self->left);
-        free(self->left);
+        PK_FREE(self->left);
     }
     if(self->right) {
         ModuleDict__dtor(self->right);
-        free(self->right);
+        PK_FREE(self->right);
     }
 }
 

+ 1 - 1
src/public/exec.c

@@ -30,7 +30,7 @@ bool _py_compile(CodeObject* out,
         PK_DECREF(src);
 
         PK_DECREF(err->src);
-        free(err);
+        PK_FREE(err);
         return false;
     }
     PK_DECREF(src);

+ 1 - 1
src/public/internal.c

@@ -51,7 +51,7 @@ void py_finalize() {
             // TODO: refactor VM__ctor and VM__dtor
             pk_current_vm = vm;
             VM__dtor(vm);
-            free(vm);
+            PK_FREE(vm);
         }
     }
     pk_current_vm = &pk_default_vm;

+ 1 - 1
src/public/modules.c

@@ -155,7 +155,7 @@ __SUCCESS:
 
     c11_string__delete(filename);
     c11_string__delete(slashed_path);
-    if(need_free) free((void*)data);
+    if(need_free) PK_FREE((void*)data);
     return ok ? 1 : -1;
 }
 

+ 2 - 2
src/public/py_dict.c

@@ -87,7 +87,7 @@ static void Dict__ctor(Dict* self, uint32_t capacity, int entries_capacity) {
 static void Dict__dtor(Dict* self) {
     self->length = 0;
     self->capacity = 0;
-    free(self->indices);
+    PK_FREE(self->indices);
     c11_vector__dtor(&self->entries);
 }
 
@@ -176,7 +176,7 @@ static void Dict__compact_entries(Dict* self) {
             self->indices[i]._[j] = mappings[idx];
         }
     }
-    free(mappings);
+    PK_FREE(mappings);
 }
 
 static bool Dict__set(Dict* self, py_TValue* key, py_TValue* val) {

+ 1 - 1
src/public/py_exception.c

@@ -164,7 +164,7 @@ void py_printexc() {
     if(!msg) return;
     pk_current_vm->callbacks.print(msg);
     pk_current_vm->callbacks.print("\n");
-    free(msg);
+    PK_FREE(msg);
 }
 
 static void c11_sbuf__write_exc(c11_sbuf* self, py_Ref exc) {