const qualifying char* inputs to various API functions

This commit is contained in:
Alex Shinn 2010-03-22 15:14:30 +09:00
parent bb3d44054e
commit 0a9085fbbd
4 changed files with 41 additions and 40 deletions

20
eval.c
View file

@ -28,7 +28,7 @@ static sexp sexp_load_module_file_op (sexp ctx, sexp file, sexp env);
static sexp sexp_find_module_file_op (sexp ctx, sexp file);
#endif
sexp sexp_compile_error (sexp ctx, char *message, sexp obj) {
sexp sexp_compile_error (sexp ctx, const char *message, sexp obj) {
sexp exn;
sexp_gc_var3(sym, irritants, msg);
sexp_gc_preserve3(ctx, sym, irritants, msg);
@ -307,8 +307,8 @@ static sexp sexp_make_lit (sexp ctx, sexp value) {
#define SEXP_STACK_SIZE (sexp_sizeof(stack)+sizeof(sexp)*SEXP_INIT_STACK_SIZE)
static void sexp_add_path (sexp ctx, char *str) {
char *colon;
static void sexp_add_path (sexp ctx, const char *str) {
const char *colon;
if (str && *str) {
colon = strchr(str, ':');
if (colon)
@ -2355,7 +2355,7 @@ sexp sexp_make_opcode (sexp ctx, sexp name, sexp op_class, sexp code,
return res;
}
sexp sexp_make_foreign (sexp ctx, char *name, int num_args,
sexp sexp_make_foreign (sexp ctx, const char *name, int num_args,
int flags, sexp_proc1 f, sexp data) {
sexp res;
if (num_args > 6) {
@ -2375,7 +2375,7 @@ sexp sexp_make_foreign (sexp ctx, char *name, int num_args,
return res;
}
sexp sexp_define_foreign_aux (sexp ctx, sexp env, char *name, int num_args,
sexp sexp_define_foreign_aux (sexp ctx, sexp env, const char *name, int num_args,
int flags, sexp_proc1 f, sexp data) {
sexp_gc_var1(op);
sexp_gc_preserve1(ctx, op);
@ -2389,8 +2389,8 @@ sexp sexp_define_foreign_aux (sexp ctx, sexp env, char *name, int num_args,
return res;
}
sexp sexp_define_foreign_param (sexp ctx, sexp env, char *name, int num_args,
sexp_proc1 f, char *param) {
sexp sexp_define_foreign_param (sexp ctx, sexp env, const char *name, int num_args,
sexp_proc1 f, const char *param) {
sexp res;
sexp_gc_var1(tmp);
sexp_gc_preserve1(ctx, tmp);
@ -2499,7 +2499,7 @@ sexp sexp_make_primitive_env (sexp ctx, sexp version) {
return e;
}
sexp sexp_find_module_file (sexp ctx, char *file) {
sexp sexp_find_module_file (sexp ctx, const char *file) {
sexp res=SEXP_FALSE, ls;
char *dir, *path;
sexp_uint_t slash, dirlen, filelen, len;
@ -2535,7 +2535,7 @@ sexp sexp_find_module_file (sexp ctx, char *file) {
#define sexp_file_not_found "couldn't find file in module path"
sexp sexp_load_module_file (sexp ctx, char *file, sexp env) {
sexp sexp_load_module_file (sexp ctx, const char *file, sexp env) {
sexp res;
sexp_gc_var1(path);
sexp_gc_preserve1(ctx, path);
@ -2768,7 +2768,7 @@ sexp sexp_eval (sexp ctx, sexp obj, sexp env) {
return res;
}
sexp sexp_eval_string (sexp ctx, char *str, sexp env) {
sexp sexp_eval_string (sexp ctx, const char *str, sexp env) {
sexp res;
sexp_gc_var1(obj);
sexp_gc_preserve1(ctx, obj);

View file

@ -126,14 +126,14 @@ enum sexp_opcode_names {
SEXP_API void sexp_scheme_init (void);
SEXP_API sexp sexp_make_eval_context (sexp context, sexp stack, sexp env, sexp_uint_t size);
SEXP_API sexp sexp_make_child_context (sexp context, sexp lambda);
SEXP_API sexp sexp_compile_error (sexp ctx, char *message, sexp obj);
SEXP_API sexp sexp_compile_error (sexp ctx, const char *message, sexp obj);
SEXP_API sexp sexp_analyze (sexp context, sexp x);
SEXP_API sexp sexp_apply (sexp context, sexp proc, sexp args);
SEXP_API sexp sexp_apply_optimization (sexp context, sexp proc, sexp ast);
SEXP_API sexp sexp_free_vars (sexp context, sexp x, sexp fv);
SEXP_API int sexp_param_index (sexp lambda, sexp name);
SEXP_API sexp sexp_eval (sexp context, sexp obj, sexp env);
SEXP_API sexp sexp_eval_string (sexp context, char *str, sexp env);
SEXP_API sexp sexp_eval_string (sexp context, const char *str, sexp env);
SEXP_API sexp sexp_load (sexp context, sexp expr, sexp env);
SEXP_API sexp sexp_make_env (sexp context);
SEXP_API sexp sexp_make_null_env (sexp context, sexp version);
@ -141,8 +141,8 @@ SEXP_API sexp sexp_make_primitive_env (sexp context, sexp version);
SEXP_API sexp sexp_make_standard_env (sexp context, sexp version);
SEXP_API sexp sexp_load_standard_parameters (sexp context, sexp env);
SEXP_API sexp sexp_load_standard_env (sexp context, sexp env, sexp version);
SEXP_API sexp sexp_find_module_file (sexp ctx, char *file);
SEXP_API sexp sexp_load_module_file (sexp ctx, char *file, sexp env);
SEXP_API sexp sexp_find_module_file (sexp ctx, const char *file);
SEXP_API sexp sexp_load_module_file (sexp ctx, const char *file, sexp env);
SEXP_API sexp sexp_add_module_directory (sexp ctx, sexp dir, sexp appendp);
SEXP_API sexp sexp_extend_env (sexp context, sexp env, sexp vars, sexp value);
SEXP_API sexp sexp_env_copy (sexp context, sexp to, sexp from, sexp ls, sexp immutp);
@ -152,13 +152,13 @@ SEXP_API sexp sexp_env_ref (sexp env, sexp sym, sexp dflt);
SEXP_API sexp sexp_env_global_ref (sexp env, sexp sym, sexp dflt);
SEXP_API void sexp_warn_undefs (sexp ctx, sexp from, sexp to, sexp out);
SEXP_API sexp sexp_make_opcode (sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp_proc1);
SEXP_API sexp sexp_make_foreign (sexp ctx, char *name, int num_args, int flags, sexp_proc1 f, sexp data);
SEXP_API sexp sexp_define_foreign_aux (sexp ctx, sexp env, char *name, int num_args, int flags, sexp_proc1 f, sexp data);
SEXP_API sexp sexp_make_foreign (sexp ctx, const char *name, int num_args, int flags, sexp_proc1 f, sexp data);
SEXP_API sexp sexp_define_foreign_aux (sexp ctx, sexp env, const char *name, int num_args, int flags, sexp_proc1 f, sexp data);
#define sexp_define_foreign(c,e,s,n,f) sexp_define_foreign_aux(c,e,s,n,0,(sexp_proc1)f,NULL)
#define sexp_define_foreign_opt(c,e,s,n,f,d) sexp_define_foreign_aux(c,e,s,n,1,(sexp_proc1)f,d)
SEXP_API sexp sexp_define_foreign_param (sexp ctx, sexp env, char *name, int num_args, sexp_proc1 f, char *param);
SEXP_API sexp sexp_define_foreign_param (sexp ctx, sexp env, const char *name, int num_args, sexp_proc1 f, const char *param);
#if SEXP_USE_TYPE_DEFS
SEXP_API sexp sexp_make_type_predicate (sexp ctx, sexp name, sexp type);

View file

@ -234,7 +234,7 @@ struct sexp_struct {
struct {
unsigned char op_class, code, num_args, flags,
arg1_type, arg2_type, inverse;
char *name;
const char *name;
sexp data, data2, proc;
sexp_proc1 func;
} opcode;
@ -810,8 +810,8 @@ enum sexp_context_globals {
SEXP_API int sexp_buffered_read_char (sexp ctx, sexp p);
SEXP_API sexp sexp_buffered_write_char (sexp ctx, int c, sexp p);
SEXP_API sexp sexp_buffered_write_string_n (sexp ctx, char *str, sexp_uint_t len, sexp p);
SEXP_API sexp sexp_buffered_write_string (sexp ctx, char *str, sexp p);
SEXP_API sexp sexp_buffered_write_string_n (sexp ctx, const char *str, sexp_uint_t len, sexp p);
SEXP_API sexp sexp_buffered_write_string (sexp ctx, const char *str, sexp p);
SEXP_API sexp sexp_buffered_flush (sexp ctx, sexp p);
#endif
@ -834,7 +834,7 @@ SEXP_API sexp sexp_c_string(sexp ctx, const char *str, sexp_sint_t slen);
SEXP_API sexp sexp_make_string(sexp ctx, sexp len, sexp ch);
SEXP_API sexp sexp_substring (sexp ctx, sexp str, sexp start, sexp end);
SEXP_API sexp sexp_string_concatenate (sexp ctx, sexp str_ls, sexp sep);
SEXP_API sexp sexp_intern(sexp ctx, char *str);
SEXP_API sexp sexp_intern(sexp ctx, const char *str);
SEXP_API sexp sexp_string_to_symbol(sexp ctx, sexp str);
SEXP_API sexp sexp_make_vector(sexp ctx, sexp len, sexp dflt);
SEXP_API sexp sexp_list_to_vector(sexp ctx, sexp ls);
@ -847,7 +847,7 @@ SEXP_API sexp sexp_read_symbol(sexp ctx, sexp in, int init, int internp);
SEXP_API sexp sexp_read_number(sexp ctx, sexp in, int base);
SEXP_API sexp sexp_read_raw(sexp ctx, sexp in);
SEXP_API sexp sexp_read(sexp ctx, sexp in);
SEXP_API sexp sexp_read_from_string(sexp ctx, char *str);
SEXP_API sexp sexp_read_from_string(sexp ctx, const char *str);
SEXP_API sexp sexp_write_to_string(sexp ctx, sexp obj);
SEXP_API sexp sexp_finalize_port (sexp ctx, sexp port);
SEXP_API sexp sexp_make_input_port(sexp ctx, FILE* in, sexp name);
@ -856,8 +856,8 @@ SEXP_API sexp sexp_make_input_string_port(sexp ctx, sexp str);
SEXP_API sexp sexp_make_output_string_port(sexp ctx);
SEXP_API sexp sexp_get_output_string(sexp ctx, sexp port);
SEXP_API sexp sexp_make_exception(sexp ctx, sexp kind, sexp message, sexp irritants, sexp procedure, sexp source);
SEXP_API sexp sexp_user_exception(sexp ctx, sexp self, char *message, sexp obj);
SEXP_API sexp sexp_type_exception(sexp ctx, char *message, sexp obj);
SEXP_API sexp sexp_user_exception(sexp ctx, sexp self, const char *msg, sexp x);
SEXP_API sexp sexp_type_exception(sexp ctx, const char *message, sexp x);
SEXP_API sexp sexp_range_exception(sexp ctx, sexp obj, sexp start, sexp end);
SEXP_API sexp sexp_print_exception(sexp ctx, sexp exn, sexp out);
SEXP_API void sexp_init(void);

33
sexp.c
View file

@ -21,7 +21,7 @@ static int sexp_initialized_p = 0;
sexp sexp_read_float_tail(sexp ctx, sexp in, double whole, int negp);
static char sexp_separators[] = {
static const char sexp_separators[] = {
/* 1 2 3 4 5 6 7 8 9 a b c d e f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, /* x0_ */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* x1_ */
@ -328,20 +328,20 @@ sexp sexp_make_exception (sexp ctx, sexp kind, sexp message, sexp irritants,
return exn;
}
sexp sexp_user_exception (sexp ctx, sexp self, char *message, sexp irritants) {
sexp sexp_user_exception (sexp ctx, sexp self, const char *ms, sexp ir) {
sexp res;
sexp_gc_var3(sym, str, irr);
sexp_gc_preserve3(ctx, sym, str, irr);
res = sexp_make_exception(ctx, sym = sexp_intern(ctx, "user"),
str = sexp_c_string(ctx, message, -1),
((sexp_pairp(irritants) || sexp_nullp(irritants))
? irritants : (irr = sexp_list1(ctx, irritants))),
str = sexp_c_string(ctx, ms, -1),
((sexp_pairp(ir) || sexp_nullp(ir))
? ir : (irr = sexp_list1(ctx, ir))),
self, SEXP_FALSE);
sexp_gc_release3(ctx);
return res;
}
sexp sexp_type_exception (sexp ctx, char *message, sexp obj) {
sexp sexp_type_exception (sexp ctx, const char *message, sexp obj) {
sexp res;
sexp_gc_var3(sym, str, irr);
sexp_gc_preserve3(ctx, sym, str, irr);
@ -424,15 +424,14 @@ sexp sexp_print_exception (sexp ctx, sexp exn, sexp out) {
return SEXP_VOID;
}
static sexp sexp_read_error (sexp ctx, char *msg, sexp irritants, sexp port) {
static sexp sexp_read_error (sexp ctx, const char *msg, sexp ir, sexp port) {
sexp res;
sexp_gc_var4(sym, name, str, irr);
sexp_gc_preserve4(ctx, sym, name, str, irr);
name = (sexp_port_name(port) ? sexp_port_name(port) : SEXP_FALSE);
name = sexp_cons(ctx, name, sexp_make_fixnum(sexp_port_line(port)));
str = sexp_c_string(ctx, msg, -1);
irr = ((sexp_pairp(irritants) || sexp_nullp(irritants))
? irritants : sexp_list1(ctx, irritants));
irr = ((sexp_pairp(ir) || sexp_nullp(ir)) ? ir : sexp_list1(ctx, ir));
res = sexp_make_exception(ctx, sym = sexp_intern(ctx, "read"),
str, irr, SEXP_FALSE, name);
sexp_gc_release4(ctx);
@ -695,21 +694,21 @@ sexp sexp_string_concatenate (sexp ctx, sexp str_ls, sexp sep) {
#if SEXP_USE_HASH_SYMS
static sexp_uint_t sexp_string_hash(char *str, sexp_uint_t acc) {
static sexp_uint_t sexp_string_hash(const char *str, sexp_uint_t acc) {
while (*str) {acc *= FNV_PRIME; acc ^= *str++;}
return acc;
}
#endif
sexp sexp_intern(sexp ctx, char *str) {
sexp sexp_intern(sexp ctx, const char *str) {
#if SEXP_USE_HUFF_SYMS
struct sexp_huff_entry he;
sexp_uint_t space=3, newbits;
char c;
#endif
sexp_uint_t len, res=FNV_OFFSET_BASIS, bucket;
char *p=str;
const char *p=str;
sexp ls;
sexp_gc_var1(sym);
@ -780,7 +779,8 @@ sexp sexp_list_to_vector(sexp ctx, sexp ls) {
return vec;
}
sexp sexp_make_cpointer (sexp ctx, sexp_uint_t type_id, void *value, sexp parent, int freep) {
sexp sexp_make_cpointer (sexp ctx, sexp_uint_t type_id, void *value,
sexp parent, int freep) {
sexp ptr;
if (! value) return SEXP_FALSE;
ptr = sexp_alloc_type(ctx, cpointer, type_id);
@ -958,7 +958,8 @@ sexp sexp_buffered_write_char (sexp ctx, int c, sexp p) {
return SEXP_VOID;
}
sexp sexp_buffered_write_string_n (sexp ctx, char *str, sexp_uint_t len, sexp p) {
sexp sexp_buffered_write_string_n (sexp ctx, const char *str,
sexp_uint_t len, sexp p) {
if (sexp_port_offset(p) >= sexp_port_size(p))
sexp_buffered_flush(ctx, p);
memcpy(sexp_port_buf(p)+sexp_port_offset(p), str, len);
@ -966,7 +967,7 @@ sexp sexp_buffered_write_string_n (sexp ctx, char *str, sexp_uint_t len, sexp p)
return SEXP_VOID;
}
sexp sexp_buffered_write_string (sexp ctx, char *str, sexp p) {
sexp sexp_buffered_write_string (sexp ctx, const char *str, sexp p) {
return sexp_buffered_write_string_n(ctx, str, strlen(str), p);
}
@ -1661,7 +1662,7 @@ sexp sexp_read (sexp ctx, sexp in) {
return res;
}
sexp sexp_read_from_string(sexp ctx, char *str) {
sexp sexp_read_from_string(sexp ctx, const char *str) {
sexp res;
sexp_gc_var2(s, in);
sexp_gc_preserve2(ctx, s, in);