mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-29 08:20:20 +02:00
* gh_data.c (gh_ints2scm, gh_doubles2scm): Make sure elements are
protected from GC while building the vector. (Thanks to Bernard Urban and Greg Harvey.)
This commit is contained in:
parent
bfb7e83924
commit
0acef67a14
1 changed files with 31 additions and 26 deletions
|
@ -1,5 +1,4 @@
|
||||||
/* Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
|
/* Copyright (C) 1995,1996,1997,1998, 1999 Free Software Foundation, Inc.
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2, or (at your option)
|
* the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
@ -126,6 +125,36 @@ gh_symbol2scm (char *symbol_str)
|
||||||
return SCM_CAR (scm_intern (symbol_str, strlen (symbol_str)));
|
return SCM_CAR (scm_intern (symbol_str, strlen (symbol_str)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
gh_ints2scm (int *d, int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
SCM v = scm_make_vector(SCM_MAKINUM(n), SCM_UNSPECIFIED);
|
||||||
|
SCM *velts = SCM_VELTS(v);
|
||||||
|
|
||||||
|
for (i = 0; i < n; ++i)
|
||||||
|
velts[i] = (d[i] >= SCM_MOST_NEGATIVE_FIXNUM
|
||||||
|
&& d[i] <= SCM_MOST_POSITIVE_FIXNUM
|
||||||
|
? SCM_MAKINUM (d[i])
|
||||||
|
: scm_long2big (d[i]));
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
gh_doubles2scm (double *d, int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
SCM v = scm_make_vector(SCM_MAKINUM(n), SCM_UNSPECIFIED);
|
||||||
|
SCM *velts = SCM_VELTS(v);
|
||||||
|
|
||||||
|
for(i = 0; i < n; i++)
|
||||||
|
velts[i] = scm_makdbl(d[i], 0.0);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do not use this function for building normal Scheme vectors, unless
|
||||||
|
you arrange for the elements to be protected from GC while you
|
||||||
|
initialize the vector. */
|
||||||
static SCM
|
static SCM
|
||||||
makvect (char* m, int len, int type)
|
makvect (char* m, int len, int type)
|
||||||
{
|
{
|
||||||
|
@ -138,30 +167,6 @@ makvect (char* m, int len, int type)
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
|
||||||
gh_ints2scm (int *d, int n)
|
|
||||||
{
|
|
||||||
SCM *m;
|
|
||||||
int i;
|
|
||||||
m = (SCM*) scm_must_malloc (n * sizeof (SCM), "vector");
|
|
||||||
for (i = 0; i < n; ++i)
|
|
||||||
m[i] = (d[i] >= SCM_MOST_NEGATIVE_FIXNUM
|
|
||||||
&& d[i] <= SCM_MOST_POSITIVE_FIXNUM
|
|
||||||
? SCM_MAKINUM (d[i])
|
|
||||||
: scm_long2big (d[i]));
|
|
||||||
return makvect ((char *) m, n, scm_tc7_vector);
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
|
||||||
gh_doubles2scm (double *d, int n)
|
|
||||||
{
|
|
||||||
SCM *m = (SCM*) scm_must_malloc (n * sizeof (SCM), "vector");
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < n; ++i)
|
|
||||||
m[i] = scm_makdbl (d[i], 0.0);
|
|
||||||
return makvect ((char *) m, n, scm_tc7_vector);
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
gh_chars2byvect (char *d, int n)
|
gh_chars2byvect (char *d, int n)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue