Hello. I've been having segfaults when using the following wrapper code. (Do not pay attention to the CAML* macros, and String_val is a macro that converts a string in OCaml to a C string, and Val_ptr is a function that wraps up a pointer into OCaml.)
CAMLprim value ml_monetdb_sql (value ml_dbfarm, value ml_dbname) { CAMLparam2(ml_dbfarm, ml_dbname); CAMLlocal1(result); char * dbfarm; char * dbname; dbfarm = String_val(ml_dbfarm); dbname = String_val(ml_dbname); Mapi mapi = monetdb_sql(dbfarm, dbname); result = Val_ptr(mapi); CAMLreturn(result); }
I'm calling this code with dbfarm and dbname set to a place I can write to, and that does not contain folders, files, or data at the time the function is called from OCaml code. When executing the following piece of code from the OCaml toplevel
#use "topfind";; #thread;; #load "monetDB5.cma";;
open MonetDB5;; let mapi = monetdb_sql "/home/yziquel/sandbox/monetdb" "testdb";;
I get a segfault arising from monetdb's shared libraries (I'm using the Debian packages on a 64 bits platform):
yziquel@seldon:~/git/ocaml-monetdb5$ ocaml -init ocamlinit Objective Caml version 3.11.1
Findlib has been successfully loaded. Additional directives: #require "package";; to load a package #list;; to list the available packages #camlp4o;; to load camlp4 (standard syntax) #camlp4r;; to load camlp4 (revised syntax) #predicates "p,q,...";; to set these predicates Topfind.reset();; to force that packages will be reloaded #thread;; to enable threads
/usr/lib/ocaml/threads: added to search path /usr/lib/ocaml/unix.cma: loaded /usr/lib/ocaml/threads/threads.cma: loaded Erreur de segmentation
Here at the last line... Looking at the code in monetdb-sql-2.34.2/src/backends/monet5/embeddedclient.c.in I'm unable to determine if the segault comes from the invocation of pthread_create or from the invocation of mapi_start_talking.
Mapi monetdb_sql(char *dbfarm, char *dbname) { Mapi mid; pthread_t sqlthread; stream **server;
int len = mo_builtin_settings(&embedded_set);
/* needed, to prevent the MonetDB config file to be used */ len = mo_add_option(&embedded_set, len, opt_config, "prefix", MONETDB5_PREFIX); len = mo_add_option(&embedded_set, len, opt_config, "config", MONETDB5_CONFFILE); len = mo_add_option(&embedded_set, len, opt_config, "monet_mod_path", "@QXlibdir@@QDIRSEP@MonetDB5@PATHSEP@@QXlibdir@@QDIRSEP@MonetDB5@QDIRSEP@lib@PATHSEP@@QXlibdir@@QDIRSEP@MonetDB5@QDIRSEP@bin");
embedded_len = mo_system_config(&embedded_set, len); embedded_len = mo_add_option(&embedded_set, embedded_len, opt_cmdline, "gdk_dbfarm", dbfarm); embedded_len = mo_add_option(&embedded_set, embedded_len, opt_cmdline, "gdk_dbname", dbname);
server = mapi_embedded_init(&mid,"sql");
pthread_create(&sqlthread, NULL, start_sql_server, (void *) server);
mapi_start_talking(mid);
return mid; }
Could someone give me hints as to what is going wrong here? All the best, -- Guillaume Yziquel http://yziquel.homelinux.org/