Previous: C to Scheme, Up: Converting data between C and Scheme


5.22.9.2 Scheme to C
— Function: int gh_scm2bool (SCM obj)
— Function: unsigned long gh_scm2ulong (SCM obj)
— Function: long gh_scm2long (SCM obj)
— Function: double gh_scm2double (SCM obj)
— Function: int gh_scm2char (SCM obj)

These routines convert the Scheme object to the given C type.

— Function: char * gh_scm2newstr (SCM str, size_t *lenp)

Given a Scheme string str, return a pointer to a new copy of its contents, followed by a null byte. If lenp is non-null, set *lenp to the string's length.

This function uses malloc to obtain storage for the copy; the caller is responsible for freeing it.

Note that Scheme strings may contain arbitrary data, including null characters. This means that null termination is not a reliable way to determine the length of the returned value. However, the function always copies the complete contents of str, and sets *lenp to the true length of the string (when lenp is non-null).

— Function: void gh_get_substr (SCM str, char *return_str, int *lenp)

Copy len characters at start from the Scheme string src to memory at dst. start is an index into src; zero means the beginning of the string. dst has already been allocated by the caller.

If start + len is off the end of src, signal an out-of-range error.

— Function: char * gh_symbol2newstr (SCM sym, int *lenp)

Takes a Scheme symbol and returns a string of the form "'symbol-name". If lenp is non-null, the string's length is returned in *lenp.

This function uses malloc to obtain storage for the returned string; the caller is responsible for freeing it.

— Function: char * gh_scm2chars (SCM vector, chars *result)
— Function: short * gh_scm2shorts (SCM vector, short *result)
— Function: long * gh_scm2longs (SCM vector, long *result)
— Function: float * gh_scm2floats (SCM vector, float *result)
— Function: double * gh_scm2doubles (SCM vector, double *result)

Copy the numbers in vector to the array pointed to by result and return it. If result is NULL, allocate a double array large enough.

vector can be an ordinary vector, a weak vector, or a signed or unsigned uniform vector of the same type as the result array. For chars, vector can be a string or substring. For floats and doubles, vector can contain a mix of inexact and integer values.

If vector is of unsigned type and contains values too large to fit in the signed destination array, those values will be wrapped around, that is, data will be copied as if the destination array was unsigned.