From ad4e4e79ac6b9fcb182f3cd834120ec79512ac9a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 23 Jun 2021 06:24:54 -0700 Subject: 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. --- socket.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'socket.c') 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; -- cgit v1.2.3