unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Brian S McQueen <bqueen@nas.nasa.gov>
Cc: guile-user@gnu.org
Subject: Re: argz SMOB
Date: Thu, 15 Jan 2004 10:43:03 -0800 (PST)	[thread overview]
Message-ID: <Pine.GSO.4.58.0401150950420.20079@marcy.nas.nasa.gov> (raw)
In-Reply-To: <m0d69w26pl.fsf@hobitin.ucw.cz>

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


  parent reply	other threads:[~2004-01-15 18:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-05 17:40 argz SMOB Brian S McQueen
2004-01-06 19:54 ` Daniel Skarda
2004-01-08 16:44   ` Brian S McQueen
2004-01-09 14:08     ` Daniel Skarda
2004-01-12 16:08       ` Brian S McQueen
2004-01-15 18:43   ` Brian S McQueen [this message]
2004-01-16  0:21     ` Paul Jarc
2004-01-16  9:10       ` null terminated strings (was: argz SMOB) Andreas Voegele
     [not found]         ` <1074245327.6733.9.camel@localhost>
2004-01-16 10:17           ` null terminated strings Andreas Voegele
2004-01-16 11:02             ` Roland Orre
2004-01-16 12:24               ` Andreas Voegele
2004-01-16 18:20                 ` Brian S McQueen
2004-01-16 20:36                   ` Paul Jarc
2004-01-16 21:06                     ` Tom Lord
2004-01-16 21:02                       ` Paul Jarc
2004-01-16 21:27                         ` Roland Orre
2004-01-19 17:28                       ` Ken Anderson
2004-01-19 18:46                         ` Per Bothner
2004-01-19 19:16                           ` Ken Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.58.0401150950420.20079@marcy.nas.nasa.gov \
    --to=bqueen@nas.nasa.gov \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).