Commits

Sulaiman Mustafa committed 453fd41

أصلحت علة في chain_insert (يتغير طول المصفوفة في مواضع يجب أن يكون فيه طولها ثابت: لم أعمل بنصائحي *حزين الوجه*)

Comments (0)

Files changed (3)

 
 #include <stdint.h>
 
+/*fun fact: (({}), ...) seems like valid c99; check standard */
+
 #define CHAIN_MTS    sizeof(uint32_t *)*2
 
 #define chain_len(C) (*( ( (uint32_t *) (((void *)(C))-CHAIN_MTS) )+1 ))
 #define chain_new(cell_type) (cell_type*) chain_new_(sizeof(cell_type))
 
 #define chain_shove(C, what) ((C) = chain_resize_((C), 0, 1), (C)[0]=(what))
-#define chain_insert(C, where, what) ((C) = chain_resize_((C), (where), 1), \
-                                     (C)[((where)>chain_len(C))?(chain_len(C)-1):(where)]=(what))
+#define chain_insert(C, where, what) {unsigned int at = (where); ((C) = chain_resize_((C), at, 1), \
+                                     (C)[(at>chain_len(C))?(chain_len(C)-1):at]=(what));}
 #define chain_push(C, what) chain_insert((C), ~((uint32_t) 0), (what))
 
 #define chain_remove(C, where) ((C)=chain_resize_((C), (where), -1))
 tests: ../chain.c ../chain.h tests.c
 	gcc -std=c99 -g -Wall -Wextra -I.. -I../../benchmark -o tests ../chain.c ../../benchmark/benchmark.c tests.c  -lrt
 
+run-tests: tests
+	./tests
 	
 benchmark: tests
 	./tests --benchmark
     chain_insert_all(buf, 2, ((int[]){4000, 4}), 2);
     TEST(!memcmp(buf, (int[]){100, 1, 4000, 4, 200, 2}, 6*sizeof(int)));
         
+    chain_insert(buf, chain_len(buf)-1, 0);
+    TEST(!memcmp(buf, (int[]){100, 1, 4000, 4, 200, 0, 2}, 7*sizeof(int)));
+    
     
     /*limits*/
     chain_error=error_func;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.