summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-23 06:24:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-23 06:24:54 -0700
commitad4e4e79ac6b9fcb182f3cd834120ec79512ac9a (patch)
tree44aae8e017bc51f526fded0d85bf3a63ba00ad8f
parenteed035b792cb3b1b2723fa2b1ca0dd7fb5e5fe31 (diff)
downloadtxr-ad4e4e79ac6b9fcb182f3cd834120ec79512ac9a.tar.gz
txr-ad4e4e79ac6b9fcb182f3cd834120ec79512ac9a.tar.bz2
txr-ad4e4e79ac6b9fcb182f3cd834120ec79512ac9a.zip
c_str now takes a self argument.
Adding a self parameter to c_str so that when a non-string occurs, the error is reported against a function. Legend: A - Pass existing self to c_str. B - Define self and pass to c_str and possibly other functions. C - Take new self parameter and pass to c_str and possibly other functions. D - Pass existing self to c_str and/or other functions. E - Define self and pass to other functions, not c_str. X - Pass nil to c_str. * buf.c (buf_strm_put_string, buf_str): B. * chksum.c (sha256_str, md5_str): C. (sha256_hash, md5_hash): D. * eval.c (load): D. * ffi.c (ffi_varray_dynsize, ffi_str_put, ffi_wstr_put, ffi_bstr_put): A. (ffi_char_array_put, ffi_wchar_array_put): C. (ffi_bchar_array_put): A. (ffi_array_put, ffi_array_out, ffi_varray_put): D. * ftw.c (ftw_wrap): A. * glob.c (glob_wrap): A. * lib.c (copy_str, length_str, coded_length,split_str_set, list_str, cmp_str, num_str, out_json_str, out_json_rec, display_width): B. (upcase_str, downcase_str, string_extend, search_str, do_match_str, do_rmatch_str, sub_str, replace_str, cat_str_append, split_str_keep, trim_str, int_str, chr_str, span_str, compl_span_str, break_str, length_str_gt, length_str_ge, length_str_lt, length_str_le, find, rfind, pos, rpos, mismatch, rmismatch): A. (c_str): Add self parameter and use in type mismatch diagnostic. If the parameter is nil, use "internal error". (flo_str): B, and correction to "flot-str" typo. (out_lazy_str, out_quasi_str, obj_print_impl): D. * lib.h (c_str): Declaration updated. * match.c (dump_var): X. (v_load): D. * parser.c (open_txr_file): C. (load_rcfile): E. (find_matching_syms, provide_atom): X. (hist_save, repl): B. * parser.h (open_txr_file): Declaration updated. * parser.y (chrlit): X. * regex.c (search_regex): A. * socket.c (getaddrinfo_wrap, sockaddr_pack): A. (dgram_put_string): B. (open_sockfd): D. (sock_connect): E. * stream.c (stdio_put_string, tail_strategy, vformat_str, open_directory, open_file, open_tail, remove_path, rename_path, tmpfile_wrap, mkdtemp_wrap, mkstemp_wrap): B. (do_parse_mode, parse_mode, make_string_byte_input_stream): B. (normalize_mode, normalize_mode_no_bin): E. (string_out_put_string, formatv, put_string, open_fileno, open_subprocess, open_command, base_name, dir_name, short_suffix, long_suffix): A. (run): D. (win_escape_cmd, win_escape_arg): X. * stream.h (parse_mode, normalize_mode, normalize_mode_no_bin): Declarations updated. * sysif.c (mkdir_wrap, do_utimes, dlopen_wrap, dlsym_wrap, dlvsym_wrap): A. (do_stat, do_lstat): C. (mkdir_nothrow_exists, ensure_dir): E. (chdir_wrap, rmdir_wrap, mkfifo_wrap, chmod_wrap, symlink_wrap, link_wrap, readlink_wrap, exec_wrap, getenv_wrap, setenv_wrap, unsetenv_wrap, getpwnam_wrap, getgrnam_wrap, crypt_wrap, fnmatch_wrap, realpath_wrap, opendir_wrap): B. (stat_impl): statfn pointer-to-function argument now takes self parameter. When calling it, we pass name. * syslog.c (openlog_wrap, syslog_wrapv): A. * time.c (time_string_local, time_string_utc, time_string_meth, time_parse_meth): A. (strptime_wrap): B. * txr.c (txr_main): D. * y.tab.c.shipped: Updated.
-rw-r--r--buf.c6
-rw-r--r--chksum.c16
-rw-r--r--eval.c2
-rw-r--r--ffi.c30
-rw-r--r--ftw.c2
-rw-r--r--glob.c4
-rw-r--r--lib.c156
-rw-r--r--lib.h2
-rw-r--r--match.c4
-rw-r--r--parser.c28
-rw-r--r--parser.h3
-rw-r--r--parser.y2
-rw-r--r--regex.c2
-rw-r--r--socket.c19
-rw-r--r--stream.c116
-rw-r--r--stream.h8
-rw-r--r--sysif.c100
-rw-r--r--syslog.c4
-rw-r--r--time.c15
-rw-r--r--txr.c7
-rw-r--r--y.tab.c.shipped2
21 files changed, 297 insertions, 231 deletions
diff --git a/buf.c b/buf.c
index 1804733a..a5592749 100644
--- a/buf.c
+++ b/buf.c
@@ -876,8 +876,9 @@ static int buf_strm_put_byte_callback(int b, mem_t *ctx)
static val buf_strm_put_string(val stream, val str)
{
+ val self = lit("put-string");
struct buf_strm *s = coerce(struct buf_strm *, stream->co.handle);
- const wchar_t *p = c_str(str);
+ const wchar_t *p = c_str(str, self);
while (*p) {
(void) utf8_encode(*p++, buf_strm_put_byte_callback, coerce(mem_t *, s));
@@ -1121,9 +1122,10 @@ void buf_swap32(val buf)
static val buf_str(val str, val null_term)
{
+ val self = lit("buf-str");
size_t sz;
val nt = default_null_arg(null_term);
- unsigned char *u8 = utf8_dup_to_buf(c_str(str), &sz, nt != nil);
+ unsigned char *u8 = utf8_dup_to_buf(c_str(str, self), &sz, nt != nil);
return make_owned_buf(unum(sz), u8);
}
diff --git a/chksum.c b/chksum.c
index 215d4f57..1f2ea3eb 100644
--- a/chksum.c
+++ b/chksum.c
@@ -137,9 +137,9 @@ static void sha256_buf(val buf, unsigned char *hash, val self)
SHA256_final(&s256, hash);
}
-static void sha256_str(val str, unsigned char *hash)
+static void sha256_str(val str, unsigned char *hash, val self)
{
- char *s = utf8_dup_to(c_str(str));
+ char *s = utf8_dup_to(c_str(str, self));
SHA256_t s256;
SHA256_init(&s256);
SHA256_update(&s256, coerce(const unsigned char *, s), strlen(s));
@@ -158,7 +158,7 @@ val sha256(val obj, val buf_in)
case STR:
case LSTR:
case LIT:
- sha256_str(obj, hash);
+ sha256_str(obj, hash, self);
return buf;
case BUF:
sha256_buf(obj, hash, self);
@@ -199,7 +199,7 @@ val sha256_hash(val ctx, val obj)
case LSTR:
case LIT:
{
- char *str = utf8_dup_to(c_str(obj));
+ char *str = utf8_dup_to(c_str(obj, self));
SHA256_update(ps256, coerce(const unsigned char *, str), strlen(str));
free(str);
}
@@ -401,9 +401,9 @@ static void md5_buf(val buf, unsigned char *hash, val self)
MD5_final(&md5, hash);
}
-static void md5_str(val str, unsigned char *hash)
+static void md5_str(val str, unsigned char *hash, val self)
{
- char *s = utf8_dup_to(c_str(str));
+ char *s = utf8_dup_to(c_str(str, self));
MD5_t md5;
MD5_init(&md5);
MD5_update(&md5, coerce(const unsigned char *, s), strlen(s));
@@ -422,7 +422,7 @@ val md5(val obj, val buf_in)
case STR:
case LSTR:
case LIT:
- md5_str(obj, hash);
+ md5_str(obj, hash, self);
return buf;
case BUF:
md5_buf(obj, hash, self);
@@ -463,7 +463,7 @@ val md5_hash(val ctx, val obj)
case LSTR:
case LIT:
{
- char *str = utf8_dup_to(c_str(obj));
+ char *str = utf8_dup_to(c_str(obj, self));
MD5_update(pmd5, coerce(const unsigned char *, str), strlen(str));
free(str);
}
diff --git a/eval.c b/eval.c
index 23579af3..cdf251a4 100644
--- a/eval.c
+++ b/eval.c
@@ -4489,7 +4489,7 @@ val load(val target)
val saved_dyn_env = dyn_env;
val rec = cdr(lookup_var(saved_dyn_env, load_recursive_s));
- open_txr_file(path, &txr_lisp_p, &name, &stream);
+ open_txr_file(path, &txr_lisp_p, &name, &stream, self);
if (match_str(or2(get_line(stream), lit("")), lit("#!"), nil))
parser_set_lineno(self, stream, two);
diff --git a/ffi.c b/ffi.c
index 13bdb314..44652e84 100644
--- a/ffi.c
+++ b/ffi.c
@@ -429,7 +429,7 @@ static cnum ffi_varray_dynsize(struct txr_ffi_type *tft, val obj, val self)
switch (tft->ch_conv) {
case conv_char:
case conv_zchar:
- return utf8_to_buf(0, c_str(obj), tft->null_term);
+ return utf8_to_buf(0, c_str(obj, self), tft->null_term);
case conv_wchar:
case conv_bchar:
case conv_none:
@@ -1952,7 +1952,7 @@ static void ffi_str_put(struct txr_ffi_type *tft, val s, mem_t *dst,
if (s == nil) {
*coerce(const char **, dst) = 0;
} else {
- const wchar_t *ws = c_str(s);
+ const wchar_t *ws = c_str(s, self);
char *u8s = utf8_dup_to(ws);
*coerce(const char **, dst) = u8s;
}
@@ -2006,7 +2006,7 @@ static void ffi_wstr_put(struct txr_ffi_type *tft, val s, mem_t *dst,
if (s == nil) {
*coerce(const wchar_t **, dst) = 0;
} else {
- const wchar_t *ws = c_str(s);
+ const wchar_t *ws = c_str(s, self);
*coerce(const wchar_t **, dst) = chk_strdup(ws);
}
}
@@ -2042,7 +2042,7 @@ static void ffi_bstr_put(struct txr_ffi_type *tft, val s, mem_t *dst,
if (s == nil) {
*coerce(unsigned char **, dst) = 0;
} else {
- const wchar_t *ws = c_str(s);
+ const wchar_t *ws = c_str(s, self);
unsigned char *u8s = chk_strdup_8bit(ws);
*coerce(unsigned char **, dst) = u8s;
}
@@ -2477,10 +2477,10 @@ static val ffi_char_array_get(struct txr_ffi_type *tft, mem_t *src,
}
static void ffi_char_array_put(struct txr_ffi_type *tft, val str, mem_t *dst,
- cnum nelem)
+ cnum nelem, val self)
{
int nt = tft->null_term;
- const wchar_t *wstr = c_str(str);
+ const wchar_t *wstr = c_str(str, self);
cnum needed = utf8_to_buf(0, wstr, nt);
if (needed <= nelem) {
@@ -2533,9 +2533,9 @@ static val ffi_wchar_array_get(struct txr_ffi_type *tft, mem_t *src,
}
static void ffi_wchar_array_put(struct txr_ffi_type *tft, val str, mem_t *dst,
- cnum nelem)
+ cnum nelem, val self)
{
- const wchar_t *wstr = c_str(str);
+ const wchar_t *wstr = c_str(str, self);
wcsncpy(coerce(wchar_t *, dst), wstr, nelem);
if (tft->null_term)
dst[nelem - 1] = 0;
@@ -2558,7 +2558,7 @@ static val ffi_bchar_array_get(struct txr_ffi_type *tft, mem_t *src,
static void ffi_bchar_array_put(struct txr_ffi_type *tft, val str, mem_t *dst,
cnum nelem, val self)
{
- const wchar_t *wstr = c_str(str);
+ const wchar_t *wstr = c_str(str, self);
cnum i;
for (i = 0; i < nelem && wstr[i]; i++) {
@@ -2691,10 +2691,10 @@ static void ffi_array_put(struct txr_ffi_type *tft, val vec, mem_t *dst,
switch (tft->ch_conv) {
case conv_char:
case conv_zchar:
- ffi_char_array_put(tft, vec, dst, tft->nelem);
+ ffi_char_array_put(tft, vec, dst, tft->nelem, self);
break;
case conv_wchar:
- ffi_wchar_array_put(tft, vec, dst, tft->nelem);
+ ffi_wchar_array_put(tft, vec, dst, tft->nelem, self);
break;
case conv_bchar:
ffi_bchar_array_put(tft, vec, dst, tft->nelem, self);
@@ -2741,10 +2741,10 @@ static void ffi_array_out(struct txr_ffi_type *tft, int copy, val vec,
switch (tft->ch_conv) {
case conv_char:
case conv_zchar:
- ffi_char_array_put(tft, vec, dst, tft->nelem);
+ ffi_char_array_put(tft, vec, dst, tft->nelem, self);
break;
case conv_wchar:
- ffi_wchar_array_put(tft, vec, dst, tft->nelem);
+ ffi_wchar_array_put(tft, vec, dst, tft->nelem, self);
break;
case conv_bchar:
ffi_bchar_array_put(tft, vec, dst, tft->nelem, self);
@@ -2841,10 +2841,10 @@ static void ffi_varray_put(struct txr_ffi_type *tft, val vec, mem_t *dst,
switch (tft->ch_conv) {
case conv_char:
case conv_zchar:
- ffi_char_array_put(tft, vec, dst, nelem);
+ ffi_char_array_put(tft, vec, dst, nelem, self);
break;
case conv_wchar:
- ffi_wchar_array_put(tft, vec, dst, nelem);
+ ffi_wchar_array_put(tft, vec, dst, nelem, self);
break;
case conv_bchar:
ffi_bchar_array_put(tft, vec, dst, nelem, self);
diff --git a/ftw.c b/ftw.c
index 4e78e801..074952e1 100644
--- a/ftw.c
+++ b/ftw.c
@@ -111,7 +111,7 @@ val ftw_wrap(val dirpath, val fn, val flags_in, val nopenfd_in)
} else {
int nopenfd = c_num(default_arg(nopenfd_in, num_fast(20)), self);
int flags = c_num(default_arg(flags_in, zero), self);
- char *dirpath_u8 = utf8_dup_to(c_str(dirpath));
+ char *dirpath_u8 = utf8_dup_to(c_str(dirpath, self));
int res = (s_callback = fn,
nftw(dirpath_u8, ftw_callback, nopenfd, flags));
s_callback = nil;
diff --git a/glob.c b/glob.c
index 4044f675..a42d5722 100644
--- a/glob.c
+++ b/glob.c
@@ -79,7 +79,7 @@ val glob_wrap(val pattern, val flags, val errfun)
c_flags &= ~GLOB_APPEND;
if (stringp(pattern)) {
- char *pat_u8 = utf8_dup_to(c_str(pattern));
+ char *pat_u8 = utf8_dup_to(c_str(pattern, self));
(void) glob(pat_u8, c_flags, s_errfunc ? errfunc_thunk : 0, &gl);
free(pat_u8);
} else {
@@ -88,7 +88,7 @@ val glob_wrap(val pattern, val flags, val errfun)
seq_iter_init(self, &iter, pattern);
while (seq_get(&iter, &elem)) {
- char *pat_u8 = utf8_dup_to(c_str(elem));
+ char *pat_u8 = utf8_dup_to(c_str(elem, self));
(void) glob(pat_u8, c_flags, s_errfunc ? errfunc_thunk : 0, &gl);
if (s_exit_point)
break;
diff --git a/lib.c b/lib.c
index 85f3f55c..75cb56d4 100644
--- a/lib.c
+++ b/lib.c
@@ -4405,9 +4405,10 @@ static val copy_lazy_str(val lstr);
val copy_str(val str)
{
+ val self = lit("copy-str");
return if3(lazy_stringp(str),
copy_lazy_str(str),
- string(c_str(str)));
+ string(c_str(str, self)));
}
val upcase_str(val str)
@@ -4415,7 +4416,7 @@ val upcase_str(val str)
val self = lit("upcase-str");
val len = length_str(str);
wchar_t *dst = chk_wmalloc(c_unum(len, self) + 1);
- const wchar_t *src = c_str(str);
+ const wchar_t *src = c_str(str, self);
val out = string_own(dst);
while ((*dst++ = towupper(*src++)))
@@ -4429,7 +4430,7 @@ val downcase_str(val str)
val self = lit("downcase-str");
val len = length_str(str);
wchar_t *dst = chk_wmalloc(c_unum(len, self) + 1);
- const wchar_t *src = c_str(str);
+ const wchar_t *src = c_str(str, self);
val out = string_own(dst);
while ((*dst++ = towlower(*src++)))
@@ -4480,7 +4481,7 @@ val string_extend(val str, val tail)
set(mkloc(str->st.len, str), num_fast(len + delta));
if (stringp(tail)) {
- wmemcpy(str->st.str + len, c_str(tail), delta + 1);
+ wmemcpy(str->st.str + len, c_str(tail, self), delta + 1);
} else if (chrp(tail)) {
str->st.str[len] = c_chr(tail);
str->st.str[len + 1] = 0;
@@ -4509,9 +4510,10 @@ val lazy_stringp(val str)
val length_str(val str)
{
+ val self = lit("length-str");
switch (type(str)) {
case LIT:
- return num(wcslen(c_str(str)));
+ return num(wcslen(c_str(str, self)));
case LSTR:
lazy_str_force(str);
return length_str(str->ls.prefix);
@@ -4528,10 +4530,11 @@ val length_str(val str)
val coded_length(val str)
{
- return unum(utf8_to_buf(0, c_str(str), 0));
+ val self = lit("coded-length");
+ return unum(utf8_to_buf(0, c_str(str, self), 0));
}
-const wchar_t *c_str(val obj)
+const wchar_t *c_str(val obj, val self)
{
switch (type(obj)) {
case LIT:
@@ -4540,13 +4543,14 @@ const wchar_t *c_str(val obj)
return obj->st.str;
case LSTR:
lazy_str_force(obj);
- return c_str(obj->ls.prefix);
+ return c_str(obj->ls.prefix, self);
case SYM:
if (opt_compat && opt_compat <= 231)
- return c_str(symbol_name(obj));
+ return c_str(symbol_name(obj), self);
/* fallthrough */
default:
- type_mismatch(lit("~s is not a string"), obj, nao);
+ self = default_arg(self, lit("internal error"));
+ type_mismatch(lit("~a: ~s is not a string"), self, obj, nao);
}
}
@@ -4562,10 +4566,10 @@ val search_str(val haystack, val needle, val start_num, val from_end)
val h_is_lazy = lazy_stringp(haystack);
cnum start = c_num(start_num, self);
cnum good = -1, pos = -1;
- const wchar_t *n = c_str(needle), *h;
+ const wchar_t *n = c_str(needle, self), *h;
if (!h_is_lazy) {
- h = c_str(haystack);
+ h = c_str(haystack, self);
if (start < 0)
start += wcslen(h);
@@ -4584,14 +4588,14 @@ val search_str(val haystack, val needle, val start_num, val from_end)
if (start < 0) {
lazy_str_force(haystack);
- h = c_str(haystack->ls.prefix);
+ h = c_str(haystack->ls.prefix, self);
start += wcslen(h);
goto nonlazy;
}
do {
lazy_str_force_upto(haystack, plus(num(start + 1), length_str(needle)));
- h = c_str(haystack->ls.prefix);
+ h = c_str(haystack->ls.prefix, self);
if (!wcsncmp(h + start, n, ln))
good = start;
@@ -4652,8 +4656,8 @@ static val do_match_str(val bigstr, val str, cnum pos, val self)
return nil;
{
- const wchar_t *bs = c_str(bigstr);
- const wchar_t *ss = c_str(str);
+ const wchar_t *bs = c_str(bigstr, self);
+ const wchar_t *ss = c_str(str, self);
return if3(wmemcmp(bs + pos, ss, sl) == 0, num(pos + sl), nil);
}
@@ -4724,8 +4728,8 @@ static val do_rmatch_str(val bigstr, val str, cnum pos, val self)
return nil;
{
- const wchar_t *bs = c_str(bigstr);
- const wchar_t *ss = c_str(str);
+ const wchar_t *bs = c_str(bigstr, self);
+ const wchar_t *ss = c_str(str, self);
cnum start = pos + 1 - sl;
return if3(wmemcmp(bs + start, ss, sl) == 0, num(start), nil);
}
@@ -4857,7 +4861,7 @@ val sub_str(val str_in, val from, val to)
} else {
size_t nchar = c_num(to, self) - c_num(from, self) + 1;
wchar_t *sub = chk_wmalloc(nchar);
- const wchar_t *str = c_str(str_in);
+ const wchar_t *str = c_str(str_in, self);
wcsncpy(sub, str + c_num(from, self), nchar);
sub[nchar-1] = 0;
return string_own(sub);
@@ -4939,7 +4943,8 @@ val replace_str(val str_in, val items, val from, val to)
if (zerop(len_it))
return str_in;
if (stringp(items)) {
- wmemmove(str_in->st.str + c_num(from, self), c_str(items), c_num(len_it, self));
+ wmemmove(str_in->st.str + c_num(from, self),
+ c_str(items, self), c_num(len_it, self));
} else {
seq_iter_t item_iter;
seq_iter_init(self, &item_iter, items);
@@ -5026,14 +5031,14 @@ static void cat_str_append(struct cat_str *cs, val item, int more_p, val self)
return;
if (stringp(item)) {
cnum len = c_num(length_str(item), self);
- wmemcpy(cs->ptr, c_str(item), len);
+ wmemcpy(cs->ptr, c_str(item, self), len);
cs->ptr += len;
} else {
*cs->ptr++ = c_chr(item);
}
if (cs->len_sep && more_p) {
- wmemcpy(cs->ptr, c_str(cs->sep), cs->len_sep);
+ wmemcpy(cs->ptr, c_str(cs->sep, self), cs->len_sep);
cs->ptr += cs->len_sep;
}
}
@@ -5232,7 +5237,7 @@ val split_str_keep(val str, val sep, val keep_sep)
if (opt_compat && opt_compat <= 100) {
return list_str(str);
} else {
- const wchar_t *cstr = c_str(str);
+ const wchar_t *cstr = c_str(str, self);
if (*cstr) {
list_collect_decl (out, iter);
@@ -5253,8 +5258,8 @@ val split_str_keep(val str, val sep, val keep_sep)
}
}
} else {
- const wchar_t *cstr = c_str(str);
- const wchar_t *csep = c_str(sep);
+ const wchar_t *cstr = c_str(str, self);
+ const wchar_t *csep = c_str(sep, self);
list_collect_decl (out, iter);
@@ -5297,8 +5302,8 @@ val split_str(val str, val sep)
val split_str_set(val str, val set)
{
val self = lit("split-str-set");
- const wchar_t *cstr = c_str(str);
- const wchar_t *cset = c_str(set);
+ const wchar_t *cstr = c_str(str, self);
+ const wchar_t *cset = c_str(set, self);
list_collect_decl (out, iter);
for (;;) {
@@ -5437,7 +5442,8 @@ val tok_where(val str, val tok_regex)
val list_str(val str)
{
- const wchar_t *cstr = c_str(str);
+ val self = lit("list-str");
+ const wchar_t *cstr = c_str(str, self);
list_collect_decl (out, iter);
while (*cstr)
@@ -5451,7 +5457,7 @@ val list_str(val str)
val trim_str(val str)
{
val self = lit("trim-str");
- const wchar_t *start = c_str(str);
+ const wchar_t *start = c_str(str, self);
const wchar_t *end = start + c_num(length_str(str), self);
if (opt_compat && opt_compat <= 148) {
@@ -5481,13 +5487,15 @@ val trim_str(val str)
val cmp_str(val astr, val bstr)
{
+ val self = lit("bstr");
+
switch (TYPE_PAIR(type(astr), type(bstr))) {
case TYPE_PAIR(LIT, LIT):
case TYPE_PAIR(STR, STR):
case TYPE_PAIR(LIT, STR):
case TYPE_PAIR(STR, LIT):
{
- int cmp = wcscmp(c_str(astr), c_str(bstr));
+ int cmp = wcscmp(c_str(astr, self), c_str(bstr, self));
return if3(cmp < 0, negone, if3(cmp > 0, one, zero));
}
case TYPE_PAIR(LSTR, LIT):
@@ -5551,7 +5559,7 @@ val str_ge(val astr, val bstr)
val int_str(val str, val base)
{
val self = lit("int-str");
- const wchar_t *wcs = c_str(str);
+ const wchar_t *wcs = c_str(str, self);
wchar_t *ptr;
long value;
cnum b = c_num(default_arg(base, num_fast(10)), self);
@@ -5638,13 +5646,14 @@ val int_str(val str, val base)
val flo_str(val str)
{
- const wchar_t *wcs = c_str(str);
+ val self = lit("flo-str");
+ const wchar_t *wcs = c_str(str, self);
wchar_t *ptr;
double value;
#if CONFIG_LOCALE_TOLERANCE
if (dec_point != '.') {
- size_t size = c_unum(length_str(str), lit("flot-str")) + 1;
+ size_t size = c_unum(length_str(str), self) + 1;
wchar_t *wcopy = alloca(sizeof *wcopy * size), *dot = wcopy;
wmemcpy(wcopy, wcs, size);
wcs = wcopy;
@@ -5664,7 +5673,8 @@ val flo_str(val str)
val num_str(val str)
{
- const wchar_t *wcs = c_str(str);
+ val self = lit("num-str");
+ const wchar_t *wcs = c_str(str, self);
const wchar_t *nws = wcs + wcsspn(wcs, L"\f\n\r\t\v");
const wchar_t *dig = nws + wcsspn(wcs, L"+-");
@@ -6087,9 +6097,9 @@ val chr_str(val str, val ind)
if (lazy_stringp(str)) {
lazy_str_force_upto(str, ind);
- return chr(c_str(str->ls.prefix)[index]);
+ return chr(c_str(str->ls.prefix, self)[index]);
} else {
- return chr(c_str(str)[index]);
+ return chr(c_str(str, self)[index]);
}
}
@@ -6125,24 +6135,27 @@ val chr_str_set(val str, val ind, val chr)
val span_str(val str, val set)
{
- const wchar_t *cstr = c_str(str);
- const wchar_t *cset = c_str(set);
+ val self = lit("span-str");
+ const wchar_t *cstr = c_str(str, self);
+ const wchar_t *cset = c_str(set, self);
size_t span = wcsspn(cstr, cset);
return num(span);
}
val compl_span_str(val str, val set)
{
- const wchar_t *cstr = c_str(str);
- const wchar_t *cset = c_str(set);
+ val self = lit("compl-span-str");
+ const wchar_t *cstr = c_str(str, self);
+ const wchar_t *cset = c_str(set, self);
size_t span = wcscspn(cstr, cset);
return num(span);
}
val break_str(val str, val set)
{
- const wchar_t *cstr = c_str(str);
- const wchar_t *cset = c_str(set);
+ val self = lit("break-str");
+ const wchar_t *cstr = c_str(str, self);
+ const wchar_t *cset = c_str(set, self);
const wchar_t *brk = wcspbrk(cstr, cset);
if (!brk)
return nil;
@@ -9014,7 +9027,7 @@ val length_str_gt(val str, val len)
switch (type(str)) {
case LIT:
{
- const wchar_t *cstr = c_str(str);
+ const wchar_t *cstr = c_str(str, self);
size_t clen = c_num(len, self);
const wchar_t *nult = wmemchr(cstr, 0, clen + 1);
return nult == 0 ? t : nil;
@@ -9035,7 +9048,7 @@ val length_str_ge(val str, val len)
switch (type(str)) {
case LIT:
{
- const wchar_t *cstr = c_str(str);
+ const wchar_t *cstr = c_str(str, self);
size_t clen = c_num(len, self);
const wchar_t *nult = wmemchr(cstr, 0, clen);
return nult == 0 ? t : nil;
@@ -9056,7 +9069,7 @@ val length_str_lt(val str, val len)
switch (type(str)) {
case LIT:
{
- const wchar_t *cstr = c_str(str);
+ const wchar_t *cstr = c_str(str, self);
size_t clen = c_num(len, self);
const wchar_t *nult = wmemchr(cstr, 0, clen);
return nult != 0 ? t : nil;
@@ -9077,7 +9090,7 @@ val length_str_le(val str, val len)
switch (type(str)) {
case LIT:
{
- const wchar_t *cstr = c_str(str);
+ const wchar_t *cstr = c_str(str, self);
size_t clen = c_num(len, self);
const wchar_t *nult = wmemchr(cstr, 0, clen + 1);
return nult != 0 ? t : nil;
@@ -10206,7 +10219,7 @@ val find(val item, val seq, val testfun, val keyfun)
(testfun == equal_f || testfun == eql_f || testfun == eq_f))
{
const wchar_t ch = c_chr(item);
- const wchar_t *cstr = c_str(seq);
+ const wchar_t *cstr = c_str(seq, self);
if (wcschr(cstr, ch))
return item;
return nil;
@@ -10265,7 +10278,7 @@ val rfind(val item, val seq, val testfun, val keyfun)
(testfun == equal_f || testfun == eql_f || testfun == eq_f))
{
const wchar_t ch = c_chr(item);
- const wchar_t *cstr = c_str(seq);
+ const wchar_t *cstr = c_str(seq, self);
if (wcschr(cstr, ch))
return item;
return nil;
@@ -10524,7 +10537,7 @@ val pos(val item, val seq, val testfun, val keyfun)
(testfun == equal_f || testfun == eql_f || testfun == eq_f))
{
const wchar_t ch = c_chr(item);
- const wchar_t *cstr = c_str(seq);
+ const wchar_t *cstr = c_str(seq, self);
const wchar_t *cpos = wcschr(cstr, ch);
if (cpos != 0)
return num(cpos - cstr);
@@ -10585,7 +10598,7 @@ val rpos(val item, val seq, val testfun, val keyfun)
(testfun == equal_f || testfun == eql_f || testfun == eq_f))
{
const wchar_t ch = c_chr(item);
- const wchar_t *cstr = c_str(seq);
+ const wchar_t *cstr = c_str(seq, self);
const wchar_t *cpos = wcsrchr(cstr, ch);
if (cpos != 0)
return num(cpos - cstr);
@@ -10891,8 +10904,8 @@ val mismatch(val left, val right, val testfun_in, val keyfun_in)
testfun == eql_f ||
testfun == eq_f))
{
- const wchar_t *lft = c_str(left), *le = lft;
- const wchar_t *rgt = c_str(right), *ri = rgt;
+ const wchar_t *lft = c_str(left, nil), *le = lft;
+ const wchar_t *rgt = c_str(right, nil), *ri = rgt;
while (*le && *ri && *le == *ri)
le++, ri++;
@@ -11011,8 +11024,8 @@ val rmismatch(val left, val right, val testfun_in, val keyfun_in)
{
cnum ll = c_num(length(left), self), li = ll - 1;
cnum rl = c_num(length(right), self), ri = rl - 1;
- const wchar_t *lft = c_str(left);
- const wchar_t *rgt = c_str(right);
+ const wchar_t *lft = c_str(left, self);
+ const wchar_t *rgt = c_str(right, self);
for (; li >= 0 && ri >= 0; li--, ri--) {
if (lft[li] != rgt[ri])
@@ -12601,11 +12614,11 @@ static void out_lazy_str(val lstr, val out, struct strm_base *strm)
cnum max_len = strm->max_length;
cnum max_chr = max_len ? max_str_chars(max_len) : 0;
- wcterm = c_str(term);
+ wcterm = c_str(term, self);
put_char(chr('"'), out);
- out_str_readable(c_str(lstr->ls.prefix), out, &semi_flag);
+ out_str_readable(c_str(lstr->ls.prefix, self), out, &semi_flag);
for (iter = lstr->ls.list; (!lim || gt(lim, zero)) && iter;
iter = cdr(iter))
@@ -12615,14 +12628,15 @@ static void out_lazy_str(val lstr, val out, struct strm_base *strm)
break;
if (max_len) {
if (length_str_gt(str, num(max_chr))) {
- out_str_readable(c_str(sub_str(str, zero, num(max_chr))), out, &semi_flag);
+ out_str_readable(c_str(sub_str(str, zero, num(max_chr)), self),
+ out, &semi_flag);
goto max_reached;
}
if (--max_chr == 0)
goto max_reached;
max_chr -= c_num(length_str(str), self);
}
- out_str_readable(c_str(str), out, &semi_flag);
+ out_str_readable(c_str(str, self), out, &semi_flag);
out_str_readable(wcterm, out, &semi_flag);
if (lim)
lim = pred(lim);
@@ -12680,10 +12694,11 @@ static void out_quasi_str(val args, val out, struct strm_ctx *ctx)
if (stringp(elem)) {
int semi_flag = 0;
if (max_len && length_str_gt(elem, num(max_chr))) {
- out_str_readable(c_str(sub_str(elem, zero, num(max_chr))), out, &semi_flag);
+ out_str_readable(c_str(sub_str(elem, zero, num(max_chr)), self),
+ out, &semi_flag);
goto max_exceeded;
} else {
- out_str_readable(c_str(elem), out, &semi_flag);
+ out_str_readable(c_str(elem, self), out, &semi_flag);
if (max_len) {
max_chr -= c_num(length(elem), self);
if (max_chr == 0) {
@@ -12721,7 +12736,8 @@ max_exceeded:
static void out_json_str(val str, val out)
{
- const wchar_t *cstr = c_str(str);
+ val self = lit("print");
+ const wchar_t *cstr = c_str(str, self);
wchar_t ch;
put_char(chr('"'), out);
@@ -12914,7 +12930,7 @@ static void out_json_rec(val obj, val out, struct strm_ctx *ctx)
{
val save_indent;
int force_br = 0;
- cnum len = c_num(length(obj), lit("print"));
+ cnum len = c_num(length(obj), self);
cnum i;
put_char(chr('['), out);
@@ -12985,8 +13001,8 @@ static void out_json_rec(val obj, val out, struct strm_ctx *ctx)
break;
}
- uw_throwf(type_error_s, lit("print: invalid object ~s in JSON"),
- obj, nao);
+ uw_throwf(type_error_s, lit("~a: invalid object ~s in JSON"),
+ self, obj, nao);
}
static void out_json(val op, val obj, val out, struct strm_ctx *ctx)
@@ -13287,9 +13303,9 @@ dot:
put_char(chr('"'), out);
if (!max_length || le(length_str(obj), num(max_chr))) {
- out_str_readable(c_str(obj), out, &semi_flag);
+ out_str_readable(c_str(obj, self), out, &semi_flag);
} else {
- out_str_readable(c_str(sub_str(obj, zero, num(max_chr))),
+ out_str_readable(c_str(sub_str(obj, zero, num(max_chr)), self),
out, &semi_flag);
put_string(lit("\\..."), out);
}
@@ -13682,8 +13698,10 @@ val tojson(val obj, val flat)
val display_width(val obj)
{
+ val self = lit("display-width");
+
if (stringp(obj)) {
- const wchar_t *s = c_str(obj);
+ const wchar_t *s = c_str(obj, self);
cnum width = 0;
for (; *s; s++) {
if (iswcntrl(*s))
@@ -13698,8 +13716,8 @@ val display_width(val obj)
return num_fast(1 + wide_display_char_p(ch));
}
- uw_throwf(type_error_s, lit("display-width: ~s isn't a character or string"),
- obj, nao);
+ uw_throwf(type_error_s, lit("~a: ~s isn't a character or string"),
+ self, obj, nao);
}
void init(val *stack_bottom)
diff --git a/lib.h b/lib.h
index 2a8ed526..262d6468 100644
--- a/lib.h
+++ b/lib.h
@@ -864,7 +864,7 @@ val stringp(val str);
val lazy_stringp(val str);
val length_str(val str);
val coded_length(val str);
-const wchar_t *c_str(val str);
+const wchar_t *c_str(val str, val self);
val search_str(val haystack, val needle, val start_num, val from_end);
val search_str_tree(val haystack, val tree, val start_num, val from_end);
val match_str(val bigstr, val str, val pos);
diff --git a/match.c b/match.c
index 2fa61026..3f47ee05 100644
--- a/match.c
+++ b/match.c
@@ -173,7 +173,7 @@ static void dump_var(val var, char *pfx1, size_t len1,
dump_byte_string(pfx1);
dump_byte_string(pfx2);
put_char(chr('='), std_output);
- dump_shell_string(c_str(str));
+ dump_shell_string(c_str(str, nil));
put_char(chr('\n'), std_output);
}
}
@@ -4350,7 +4350,7 @@ static val v_load(match_files_ctx *c)
val saved_dyn_env = dyn_env;
val rec = cdr(lookup_var(saved_dyn_env, load_recursive_s));
- open_txr_file(path, &txr_lisp_p, &name, &stream);
+ open_txr_file(path, &txr_lisp_p, &name, &stream, self);
uw_simple_catch_begin;
diff --git a/parser.c b/parser.c
index fd274ebb..2ef62537 100644
--- a/parser.c
+++ b/parser.c
@@ -508,7 +508,8 @@ val parser_circ_ref(parser_t *p, val num)
return obj;
}
-void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
+void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream,
+ val self)
{
enum { none, tl, tlo, txr } suffix;
@@ -531,7 +532,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
if (suffix == none && !*txr_lisp_p) {
spec_file_try = scat(lit("."), spec_file, lit("txr"), nao);
- if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0)
+ if ((in = w_fopen(c_str(spec_file_try, nil), L"r")) != 0)
goto found;
#ifdef ENOENT
if (in == 0 && errno != ENOENT)
@@ -543,7 +544,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
spec_file_try = scat(lit("."), spec_file, lit("tlo"), nao);
errno = 0;
- if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0) {
+ if ((in = w_fopen(c_str(spec_file_try, nil), L"r")) != 0) {
*txr_lisp_p = chr('o');
goto found;
}
@@ -555,7 +556,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
spec_file_try = scat(lit("."), spec_file, lit("tl"), nao);
errno = 0;
- if ((in = w_fopen(c_str(spec_file_try), L"r")) != 0) {
+ if ((in = w_fopen(c_str(spec_file_try, nil), L"r")) != 0) {
*txr_lisp_p = t;
goto found;
}
@@ -569,7 +570,7 @@ void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream)
{
spec_file_try = spec_file;
errno = 0;
- in = w_fopen(c_str(spec_file_try), L"r");
+ in = w_fopen(c_str(spec_file_try, self), L"r");
if (in != 0) {
switch (suffix) {
case tl:
@@ -886,6 +887,7 @@ static void report_security_problem(val name)
static void load_rcfile(val name)
{
+ val self = lit("listener");
val resolved_name;
val lisp_p = t;
val stream = nil;
@@ -894,7 +896,7 @@ static void load_rcfile(val name)
uw_catch_begin (catch_syms, sy, va);
- open_txr_file(name, &lisp_p, &resolved_name, &stream);
+ open_txr_file(name, &lisp_p, &resolved_name, &stream, self);
if (stream) {
if (!funcall1(path_private_to_me_p, stream)) {
@@ -902,7 +904,7 @@ static void load_rcfile(val name)
} else {
val saved_dyn_env = set_dyn_env(make_env(nil, nil, dyn_env));
env_vbind(dyn_env, load_path_s, resolved_name);
- read_eval_stream(lit("listener"), stream, std_output);
+ read_eval_stream(self, stream, std_output);
dyn_env = saved_dyn_env;
}
}
@@ -1008,7 +1010,7 @@ static void find_matching_syms(lino_completions_t *cpl,
else
comple = scat2(line_prefix, name);
- lino_add_completion(cpl, c_str(comple));
+ lino_add_completion(cpl, c_str(comple, nil));
gc_hint(comple);
}
}
@@ -1142,7 +1144,7 @@ static wchar_t *provide_atom(lino_t *l, const wchar_t *str, int n, void *ctx)
}
if (obj != nao)
- out = chk_strdup(c_str(tostring(obj)));
+ out = chk_strdup(c_str(tostring(obj), nil));
uw_catch (exsym, exvals) {
(void) exsym;
@@ -1446,7 +1448,7 @@ static void hist_save(lino_t *ls, val in_stream, val out_stream,
val self = lit("listener");
if (histfile_w && lino_have_new_lines(ls)) {
val histfile_tmp = scat2(histfile, lit(".tmp"));
- const wchar_t *histfile_tmp_w = c_str(histfile_tmp);
+ const wchar_t *histfile_tmp_w = c_str(histfile_tmp, self);
lino_t *ltmp = lino_make(coerce(mem_t *, in_stream),
coerce(mem_t *, out_stream));
lino_hist_set_max_len(ltmp, c_num(cdr(hist_len_var), self));
@@ -1483,7 +1485,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
val counter = one;
val home = if3(repl_level == 1, get_home_path(), nil);
val histfile = if2(home, scat2(home, lit("/.txr_history")));
- const wchar_t *histfile_w = if3(home, c_str(histfile), NULL);
+ const wchar_t *histfile_w = if3(home, c_str(histfile, self), NULL);
val rcfile = if2(home && !opt_noprofile, scat2(home, lit("/.txr_profile")));
val old_sig_handler = set_sig_handler(num(SIGINT), func_n2(repl_intr));
val hist_len_var = lookup_global_var(listener_hist_len_s);
@@ -1549,7 +1551,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
lino_set_selinclusive(ls, cdr(sel_inclusive_var) != nil);
reg_varl(counter_sym, counter);
reg_varl(var_counter_sym, var_counter);
- line_w = linenoise(ls, c_str(prompt));
+ line_w = linenoise(ls, c_str(prompt, self));
rplacd(multi_line_var, tnil(lino_get_multiline(ls)));
@@ -1614,7 +1616,7 @@ val repl(val bindings, val in_stream, val out_stream, val env)
reg_varl(var_sym, value);
sethash(result_hash, var_counter, value);
pfun(value, out_stream);
- lino_set_result(ls, chk_strdup(c_str(tsfun(value))));
+ lino_set_result(ls, chk_strdup(c_str(tsfun(value), self)));
lino_hist_add(ls, line_w);
if (cdr(greedy_eval)) {
val error_p = nil;
diff --git a/parser.h b/parser.h
index 53bfa5ad..81dcc223 100644
--- a/parser.h
+++ b/parser.h
@@ -96,7 +96,8 @@ parser_t *yyget_extra(yyscan_t scanner);
void yyset_extra(parser_t *, yyscan_t);
void yyset_hold_char(yyscan_t, int);
void parser_l_init(void);
-void open_txr_file(val spec_file, val *txr_lisp_p, val *name, val *stream);
+void open_txr_file(val spec_file, val *txr_lisp_p,
+ val *name, val *stream, val self);
void prime_parser(parser_t *, val name, enum prime_parser);
void prime_parser_post(parser_t *, enum prime_parser);
#ifdef SPACE
diff --git a/parser.y b/parser.y
index c8abd205..c1cce317 100644
--- a/parser.y
+++ b/parser.y
@@ -1374,7 +1374,7 @@ strlit : '"' '"' { $$ = null_string; }
chrlit : HASH_BACKSLASH SYMTOK { wchar_t ch;
val str = string_own($2);
- const wchar_t *cstr = c_str(str);
+ const wchar_t *cstr = c_str(str, nil);
if (cstr[1] == 0)
{ ch = cstr[0]; }
diff --git a/regex.c b/regex.c
index a0eecff8..41c912a8 100644
--- a/regex.c
+++ b/regex.c
@@ -2593,7 +2593,7 @@ val search_regex(val haystack, val needle_regex, val start,
if (from_end) {
cnum i;
cnum s = c_num(start, self);
- const wchar_t *h = c_str(haystack);
+ const wchar_t *h = c_str(haystack, self);
slen = (slen ? slen : length_str(haystack));
diff --git a/socket.c b/socket.c
index 3893d07d..f512e98f 100644
--- a/socket.c
+++ b/socket.c
@@ -180,8 +180,8 @@ static val getaddrinfo_wrap(val node_in, val service_in, val hints_in)
val service = default_arg(service_in, nil);
val hints = default_arg(hints_in, nil);
struct addrinfo hints_ai, *phints = hints ? &hints_ai : 0, *alist = 0, *aiter;
- char *node_u8 = stringp(node) ? utf8_dup_to(c_str(node)) : 0;
- char *service_u8 = stringp(service) ? utf8_dup_to(c_str(service)) : 0;
+ char *node_u8 = stringp(node) ? utf8_dup_to(c_str(node, self)) : 0;
+ char *service_u8 = stringp(service) ? utf8_dup_to(c_str(service, self)) : 0;
val node_num_p = integerp(node);
val svc_num_p = integerp(service);
int res = 0;
@@ -281,7 +281,7 @@ static void sockaddr_pack(val sockaddr, val family,
val path = slot(sockaddr, path_s);
struct sockaddr_un *sa = coerce(struct sockaddr_un *, buf);
size_t size;
- unsigned char *path_u8 = utf8_dup_to_buf(c_str(path), &size, 0);
+ unsigned char *path_u8 = utf8_dup_to_buf(c_str(path, self), &size, 0);
memset(sa, 0, sizeof *sa);
sa->sun_family = AF_UNIX;
memcpy(sa->sun_path, path_u8, MIN(size, sizeof sa->sun_path));
@@ -382,8 +382,9 @@ static int dgram_put_byte_callback(int b, mem_t *ctx)
static val dgram_put_string(val stream, val str)
{
+ val self = lit("put-string");
struct dgram_stream *d = coerce(struct dgram_stream *, stream->co.handle);
- const wchar_t *s = c_str(str);
+ const wchar_t *s = c_str(str, self);
while (*s) {
if (!utf8_encode(*s++, dgram_put_byte_callback, coerce(mem_t *, d)))
@@ -817,9 +818,12 @@ static val open_sockfd(val fd, val family, val type, val mode_str, val self)
if (type == num_fast(SOCK_DGRAM)) {
return make_dgram_sock_stream(c_num(fd, self), family, nil, 0, 0, 0, 0,
- parse_mode(mode_str, m_rpb), 0);
+ parse_mode(mode_str, m_rpb, self), 0);
} else {
- FILE *f = (errno = 0, w_fdopen(c_num(fd, self), c_str(normalize_mode(&m, mode_str, m_rpb))));
+ FILE *f = (errno = 0, w_fdopen(c_num(fd, self),
+ c_str(normalize_mode(&m, mode_str,
+ m_rpb, self),
+ self)));
if (!f) {
int eno = errno;
@@ -832,7 +836,6 @@ static val open_sockfd(val fd, val family, val type, val mode_str, val self)
}
}
-
static val sock_connect(val sock, val sockaddr, val timeout)
{
val self = lit("sock-connect");
@@ -996,7 +999,7 @@ static val sock_accept(val sock, val mode_str, val timeout_in)
}
return make_dgram_sock_stream(afd, family, peer, dgram, nbytes,
coerce(struct sockaddr *, &sa), salen,
- parse_mode(mode_str, mode_rpb), d);
+ parse_mode(mode_str, mode_rpb, self), d);
}
} else {
int afd = -1;
diff --git a/stream.c b/stream.c
index 6c6a6e65..89870eb3 100644
--- a/stream.c
+++ b/stream.c
@@ -686,12 +686,13 @@ static int stdio_get_char_callback(mem_t *f)
static val stdio_put_string(val stream, val str)
{
+ val self = lit("put-string");
struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle);
errno = 0;
if (h->f != 0) {
- const wchar_t *s = c_str(str);
+ const wchar_t *s = c_str(str, self);
stdio_switch(h, stdio_write);
@@ -1157,6 +1158,7 @@ static void tail_calc(unsigned long *state, int *usec, int *mod)
static void tail_strategy(val stream, unsigned long *state)
{
+ val self = lit("open-tail");
struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle);
int usec = 0, mod = 0;
val mode = nil;
@@ -1192,11 +1194,11 @@ static void tail_strategy(val stream, unsigned long *state)
FILE *newf;
if (!mode)
- mode = normalize_mode(&m, h->mode, m_r);
+ mode = normalize_mode(&m, h->mode, m_r, self);
/* Try to open the file.
*/
- if (!(newf = w_fopen_mode(c_str(h->descr), c_str(mode), m))) {
+ if (!(newf = w_fopen_mode(c_str(h->descr, self), c_str(mode, self), m))) {
/* If already have the file open previously, and the name
* does not open any more, then the file has rotated.
* Have the caller try to read the last bit of data
@@ -1428,10 +1430,11 @@ static struct strm_ops pipe_ops =
stdio_clear_error,
stdio_get_fd);
-static struct stdio_mode do_parse_mode(val mode_str, struct stdio_mode m_dfl)
+static struct stdio_mode do_parse_mode(val mode_str, struct stdio_mode m_dfl,
+ val self)
{
struct stdio_mode m = stdio_mode_init_blank;
- const wchar_t *ms = c_str(default_arg(mode_str, lit("")));
+ const wchar_t *ms = c_str(default_arg(mode_str, lit("")), self);
int nredir = 0;
switch (*ms) {
@@ -1564,11 +1567,12 @@ static struct stdio_mode do_parse_mode(val mode_str, struct stdio_mode m_dfl)
return m;
}
-struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl)
+struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl, val self)
{
- struct stdio_mode m = do_parse_mode(mode_str, m_dfl);
+ struct stdio_mode m = do_parse_mode(mode_str, m_dfl, self);
if (m.malformed)
- uw_throwf(file_error_s, lit("invalid mode string ~s"), mode_str, nao);
+ uw_throwf(file_error_s, lit("~s: invalid mode string ~s"), self,
+ mode_str, nao);
return m;
}
@@ -1605,9 +1609,10 @@ static val format_mode(const struct stdio_mode m)
return string(buf);
}
-val normalize_mode(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl)
+val normalize_mode(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl,
+ val self)
{
- *m = do_parse_mode(mode_str, m_dfl);
+ *m = do_parse_mode(mode_str, m_dfl, self);
if (m->malformed)
uw_throwf(file_error_s, lit("invalid file open mode ~s"), mode_str, nao);
@@ -1615,15 +1620,17 @@ val normalize_mode(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl)
return format_mode(*m);
}
-val normalize_mode_no_bin(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl)
+val normalize_mode_no_bin(struct stdio_mode *m, val mode_str,
+ struct stdio_mode m_dfl, val self)
{
#ifdef __CYGWIN__
- return normalize_mode(m, mode_str, m_dfl);
+ return normalize_mode(m, mode_str, m_dfl, self);
#else
- *m = do_parse_mode(mode_str, m_dfl);
+ *m = do_parse_mode(mode_str, m_dfl, self);
if (m->malformed)
- uw_throwf(file_error_s, lit("invalid file open mode ~s"), mode_str, nao);
+ uw_throwf(file_error_s, lit("~a: invalid file open mode ~s"),
+ self, mode_str, nao);
m->binary = 0;
@@ -2066,10 +2073,11 @@ static struct strm_ops byte_in_ops =
val make_string_byte_input_stream(val string)
{
+ val self = lit("make-string-byte-input-stream");
type_assert (stringp(string), (lit("~a is not a string"), string, nao));
{
- const wchar_t *wstring = c_str(string);
+ const wchar_t *wstring = c_str(string, self);
struct byte_input *bi = coerce(struct byte_input *, chk_malloc(sizeof *bi));
strm_base_init(&bi->a);
bi->buf = utf8_dup_to_buf(wstring, &bi->size, 0);
@@ -2281,7 +2289,7 @@ static val string_out_put_string(val stream, val str)
string_out_byte_flush(so, stream);
{
- const wchar_t *s = c_str(str);
+ const wchar_t *s = c_str(str, self);
size_t len = c_num(length_str(str), self);
size_t old_size = so->size;
size_t required_size = len + so->fill + 1;
@@ -3277,7 +3285,8 @@ static cnum calc_fitlen(const wchar_t *cstr, int precision, int width)
static void vformat_str(val stream, val str, int width, enum align align,
int precision)
{
- const wchar_t *cstr = c_str(str);
+ val self = lit("format");
+ const wchar_t *cstr = c_str(str, self);
cnum fitlen = calc_fitlen(cstr, precision, width);
cnum slack = (fitlen < width) ? width - fitlen : 0;
cnum i, w;
@@ -3313,7 +3322,7 @@ val formatv(val stream_in, val fmtstr, struct args *al)
uw_simple_catch_begin;
{
- const wchar_t *fmt = c_str(fmtstr);
+ const wchar_t *fmt = c_str(fmtstr, self);
enum {
vf_init, vf_width, vf_digits, vf_star, vf_precision, vf_spec
} state = vf_init, saved_state = vf_init;
@@ -3852,7 +3861,7 @@ val put_string(val string, val stream_in)
cobj_ops(self, stream, stream_s));
cnum col = s->column;
- const wchar_t *str = c_str(string), *p = str;
+ const wchar_t *str = c_str(string, self), *p = str;
if (s->indent_mode != indent_off && s->indent_mode != indent_foff) {
while (*str)
@@ -4165,7 +4174,8 @@ val get_string(val stream_in, val nchars, val close_after_p)
val open_directory(val path)
{
- DIR *d = w_opendir(c_str(path));
+ val self = lit("open-directory");
+ DIR *d = w_opendir(c_str(path, self));
if (!d) {
int eno = errno;
@@ -4179,9 +4189,10 @@ val open_directory(val path)
val open_file(val path, val mode_str)
{
+ val self = lit("open-file");
struct stdio_mode m, m_r = stdio_mode_init_r;
- val norm_mode = normalize_mode(&m, mode_str, m_r);
- FILE *f = w_fopen_mode(c_str(path), c_str(norm_mode), m);
+ val norm_mode = normalize_mode(&m, mode_str, m_r, self);
+ FILE *f = w_fopen_mode(c_str(path, self), c_str(norm_mode, self), m);
if (!f) {
int eno = errno;
@@ -4196,7 +4207,9 @@ val open_fileno(val fd, val mode_str)
{
val self = lit("open-fileno");
struct stdio_mode m, m_r = stdio_mode_init_r;
- FILE *f = (errno = 0, w_fdopen(c_num(fd, self), c_str(normalize_mode(&m, mode_str, m_r))));
+ FILE *f = (errno = 0, w_fdopen(c_num(fd, self),
+ c_str(normalize_mode(&m, mode_str, m_r, self),
+ self)));
if (!f) {
int eno = errno;
@@ -4212,9 +4225,10 @@ val open_fileno(val fd, val mode_str)
val open_tail(val path, val mode_str, val seek_end_p)
{
+ val self = lit("open-tail");
struct stdio_mode m, m_r = stdio_mode_init_r;
- val mode = normalize_mode(&m, mode_str, m_r);
- FILE *f = w_fopen_mode(c_str(path), c_str(mode), m);
+ val mode = normalize_mode(&m, mode_str, m_r, self);
+ FILE *f = w_fopen_mode(c_str(path, self), c_str(mode, self), m);
struct stdio_handle *h;
val stream;
unsigned long state = 0;
@@ -4351,7 +4365,7 @@ static val open_subprocess(val name, val mode_str, val args, val fun)
{
val self = lit("open-subprocess");
struct stdio_mode m, m_r = stdio_mode_init_r;
- val mode = normalize_mode(&m, mode_str, m_r);
+ val mode = normalize_mode(&m, mode_str, m_r, self);
int input = m.read != 0;
int fd[2];
pid_t pid;
@@ -4390,7 +4404,7 @@ static val open_subprocess(val name, val mode_str, val args, val fun)
if (argv) {
for (i = 0, iter = cons(name, args); iter; i++, iter = cdr(iter)) {
val arg = car(iter);
- argv[i] = utf8_dup_to(c_str(arg));
+ argv[i] = utf8_dup_to(c_str(arg, self));
}
argv[i] = 0;
}
@@ -4458,7 +4472,7 @@ static val open_subprocess(val name, val mode_str, val args, val fun)
_exit(errno);
} else {
int whichfd;
- char *utf8mode = utf8_dup_to(c_str(mode));
+ char *utf8mode = utf8_dup_to(c_str(mode, self));
FILE *f;
if (input) {
@@ -4540,7 +4554,7 @@ val open_command(val path, val mode_str)
fds_swizzle(&sfds, fds_flags, self);
- f = w_popen(c_str(path), c_str(mode));
+ f = w_popen(c_str(path, self), c_str(mode, self));
if (!f) {
int eno = errno;
@@ -4570,7 +4584,7 @@ static val win_escape_cmd(val str)
const wchar_t *s;
val out = string(L"");
- for (s = c_str(str); *s; s++) {
+ for (s = c_str(str, nil); *s; s++) {
switch (*s) {
case ' ': case '\t':
string_extend(out, lit("\""));
@@ -4591,7 +4605,7 @@ static val win_escape_arg(val str)
const wchar_t *s;
val out = string(L"");
- for (s = c_str(str); *s; s++) {
+ for (s = c_str(str, nil); *s; s++) {
switch (*s) {
case '"':
string_extend_count(bscount, out, lit("\\\\"));
@@ -4702,13 +4716,13 @@ static val run(val command, val args)
wargv = coerce(const wchar_t **, chk_xalloc(nargs + 1, sizeof *wargv, self));
for (i = 0, iter = cons(command, args); iter; i++, iter = cdr(iter))
- wargv[i] = c_str(car(iter));
+ wargv[i] = c_str(car(iter), self);
wargv[i] = 0;
#if HAVE_WSPAWN
- status = _wspawnvp(_P_WAIT, c_str(command), wargv);
+ status = _wspawnvp(_P_WAIT, c_str(command, self), wargv);
#else
- status = w_spawnvp(_P_WAIT, c_str(command), nargs, wargv);
+ status = w_spawnvp(_P_WAIT, c_str(command, self), nargs, wargv);
#endif
free(strip_qual(wchar_t **, wargv));
@@ -4751,7 +4765,7 @@ static val run(val name, val args)
for (i = 0, iter = cons(name, args); iter; i++, iter = cdr(iter)) {
val arg = car(iter);
- argv[i] = utf8_dup_to(c_str(arg));
+ argv[i] = utf8_dup_to(c_str(arg, self));
}
argv[i] = 0;
@@ -4807,7 +4821,9 @@ static val sh(val command)
val remove_path(val path, val throw_on_error)
{
- if (w_remove(c_str(path)) < 0) {
+ val self = lit("remove-path");
+
+ if (w_remove(c_str(path, self)) < 0) {
if (default_null_arg(throw_on_error) || errno != ENOENT) {
int eno = errno;
uw_throwf(errno_to_file_error(eno), lit("trying to remove ~s: ~d/~s"),
@@ -4821,7 +4837,9 @@ val remove_path(val path, val throw_on_error)
val rename_path(val from, val to)
{
- if (w_rename(c_str(from), c_str(to)) < 0) {
+ val self = lit("rename-path");
+
+ if (w_rename(c_str(from, self), c_str(to, self)) < 0) {
int eno = errno;
uw_throwf(errno_to_file_error(eno),
lit("trying to rename ~s to ~s: ~d/~s"),
@@ -4948,7 +4966,7 @@ static void detect_path_separators(void)
val base_name(val path, val suff)
{
val self = lit("base-name");
- const wchar_t *wpath = c_str(path);
+ const wchar_t *wpath = c_str(path, self);
const wchar_t *end = wpath + c_num(length_str(path), self);
const wchar_t *rsep;
const wchar_t *psc = coerce(const wchar_t *, path_sep_chars);
@@ -4981,7 +4999,7 @@ val base_name(val path, val suff)
val dir_name(val path)
{
val self = lit("dir-name");
- const wchar_t *wpath = c_str(path);
+ const wchar_t *wpath = c_str(path, self);
const wchar_t *rsep = wpath + c_num(length_str(path), self);
const wchar_t *psc = coerce(const wchar_t *, path_sep_chars);
@@ -5016,8 +5034,9 @@ val dir_name(val path)
val short_suffix(val name, val alt_in)
{
+ val self = lit("short-suffix");
const wchar_t *psc = coerce(const wchar_t *, path_sep_chars);
- const wchar_t *str = c_str(name);
+ const wchar_t *str = c_str(name, self);
const wchar_t *dot = wcsrchr(str, '.');
const wchar_t *sl = if3(dot, wcspbrk(dot + 1, psc), 0);
@@ -5033,8 +5052,9 @@ val short_suffix(val name, val alt_in)
val long_suffix(val name, val alt_in)
{
+ val self = lit("long-suffix");
const wchar_t *psc = coerce(const wchar_t *, path_sep_chars);
- const wchar_t *str = c_str(name);
+ const wchar_t *str = c_str(name, self);
const wchar_t *dot = wcschr(str, '.');
{
@@ -5114,20 +5134,22 @@ val make_byte_input_stream(val obj)
val tmpfile_wrap(void)
{
+ val self = lit("tmpfile");
struct stdio_mode m_blank = stdio_mode_init_blank;
- struct stdio_mode m = do_parse_mode(lit("w+b"), m_blank);
+ struct stdio_mode m = do_parse_mode(lit("w+b"), m_blank, self);
FILE *tf = tmpfile();
if (tf != 0)
- return set_mode_props(m, make_stdio_stream(tf, lit("tmpfile")));
- uw_throwf(file_error_s, lit("tmpnam failed: ~d/~s"),
- num(errno), errno_to_str(errno), nao);
+ return set_mode_props(m, make_stdio_stream(tf, self));
+ uw_throwf(file_error_s, lit("~a failed: ~d/~s"),
+ self, num(errno), errno_to_str(errno), nao);
}
#if HAVE_MKDTEMP
val mkdtemp_wrap(val prefix)
{
- char *tmpl = utf8_dup_to(c_str(scat2(prefix, lit("XXXXXX"))));
+ val self = lit("mkdtemp");
+ char *tmpl = utf8_dup_to(c_str(scat2(prefix, lit("XXXXXX")), self));
if (mkdtemp(tmpl) != 0) {
val ret = string_utf8(tmpl);
@@ -5150,7 +5172,7 @@ val mkstemp_wrap(val prefix, val suffix)
val suff = default_arg(suffix, null_string);
val templ = scat3(prefix, lit("XXXXXX"), suff);
cnum slen = c_num(length(suff), self);
- char *tmpl = utf8_dup_to(c_str(templ));
+ char *tmpl = utf8_dup_to(c_str(templ, self));
val name;
int fd;
diff --git a/stream.h b/stream.h
index 30971c8c..0030465c 100644
--- a/stream.h
+++ b/stream.h
@@ -157,9 +157,11 @@ void fill_stream_ops(struct strm_ops *ops);
void stream_print_op(val stream, val out, val pretty, struct strm_ctx *);
void stream_mark_op(val stream);
void stream_destroy_op(val stream);
-struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl);
-val normalize_mode(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl);
-val normalize_mode_no_bin(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl);
+struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl, val self);
+val normalize_mode(struct stdio_mode *m, val mode_str,
+ struct stdio_mode m_dfl, val self);
+val normalize_mode_no_bin(struct stdio_mode *m, val mode_str,
+ struct stdio_mode m_dfl, val self);
val set_mode_props(const struct stdio_mode m, val stream);
val generic_get_line(val stream);
val errno_to_string(val err);
diff --git a/sysif.c b/sysif.c
index f9717ede..f0479f1a 100644
--- a/sysif.c
+++ b/sysif.c
@@ -374,7 +374,7 @@ static val mkdir_wrap(val path, val mode)
{
val self = lit("mkdir");
cnum cmode = c_num(default_arg(mode, num_fast(0777)), self);
- char *u8path = utf8_dup_to(c_str(path));
+ char *u8path = utf8_dup_to(c_str(path, self));
int err = mkdir(u8path, cmode);
free(u8path);
@@ -389,7 +389,7 @@ static val mkdir_wrap(val path, val mode)
#elif HAVE_WINDOWS_H
static val mkdir_wrap(val path, val mode)
{
- int err = _wmkdir(c_str(path));
+ int err = _wmkdir(c_str(path, self));
(void) mode;
if (err < 0) {
@@ -422,10 +422,10 @@ static int get_fd(val stream, val self)
#endif
#if HAVE_SYS_STAT
-static int do_stat(val wpath, struct stat *buf)
+static int do_stat(val wpath, struct stat *buf, val self)
{
if (stringp(wpath)) {
- char *path = utf8_dup_to(c_str(wpath));
+ char *path = utf8_dup_to(c_str(wpath, self));
int res = stat(path, buf);
free(path);
return res;
@@ -437,9 +437,9 @@ static int do_stat(val wpath, struct stat *buf)
}
#ifdef S_IFLNK
-static int do_lstat(val wpath, struct stat *buf)
+static int do_lstat(val wpath, struct stat *buf, val self)
{
- char *path = utf8_dup_to(c_str(wpath));
+ char *path = utf8_dup_to(c_str(wpath, self));
int res = lstat(path, buf);
free(path);
return res;
@@ -450,7 +450,7 @@ static int do_lstat(val wpath, struct stat *buf)
#endif
#if HAVE_MKDIR || HAVE_WINDOWS_H
-static val mkdir_nothrow_exists(val path, val mode)
+static val mkdir_nothrow_exists(val path, val mode, val self)
{
val ret = t;
@@ -469,7 +469,7 @@ static val mkdir_nothrow_exists(val path, val mode)
#if HAVE_SYS_STAT
{
struct stat st;
- int err = do_stat(path, &st);
+ int err = do_stat(path, &st, self);
if (err == 0 && !S_ISDIR(st.st_mode))
ret = num(EEXIST);
}
@@ -503,7 +503,7 @@ static val ensure_dir(val path, val mode)
for (;;) {
if (length(partial_path) != zero)
- ret = mkdir_nothrow_exists(partial_path, mode);
+ ret = mkdir_nothrow_exists(partial_path, mode, self);
if (!split_path)
break;
@@ -525,7 +525,8 @@ static val ensure_dir(val path, val mode)
#if HAVE_UNISTD_H
static val chdir_wrap(val path)
{
- char *u8path = utf8_dup_to(c_str(path));
+ val self = lit("chdir");
+ char *u8path = utf8_dup_to(c_str(path, self));
int err = chdir(u8path);
free(u8path);
@@ -566,7 +567,8 @@ val getcwd_wrap(void)
static val rmdir_wrap(val path)
{
- char *u8path = utf8_dup_to(c_str(path));
+ val self = lit("rmdir");
+ char *u8path = utf8_dup_to(c_str(path, self));
int err = rmdir(u8path);
free(u8path);
@@ -609,7 +611,7 @@ static val mknod_wrap(val path, val mode, val dev)
val self = lit("mknod");
cnum cmode = c_num(mode, self);
cnum cdev = c_num(default_arg(dev, zero), self);
- char *u8path = utf8_dup_to(c_str(path));
+ char *u8path = utf8_dup_to(c_str(path, self));
int err = mknod(u8path, cmode, cdev);
free(u8path);
@@ -637,7 +639,7 @@ static val mkfifo_wrap(val path, val mode)
{
val self = lit("mkfifo");
cnum cmode = c_num(mode, self);
- char *u8path = utf8_dup_to(c_str(path));
+ char *u8path = utf8_dup_to(c_str(path, self));
int err = mkfifo(u8path, cmode);
free(u8path);
@@ -667,7 +669,7 @@ static val chmod_wrap(val target, val mode)
val self = lit("chmod");
cnum cmode = 0;
int err = 0;
- char *u8path = if3(stringp(target), utf8_dup_to(c_str(target)), 0);
+ char *u8path = if3(stringp(target), utf8_dup_to(c_str(target, self)), 0);
int fd = if3(u8path, -1, get_fd(target, self));
if (integerp(mode)) {
@@ -685,7 +687,7 @@ static val chmod_wrap(val target, val mode)
err = fstat(fd, &st);
if (err == 0) {
- const wchar_t *cm = c_str(mode);
+ const wchar_t *cm = c_str(mode, self);
wchar_t ch;
mode_t srcm = 0, oldm = st.st_mode;
@@ -843,7 +845,7 @@ static val do_chown(val target, val uid, val gid, val link_p, val self)
int err;
if (stringp(target)) {
- char *u8path = utf8_dup_to(c_str(target));
+ char *u8path = utf8_dup_to(c_str(target, self));
err = if3(link_p, lchown, chown)(u8path, cuid, cgid);
free(u8path);
} else {
@@ -877,8 +879,9 @@ static val lchown_wrap(val target, val uid, val gid)
static val symlink_wrap(val target, val to)
{
- const wchar_t *wtarget = c_str(target);
- const wchar_t *wto = c_str(to);
+ val self = lit("symlink");
+ const wchar_t *wtarget = c_str(target, self);
+ const wchar_t *wto = c_str(to, self);
char *u8target = utf8_dup_to(wtarget);
char *u8to = utf8_dup_to(wto);
int err = symlink(u8target, u8to);
@@ -896,8 +899,9 @@ static val symlink_wrap(val target, val to)
static val link_wrap(val target, val to)
{
- const wchar_t *wtarget = c_str(target);
- const wchar_t *wto = c_str(to);
+ val self = lit("link");
+ const wchar_t *wtarget = c_str(target, self);
+ const wchar_t *wto = c_str(to, self);
char *u8target = utf8_dup_to(wtarget);
char *u8to = utf8_dup_to(wto);
int err = link(u8target, u8to);
@@ -915,7 +919,8 @@ static val link_wrap(val target, val to)
static val readlink_wrap(val path)
{
- char *u8path = utf8_dup_to(c_str(path));
+ val self = lit("readlink");
+ char *u8path = utf8_dup_to(c_str(path, self));
ssize_t guess = 256;
for (;;) {
@@ -1129,7 +1134,7 @@ val exec_wrap(val file, val args_opt)
for (i = 0, iter = cons(file, args); iter; i++, iter = cdr(iter)) {
val arg = car(iter);
- argv[i] = utf8_dup_to(c_str(arg));
+ argv[i] = utf8_dup_to(c_str(arg, self));
}
argv[i] = 0;
@@ -1230,12 +1235,12 @@ val stat_to_struct(struct stat st, val path, val stat_opt)
}
#endif
-static val stat_impl(val obj, int (*statfn)(val, struct stat *),
+static val stat_impl(val obj, int (*statfn)(val, struct stat *, val),
val name, val path, val stat_opt)
{
#if HAVE_SYS_STAT
struct stat st;
- int res = statfn(obj, &st);
+ int res = statfn(obj, &st, name);
if (res == -1) {
int eno = errno;
@@ -1276,7 +1281,7 @@ static val do_utimes(val target, val atime, val atimens,
int res = -1;
if (stringp(target)) {
- char *u8path = utf8_dup_to(c_str(target));
+ char *u8path = utf8_dup_to(c_str(target, self));
#if HAVE_FUTIMENS
int flags = if3(symlink_nofollow, AT_SYMLINK_NOFOLLOW, 0);
struct timespec times[2];
@@ -1394,7 +1399,8 @@ static val pipe_wrap(void)
val getenv_wrap(val name)
{
- char *nameu8 = utf8_dup_to(c_str(name));
+ val self = lit("getenv");
+ char *nameu8 = utf8_dup_to(c_str(name, self));
char *lookup = getenv(nameu8);
val result = lookup ? string_utf8(lookup) : nil;
free(nameu8);
@@ -1408,8 +1414,8 @@ val getenv_wrap(val name)
static val setenv_wrap(val name, val value, val overwrite)
{
val self = lit("setenv");
- const wchar_t *wname = c_str(name);
- const wchar_t *wvalu = value ? c_str(value) : 0;
+ const wchar_t *wname = c_str(name, self);
+ const wchar_t *wvalu = value ? c_str(value, self) : 0;
int ovw = default_arg_strict(overwrite, t) != nil;
char *nameu8 = utf8_dup_to(wname);
char *valu8 = wvalu ? utf8_dup_to(wvalu) : 0;
@@ -1440,7 +1446,8 @@ static val setenv_wrap(val name, val value, val overwrite)
static val unsetenv_wrap(val name)
{
- char *nameu8 = utf8_dup_to(c_str(name));
+ val self = lit("unsetenv");
+ char *nameu8 = utf8_dup_to(c_str(name, self));
unsetenv(nameu8);
free(nameu8);
env_list = nil;
@@ -1867,9 +1874,10 @@ static val getpwuid_wrap(val uid)
static val getpwnam_wrap(val wname)
{
+ val self = lit("getpwnam");
char buf[1024];
struct passwd pw, *p;
- char *name = utf8_dup_to(c_str(wname));
+ char *name = utf8_dup_to(c_str(wname, self));
int res = getpwnam_r(name, &pw, buf, sizeof buf, &p);
free(name);
@@ -1893,7 +1901,8 @@ static val getpwuid_wrap(val uid)
static val getpwnam_wrap(val wname)
{
- char *name = utf8_dup_to(c_str(wname));
+ val self = lit("getpwnam");
+ char *name = utf8_dup_to(c_str(wname, self));
struct passwd *p = getpwnam(name);
free(name);
return (p != 0) ? make_pwstruct(p) : nil;
@@ -1962,9 +1971,10 @@ static val getgrgid_wrap(val uid)
static val getgrnam_wrap(val wname)
{
+ val self = lit("getgrnam");
char buf[1024];
struct group gr, *g;
- char *name = utf8_dup_to(c_str(wname));
+ char *name = utf8_dup_to(c_str(wname, self));
int res = getgrnam_r(name, &gr, buf, sizeof buf, &g);
free(name);
@@ -1981,7 +1991,8 @@ static val getgrgid_wrap(val uid)
static val getgrnam_wrap(val wname)
{
- char *name = utf8_dup_to(c_str(wname));
+ val self = lit("getgrnam");
+ char *name = utf8_dup_to(c_str(wname, self));
struct group *g = getgrnam(name);
free(name);
return (g != 0) ? make_grstruct(g) : nil;
@@ -2049,8 +2060,9 @@ badsalt:
static val crypt_wrap(val wkey, val wsalt)
{
- const wchar_t *cwkey = c_str(wkey);
- const wchar_t *cwsalt = validate_salt(c_str(wsalt));
+ val self = lit("crypt");
+ const wchar_t *cwkey = c_str(wkey, self);
+ const wchar_t *cwsalt = validate_salt(c_str(wsalt, self));
if (cwsalt != 0) {
char *key = utf8_dup_to(cwkey);
@@ -2125,8 +2137,8 @@ int stdio_fseek(FILE *f, val off, int whence)
static val fnmatch_wrap(val pattern, val string, val flags)
{
val self = lit("fnmatch");
- const wchar_t *pattern_ws = c_str(pattern);
- const wchar_t *string_ws = c_str(string);
+ const wchar_t *pattern_ws = c_str(pattern, self);
+ const wchar_t *string_ws = c_str(string, self);
cnum c_flags = c_num(default_arg(flags, zero), self);
char *pattern_u8 = utf8_dup_to(pattern_ws);
char *string_u8 = utf8_dup_to(string_ws);
@@ -2187,7 +2199,7 @@ static val dlopen_wrap(val name, val flags)
{
val self = lit("dlopen");
const wchar_t *name_ws = if3(null_or_missing_p(name),
- 0, c_str(name));
+ 0, c_str(name, self));
char *name_u8 = if3(name_ws != 0, utf8_dup_to(name_ws), 0);
cnum f = if3(missingp(flags), RTLD_LAZY, c_num(flags, self));
mem_t *ptr = coerce(mem_t *, (dlerror(), dlopen(name_u8, f)));
@@ -2220,7 +2232,7 @@ static val dlclose_wrap(val cptr)
static val dlsym_wrap(val dlptr, val name)
{
val self = lit("dlsym");
- const wchar_t *name_ws = c_str(name);
+ const wchar_t *name_ws = c_str(name, self);
char *name_u8 = utf8_dup_to(name_ws);
mem_t *dl = cptr_handle(dlptr, dlhandle_s, self);
mem_t *sym = coerce(mem_t *, dlsym(dl, name_u8));
@@ -2256,8 +2268,8 @@ static val dlvsym_wrap(val dlptr, val name, val ver)
if (null_or_missing_p(ver)) {
return dlsym_wrap(dlptr, name);
} else {
- const wchar_t *name_ws = c_str(name);
- const wchar_t *ver_ws = c_str(ver);
+ const wchar_t *name_ws = c_str(name, self);
+ const wchar_t *ver_ws = c_str(ver, self);
char *name_u8 = utf8_dup_to(name_ws);
char *ver_u8 = utf8_dup_to(ver_ws);
mem_t *dl = cptr_handle(dlptr, dlhandle_s, self);
@@ -2283,7 +2295,8 @@ static val dlvsym_checked(val dlptr, val name, val ver)
#if HAVE_REALPATH
static val realpath_wrap(val path)
{
- const wchar_t *path_ws = c_str(path);
+ val self = lit("realpath");
+ const wchar_t *path_ws = c_str(path, self);
char *path_u8 = utf8_dup_to(path_ws);
char *rp_u8 = realpath(path_u8, 0);
val rp = if2(rp_u8, string_utf8(rp_u8));
@@ -2341,7 +2354,8 @@ static struct cobj_ops opendir_ops = cobj_ops_init(eq,
cobj_eq_hash_op);
static val opendir_wrap(val path, val prefix_p)
{
- DIR *dir = w_opendir(c_str(path));
+ val self = lit("opendir");
+ DIR *dir = w_opendir(c_str(path, self));
if (dir == 0) {
uw_throwf(system_error_s, lit("opendir failed for ~a: ~d/~s"),
diff --git a/syslog.c b/syslog.c
index efe20565..2ed83e9f 100644
--- a/syslog.c
+++ b/syslog.c
@@ -95,7 +95,7 @@ val openlog_wrap(val wident, val optmask, val facility)
cnum cfacility = c_num(default_arg(facility, num_fast(LOG_USER)), self);
char *old_ident = ident;
- ident = utf8_dup_to(c_str(wident));
+ ident = utf8_dup_to(c_str(wident, self));
openlog(ident, coptmask, cfacility);
@@ -115,7 +115,7 @@ val syslog_wrapv(val prio, val fmt, struct args *args)
val self = lit("syslog");
val text = formatv(nil, fmt, args);
cnum cprio = c_num(prio, self);
- char *u8text = utf8_dup_to(c_str(text));
+ char *u8text = utf8_dup_to(c_str(text, self));
syslog(cprio, "%s", u8text);
return nil;
}
diff --git a/time.c b/time.c
index 2c2285ef..e093a0ff 100644
--- a/time.c
+++ b/time.c
@@ -125,7 +125,7 @@ val time_string_local(val time, val format)
{
val self = lit("time-string-local");
time_t secs = c_time(time, self);
- const wchar_t *wcfmt = c_str(format);
+ const wchar_t *wcfmt = c_str(format, self);
char *u8fmt = utf8_dup_to(wcfmt);
val timestr = string_time(localtime_r, u8fmt, secs);
free(u8fmt);
@@ -136,7 +136,7 @@ val time_string_utc(val time, val format)
{
val self = lit("time-string-utc");
time_t secs = c_time(time, self);
- const wchar_t *wcfmt = c_str(format);
+ const wchar_t *wcfmt = c_str(format, self);
char *u8fmt = utf8_dup_to(wcfmt);
val timestr = string_time(gmtime_r, u8fmt, secs);
free(u8fmt);
@@ -317,8 +317,9 @@ static struct tm epoch_tm(void)
static int strptime_wrap(val string, val format, struct tm *ptms)
{
- const wchar_t *w_str = c_str(string);
- const wchar_t *w_fmt = c_str(format);
+ val self = lit("strptime");
+ const wchar_t *w_str = c_str(string, self);
+ const wchar_t *w_fmt = c_str(format, self);
char *str = utf8_dup_to(w_str);
char *fmt = utf8_dup_to(w_fmt);
char *ptr = strptime(str, fmt, ptms);
@@ -407,7 +408,7 @@ static val time_string_meth(val time_struct, val format)
struct tm tms = all_zero_init;
time_struct_to_tm(&tms, time_struct, t, self);
char buffer[512] = "";
- char *fmt = utf8_dup_to(c_str(format));
+ char *fmt = utf8_dup_to(c_str(format, self));
if (strftime(buffer, sizeof buffer, fmt, &tms) == 0)
buffer[0] = 0;
@@ -427,8 +428,8 @@ static val time_parse_meth(val time_struct, val format, val string)
val ret = nil;
{
- const wchar_t *w_str = c_str(string);
- const wchar_t *w_fmt = c_str(format);
+ const wchar_t *w_str = c_str(string, self);
+ const wchar_t *w_fmt = c_str(format, self);
char *str = utf8_dup_to(w_str);
char *fmt = utf8_dup_to(w_fmt);
char *ptr = strptime(str, fmt, &tms);
diff --git a/txr.c b/txr.c
index 44a07843..32f92716 100644
--- a/txr.c
+++ b/txr.c
@@ -583,7 +583,7 @@ int txr_main(int argc, char **argv)
if (car(arg) != chr('-')) {
if (!parse_stream) {
spec_file_str = arg;
- open_txr_file(arg, &txr_lisp_p, &spec_file_str, &parse_stream);
+ open_txr_file(arg, &txr_lisp_p, &spec_file_str, &parse_stream, self);
simulate_setuid_setgid(parse_stream);
dyn_env = make_env(nil, nil, dyn_env);
env_vbind(dyn_env, load_path_s, spec_file_str);
@@ -886,8 +886,9 @@ int txr_main(int argc, char **argv)
prog_string, arg, spec_file_str, nao);
return EXIT_FAILURE;
}
- if (wcscmp(c_str(spec_file), L"-") != 0) {
- open_txr_file(spec_file, &txr_lisp_p, &spec_file_str, &parse_stream);
+ if (wcscmp(c_str(spec_file, self), L"-") != 0) {
+ open_txr_file(spec_file, &txr_lisp_p, &spec_file_str,
+ &parse_stream, self);
simulate_setuid_setgid(parse_stream);
dyn_env = make_env(nil, nil, dyn_env);
env_vbind(dyn_env, load_path_s, spec_file_str);
diff --git a/y.tab.c.shipped b/y.tab.c.shipped
index f1e85135..9f456895 100644
--- a/y.tab.c.shipped
+++ b/y.tab.c.shipped
@@ -6542,7 +6542,7 @@ yyreduce:
#line 1375 "parser.y"
{ wchar_t ch;
val str = string_own((yyvsp[(2) - (2)].lexeme));
- const wchar_t *cstr = c_str(str);
+ const wchar_t *cstr = c_str(str, nil);
if (cstr[1] == 0)
{ ch = cstr[0]; }