Changeset: 808e602343e7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/808e602343e7
Modified Files:
        gdk/gdk_calc.c
        sql/backends/monet5/UDF/capi/capi.c
Branch: default
Log Message:

Merge with Sep2022 branch.


diffs (truncated from 499 to 300 lines):

diff --git a/.editorconfig b/.editorconfig
--- a/.editorconfig
+++ b/.editorconfig
@@ -23,3 +23,7 @@ charset = utf-8
 indent_style = space
 indent_size = 2
 trim_trailing_whitespace = true
+
+[{clients/{mapilib,odbc},gdk}/**.{c,h}{,.in}]
+tab_width = 8
+max_line_length = 72
diff --git a/clients/mapilib/.editorconfig b/clients/mapilib/.editorconfig
deleted file mode 100644
--- a/clients/mapilib/.editorconfig
+++ /dev/null
@@ -1,3 +0,0 @@
-[*.{c,h}]
-tab_width = 8
-max_line_length = 72
diff --git a/clients/odbc/.editorconfig b/clients/odbc/.editorconfig
deleted file mode 100644
--- a/clients/odbc/.editorconfig
+++ /dev/null
@@ -1,3 +0,0 @@
-[*.{c,h}]
-tab_width = 8
-max_line_length = 72
diff --git a/gdk/.editorconfig b/gdk/.editorconfig
deleted file mode 100644
--- a/gdk/.editorconfig
+++ /dev/null
@@ -1,3 +0,0 @@
-[*.{c,h}]
-tab_width = 8
-max_line_length = 72
diff --git a/gdk/gdk_calc_convert.c b/gdk/gdk_calc_convert.c
--- a/gdk/gdk_calc_convert.c
+++ b/gdk/gdk_calc_convert.c
@@ -489,7 +489,7 @@ convert_##TYPE##_msk(const TYPE *src, ui
                     oid candoff, bool *reduce)                         \
 {                                                                      \
        BUN cnt = ci->ncand / 32;                                       \
-       BUN i, j, k;                                                    \
+       BUN i, j;                                                       \
        uint32_t mask;                                                  \
        oid x;                                                          \
        lng timeoffset = 0;                                             \
@@ -499,14 +499,12 @@ convert_##TYPE##_msk(const TYPE *src, ui
        }                                                               \
                                                                        \
        *reduce = true;                                                 \
-       k = 0;                                                          \
        if (ci->tpe == cand_dense) {                                    \
                TIMEOUT_LOOP_IDX(i, cnt, timeoffset) {                  \
                        mask = 0;                                       \
                        for (j = 0; j < 32; j++) {                      \
                                x = canditer_next_dense(ci) - candoff;  \
                                mask |= (uint32_t) (!is_##TYPE##_nil(src[x]) && 
src[x] != 0) << j; \
-                               k++;                                    \
                        }                                               \
                        dst[i] = mask;                                  \
                }                                                       \
@@ -517,7 +515,6 @@ convert_##TYPE##_msk(const TYPE *src, ui
                        for (j = 0; j < cnt; j++) {                     \
                                x = canditer_next_dense(ci) - candoff;  \
                                mask |= (uint32_t) (!is_##TYPE##_nil(src[x]) && 
src[x] != 0) << j; \
-                               k++;                                    \
                        }                                               \
                        dst[i] = mask;                                  \
                }                                                       \
@@ -527,7 +524,6 @@ convert_##TYPE##_msk(const TYPE *src, ui
                        for (j = 0; j < 32; j++) {                      \
                                x = canditer_next(ci) - candoff;        \
                                mask |= (uint32_t) (!is_##TYPE##_nil(src[x]) && 
src[x] != 0) << j; \
-                               k++;                                    \
                        }                                               \
                        dst[i] = mask;                                  \
                }                                                       \
@@ -538,7 +534,6 @@ convert_##TYPE##_msk(const TYPE *src, ui
                        for (j = 0; j < cnt; j++) {                     \
                                x = canditer_next(ci) - candoff;        \
                                mask |= (uint32_t) (!is_##TYPE##_nil(src[x]) && 
src[x] != 0) << j; \
-                               k++;                                    \
                        }                                               \
                        dst[i] = mask;                                  \
                }                                                       \
diff --git a/sql/backends/monet5/UDF/capi/Tests/All 
b/sql/backends/monet5/UDF/capi/Tests/All
--- a/sql/backends/monet5/UDF/capi/Tests/All
+++ b/sql/backends/monet5/UDF/capi/Tests/All
@@ -16,5 +16,5 @@ NOT_WIN32?capi13
 NOT_WIN32?capi14
 NOT_WIN32?capi15
 NOT_WIN32?capi16
-#NOT_WIN32?capi17 no oids
+NOT_WIN32?capi17
 NOT_WIN32?capi18
diff --git a/sql/backends/monet5/UDF/capi/Tests/capi17.test 
b/sql/backends/monet5/UDF/capi/Tests/capi17.test
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/UDF/capi/Tests/capi17.test
@@ -0,0 +1,75 @@
+statement ok
+create or replace function my_test(stub string)
+returns string
+language c {
+    result->initialize(result, stub.count);
+    for (int i = 0; i < stub.count; i++) {
+        result->data[i] = malloc(4);
+        result->data[i][0] = 'a';
+        result->data[i][1] = 'b';
+        result->data[i][2] = 'c';
+        result->data[i][3] = '\0';
+    }
+}
+
+query T rowsort
+select my_test('');
+----
+abc
+
+statement ok
+create or replace function my_test(stub int)
+returns string
+language c {
+    result->initialize(result, stub.count);
+    for (int i = 0; i < stub.count; i++) {
+        result->data[i] = malloc(4);
+        result->data[i][0] = 'a';
+        result->data[i][1] = 'b';
+        result->data[i][2] = 'c';
+        result->data[i][3] = '\0';
+    }
+}
+
+query T rowsort
+select my_test(1);
+----
+abc
+
+statement ok
+create or replace aggregate my_test2(stub string)
+returns string
+language c {
+    result->initialize(result, aggr_group.count);
+    for (int i = 0; i < aggr_group.count; i++) {
+        result->data[i] = malloc(4);
+        result->data[i][0] = 'a';
+        result->data[i][1] = 'b';
+        result->data[i][2] = 'c';
+        result->data[i][3] = '\0';
+    }
+}
+
+query T rowsort
+select my_test2('') from sys._tables;
+----
+abc
+
+statement ok
+create or replace aggregate my_test2(stub string)
+returns string
+language c {
+    result->initialize(result, aggr_group.count);
+    for (int i = 0; i < aggr_group.count; i++) {
+        result->data[i] = malloc(4);
+        result->data[i][0] = 'a';
+        result->data[i][1] = 'b';
+        result->data[i][2] = 'c';
+        result->data[i][3] = '\0';
+    }
+};
+
+query T rowsort
+select count(*) > 1 from (select my_test2('') from sys._tables group by id) as 
c
+----
+True
diff --git a/sql/backends/monet5/UDF/capi/capi.c 
b/sql/backends/monet5/UDF/capi/capi.c
--- a/sql/backends/monet5/UDF/capi/capi.c
+++ b/sql/backends/monet5/UDF/capi/capi.c
@@ -201,30 +201,6 @@ static void wrapped_GDK_free(void* ptr) 
        return;
 }
 
-static void *wrapped_GDK_malloc_nojump(size_t size)
-{
-       if (size == 0)
-               return NULL;
-       void *ptr = GDKmalloc(size + sizeof(allocated_region));
-       if (!ptr) {
-               return NULL;
-       }
-       return add_allocated_region(ptr);
-}
-
-static void *wrapped_GDK_zalloc_nojump(size_t size)
-{
-       if (size == 0)
-               return NULL;
-       void *ptr = GDKzalloc(size + sizeof(allocated_region));
-       if (!ptr) {
-               return NULL;
-       }
-       /*return add_allocated_region(ptr); we GDKfree this already in the 
CUDFeval, so no need to keep it in the
-        * allocated_regions */
-       return ptr;
-}
-
 #define GENERATE_NUMERIC_IS_NULL(type, tpename) \
        static int tpename##_is_null(type value) { return 
