* Re: null terminated strings (was: argz SMOB)
@ 2004-01-16 10:09 Roland Orre
0 siblings, 0 replies; 2+ messages in thread
From: Roland Orre @ 2004-01-16 10:09 UTC (permalink / raw)
On Fri, 2004-01-16 at 10:10, Andreas Voegele wrote:
> "Remove calls to SCM_STRING_COERCE_0TERMINATION_X. Since the
> substring type is gone, all strings are 0-terminated anyway."
Such a statement is very worrying. What happened to the promises
that all substrings will be shared strings?
Roland Orre
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 2+ messages in thread
* argz SMOB @ 2004-01-05 17:40 Brian S McQueen 2004-01-06 19:54 ` Daniel Skarda 0 siblings, 1 reply; 2+ messages in thread From: Brian S McQueen @ 2004-01-05 17:40 UTC (permalink / raw) I have the beginnings of a SMOB library for GNU libc's argz. I will also be adding the envz functionality. Brian McQueen _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: argz SMOB 2004-01-05 17:40 argz SMOB Brian S McQueen @ 2004-01-06 19:54 ` Daniel Skarda 2004-01-15 18:43 ` Brian S McQueen 0 siblings, 1 reply; 2+ messages in thread From: Daniel Skarda @ 2004-01-06 19:54 UTC (permalink / raw) Cc: guile-user Hello, Brian S McQueen <bqueen@nas.nasa.gov> writes: > I have the beginnings of a SMOB library for GNU libc's argz. I will also > be adding the envz functionality. I am sorry I do not see what is it good for. Could you please explain what is your itch you are trying to scratch with this SMOB library? 0. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: argz SMOB 2004-01-06 19:54 ` Daniel Skarda @ 2004-01-15 18:43 ` Brian S McQueen 2004-01-16 0:21 ` Paul Jarc 0 siblings, 1 reply; 2+ messages in thread From: Brian S McQueen @ 2004-01-15 18:43 UTC (permalink / raw) Cc: guile-user 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: argz SMOB 2004-01-15 18:43 ` Brian S McQueen @ 2004-01-16 0:21 ` Paul Jarc 2004-01-16 9:10 ` null terminated strings (was: argz SMOB) Andreas Voegele 0 siblings, 1 reply; 2+ messages in thread From: Paul Jarc @ 2004-01-16 0:21 UTC (permalink / raw) Cc: guile-user, Daniel Skarda Brian S McQueen <bqueen@nas.nasa.gov> wrote: > Particularly, I wonder about the best way to produce a null > terminated C string from a scheme string. SCM_STRING_COERCE_0TERMINATION_X(scheme_string); char* s=SCM_STRING_CHARS(scheme_string); Or do you need a separate copy? > 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"); You could also write that as: #define FUNC_NAME s_printer_hostile_printer SCM_DEFINE(printer_hostile_printer, "printer_hostile_printer", 1, 0, 0, (SCM scm_out_buff)) { struct argz_holder out_buff; SCM_VALIDATE_STRING(SCM_ARG1, scm_out_buff); paul _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 2+ messages in thread
* null terminated strings (was: argz SMOB) 2004-01-16 0:21 ` Paul Jarc @ 2004-01-16 9:10 ` Andreas Voegele 0 siblings, 0 replies; 2+ messages in thread From: Andreas Voegele @ 2004-01-16 9:10 UTC (permalink / raw) Paul Jarc writes: > Brian S McQueen <bqueen@nas.nasa.gov> wrote: >> Particularly, I wonder about the best way to produce a null >> terminated C string from a scheme string. > > SCM_STRING_COERCE_0TERMINATION_X(scheme_string); > char* s=SCM_STRING_CHARS(scheme_string); Is it necessary or desirable to use the macro SCM_STRING_COERCE_0TERMINATION_X if one uses Guile 1.6? I've found the following statement in the file libguile/strings.c that comes with Guile 1.6.4: "[...] we promise that strings are null-terminated." And in guile-readline/Changelog: "Remove calls to SCM_STRING_COERCE_0TERMINATION_X. Since the substring type is gone, all strings are 0-terminated anyway." _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-01-16 10:09 UTC | newest] Thread overview: 2+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-01-16 10:09 null terminated strings (was: argz SMOB) Roland Orre -- strict thread matches above, loose matches on Subject: below -- 2004-01-05 17:40 argz SMOB Brian S McQueen 2004-01-06 19:54 ` Daniel Skarda 2004-01-15 18:43 ` Brian S McQueen 2004-01-16 0:21 ` Paul Jarc 2004-01-16 9:10 ` null terminated strings (was: argz SMOB) Andreas Voegele
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).