Changeset: 783204486bc3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=783204486bc3
Added Files:
        sql/backends/monet5/UDF/capi/Tests/capi15.sql
        sql/backends/monet5/UDF/capi/Tests/capi15.stable.err
        sql/backends/monet5/UDF/capi/Tests/capi15.stable.out
Modified Files:
        sql/backends/monet5/UDF/capi/Tests/All
        sql/backends/monet5/UDF/capi/capi.c
Branch: Mar2018
Log Message:

Fix for zero length input columns in JIT C API.


diffs (truncated from 366 to 300 lines):

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
@@ -14,4 +14,5 @@ NOT_WIN32?capi11
 NOT_WIN32?capi12
 NOT_WIN32?capi13
 NOT_WIN32?capi14
+NOT_WIN32?capi15
 
diff --git a/sql/backends/monet5/UDF/capi/Tests/capi15.sql 
b/sql/backends/monet5/UDF/capi/Tests/capi15.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/UDF/capi/Tests/capi15.sql
@@ -0,0 +1,19 @@
+
+START TRANSACTION;
+
+CREATE FUNCTION capi16(i INTEGER, j STRING, k BLOB, l DATE, m TIMESTAMP, n 
TIME)
+RETURNS INTEGER
+LANGUAGE C {
+    result->initialize(result, i.count);
+    for(size_t it = 0; it < i.count; it++) {
+        result->data[it] = i.data[it] * 2;
+    }
+};
+
+CREATE TABLE capi16table(i INTEGER, j STRING, k BLOB, l DATE, m TIMESTAMP, n 
TIME);
+SELECT i, capi16(i, j, k, l, m, n) FROM capi16table;
+
+DROP TABLE capi16table;
+DROP FUNCTION capi16;
+
+ROLLBACK;
diff --git a/sql/backends/monet5/UDF/capi/Tests/capi15.stable.err 
b/sql/backends/monet5/UDF/capi/Tests/capi15.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/UDF/capi/Tests/capi15.stable.err
@@ -0,0 +1,35 @@
+stderr of test 'capi15` in directory 'sql/backends/monet5/UDF/capi` itself:
+
+
+# 14:47:44 >  
+# 14:47:44 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=32682" "--set" 
"mapi_usock=/var/tmp/mtest-72472/.s.monetdb.32682" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/Users/myth/opt/var/MonetDB/mTests_sql_backends_monet5_UDF_capi" 
"--set" "embedded_c=true"
+# 14:47:44 >  
+
+# builtin opt  gdk_dbpath = /Users/myth/opt/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 32682
+# cmdline opt  mapi_usock = /var/tmp/mtest-72472/.s.monetdb.32682
+# cmdline opt  monet_prompt = 
+# cmdline opt  gdk_dbpath = 
/Users/myth/opt/var/MonetDB/mTests_sql_backends_monet5_UDF_capi
+# cmdline opt  embedded_c = true
+# cmdline opt  gdk_debug = 553648138
+
+# 14:47:44 >  
+# 14:47:44 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-72472" "--port=32682"
+# 14:47:44 >  
+
+
+# 14:47:45 >  
+# 14:47:45 >  "Done."
+# 14:47:45 >  
+
diff --git a/sql/backends/monet5/UDF/capi/Tests/capi15.stable.out 
b/sql/backends/monet5/UDF/capi/Tests/capi15.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/UDF/capi/Tests/capi15.stable.out
@@ -0,0 +1,85 @@
+stdout of test 'capi15` in directory 'sql/backends/monet5/UDF/capi` itself:
+
+
+# 14:47:44 >  
+# 14:47:44 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=32682" "--set" 
"mapi_usock=/var/tmp/mtest-72472/.s.monetdb.32682" "--set" "monet_prompt=" 
"--forcemito" 
"--dbpath=/Users/myth/opt/var/MonetDB/mTests_sql_backends_monet5_UDF_capi" 
"--set" "embedded_c=true"
+# 14:47:44 >  
+
+# MonetDB 5 server v11.29.4
+# This is an unreleased version
+# Serving database 'mTests_sql_backends_monet5_UDF_capi', using 4 threads
+# Compiled for x86_64-apple-darwin15.6.0/64bit with 128bit integers
+# Found 8.000 GiB available main-memory.
+# Copyright (c) 1993 - July 2008 CWI.
+# Copyright (c) August 2008 - 2018 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on 
mapi:monetdb://dhcp-30.eduroam.cwi.nl:32682/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-72472/.s.monetdb.32682
+# MonetDB/SQL module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_querylog.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 17_temporal.sql
+# loading sql script: 18_index.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 21_dependency_views.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 26_sysmon.sql
+# loading sql script: 27_rejects.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 39_analytics_hge.sql
+# loading sql script: 40_json.sql
+# loading sql script: 40_json_hge.sql
+# loading sql script: 41_md5sum.sql
+# loading sql script: 45_uuid.sql
+# loading sql script: 46_profiler.sql
+# loading sql script: 51_sys_schema_extension.sql
+# loading sql script: 60_wlcr.sql
+# loading sql script: 72_fits.sql
+# loading sql script: 74_netcdf.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_statistics.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 80_udf_hge.sql
+# loading sql script: 90_generator.sql
+# loading sql script: 90_generator_hge.sql
+# loading sql script: 99_system.sql
+
+# 14:47:44 >  
+# 14:47:44 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-72472" "--port=32682"
+# 14:47:44 >  
+
+#START TRANSACTION;
+#CREATE FUNCTION capi16(i INTEGER, j STRING, k BLOB, l DATE, m TIMESTAMP, n 
TIME)
+#RETURNS INTEGER
+#LANGUAGE C {
+#    result->initialize(result, i.count);
+#    for(size_t it = 0; it < i.count; it++) {
+#        result->data[it] = i.data[it] * 2;
+#    }
+#};
+#CREATE TABLE capi16table(i INTEGER, j STRING, k BLOB, l DATE, m TIMESTAMP, n 
TIME);
+#SELECT i, capi16(i, j, k, l, m, n) FROM capi16table;
+% sys.capi16table,     sys.L3 # table_name
+% i,   L3 # name
+% int, int # type
+% 1,   1 # length
+#DROP TABLE capi16table;
+#DROP FUNCTION capi16;
+#ROLLBACK;
+
+# 14:47:45 >  
+# 14:47:45 >  "Done."
+# 14:47:45 >  
+
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
@@ -167,6 +167,8 @@ static char *clear_mprotect(void *addr, 
 
 static void *jump_GDK_malloc(size_t size)
 {
+       if (size == 0)
+               return NULL;
        void *ptr = GDKmalloc(size);
        if (!ptr && option_enable_longjmp) {
                longjmp(jump_buffer[THRgettid()], 2);
@@ -186,12 +188,16 @@ static void *add_allocated_region(void *
 
 static void *wrapped_GDK_malloc(size_t size)
 {
+       if (size == 0)
+               return NULL;
        void *ptr = jump_GDK_malloc(size + sizeof(allocated_region));
        return add_allocated_region(ptr);
 }
 
 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;
@@ -201,6 +207,8 @@ static void *wrapped_GDK_malloc_nojump(s
 
 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;
@@ -322,7 +330,7 @@ static void blob_initialize(struct cudf_
                        /* cannot mprotect bat region, copy data */             
           \
                        bat_data->data = wrapped_GDK_malloc_nojump(             
           \
                                bat_data->count * 
sizeof(bat_data->null_value));               \
-                       if (!bat_data->data) {                                  
           \
+                       if (bat_data->count > 0 && !bat_data->data) {           
           \
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);      \
                                goto wrapup;                                    
               \
                        }                                                       
           \
@@ -993,9 +1001,9 @@ static str CUDFeval(Client cntxt, MalBlk
                        str mprotect_retval;
                        GENERATE_BAT_INPUT_BASE(str);
                        bat_data->count = BATcount(input_bats[index]);
-                       bat_data->data = GDKmalloc(sizeof(char *) * 
bat_data->count);
+                       bat_data->data = bat_data->count == 0 ? NULL : 
GDKmalloc(sizeof(char *) * bat_data->count);
                        bat_data->null_value = NULL;
-                       if (!bat_data->data) {
+                       if (bat_data->count > 0 && !bat_data->data) {
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
@@ -1042,9 +1050,9 @@ static str CUDFeval(Client cntxt, MalBlk
                        date *baseptr;
                        GENERATE_BAT_INPUT_BASE(date);
                        bat_data->count = BATcount(input_bats[index]);
-                       bat_data->data =
+                       bat_data->data = bat_data->count == 0 ? NULL :
                                GDKmalloc(sizeof(bat_data->null_value) * 
bat_data->count);
-                       if (!bat_data->data) {
+                       if (bat_data->count > 0 && !bat_data->data) {
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
@@ -1058,9 +1066,9 @@ static str CUDFeval(Client cntxt, MalBlk
                        daytime *baseptr;
                        GENERATE_BAT_INPUT_BASE(time);
                        bat_data->count = BATcount(input_bats[index]);
-                       bat_data->data =
+                       bat_data->data = bat_data->count == 0 ? NULL :
                                GDKmalloc(sizeof(bat_data->null_value) * 
bat_data->count);
-                       if (!bat_data->data) {
+                       if (bat_data->count > 0 && !bat_data->data) {
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
@@ -1074,9 +1082,9 @@ static str CUDFeval(Client cntxt, MalBlk
                        timestamp *baseptr;
                        GENERATE_BAT_INPUT_BASE(timestamp);
                        bat_data->count = BATcount(input_bats[index]);
-                       bat_data->data =
+                       bat_data->data = bat_data->count == 0 ? NULL :
                                GDKmalloc(sizeof(bat_data->null_value) * 
bat_data->count);
-                       if (!bat_data->data) {
+                       if (bat_data->count > 0 && !bat_data->data) {
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
@@ -1093,9 +1101,9 @@ static str CUDFeval(Client cntxt, MalBlk
                        bool can_mprotect_varheap = false;
                        GENERATE_BAT_INPUT_BASE(blob);
                        bat_data->count = BATcount(input_bats[index]);
-                       bat_data->data =
+                       bat_data->data = bat_data->count == 0 ? NULL :
                                GDKmalloc(sizeof(cudf_data_blob) * 
bat_data->count);
-                       if (!bat_data->data) {
+                       if (bat_data->count > 0 && !bat_data->data) {
                                msg = createException(MAL, "cudf.eval", 
MAL_MALLOC_FAIL);
                                goto wrapup;
                        }
@@ -1111,15 +1119,16 @@ static str CUDFeval(Client cntxt, MalBlk
                        {
                                blob *t = (blob *)BUNtail(li, p);
                                if (t->nitems == ~(size_t)0) {
-                                       bat_data->data[j].size = 0;
+                                       bat_data->data[j].size = ~(size_t) 0;
                                        bat_data->data[j].data = NULL;
                                } else {
                                        bat_data->data[j].size = t->nitems;
                                        if (can_mprotect_varheap) {
                                                bat_data->data[j].data = 
&t->data[0];
                                        } else {
-                                               bat_data->data[j].data = 
wrapped_GDK_malloc_nojump(t->nitems);
-                                               if (!bat_data->data[j].data) {
+                                               bat_data->data[j].data = 
t->nitems == 0 ? NULL : 
+                                                       
wrapped_GDK_malloc_nojump(t->nitems);
+                                               if (t->nitems > 0 && 
!bat_data->data[j].data) {
                                                        msg = 
createException(MAL, "cudf.eval", MAL_MALLOC_FAIL);
                                                        goto wrapup;
                                                }
@@ -1128,7 +1137,7 @@ static str CUDFeval(Client cntxt, MalBlk
                                }
                                j++;
                        }
-                       bat_data->null_value.size = 0;
+                       bat_data->null_value.size = ~(size_t) 0;
                        bat_data->null_value.data = NULL;
                        if (can_mprotect_varheap) {
                                // for blob columns, mprotect the varheap of 
the BAT
@@ -1149,8 +1158,9 @@ static str CUDFeval(Client cntxt, MalBlk
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to