When creating a C-STRING, leave only as many characters as dictated by the fill pointer

This commit is contained in:
jjgarcia 2005-06-28 13:48:31 +00:00
parent c5205fb67c
commit 53b286e0ce
2 changed files with 19 additions and 3 deletions

View file

@ -45,8 +45,26 @@ ecl_foreign_data_pointer_safe(cl_object f)
char *
ecl_string_pointer_safe(cl_object f)
{
cl_index l;
if (type_of(f) != t_string)
FEwrong_type_argument(@'string', f);
#ifdef USE_BOEHM
/* This function is only used in CMPFFI.LSP as to convert lisp objects
* to a null terminated string. This code is safe with the
* Boehm-Weiser garbage collector because the pointer is stored in the
* stack as part of the argument list and cannot be lost. We still have to
* figure out what to do with the older garbage collector.
*/
if (f->string.hasfillp && ((l = f->string.fillp) < f->string.dim)) {
unsigned char *s = cl_alloc_atomic(l + 1);
memcpy(s, f->string.self, l);
s[l] = 0;
return s;
}
#else
# error "ecl_string_pointer_safe does not work with the old garbage collector"
#endif
return f->string.self;
}

View file

@ -225,9 +225,7 @@
((:cstring)
(case loc-rep-type
((:object)
(if (safe-compile)
(wt "ecl_string_pointer_safe(" loc ")")
(wt "(" loc ")->string.self")))
(wt "ecl_string_pointer_safe(" loc ")"))
((:pointer-void)
(wt "(char *)(" loc ")"))
(otherwise