From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Marco Maggi" Newsgroups: gmane.lisp.guile.user Subject: Re: modules and C Date: Fri, 23 Mar 2007 08:01:48 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1174633330 28560 80.91.229.12 (23 Mar 2007 07:02:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 23 Mar 2007 07:02:10 +0000 (UTC) To: "guile-user" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Mar 23 08:02:03 2007 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HUdmk-0005QR-HO for guile-user@m.gmane.org; Fri, 23 Mar 2007 08:02:03 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HUdob-0006WO-I1 for guile-user@m.gmane.org; Fri, 23 Mar 2007 02:03:57 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HUdoW-0006Jy-1u for guile-user@gnu.org; Fri, 23 Mar 2007 03:03:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HUdoV-0006En-35 for guile-user@gnu.org; Fri, 23 Mar 2007 03:03:51 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HUdoU-0006EY-Lx for guile-user@gnu.org; Fri, 23 Mar 2007 02:03:50 -0500 Original-Received: from relay-pt1.poste.it ([62.241.4.164]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HUdma-0005gd-Dw for guile-user@gnu.org; Fri, 23 Mar 2007 03:01:53 -0400 Original-Received: from poste.it (192.168.144.185) by relay-pt1.poste.it (7.2.063) (authenticated as marco.maggi-ipsu@poste.it) id 460326E7000034BC for guile-user@gnu.org; Fri, 23 Mar 2007 08:01:48 +0100 X-Sensitivity: 3 X-XaM3-API-Version: 4.3 (R1) (B3pl17) X-SenderIP: 81.211.180.156 X-detected-kernel: Solaris 9 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:5889 Archived-At: "David Fang" wrote: > What do I need to do to export my scm_c_define_gsubr'd > functions to the module? YMMV. This is what I do: 1. write a C module with its own initialisation function, let's say that the module's file is "module.c" : /* C module */ #include /* module functions here */ void my_module_init (void) { } /* end of module */ put the init function in an internal header file: void my_module_init (void); 2. wrap all the Scheme interface function declarations into SCM_DEFINE: for a function with a prototype: extern SCM my_scheme_func (SCM arg1, SCM arg2); declared in a header file, I write in the body of the module: #undef SFN #define SFN "my-scheme-func" SCM_DEFINE(my_scheme_func, SFN, 2, 0, 0, (SCM arg1, SCM arg2), "") { SCM s_result; /* do something with 'arg1' and 'arg2' */ return s_result; } the symbol SFN is defined to be the name of the Scheme procedure: that way the name is available in the function's body for calls to 'scm_error()', for example: /* to throw a 'wrong-type-arg' error */ if (error_condition) scm_error(scm_arg_type_key, SFN, "error message", SCM_BOOL_F, SCM_BOOL_F); 3. in the body of the module initialisation function put an include for a ".x" file: void my_module_init (void) { /* other init stuff */ #ifndef SCM_MAGIC_SNARFER # include "module.x" #endif } 4. before compiling: preprocess the "module.c" file with the Guile snarfer program; I use a rule in the Makefile, something like this .SECONDARY: %.x GUILE_SNARF =3D guile-snarf %.x : %.c $(GUILE_SNARF) $(@) $(<) $(INCLUDES) %.o : %.c $.x the ".x" file holds the function invocations required to define the functions from "module.c" something like: scm_c_define_gsubr(s_my_scheme_func, 2, 0, 0, (SCM (*)()) my_scheme_func); ; when the snarfer processes the file the: #include "module.x" is excluded, but it is included when the compiler does its job; now you can use 'scm_c_call_with_current_module()' and invoke the initialisation function. -- Marco Maggi _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user