[MonetDB-users] Difficulty with External C Function

I'm having difficulty linking a custom external C function into MonetDB without crashing the database connection. If anyone knows of a documented end-to-end example of adding external functions compiled with GCC, please let me know. I've documented a minimal example below that crashes the connection for me each time. Software: Red Hat Linux knock-off CentOS, i386. Most recent MonetDB download from Sourceforge (server 5.2.2, client 1.20.2, common 1.20.0). GCC 4.1.1 1. Create a simple C file named te.c. int TEtest( ) { return 4; } 2. Compile file, move it to the proper directory, and create symlinks. $ gcc -c -fPIC te.c -o te.o $ gcc -shared -Wl,-soname,lib_te.so.0 -o lib_te.so.0.0.0 te.o (also tried with soname = libte.so.0, leaving output as lib_te.so.0.0.0) $ cp lib_te.so.0.0.0 $mhome/lib/MonetDB5/lib $ cd $mhome/lib/MonetDB5/lib $ ln -s lib_te.so.0.0.0 lib_te.so.0 $ ln -s lib_te.so.0.0.0 lib_te.so 3. Create a MAL file, saved as $mhome/lib/MonetDB5/te.mal module te; command test( ):int address TEtest(); command doesnotexist( ):int address TEdoesnotexist; 4. Update mal_init.mal by adding the following 2 lines: library te; include te; 5. Start a random DB and try to invoke the test function. Merovingian log show database dino killed by signal 11 afterwards. $ cd $mhome/bin $ ./merovingian & [1] xxxx $ ./mclient -lmal --database=dino -h COS1 mal> te.test( ); MAPI = monetdb@COS1:50001 ACTION= read_line QUERY = te.test(); ERROR = Connection terminated If I instead invoke te.doesnotexist(), I get a different error (below.) This leads me to think that MonetDB is findng and loading my compiled .so file, but it wasn't compiled correctly or otherwise isn't providing what MonetDB expects. mal> te.doesnotexist(); MAPI = monetdb@COS1:50001 QUERY = te.doesnotexist(); ERROR = !TypeException:user.main[1]:'te.doesnotexist' undefined in: _1:int := te.doesnotexist() Any pointers are appreciated. Thomas Schulte

On Fri, Nov 30, 2007 at 10:22:14AM -0700, Thomas J. Schulte wrote:
I'm having difficulty linking a custom external C function into MonetDB without crashing the database connection. If anyone knows of a documented end-to-end example of adding external functions compiled with GCC, please let me know. I've documented a minimal example below that crashes the connection for me each time.
Software:
Red Hat Linux knock-off CentOS, i386.
Most recent MonetDB download from Sourceforge (server 5.2.2, client 1.20.2, common 1.20.0).
GCC 4.1.1
1. Create a simple C file named te.c.
int
TEtest( )
{
return 4;
}
mal c-functions return a str (exception or MAT_SUCCEED) your example has an mal level output variable of type int so your function signature should be str TEtest(int *res) { *res = 4; return MAL_SUCCEED; } Niels
2. Compile file, move it to the proper directory, and create symlinks.
$ gcc -c -fPIC te.c -o te.o
$ gcc -shared -Wl,-soname,lib_te.so.0 -o lib_te.so.0.0.0 te.o (also tried with soname = libte.so.0, leaving output as lib_te.so.0.0.0)
$ cp lib_te.so.0.0.0 $mhome/lib/MonetDB5/lib
$ cd $mhome/lib/MonetDB5/lib
$ ln -s lib_te.so.0.0.0 lib_te.so.0
$ ln -s lib_te.so.0.0.0 lib_te.so
3. Create a MAL file, saved as $mhome/lib/MonetDB5/te.mal
module te;
command test( ):int address TEtest();
command doesnotexist( ):int address TEdoesnotexist;
4. Update mal_init.mal by adding the following 2 lines:
library te; include te;
5. Start a random DB and try to invoke the test function. Merovingian log show database dino killed by signal 11 afterwards.
$ cd $mhome/bin
$ ./merovingian & [1] xxxx
$ ./mclient -lmal --database=dino -h COS1 mal> te.test( ); MAPI = [1]monetdb@COS1:50001 ACTION= read_line QUERY = te.test(); ERROR = Connection terminated
If I instead invoke te.doesnotexist(), I get a different error (below.) This leads me to think that MonetDB is findng and loading my compiled .so file, but it wasn't compiled correctly or otherwise isn't providing what MonetDB expects.
mal> te.doesnotexist(); MAPI = [2]monetdb@COS1:50001 QUERY = te.doesnotexist(); ERROR = !TypeException:user.main[1]:'te.doesnotexist' undefined in: _1:int := te.doesnotexist()
Any pointers are appreciated.
Thomas Schulte
References
1. mailto:monetdb@COS1:50001 2. mailto:monetdb@COS1:50001
------------------------------------------------------------------------- SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 _______________________________________________ MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
-- Niels Nes, Centre for Mathematics and Computer Science (CWI) Kruislaan 413, 1098 SJ Amsterdam, The Netherlands room C0.02, phone ++31 20 592-4098, fax ++31 20 592-4312 url: http://www.cwi.nl/~niels e-mail: Niels.Nes@cwi.nl

