From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Brian S McQueen Newsgroups: gmane.lisp.guile.user Subject: Re: argz SMOB Date: Thu, 15 Jan 2004 10:43:03 -0800 (PST) Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: sea.gmane.org 1074193558 2621 80.91.224.253 (15 Jan 2004 19:05:58 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 15 Jan 2004 19:05:58 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jan 15 20:05:49 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AhCoP-0001nQ-00 for ; Thu, 15 Jan 2004 20:05:49 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AhCij-00034M-AS for guile-user@m.gmane.org; Thu, 15 Jan 2004 13:59:57 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AhCUI-0008W5-2v for guile-user@gnu.org; Thu, 15 Jan 2004 13:45:02 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AhCTX-0008Ii-MW for guile-user@gnu.org; Thu, 15 Jan 2004 13:44:48 -0500 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1AhCTX-0008GZ-1v for guile-user@gnu.org; Thu, 15 Jan 2004 13:44:15 -0500 Original-Received: from [129.99.113.17] (helo=marcy.nas.nasa.gov) by mx20.gnu.org with esmtp (Exim 4.24) id 1AhCSW-0002Mb-0u for guile-user@gnu.org; Thu, 15 Jan 2004 13:43:12 -0500 Original-Received: from localhost (bqueen@localhost) by marcy.nas.nasa.gov (8.11.7p1+Sun/8.11.7/NAS-6n) with ESMTP id i0FIh3G14555; Thu, 15 Jan 2004 10:43:03 -0800 (PST) Original-To: Daniel Skarda <0rfelyus@ucw.cz> In-Reply-To: X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:2594 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:2594 Since scheme strings can contain the null character, I noticed there was no need for an argz smob. I removed it by using scheme strings instead and it works excellently. The C functions that produce argzs, are all callable from scheme since the argz is defined by a pointer and a length, just as are scheme strings. The C functions are wrapped in simple functions which use the guile API, and the trailing null char in each argz is dropped. I am sure that nobody is particularly interested in argzs, but some readers may be interested in a real life example of the guile API. Below are some examples of how I gained access to some C function from guile. If any of you veterans have any more constructive advice, I would be glad to hear it, but don't ask me to get rid of the argz. They are here to stay! Particularly, I wonder about the best way to produce a null terminated C string from a scheme string. I used scm_must_malloc, memcpy, memset. I expected a ready made guile call for this purpose, but I did not find any. A simple call to a function which is expecting an argz and returns nothing: static SCM printer_hostile_printer(SCM scm_out_buff) { struct argz_holder out_buff; SCM_ASSERT (SCM_STRINGP (scm_out_buff), scm_out_buff, SCM_ARG1, "printer_hostile_printer"); out_buff.argz = SCM_STRING_CHARS(scm_out_buff); out_buff.argz_len = SCM_STRING_LENGTH(scm_out_buff); output_printer(&out_buff); return SCM_UNDEFINED; } A call to a database query function which returns an argz full of query results: static SCM get_from_db(SCM scm_login) { char *login_chrs; int login_len; char * login; struct db_parm_holder login_parm = { 0 }; struct db_parm_holder argz_parm = { 0 }; SCM ret_val; SCM_ASSERT (SCM_STRINGP (scm_login), scm_login, SCM_ARG1, "get_from_db"); login_chrs = SCM_STRING_CHARS(scm_login); login_len = SCM_STRING_LENGTH(scm_login); login = (char *)scm_must_malloc(login_len + 1, "get_from_db"); memcpy(login, login_chrs, login_len); memset(login + login_len, '\0', 1); set_db_in_parm_str(&login_parm, "@login", USER_ID_LEN, login); set_db_ret_parm_envz(&argz_parm, NULL); db_query_va("get_from_db", &login_parm, &argz_parm, NULL); //don't take the last null term on the argz ret_val = scm_mem2string(argz_parm.data, argz_parm.data_len - 1); free(argz_parm.data); scm_must_free(login); return ret_val; } _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user