merge remote changes default tip

Wed, 18 Dec 2024 15:40:13 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 18 Dec 2024 15:40:13 +0100
changeset 1026
ca20f9ffcb62
parent 1025
439407fc29e1 (current diff)
parent 1023
989e144c912a (diff)

merge remote changes

tests/test_buffer.c file | annotate | diff | comparison | revisions
--- a/msvc/libucx/libucx.vcxproj	Wed Dec 18 15:36:45 2024 +0100
+++ b/msvc/libucx/libucx.vcxproj	Wed Dec 18 15:40:13 2024 +0100
@@ -58,6 +58,7 @@
     <ClCompile Include="..\..\src\string.c" />
     <ClCompile Include="..\..\src\tree.c" />
     <ClCompile Include="..\..\src\streams.c" />
+    <ClCompile Include="..\..\src\szmul.c" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
     <VCProjectVersion>17.0</VCProjectVersion>
--- a/msvc/libucx/libucx.vcxproj.filters	Wed Dec 18 15:36:45 2024 +0100
+++ b/msvc/libucx/libucx.vcxproj.filters	Wed Dec 18 15:40:13 2024 +0100
@@ -124,5 +124,8 @@
     <ClCompile Include="..\..\src\streams.c">
       <Filter>Source</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\szmul.c">
+      <Filter>Source</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
--- a/src/array_list.c	Wed Dec 18 15:36:45 2024 +0100
+++ b/src/array_list.c	Wed Dec 18 15:40:13 2024 +0100
@@ -108,7 +108,7 @@
     size_t oldcap;
     size_t oldsize;
     size_t max_size;