En hoe snel it vanaf huis? Niels Nes wrote:
On Fri, Nov 30, 2007 at 10:22:14AM -0700, Thomas J. Schulte wrote:
I'm having difficulty linking a custom external C function into MonetDB without crashing the database connection. If anyone knows of a documented end-to-end example of adding external functions compiled with GCC, please let me know. I've documented a minimal example below that crashes the connection for me each time.
Software:
Red Hat Linux knock-off CentOS, i386.
Most recent MonetDB download from Sourceforge (server 5.2.2, client 1.20.2, common 1.20.0).
GCC 4.1.1
1. Create a simple C file named te.c.
int
TEtest( )
{
return 4;
}
mal c-functions return a str (exception or MAT_SUCCEED) your example has an mal level output variable of type int so your function signature should be
str TEtest(int *res) { *res = 4; return MAL_SUCCEED; }
Niels
2. Compile file, move it to the proper directory, and create symlinks.
$ gcc -c -fPIC te.c -o te.o
$ gcc -shared -Wl,-soname,lib_te.so.0 -o lib_te.so.0.0.0 te.o (also tried with soname = libte.so.0, leaving output as lib_te.so.0.0.0)
$ cp lib_te.so.0.0.0 $mhome/lib/MonetDB5/lib
$ cd $mhome/lib/MonetDB5/lib
$ ln -s lib_te.so.0.0.0 lib_te.so.0
$ ln -s lib_te.so.0.0.0 lib_te.so
3. Create a MAL file, saved as $mhome/lib/MonetDB5/te.mal
module te;
command test( ):int address TEtest();
command doesnotexist( ):int address TEdoesnotexist;
4. Update mal_init.mal by adding the following 2 lines:
library te; include te;
5. Start a random DB and try to invoke the test function. Merovingian log show database dino killed by signal 11 afterwards.
$ cd $mhome/bin
$ ./merovingian & [1] xxxx
$ ./mclient -lmal --database=dino -h COS1 mal> te.test( ); MAPI = [1]monetdb@COS1:50001 ACTION= read_line QUERY = te.test(); ERROR = Connection terminated
If I instead invoke te.doesnotexist(), I get a different error (below.) This leads me to think that MonetDB is findng and loading my compiled .so file, but it wasn't compiled correctly or otherwise isn't providing what MonetDB expects.
mal> te.doesnotexist(); MAPI = [2]monetdb@COS1:50001 QUERY = te.doesnotexist(); ERROR = !TypeException:user.main[1]:'te.doesnotexist' undefined in: _1:int := te.doesnotexist()
Any pointers are appreciated.
Thomas Schulte
References
1. mailto:monetdb@COS1:50001 2. mailto:monetdb@COS1:50001
------------------------------------------------------------------------- SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 _______________________________________________ MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
participants (3)
-
Martin Kersten
-
Niels Nes
-
Thomas J. Schulte