Added const keywords wherever I could find a reasonable place
to improve error detection and efficiency.
This commit is contained in:
parent
1d62cb2182
commit
bd33154d9a
|
@ -20,4 +20,4 @@ extern char *copystring(char *, const char *);
|
||||||
|
|
||||||
extern scheme_value strlen_or_false(const char *);
|
extern scheme_value strlen_or_false(const char *);
|
||||||
|
|
||||||
extern void cig_check_nargs(int arity, int nargs, char *fn);
|
extern void cig_check_nargs(int arity, int nargs, const char *fn);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
** If C string is NULL, do nothing and return #f.
|
** If C string is NULL, do nothing and return #f.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int c2scheme_strcpy(scheme_value sstr, char *cstr)
|
int c2scheme_strcpy(scheme_value sstr, const char *cstr)
|
||||||
{
|
{
|
||||||
if( cstr ) {
|
if( cstr ) {
|
||||||
strncpy( (char*) StobData(sstr), cstr, STRING_LENGTH(sstr) );
|
strncpy( (char*) StobData(sstr), cstr, STRING_LENGTH(sstr) );
|
||||||
|
@ -28,7 +28,7 @@ int c2scheme_strcpy(scheme_value sstr, char *cstr)
|
||||||
|
|
||||||
|
|
||||||
/* Same as above, but free the C string when we are done. */
|
/* Same as above, but free the C string when we are done. */
|
||||||
int c2scheme_strcpy_free(scheme_value sstr, char *cstr)
|
int c2scheme_strcpy_free(scheme_value sstr, const char *cstr)
|
||||||
{
|
{
|
||||||
if( cstr ) {
|
if( cstr ) {
|
||||||
strncpy( (char*) StobData(sstr), cstr, STRING_LENGTH(sstr) );
|
strncpy( (char*) StobData(sstr), cstr, STRING_LENGTH(sstr) );
|
||||||
|
@ -42,11 +42,10 @@ char *scheme2c_strcpy(scheme_value sstr)
|
||||||
{
|
{
|
||||||
char *result;
|
char *result;
|
||||||
int slen;
|
int slen;
|
||||||
extern void *memcpy(void*, const void*, size_t);
|
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
slen = STRING_LENGTH(sstr);
|
slen = STRING_LENGTH(sstr);
|
||||||
result = (char*) malloc(slen+1);
|
result = Malloc(char, slen+1);
|
||||||
|
|
||||||
if( result == NULL ) {
|
if( result == NULL ) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -56,7 +55,7 @@ char *scheme2c_strcpy(scheme_value sstr)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(result, (void *) cig_string_body(sstr), slen);
|
memcpy(result, cig_string_body(sstr), slen);
|
||||||
result[slen] = '\000';
|
result[slen] = '\000';
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -66,9 +65,9 @@ char *scheme2c_strcpy(scheme_value sstr)
|
||||||
** The terminating null is not counted. Returns #f on NULL.
|
** The terminating null is not counted. Returns #f on NULL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
scheme_value c_veclen(long *vec)
|
scheme_value c_veclen(const long *vec)
|
||||||
{
|
{
|
||||||
long *vptr = vec;
|
const long *vptr = vec;
|
||||||
if( !vptr ) return SCHFALSE;
|
if( !vptr ) return SCHFALSE;
|
||||||
while( *vptr ) vptr++;
|
while( *vptr ) vptr++;
|
||||||
return ENTER_FIXNUM(vptr - vec);
|
return ENTER_FIXNUM(vptr - vec);
|
||||||
|
@ -112,7 +111,7 @@ char *copystring_or_die(const char *str ) /* Note: NULL -> NULL. */
|
||||||
else return NULL;
|
else return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cstring_nullp( char *s ) { return ! s; }
|
int cstring_nullp( const char *s ) { return ! s; }
|
||||||
|
|
||||||
scheme_value strlen_or_false(const char *s)
|
scheme_value strlen_or_false(const char *s)
|
||||||
{ return s ? ENTER_FIXNUM(strlen(s)) : SCHFALSE; }
|
{ return s ? ENTER_FIXNUM(strlen(s)) : SCHFALSE; }
|
||||||
|
@ -138,7 +137,7 @@ void set_strvec_carriers(scheme_value svec, char const * const * cvec)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function for arg checking. Why bother, actually? */
|
/* Helper function for arg checking. Why bother, actually? */
|
||||||
void cig_check_nargs(int arity, int nargs, char *fn)
|
void cig_check_nargs(int arity, int nargs, const char *fn)
|
||||||
{
|
{
|
||||||
if( arity != nargs ) {
|
if( arity != nargs ) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|
Loading…
Reference in New Issue