[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: argz SMOB

From: Brian S McQueen
Subject: Re: argz SMOB
Date: Thu, 15 Jan 2004 10:43:03 -0800 (PST)

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

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,

  out_buff.argz = SCM_STRING_CHARS(scm_out_buff);
  out_buff.argz_len = SCM_STRING_LENGTH(scm_out_buff);




A call to a database query function which returns an argz full of query

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,

  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_len - 1);



  return ret_val;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]