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: null terminated strings Date: Fri, 16 Jan 2004 10:20:30 -0800 (PST) Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: References: <87oet4ntsm.fsf_-_@ID-28718.user.uni-berlin.de> <1074245327.6733.9.camel@localhost> <87u12wjiy7.fsf@ID-28718.user.uni-berlin.de> <1074250929.6734.63.camel@localhost> <87eku0f5em.fsf@ID-28718.user.uni-berlin.de> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: sea.gmane.org 1074284796 18281 80.91.224.253 (16 Jan 2004 20:26:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Jan 2004 20:26:36 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jan 16 21:26:32 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 1AhaY4-0007SL-00 for ; Fri, 16 Jan 2004 21:26:32 +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 1AhaX9-00034w-Hi for guile-user@m.gmane.org; Fri, 16 Jan 2004 15:25:35 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AhYvW-00048r-9X for guile-user@gnu.org; Fri, 16 Jan 2004 13:42:38 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AhYhA-0000OD-Vu for guile-user@gnu.org; Fri, 16 Jan 2004 13:28:20 -0500 Original-Received: from [129.99.113.17] (helo=marcy.nas.nasa.gov) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AhYaB-00070O-BE for guile-user@gnu.org; Fri, 16 Jan 2004 13:20:35 -0500 Original-Received: from localhost (bqueen@localhost) by marcy.nas.nasa.gov (8.11.7p1+Sun/8.11.7/NAS-6n) with ESMTP id i0GIKUV01027 for ; Fri, 16 Jan 2004 10:20:30 -0800 (PST) Original-To: guile-user@gnu.org In-Reply-To: <87eku0f5em.fsf@ID-28718.user.uni-berlin.de> 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:2619 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:2619 I know you folks are discussing an important topic regarding the design and future of libguile, but my more simple, but I am a very basic question on this subject. I am wondering about the most practical way for a programmer to get a C string from a scheme string. So what are some common techniques? The approach I used was tedious, so I expect you folks have a better way. I did this: login_chrs = SCM_STRING_CHARS(login_scm); login_len = SCM_STRING_LENGTH(login_scm); login = (char *)scm_must_malloc(login_len + 1, "func"); memcpy(login, login_chrs, login_len); memset(login + login_len, '\0', 1); If the scheme string is truly null terminated, this can be greatly simplified. Brian On Fri, 16 Jan 2004, Andreas Voegele wrote: > Roland Orre writes: > > > On Fri, 2004-01-16 at 11:17, Andreas Voegele wrote: > >> Roland Orre writes: > >> > >> > 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? > >> > >> I'm new to Guile. I don't know why shared strings were removed from > >> Guile, but things were probably simplified greatly by this decision. > >> I think that it is very useful to zero terminate all strings since > >> embedding and extending Guile becomes easier. > > > > During all years I've used scm and later guile (I think 14 years now) > > I have very very rarely had any need for null terminated strings. There > > is a function in guile to convert a null terminated string to a guile > > string, this I've used a few times. In C programming I often don't > > rely on null terminated strings either as there are many C library > > functions that works with length, which I consider more elegant. > > It probably depends on what you're doing with Guile. I intend to use > Guile to glue together code from a lot of existing C libraries. I'm > currently writing wrappers for several C libraries and a lot of > functions provided by these libraries require null terminated strings. > > On the other hand, I agree that a stable API is important. Because of > this I also thought about using Guile 1.4 but I came to the conclusion > that Guile 1.6 is better when you need to wrap a lot of C libraries. > (I know SWIG but I don't like it very much.) > > > The absence of shared substrings on the other hand means a lot of > > special code to be able to do something similar without having to > > copy and create strings all the time. For instance in a conversion > > routine for fixed data base tables I made some years ago I had first > > used substrings. The program took 15 hours to run on a specific > > table. When I changed to use shared substrings it took about 1 hour > > on the same table. > > That's indeed a huge difference. > > > I think it is quite bad to have the requirement that guile should > > rely on null terminated strings as it is often quite easy to come > > around this from my point of view. In guile 1.6.4 it is also > > expressed so that all substrings are intended to become internally > > shared, which I don't see have happened yet. > > I'm wondering how substrings could be shared when there's also a > promise that all strings are null terminated. > > > _______________________________________________ > Guile-user mailing list > Guile-user@gnu.org > http://mail.gnu.org/mailman/listinfo/guile-user > _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user