* Where possible, accept const pointers as parameters.
[bpt/guile.git] / libguile / gh_data.c
CommitLineData
16d35552 1/* Copyright (C) 1995,1996,1997,1998, 1999, 2000 Free Software Foundation, Inc.
ee2a8b9b
JB
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2, or (at your option)
5 * any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this software; see the file COPYING. If not, write to
82892bed
JB
14 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15 * Boston, MA 02111-1307 USA
ee2a8b9b
JB
16 *
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
19 *
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
25 *
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
28 *
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
36 *
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
82892bed 39 * If you do not wish that, delete this exception notice. */
ee2a8b9b
JB
40\f
41
42/* data initialization and C<->Scheme data conversion */
43
44#include <stdio.h>
45
a0599745 46#include "libguile/gh.h"
bd9e24b3
GH
47#ifdef HAVE_STRING_H
48#include <string.h>
49#endif
ee2a8b9b
JB
50
51/* data conversion C->scheme */
bcee10dd
DH
52
53#if (SCM_DEBUG_DEPRECATED == 0)
54
ee2a8b9b 55SCM
dbb3005d
MG
56gh_int2scmb (int x) /* this is being phased out */
57{
156dcb09 58 return SCM_BOOL(x);
dbb3005d 59}
bcee10dd
DH
60
61#endif /* SCM_DEBUG_DEPRECATED == 0 */
62
dbb3005d
MG
63SCM
64gh_bool2scm (int x)
ee2a8b9b 65{
156dcb09 66 return SCM_BOOL(x);
ee2a8b9b
JB
67}
68SCM
69gh_int2scm (int x)
70{
71 return scm_long2num ((long) x);
72}
73SCM
74gh_ulong2scm (unsigned long x)
75{
76 return scm_ulong2num (x);
77}
78SCM
79gh_long2scm (long x)
80{
81 return scm_long2num (x);
82}
83SCM
84gh_double2scm (double x)
85{
f8de44c1 86 return scm_make_real (x);
ee2a8b9b
JB
87}
88SCM
89gh_char2scm (char c)
90{
7866a09b 91 return SCM_MAKE_CHAR (c);
ee2a8b9b
JB
92}
93SCM
70d63753 94gh_str2scm (const char *s, int len)
ee2a8b9b
JB
95{
96 return scm_makfromstr (s, len, 0);
97}
98SCM
6e706938 99gh_str02scm (const char *s)
ee2a8b9b
JB
100{
101 return scm_makfrom0str (s);
102}
103/* Copy LEN characters at SRC into the *existing* Scheme string DST,
104 starting at START. START is an index into DST; zero means the
105 beginning of the string.
106
107 If START + LEN is off the end of DST, signal an out-of-range
108 error. */
109void
110gh_set_substr (char *src, SCM dst, int start, int len)
111{
2c92112b 112 char *dst_ptr;
fd88bd7c
JB
113 unsigned long dst_len;
114 unsigned long effective_length;
ee2a8b9b 115
0c95b57d 116 SCM_ASSERT (SCM_STRINGP (dst), dst, SCM_ARG3,
ee2a8b9b 117 "gh_set_substr");
fd88bd7c 118
ee2a8b9b
JB
119 dst_ptr = SCM_CHARS (dst);
120 dst_len = SCM_LENGTH (dst);
fd88bd7c
JB
121 SCM_ASSERT (len >= 0 && (unsigned) len <= dst_len,
122 dst, SCM_ARG4, "gh_set_substr");
123
124 scm_protect_object (dst);
125 effective_length = ((unsigned) len < dst_len) ? len : dst_len;
126 memmove (dst_ptr + start, src, effective_length);
ee2a8b9b
JB
127 scm_unprotect_object (dst);
128}
129
130/* Return the symbol named SYMBOL_STR. */
131SCM
4921140c 132gh_symbol2scm (const char *symbol_str)
ee2a8b9b
JB
133{
134 return SCM_CAR (scm_intern (symbol_str, strlen (symbol_str)));
135}
136
b774ee1f
MD
137SCM
138gh_ints2scm (int *d, int n)
139{
b774ee1f 140 int i;
0acef67a
JB
141 SCM v = scm_make_vector(SCM_MAKINUM(n), SCM_UNSPECIFIED);
142 SCM *velts = SCM_VELTS(v);
143
b774ee1f 144 for (i = 0; i < n; ++i)
0acef67a
JB
145 velts[i] = (d[i] >= SCM_MOST_NEGATIVE_FIXNUM
146 && d[i] <= SCM_MOST_POSITIVE_FIXNUM
147 ? SCM_MAKINUM (d[i])
148 : scm_long2big (d[i]));
149 return v;
3ffc7a36
MD
150}
151
152SCM
bcee10dd 153gh_doubles2scm (const double *d, int n)
3ffc7a36 154{
3ffc7a36 155 int i;
0acef67a
JB
156 SCM v = scm_make_vector(SCM_MAKINUM(n), SCM_UNSPECIFIED);
157 SCM *velts = SCM_VELTS(v);
158
159 for(i = 0; i < n; i++)
f8de44c1 160 velts[i] = scm_make_real (d[i]);
0acef67a
JB
161 return v;
162}
163
afe5177e 164#ifdef HAVE_ARRAYS
0acef67a
JB
165/* Do not use this function for building normal Scheme vectors, unless
166 you arrange for the elements to be protected from GC while you
167 initialize the vector. */
168static SCM
169makvect (char* m, int len, int type)
170{
171 SCM ans;
172 SCM_NEWCELL (ans);
173 SCM_DEFER_INTS;
174 SCM_SETCHARS (ans, m);
175 SCM_SETLENGTH (ans, len, type);
176 SCM_ALLOW_INTS;
177 return ans;
b774ee1f
MD
178}
179
3ffc7a36 180SCM
bcee10dd 181gh_chars2byvect (const char *d, int n)
3ffc7a36
MD
182{
183 char *m = scm_must_malloc (n * sizeof (char), "vector");
184 memcpy (m, d, n * sizeof (char));
185 return makvect (m, n, scm_tc7_byvect);
186}
187
188SCM
bcee10dd 189gh_shorts2svect (const short *d, int n)
3ffc7a36
MD
190{
191 char *m = scm_must_malloc (n * sizeof (short), "vector");
192 memcpy (m, d, n * sizeof (short));
193 return makvect (m, n, scm_tc7_svect);
194}
195
b774ee1f 196SCM
bcee10dd 197gh_longs2ivect (const long *d, int n)
b774ee1f
MD
198{
199 char *m = scm_must_malloc (n * sizeof (long), "vector");
200 memcpy (m, d, n * sizeof (long));
201 return makvect (m, n, scm_tc7_ivect);
202}
203
204SCM
bcee10dd 205gh_ulongs2uvect (const unsigned long *d, int n)
b774ee1f
MD
206{
207 char *m = scm_must_malloc (n * sizeof (unsigned long), "vector");
208 memcpy (m, d, n * sizeof (unsigned long));
209 return makvect (m, n, scm_tc7_uvect);
210}
211
212SCM
bcee10dd 213gh_floats2fvect (const float *d, int n)
b774ee1f 214{
3ffc7a36
MD
215 char *m = scm_must_malloc (n * sizeof (float), "vector");
216 memcpy (m, d, n * sizeof (float));
217 return makvect (m, n, scm_tc7_fvect);
b774ee1f
MD
218}
219
f3a2c4cf 220SCM
bcee10dd 221gh_doubles2dvect (const double *d, int n)
f3a2c4cf 222{
f3a2c4cf
MD
223 char *m = scm_must_malloc (n * sizeof (double), "vector");
224 memcpy (m, d, n * sizeof (double));
b774ee1f 225 return makvect (m, n, scm_tc7_dvect);
f3a2c4cf
MD
226}
227#endif
ee2a8b9b
JB
228
229/* data conversion scheme->C */
230int
231gh_scm2bool (SCM obj)
232{
fbd485ba 233 return (SCM_FALSEP (obj)) ? 0 : 1;
ee2a8b9b
JB
234}
235unsigned long
236gh_scm2ulong (SCM obj)
237{
238 return scm_num2ulong (obj, (char *) SCM_ARG1, "gh_scm2ulong");
239}
240long
241gh_scm2long (SCM obj)
242{
243 return scm_num2long (obj, (char *) SCM_ARG1, "gh_scm2long");
244}
245int
246gh_scm2int (SCM obj)
247{
248 /* NOTE: possible loss of precision here */
249 return (int) scm_num2long (obj, (char *) SCM_ARG1, "gh_scm2int");
250}
251double
252gh_scm2double (SCM obj)
253{
254 return scm_num2dbl (obj, "gh_scm2double");
255}
256char
257gh_scm2char (SCM obj)
258{
7866a09b 259 return SCM_CHAR (obj);
ee2a8b9b
JB
260}
261
3ffc7a36
MD
262/* Convert a vector, weak vector, string, substring or uniform vector
263 into an array of chars. If result array in arg 2 is NULL, malloc a
264 new one. */
265char *
266gh_scm2chars (SCM obj, char *m)
f3a2c4cf
MD
267{
268 int i, n;
3ffc7a36 269 long v;
f3a2c4cf
MD
270 SCM val;
271 if (!SCM_NIMP (obj))
272 scm_wrong_type_arg (0, 0, obj);
273 switch (SCM_TYP7 (obj))
274 {
275 case scm_tc7_vector:
276 case scm_tc7_wvect:
277 n = SCM_LENGTH (obj);
f3a2c4cf
MD
278 for (i = 0; i < n; ++i)
279 {
280 val = SCM_VELTS (obj)[i];
281 if (SCM_INUMP (val))
3ffc7a36
MD
282 {
283 v = SCM_INUM (val);
284 if (v < -128 || v > 255)
285 scm_out_of_range (0, obj);
286 }
f3a2c4cf 287 else
3ffc7a36
MD
288 scm_wrong_type_arg (0, 0, obj);
289 }
290 if (m == 0)
291 m = (char *) malloc (n * sizeof (char));
292 for (i = 0; i < n; ++i)
293 m[i] = SCM_INUM (SCM_VELTS (obj)[i]);
294 break;
afe5177e 295#ifdef HAVE_ARRAYS
3ffc7a36 296 case scm_tc7_byvect:
afe5177e 297#endif
3ffc7a36
MD
298 case scm_tc7_string:
299 case scm_tc7_substring:
300 n = SCM_LENGTH (obj);
301 if (m == 0)
302 m = (char *) malloc (n * sizeof (char));
303 memcpy (m, SCM_VELTS (obj), n * sizeof (char));
304 break;
305 default:
306 scm_wrong_type_arg (0, 0, obj);
307 }
308 return m;
309}
310
311/* Convert a vector, weak vector or uniform vector into an array of
312 shorts. If result array in arg 2 is NULL, malloc a new one. */
313short *
314gh_scm2shorts (SCM obj, short *m)
315{
316 int i, n;
317 long v;
318 SCM val;
319 if (!SCM_NIMP (obj))
320 scm_wrong_type_arg (0, 0, obj);
321 switch (SCM_TYP7 (obj))
322 {
323 case scm_tc7_vector:
324 case scm_tc7_wvect:
325 n = SCM_LENGTH (obj);
326 for (i = 0; i < n; ++i)
327 {
328 val = SCM_VELTS (obj)[i];
329 if (SCM_INUMP (val))
f3a2c4cf 330 {
3ffc7a36
MD
331 v = SCM_INUM (val);
332 if (v < -32768 || v > 65535)
333 scm_out_of_range (0, obj);
f3a2c4cf 334 }
3ffc7a36
MD
335 else
336 scm_wrong_type_arg (0, 0, obj);
337 }
338 if (m == 0)
339 m = (short *) malloc (n * sizeof (short));
340 for (i = 0; i < n; ++i)
341 m[i] = SCM_INUM (SCM_VELTS (obj)[i]);
342 break;
afe5177e 343#ifdef HAVE_ARRAYS
3ffc7a36
MD
344 case scm_tc7_svect:
345 n = SCM_LENGTH (obj);
346 if (m == 0)
347 m = (short *) malloc (n * sizeof (short));
348 memcpy (m, SCM_VELTS (obj), n * sizeof (short));
349 break;
afe5177e 350#endif
3ffc7a36
MD
351 default:
352 scm_wrong_type_arg (0, 0, obj);
353 }
354 return m;
355}
356
357/* Convert a vector, weak vector or uniform vector into an array of
358 longs. If result array in arg 2 is NULL, malloc a new one. */
359long *
360gh_scm2longs (SCM obj, long *m)
361{
362 int i, n;
363 SCM val;
364 if (!SCM_NIMP (obj))
365 scm_wrong_type_arg (0, 0, obj);
366 switch (SCM_TYP7 (obj))
367 {
368 case scm_tc7_vector:
369 case scm_tc7_wvect:
370 n = SCM_LENGTH (obj);
371 for (i = 0; i < n; ++i)
372 {
373 val = SCM_VELTS (obj)[i];
0c95b57d 374 if (!SCM_INUMP (val) && !SCM_BIGP (val))
3ffc7a36
MD
375 scm_wrong_type_arg (0, 0, obj);
376 }
377 if (m == 0)
378 m = (long *) malloc (n * sizeof (long));
379 for (i = 0; i < n; ++i)
380 {
381 val = SCM_VELTS (obj)[i];
382 m[i] = SCM_INUMP (val) ? SCM_INUM (val) : scm_num2long (val, 0, 0);
383 }
384 break;
afe5177e 385#ifdef HAVE_ARRAYS
3ffc7a36
MD
386 case scm_tc7_ivect:
387 case scm_tc7_uvect:
388 n = SCM_LENGTH (obj);
389 if (m == 0)
390 m = (long *) malloc (n * sizeof (long));
391 memcpy (m, SCM_VELTS (obj), n * sizeof (long));
392 break;
afe5177e 393#endif
3ffc7a36
MD
394 default:
395 scm_wrong_type_arg (0, 0, obj);
396 }
397 return m;
398}
399
400/* Convert a vector, weak vector or uniform vector into an array of
401 floats. If result array in arg 2 is NULL, malloc a new one. */
402float *
403gh_scm2floats (SCM obj, float *m)
404{
405 int i, n;
406 SCM val;
407 if (!SCM_NIMP (obj))
408 scm_wrong_type_arg (0, 0, obj);
409 switch (SCM_TYP7 (obj))
410 {
411 case scm_tc7_vector:
412 case scm_tc7_wvect:
413 n = SCM_LENGTH (obj);
414 for (i = 0; i < n; ++i)
415 {
416 val = SCM_VELTS (obj)[i];
417 if (!SCM_INUMP (val)
0c95b57d 418 && !(SCM_BIGP (val) || SCM_REALP (val)))
3ffc7a36
MD
419 scm_wrong_type_arg (0, 0, val);
420 }
421 if (m == 0)
422 m = (float *) malloc (n * sizeof (float));
423 for (i = 0; i < n; ++i)
424 {
425 val = SCM_VELTS (obj)[i];
426 if (SCM_INUMP (val))
427 m[i] = SCM_INUM (val);
428 else if (SCM_BIGP (val))
429 m[i] = scm_num2long (val, 0, 0);
430 else
eb42e2f0 431 m[i] = SCM_REAL_VALUE (val);
f3a2c4cf
MD
432 }
433 break;
afe5177e 434#ifdef HAVE_ARRAYS
f3a2c4cf
MD
435 case scm_tc7_fvect:
436 n = SCM_LENGTH (obj);
3ffc7a36
MD
437 if (m == 0)
438 m = (float *) malloc (n * sizeof (float));
439 memcpy (m, (float *) SCM_VELTS (obj), n * sizeof (float));
f3a2c4cf 440 break;
16d35552 441
f3a2c4cf
MD
442 case scm_tc7_dvect:
443 n = SCM_LENGTH (obj);
3ffc7a36
MD
444 if (m == 0)
445 m = (float*) malloc (n * sizeof (float));
f3a2c4cf 446 for (i = 0; i < n; ++i)
3ffc7a36
MD
447 m[i] = ((double *) SCM_VELTS (obj))[i];
448 break;
449#endif
450 default:
451 scm_wrong_type_arg (0, 0, obj);
452 }
453 return m;
454}
455
456/* Convert a vector, weak vector or uniform vector into an array of
457 doubles. If result array in arg 2 is NULL, malloc a new one. */
458double *
459gh_scm2doubles (SCM obj, double *m)
460{
461 int i, n;
462 SCM val;
463 if (!SCM_NIMP (obj))
464 scm_wrong_type_arg (0, 0, obj);
465 switch (SCM_TYP7 (obj))
466 {
467 case scm_tc7_vector:
468 case scm_tc7_wvect:
469 n = SCM_LENGTH (obj);
470 for (i = 0; i < n; ++i)
471 {
472 val = SCM_VELTS (obj)[i];
473 if (!SCM_INUMP (val)
0c95b57d 474 && !(SCM_BIGP (val) || SCM_REALP (val)))
3ffc7a36
MD
475 scm_wrong_type_arg (0, 0, val);
476 }
477 if (m == 0)
478 m = (double *) malloc (n * sizeof (double));
479 for (i = 0; i < n; ++i)
480 {
481 val = SCM_VELTS (obj)[i];
482 if (SCM_INUMP (val))
483 m[i] = SCM_INUM (val);
484 else if (SCM_BIGP (val))
485 m[i] = scm_num2long (val, 0, 0);
486 else
eb42e2f0 487 m[i] = SCM_REAL_VALUE (val);
3ffc7a36
MD
488 }
489 break;
afe5177e 490#ifdef HAVE_ARRAYS
3ffc7a36
MD
491 case scm_tc7_fvect:
492 n = SCM_LENGTH (obj);
493 if (m == 0)
494 m = (double *) malloc (n * sizeof (double));
495 for (i = 0; i < n; ++i)
496 m[i] = ((float *) SCM_VELTS (obj))[i];
497 break;
16d35552 498
3ffc7a36
MD
499 case scm_tc7_dvect:
500 n = SCM_LENGTH (obj);
501 if (m == 0)
502 m = (double*) malloc (n * sizeof (double));
503 memcpy (m, SCM_VELTS (obj), n * sizeof (double));
f3a2c4cf
MD
504 break;
505#endif
506 default:
507 scm_wrong_type_arg (0, 0, obj);
508 }
509 return m;
510}
511
ee2a8b9b
JB
512/* string conversions between C and Scheme */
513
514/* gh_scm2newstr() -- Given a Scheme string STR, return a pointer to a
515 new copy of its contents, followed by a null byte. If lenp is
516 non-null, set *lenp to the string's length.
517
518 This function uses malloc to obtain storage for the copy; the
519 caller is responsible for freeing it.
520
521 Note that Scheme strings may contain arbitrary data, including null
522 characters. This means that null termination is not a reliable way
523 to determine the length of the returned value. However, the
524 function always copies the complete contents of STR, and sets
525 *LEN_P to the true length of the string (when LEN_P is non-null). */
526char *
527gh_scm2newstr (SCM str, int *lenp)
528{
529 char *ret_str;
530 int len;
531
0c95b57d 532 SCM_ASSERT (SCM_ROSTRINGP (str), str, SCM_ARG3,
ee2a8b9b
JB
533 "gh_scm2newstr");
534
535 /* protect str from GC while we copy off its data */
536 scm_protect_object (str);
537
538 len = SCM_LENGTH (str);
539
9b1b00fe
JB
540 ret_str = (char *) scm_must_malloc ((len + 1) * sizeof (char),
541 "gh_scm2newstr");
ee2a8b9b 542 /* so we copy tmp_str to ret_str, which is what we will allocate */
66d1e129 543 memcpy (ret_str, SCM_ROCHARS (str), len); /* test ROCHARS here -twp */
ee2a8b9b
JB
544 /* now make sure we null-terminate it */
545 ret_str[len] = '\0';
546
547 scm_unprotect_object (str);
548
549 if (lenp != NULL)
550 {
551 *lenp = len;
552 }
553
554 return ret_str;
555}
556
557
558/* Copy LEN characters at START from the Scheme string SRC to memory
559 at DST. START is an index into SRC; zero means the beginning of
560 the string. DST has already been allocated by the caller.
561
562 If START + LEN is off the end of SRC, silently truncate the source
563 region to fit the string. If truncation occurs, the corresponding
564 area of DST is left unchanged. */
565void
566gh_get_substr (SCM src, char *dst, int start, int len)
567{
568 int src_len, effective_length;
0c95b57d 569 SCM_ASSERT (SCM_ROSTRINGP (src), src, SCM_ARG3,
ee2a8b9b
JB
570 "gh_get_substr");
571
572 scm_protect_object (src);
573 src_len = SCM_LENGTH (src);
574 effective_length = (len < src_len) ? len : src_len;
66d1e129 575 memcpy (dst + start, SCM_ROCHARS (src), effective_length * sizeof (char));
ee2a8b9b
JB
576 /* FIXME: must signal an error if len > src_len */
577 scm_unprotect_object (src);
578}
579
580
581/* gh_scm2newsymbol() -- Given a Scheme symbol 'identifier, return a
582 pointer to a string with the symbol characters "identifier",
583 followed by a null byte. If lenp is non-null, set *lenp to the
584 string's length.
585
586 This function uses malloc to obtain storage for the copy; the
587 caller is responsible for freeing it. */
588char *
589gh_symbol2newstr (SCM sym, int *lenp)
590{
591 char *ret_str;
592 int len;
593
0c95b57d 594 SCM_ASSERT (SCM_SYMBOLP (sym), sym, SCM_ARG3,
ee2a8b9b
JB
595 "gh_scm2newsymbol");
596
597 /* protect str from GC while we copy off its data */
598 scm_protect_object (sym);
599
600 len = SCM_LENGTH (sym);
601
9b1b00fe
JB
602 ret_str = (char *) scm_must_malloc ((len + 1) * sizeof (char),
603 "gh_symbol2newstr");
ee2a8b9b
JB
604 /* so we copy tmp_str to ret_str, which is what we will allocate */
605 memcpy (ret_str, SCM_CHARS (sym), len);
606 /* now make sure we null-terminate it */
607 ret_str[len] = '\0';
608
609 scm_unprotect_object (sym);
610
611 if (lenp != NULL)
612 {
613 *lenp = len;
614 }
615
616 return ret_str;
617}
618
619
620/* create a new vector of the given length, all initialized to the
621 given value */
e5eece74
MG
622SCM
623gh_make_vector (SCM len, SCM fill)
ee2a8b9b 624{
a8741caa 625 return scm_make_vector (len, fill);
ee2a8b9b
JB
626}
627
628/* set the given element of the given vector to the given value */
629SCM
956328d2 630gh_vector_set_x (SCM vec, SCM pos, SCM val)
ee2a8b9b
JB
631{
632 return scm_vector_set_x (vec, pos, val);
633}
634
635/* retrieve the given element of the given vector */
636SCM
e5eece74 637gh_vector_ref (SCM vec, SCM pos)
ee2a8b9b
JB
638{
639 return scm_vector_ref (vec, pos);
640}
641
642/* returns the length of the given vector */
643unsigned long
644gh_vector_length (SCM v)
645{
646 return gh_scm2ulong (scm_vector_length (v));
647}
35379308 648
afe5177e 649#ifdef HAVE_ARRAYS
ef5d3ae1
MG
650/* uniform vector support */
651
652/* returns the length as a C unsigned long integer */
653unsigned long
654gh_uniform_vector_length (SCM v)
655{
656 return gh_scm2ulong (scm_uniform_vector_length (v));
657}
658
659/* gets the given element from a uniform vector; ilist is a list (or
660 possibly a single integer) of indices, and its length is the
661 dimension of the uniform vector */
662SCM
663gh_uniform_vector_ref (SCM v, SCM ilist)
664{
665 return scm_uniform_vector_ref (v, ilist);
666}
667
668/* sets an individual element in a uniform vector */
669/* SCM */
670/* gh_list_to_uniform_array ( */
afe5177e 671#endif
ef5d3ae1 672
35379308
JB
673/* Data lookups between C and Scheme
674
675 Look up a symbol with a given name, and return the object to which
676 it is bound. gh_lookup examines the Guile top level, and
677 gh_module_lookup checks the module namespace specified by the
678 `vec' argument.
679
680 The return value is the Scheme object to which SNAME is bound, or
681 SCM_UNDEFINED if SNAME is not bound in the given context. [FIXME:
682 should this be SCM_UNSPECIFIED? Can a symbol ever legitimately be
683 bound to SCM_UNDEFINED or SCM_UNSPECIFIED? What is the difference?
684 -twp] */
685
686SCM
bcee10dd 687gh_lookup (const char *sname)
35379308
JB
688{
689 return gh_module_lookup (SCM_BOOL_F, sname);
690}
691
692SCM
bcee10dd 693gh_module_lookup (SCM vec, const char *sname)
35379308
JB
694{
695 SCM sym = gh_symbol2scm (sname);
fbd485ba 696 if (SCM_TRUE_P (scm_symbol_bound_p (vec, sym)))
35379308
JB
697 return scm_symbol_binding (vec, sym);
698 else
699 return SCM_UNDEFINED;
700}
89e00824
ML
701
702/*
703 Local Variables:
704 c-file-style: "gnu"
705 End:
706*/