is_##tpename##_nil(value); }
 
@@ -303,12 +279,13 @@ static void blob_initialize(struct cudf_
                        size_t it = 0;                                          
           \
                        tpe val = b->tseqbase;                                  
           \
                        /* bat is dense, materialize it */                      
           \
-                       bat_data->data = wrapped_GDK_malloc_nojump(             
           \
+                       bat_data->data = GDKmalloc(                        \
                                bat_data->count * 
sizeof(bat_data->null_value));               \
                        if (!bat_data->data) {                                  
           \
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);      \
                                goto wrapup;                                    
               \
                        }                                                       
           \
+                       bat_data->alloced = true;                               
                                                   \
                        for (it = 0; it < bat_data->count; it++) {              
           \
                                bat_data->data[it] = val++;                     
               \
                        }                                                       
           \
@@ -325,12 +302,13 @@ static void blob_initialize(struct cudf_
                        }                                                       
           \
                } else {                                                        
       \
                        /* cannot mprotect bat region, copy data */             
           \
-                       bat_data->data = wrapped_GDK_malloc_nojump(             
           \
+                       bat_data->data = GDKmalloc(                        \
                                bat_data->count * 
sizeof(bat_data->null_value));               \
                        if (bat_data->count > 0 && !bat_data->data) {           
           \
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);      \
                                goto wrapup;                                    
               \
                        }                                                       
           \
+                       bat_data->alloced = true;                               
                                                   \
                        memcpy(bat_data->data, Tloc(b, 0),                      
           \
                                bat_data->count * 
sizeof(bat_data->null_value));                \
                }                                                               
       \
@@ -367,6 +345,8 @@ const char *ldflags_pragma = "#pragma LD
 #define JIT_COMPILER_NAME "cc"
 #define JIT_CPP_COMPILER_NAME "c++"
 
+static bool isAlloced(int type, void *struct_ptr);
+static bool isValloced(int type, void *struct_ptr);
 static size_t GetTypeCount(int type, void *struct_ptr);
 static void *GetTypeData(int type, void *struct_ptr);
 static void *GetTypeBat(int type, void *struct_ptr);
@@ -1078,12 +1058,14 @@ static str CUDFeval(Client cntxt, MalBlk
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
+                       bat_data->alloced = true;
                        j = 0;
 
                        // check if we can mprotect the varheap
                        // if we can't mprotect, copy the strings instead
                        assert(input_bats[index]->tvheap);
                        can_mprotect_varheap = 
can_mprotect_region(input_bats[index]->tvheap->base);
+                       bat_data->valloced = !can_mprotect_varheap;
 
                        li = bat_iterator(input_bats[index]);
                        BATloop(input_bats[index], p, q)
@@ -1095,7 +1077,7 @@ static str CUDFeval(Client cntxt, MalBlk
                                        if (can_mprotect_varheap) {
                                                bat_data->data[j] = t;
                                        } else {
-                                               bat_data->data[j] = 
wrapped_GDK_malloc_nojump(strlen(t) + 1);
+                                               bat_data->data[j] = 
GDKmalloc(strlen(t) + 1);
                                                if (!bat_data->data[j]) {
                                                        bat_iterator_end(&li);
                                                        msg = 
createException(MAL, "cudf.eval", MAL_MALLOC_FAIL);
@@ -1129,6 +1111,7 @@ static str CUDFeval(Client cntxt, MalBlk
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
+                       bat_data->alloced = true;
 
                        baseptr = (date *)Tloc(input_bats[index], 0);
                        for (j = 0; j < bat_data->count; j++) {
@@ -1145,6 +1128,7 @@ static str CUDFeval(Client cntxt, MalBlk
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
+                       bat_data->alloced = true;
 
                        baseptr = (daytime *)Tloc(input_bats[index], 0);
                        for (j = 0; j < bat_data->count; j++) {
@@ -1161,6 +1145,7 @@ static str CUDFeval(Client cntxt, MalBlk
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
+                       bat_data->alloced = true;
 
                        baseptr = (timestamp *)Tloc(input_bats[index], 0);
                        for (j = 0; j < bat_data->count; j++) {
@@ -1180,12 +1165,14 @@ static str CUDFeval(Client cntxt, MalBlk
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to