Keep backward-compatible API and warn when users use them. main
authormomoyon <momoyon@momoyon.org>
Tue, 3 Jun 2025 16:00:14 +0000 (21:00 +0500)
committermomoyon <momoyon@momoyon.org>
Tue, 3 Jun 2025 16:00:14 +0000 (21:00 +0500)
commonlib.h

index d28525f4d880de3b623c6153d6ca770fdd6c1807..836437b052f14b9b8fb5254a13e534882a0b116d 100644 (file)
 #define darr_remove c_darr_remove
 #define darr_delete c_darr_delete
 #define DYNAMIC_ARRAY_INITIAL_CAPACITY c_DYNAMIC_ARRAY_INITIAL_CAPACITY
 #define darr_remove c_darr_remove
 #define darr_delete c_darr_delete
 #define DYNAMIC_ARRAY_INITIAL_CAPACITY c_DYNAMIC_ARRAY_INITIAL_CAPACITY
+// Deprecated Dynamic-array API
+#define da_append c_da_append
+#define da_delete c_da_delete
+#define da_remove c_da_remove
 // #define c_DYNAMIC_ARRAY_INITIAL_CAPACITY
 #define arr_stack_init c_arr_stack_init
 #define arr_heap_init c_arr_heap_init
 // #define c_DYNAMIC_ARRAY_INITIAL_CAPACITY
 #define arr_stack_init c_arr_stack_init
 #define arr_heap_init c_arr_heap_init
@@ -197,7 +201,11 @@ typedef struct c_Arena c_Arena;
 
 #define c_DYNAMIC_ARRAY_INITIAL_CAPACITY (sizeof(size_t))
 
 
 #define c_DYNAMIC_ARRAY_INITIAL_CAPACITY (sizeof(size_t))
 
-#define c_darr_append(da, elm) do {\
+#define c_darr_append(da, elm) c_darr_append_impl(da, elm, c_darr_append)
+#define c_darr_append_impl(da, elm, api) do {\
+        if (strcmp(#api, "c_darr_append") != 0) {\
+            c_log_warning("%s is deprecated please use the newer api!", #api);\
+        }\
                if ((da).items == NULL) {\
                        (da).capacity = c_DYNAMIC_ARRAY_INITIAL_CAPACITY;\
                        (da).count = 0;\
                if ((da).items == NULL) {\
                        (da).capacity = c_DYNAMIC_ARRAY_INITIAL_CAPACITY;\
                        (da).count = 0;\
@@ -215,7 +223,12 @@ typedef struct c_Arena c_Arena;
 // NOTE: darr_shift will make the da loose its ptr, so store the ptr elsewhere if you want to free it later!!!
 #define c_darr_shift(da) (assert((da).count > 0 && "Array is empty"), (da).count--, *(da).items++)
 #define c_darr_free(da) C_FREE((da).items)
 // NOTE: darr_shift will make the da loose its ptr, so store the ptr elsewhere if you want to free it later!!!
 #define c_darr_shift(da) (assert((da).count > 0 && "Array is empty"), (da).count--, *(da).items++)
 #define c_darr_free(da) C_FREE((da).items)
-#define c_darr_delete(da, type, idx) do {\
+
+#define c_darr_delete(da, type, idx) c_darr_delete_impl(da, type, idx, c_darr_delete)
+#define c_darr_delete_impl(da, type, idx, api) do {\
+        if (strcmp(#api, "c_darr_delete") != 0) {\
+            c_log_warning("%s is deprecated please use the newer api!", #api);\
+        }\
         if ((idx) >= 0 && (idx) <= (da).count-1) {\
             type temp = (da).items[(idx)];\
             (da).items[(idx)] = (da).items[(da).count-1];\
         if ((idx) >= 0 && (idx) <= (da).count-1) {\
             type temp = (da).items[(idx)];\
             (da).items[(idx)] = (da).items[(da).count-1];\
@@ -225,7 +238,12 @@ typedef struct c_Arena c_Arena;
             exit(1);\
         }\
     } while (0)
             exit(1);\
         }\
     } while (0)
-#define c_darr_remove(da, type, elm_ptr, idx) do {\
+
+#define c_darr_remove(da, type, elm_ptr, idx) c_darr_remove_impl(da, type, elm_ptr, idx, c_darr_remove)
+#define c_darr_remove_impl(da, type, elm_ptr, idx, api) do {\
+        if (strcmp(#api, "c_darr_remove") != 0) {\
+            c_log_warning("%s is deprecated please use the newer api!", #api);\
+        }\
         if ((idx) >= 0 && (idx) <= (da).count-1) {\
             type temp = (da).items[(idx)];\
             (da).items[(idx)] = (da).items[(da).count-1];\
         if ((idx) >= 0 && (idx) <= (da).count-1) {\
             type temp = (da).items[(idx)];\
             (da).items[(idx)] = (da).items[(da).count-1];\
@@ -242,6 +260,11 @@ typedef struct c_Arena c_Arena;
         }\
     } while (0)
 
         }\
     } while (0)
 
+// Deprecated API
+#define c_da_append(da, elm) c_darr_append_impl(da, elm, c_da_append)
+#define c_da_delete(da, type, idx) c_darr_delete_impl(da, type, idx, c_da_delete)
+#define c_da_remove(da, type, elm_ptr, idx) c_darr_remove_impl(da, type, elm_ptr, idx, c_da_remove)
+
 //
 // Static-Array
 //
 //
 // Static-Array
 //