-    if (width == 0 || width == __WORDSIZE) {
+    if (width == 0 || width == CX_WORDSIZE) {
         oldcap = *(size_t*) capacity;
         oldsize = *(size_t*) size;
         max_size = SIZE_MAX;
@@ -121,7 +121,7 @@
         oldsize = *(uint8_t*) size;
         max_size = UINT8_MAX;
     }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
     else if (width == 32) {
         oldcap = *(uint32_t*) capacity;
         oldsize = *(uint32_t*) size;
@@ -162,16 +162,16 @@
         *array = newmem;
 
         // store new capacity
-        if (width == 0 || width == __WORDSIZE) {
+        if (width == 0 || width == CX_WORDSIZE) {
             *(size_t*) capacity = newcap;
         } else if (width == 16) {
-            *(uint16_t*) capacity = newcap;
+            *(uint16_t*) capacity = (uint16_t) newcap;
         } else if (width == 8) {
-            *(uint8_t*) capacity = newcap;
+            *(uint8_t*) capacity = (uint8_t) newcap;
         }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
         else if (width == 32) {
-            *(uint32_t*) capacity = newcap;
+            *(uint32_t*) capacity = (uint32_t) newcap;
         }
 #endif
     }
@@ -201,7 +201,7 @@
     size_t oldcap;
     size_t oldsize;
     size_t max_size;
-    if (width == 0 || width == __WORDSIZE) {
+    if (width == 0 || width == CX_WORDSIZE) {
         oldcap = *(size_t*) capacity;
         oldsize = *(size_t*) size;
         max_size = SIZE_MAX;
@@ -214,7 +214,7 @@
         oldsize = *(uint8_t*) size;
         max_size = UINT8_MAX;
     }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
     else if (width == 32) {
         oldcap = *(uint32_t*) capacity;
         oldsize = *(uint32_t*) size;
@@ -278,20 +278,20 @@
 
     // if any of size or capacity changed, store them back
     if (newsize != oldsize || newcap != oldcap) {
-        if (width == 0 || width == __WORDSIZE) {
+        if (width == 0 || width == CX_WORDSIZE) {
             *(size_t*) capacity = newcap;
             *(size_t*) size = newsize;
         } else if (width == 16) {
-            *(uint16_t*) capacity = newcap;
-            *(uint16_t*) size = newsize;
+            *(uint16_t*) capacity = (uint16_t) newcap;
+            *(uint16_t*) size = (uint16_t) newsize;
         } else if (width == 8) {
-            *(uint8_t*) capacity = newcap;
-            *(uint8_t*) size = newsize;
+            *(uint8_t*) capacity = (uint8_t) newcap;
+            *(uint8_t*) size = (uint8_t) newsize;
         }
-#if __WORDSIZE == 64
+#if CX_WORDSIZE == 64
         else if (width == 32) {
-            *(uint32_t*) capacity = newcap;
-            *(uint32_t*) size = newsize;
+            *(uint32_t*) capacity = (uint32_t) newcap;
+            *(uint32_t*) size = (uint32_t) newsize;
         }
 #endif
     }
@@ -435,6 +435,9 @@
         return 0;
     }
 
+    // special case: there is only one element and that is smaller
+    if (size == 1) return 0;
+
     // check the last array element
     result = cmp_func(elem, array + elem_size * (size - 1));
     if (result >= 0) {
--- a/src/cx/common.h	Wed Dec 18 15:36:45 2024 +0100
+++ b/src/cx/common.h	Wed Dec 18 15:40:13 2024 +0100
@@ -99,6 +99,18 @@
 #include <sys/types.h>
 
 // ---------------------------------------------------------------------------
+//       Architecture Detection
+// ---------------------------------------------------------------------------
+
+#if INTPTR_MAX == INT64_MAX
+#define CX_WORDSIZE 64
+#elif INTPTR_MAX == INT32_MAX
+#define CX_WORDSIZE 32
+#else
+#error Unknown pointer size or missing size macros!
+#endif
+
+// ---------------------------------------------------------------------------
 //       Attribute definitions
 // ---------------------------------------------------------------------------
 
--- a/src/json.c	Wed Dec 18 15:36:45 2024 +0100
+++ b/src/json.c	Wed Dec 18 15:40:13 2024 +0100
@@ -100,7 +100,7 @@
         allocated = true;
         str = cx_strcat_m(json->uncompleted.content, 1, str);
         if (str.ptr == NULL) {
-            return (CxJsonToken){CX_JSON_NO_TOKEN, false, {0, 0}};
+            return (CxJsonToken){CX_JSON_NO_TOKEN, false, {NULL, 0}};
         }
     }
     json->uncompleted = (CxJsonToken){0};
@@ -120,7 +120,7 @@
         if (allocated) {
             cx_strfree(&str);
         }
-        return (CxJsonToken){CX_JSON_TOKEN_ERROR, false, {0, 0}};
+        return (CxJsonToken){CX_JSON_TOKEN_ERROR, false, {NULL, 0}};
     }
     return (CxJsonToken){ttype, allocated, str};
 }
@@ -184,7 +184,7 @@
                 } else if (ctype != CX_JSON_NO_TOKEN) {
                     // single-char token
                     json->buffer.pos = i + 1;
-                    *result = (CxJsonToken){ctype, NULL, {0, 0}};
+                    *result = (CxJsonToken){ctype, false, {NULL, 0}};
                     return CX_JSON_NO_ERROR;
                 } else {
                     ttype = CX_JSON_TOKEN_LITERAL; // number or literal
--- a/tests/test_buffer.c	Wed Dec 18 15:36:45 2024 +0100
+++ b/tests/test_buffer.c	Wed Dec 18 15:40:13 2024 +0100
@@ -977,7 +977,7 @@
         CX_TEST_ASSERT(buf.size == 8);
         CX_TEST_ASSERT(buf.pos == 8);
         CX_TEST_ASSERT(buf.capacity > 8);
-        CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest\0A", 10));
+        CX_TEST_ASSERT(0 == memcmp(buf.space, "preptest\0", 9));
     }
     cxBufferDestroy(&buf);
 }
--- a/tests/test_list.c	Wed Dec 18 15:36:45 2024 +0100
+++ b/tests/test_list.c	Wed Dec 18 15:40:13 2024 +0100
@@ -250,6 +250,30 @@
         CX_TEST_ASSERT(18 == cx_array_binary_search_inf(array, 18, sizeof(int), &s, cx_cmp_int));
         CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 18, sizeof(int), &s, cx_cmp_int));
         CX_TEST_ASSERT(18 == cx_array_binary_search(array, 18, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 0
+        s = 40;
+        CX_TEST_ASSERT(0 == cx_array_binary_search_inf(array, 0, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 0, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search(array, 0, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 1, searched element is smaller
+        s = 30;
+        CX_TEST_ASSERT(1 == cx_array_binary_search_inf(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(1 == cx_array_binary_search(array, 1, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 1, searched element is larger
+        s = 50;
+        CX_TEST_ASSERT(0 == cx_array_binary_search_inf(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(1 == cx_array_binary_search_sup(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(1 == cx_array_binary_search(array, 1, sizeof(int), &s, cx_cmp_int));
+
+        // special case - size 1, element matches
+        s = 40;
+        CX_TEST_ASSERT(0 == cx_array_binary_search_inf(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search_sup(array, 1, sizeof(int), &s, cx_cmp_int));
+        CX_TEST_ASSERT(0 == cx_array_binary_search(array, 1, sizeof(int), &s, cx_cmp_int));
     }
 }
 

mercurial