From 36284627919a6968174b5f17369349187a2b4b1b Mon Sep 17 00:00:00 2001 From: Dirk Herrmann Date: Tue, 26 Jun 2001 10:59:34 +0000 Subject: [PATCH] * Deprecated scm_makfromstr and added scm_mem2string as a replacement. * Eliminated some potential gc problems. * Eliminated some signedness problems. * Minor changes. --- NEWS | 4 ++++ RELEASE | 2 +- doc/ChangeLog | 5 +++++ doc/oldfmt.c | 7 +++---- libguile/ChangeLog | 50 +++++++++++++++++++++++++++++++++++++++++++++ libguile/filesys.c | 35 +++++++++++++++---------------- libguile/gh_data.c | 2 +- libguile/load.c | 7 +++---- libguile/net_db.c | 19 ++++++++--------- libguile/numbers.c | 4 ++-- libguile/objects.c | 2 +- libguile/ports.c | 19 +++++++---------- libguile/read.c | 23 +++++++++------------ libguile/simpos.c | 4 ++-- libguile/socket.c | 5 ++--- libguile/stime.c | 4 ++-- libguile/strings.c | 26 ++++++++++++++++++----- libguile/strings.h | 19 +++++++++-------- libguile/strop.c | 15 +++++++++----- libguile/strports.c | 6 +++++- libguile/symbols.c | 5 ++++- libguile/validate.h | 8 +++++--- libguile/vports.c | 4 ++-- srfi/ChangeLog | 10 +++++++++ srfi/srfi-13.c | 31 +++++++++++++--------------- 25 files changed, 200 insertions(+), 116 deletions(-) diff --git a/NEWS b/NEWS index 56f595a40..5e26e4734 100644 --- a/NEWS +++ b/NEWS @@ -681,6 +681,10 @@ The old names are still available with status `deprecated'. scm_tc_dblc - replaced by scm_tc16_complex. scm_list_star - replaced by scm_cons_star. +** Deprecated: scm_makfromstr + +Use scm_mem2string instead. + ** Deprecated: scm_make_shared_substring Explicit shared substrings will disappear from Guile. diff --git a/RELEASE b/RELEASE index a26eec933..15fd89751 100644 --- a/RELEASE +++ b/RELEASE @@ -68,7 +68,7 @@ After signal handling and threading have been fixed: load.c: scm_read_and_eval_x smob.c: scm_make_smob_type_mfpe, scm_set_smob_mfpe gc.c: scm_remember - string.c: scm_makstr + string.c: scm_makstr, scm_makfromstr - remove deprecated procedures: boot-9.scm: eval-in-module, id, -1+, return-it, string-character-length, flags diff --git a/doc/ChangeLog b/doc/ChangeLog index 8125f7351..5e0f0848a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2001-06-26 Dirk Herrmann + + * oldfmt.c (scm_oldfmt): Use scm_mem2string instead of + scm_makfromstr. + 2001-06-25 Neil Jerram * gh.texi (GH deprecation): Remove paragraph about portability. diff --git a/doc/oldfmt.c b/doc/oldfmt.c index bfd00fe1d..19fbffcc5 100644 --- a/doc/oldfmt.c +++ b/doc/oldfmt.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2000,2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -211,9 +211,8 @@ scm_oldfmt (SCM s) int n; SCM_ASSERT (SCM_NIMP (s) && SCM_STRINGP (s), s, 1, s_oldfmt); n = SCM_LENGTH (s); - return scm_return_first (scm_makfromstr (scm_c_oldfmt (SCM_ROCHARS (s), n), - n, - 0), + return scm_return_first (scm_mem2string (scm_c_oldfmt (SCM_ROCHARS (s), n), + n), s); #endif } diff --git a/libguile/ChangeLog b/libguile/ChangeLog index d5233dc80..ddffe6faf 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,53 @@ +2001-06-26 Dirk Herrmann + + * filesys.c (scm_close), ports.c (scm_close_port, + scm_port_closed_p), strop.c (scm_string_null_p): Use SCM_BOOL + instead of SCM_NEGATE_BOOL. + + * filesys.c (scm_stat): Clean up type dispatch. + + * filesys.c (scm_stat), ports.c (scm_input_port_p, + scm_output_port_p): Get rid of redundant IM type check. + + * filesys.c (scm_readdir, scm_getcwd, scm_readlink), gh_data.c + (gh_str2scm), load.c (scm_primitive_load, scm_internal_parse_path, + scm_search_path), net_db.c (scm_gethost, scm_getnet, scm_getproto, + scm_return_entry), numbers.c (scm_number_to_string), objects.c + (scm_make_subclass_object), ports.c (scm_port_mode), read.c + (scm_lreadr), simpos.c (scm_getenv), socket.c (scm_inet_ntoa, + scm_addr_vector), stime.c (scm_strftime), strings.c + (scm_makfromstrs, scm_makfrom0str, scm_substring), strings.h + (SCM_STRING_COERCE_0TERMINATION_X), strop.c (string_copy, + scm_string_split), strports.c (scm_strport_to_string), symbols.c + (scm_symbol_to_string), vports.c (sf_write): Use scm_mem2string + instead of scm_makfromstr. + + * net_db.c (scm_sethost, scm_setnet, scm_setproto, scm_setserv), + ports.c (scm_close_all_ports_except), read.c (scm_lreadr, + scm_read_hash_extend), stime.c (scm_strftime), strings.c + (scm_string_append, scm_string), strings.h (SCM_STRINGP, + SCM_STRING_COERCE_0TERMINATION_X, SCM_RWSTRINGP), strop.c + (string_capitalize_x): Prefer explicit type check over SCM_N?IMP, + !SCM_ over SCM_N. + + * strings.[ch] (scm_makfromstr): Deprecated. + + (scm_mem2string): New function, replaces scm_makfromstr. + + * strings.c (scm_substring), strop.c (string_copy, + scm_string_split), strports.c (scm_strport_to_string), symbols.c + (scm_symbol_to_string): Fix gc problem. + + * strings.h (STRINGSH, SCM_STRINGS_H): Rename H to + SCM__H. + + * validate.h (SCM_VALIDATE_SUBSTRING_SPEC_COPY): Eliminate + warning about comparing signed and unsigned values. This fix is + not optimal, since it won't work reliably if sizeof (c_start) > + sizeof (size_t) or sizeof (c_end) > sizeof (size_t). A better + solution is to define this macro as an inline function, thus + allowing to specifiy the types of c_start and c_end. + 2001-06-25 Dirk Herrmann * debug.h (SCM_DEBUGOBJ_FRAME): Deliver result as a diff --git a/libguile/filesys.c b/libguile/filesys.c index 913343234..1d4afd341 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -333,7 +333,7 @@ SCM_DEFINE (scm_close, "close", 1, 0, 0, not an error. */ if (rv < 0 && errno != EBADF) SCM_SYSERROR; - return SCM_NEGATE_BOOL(rv < 0); + return SCM_BOOL (rv >= 0); } #undef FUNC_NAME @@ -529,23 +529,22 @@ SCM_DEFINE (scm_stat, "stat", 1, 0, 0, struct stat stat_temp; if (SCM_INUMP (object)) - SCM_SYSCALL (rv = fstat (SCM_INUM (object), &stat_temp)); + { + SCM_SYSCALL (rv = fstat (SCM_INUM (object), &stat_temp)); + } + else if (SCM_STRINGP (object)) + { + SCM_STRING_COERCE_0TERMINATION_X (object); + SCM_SYSCALL (rv = stat (SCM_STRING_CHARS (object), &stat_temp)); + } else { - SCM_VALIDATE_NIM (1,object); - if (SCM_STRINGP (object)) - { - SCM_STRING_COERCE_0TERMINATION_X (object); - SCM_SYSCALL (rv = stat (SCM_STRING_CHARS (object), &stat_temp)); - } - else - { - object = SCM_COERCE_OUTPORT (object); - SCM_VALIDATE_OPFPORT(1,object); - fdes = SCM_FPORT_FDES (object); - SCM_SYSCALL (rv = fstat (fdes, &stat_temp)); - } + object = SCM_COERCE_OUTPORT (object); + SCM_VALIDATE_OPFPORT (1, object); + fdes = SCM_FPORT_FDES (object); + SCM_SYSCALL (rv = fstat (fdes, &stat_temp)); } + if (rv == -1) { int en = errno; @@ -735,7 +734,7 @@ SCM_DEFINE (scm_readdir, "readdir", 1, 0, 0, if (errno != 0) SCM_SYSERROR; - return (rdent ? scm_makfromstr (rdent->d_name, NAMLEN (rdent), 0) + return (rdent ? scm_mem2string (rdent->d_name, NAMLEN (rdent)) : SCM_EOF_VAL); } #undef FUNC_NAME @@ -845,7 +844,7 @@ SCM_DEFINE (scm_getcwd, "getcwd", 0, 0, 0, } if (rv == 0) SCM_SYSERROR; - result = scm_makfromstr (wd, strlen (wd), 0); + result = scm_mem2string (wd, strlen (wd)); scm_must_free (wd); return result; } @@ -1272,7 +1271,7 @@ SCM_DEFINE (scm_readlink, "readlink", 1, 0, 0, } if (rv == -1) SCM_SYSERROR; - result = scm_makfromstr (buf, rv, 0); + result = scm_mem2string (buf, rv); scm_must_free (buf); return result; } diff --git a/libguile/gh_data.c b/libguile/gh_data.c index 3843a0741..f55b87ed9 100644 --- a/libguile/gh_data.c +++ b/libguile/gh_data.c @@ -81,7 +81,7 @@ gh_char2scm (char c) SCM gh_str2scm (const char *s, size_t len) { - return scm_makfromstr (s, len, 0); + return scm_mem2string (s, len); } SCM gh_str02scm (const char *s) diff --git a/libguile/load.c b/libguile/load.c index 73eb2b9ab..3f6fff049 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -123,8 +123,7 @@ SCM_DEFINE (scm_primitive_load, "primitive-load", 1, 0, 0, { /* scope */ SCM port, save_port; - port = scm_open_file (filename, - scm_makfromstr ("r", (size_t) sizeof (char), 0)); + port = scm_open_file (filename, scm_mem2string ("r", sizeof (char))); save_port = port; scm_internal_dynamic_wind (swap_port, load, @@ -205,7 +204,7 @@ scm_internal_parse_path (char *path, SCM tail) /* Scan back to the beginning of the current element. */ do scan--; while (scan >= path && *scan != ':'); - tail = scm_cons (scm_makfromstr (scan + 1, elt_end - (scan + 1), 0), + tail = scm_cons (scm_mem2string (scan + 1, elt_end - (scan + 1)), tail); elt_end = scan; } while (scan >= path); @@ -389,7 +388,7 @@ SCM_DEFINE (scm_search_path, "search-path", 2, 1, 0, if (stat (buf, &mode) == 0 && ! (mode.st_mode & S_IFDIR)) { - result = scm_makfromstr (buf, len + ext_len, 0); + result = scm_mem2string (buf, len + ext_len); goto end; } } diff --git a/libguile/net_db.c b/libguile/net_db.c index 4f5e64ed8..66e327a85 100644 --- a/libguile/net_db.c +++ b/libguile/net_db.c @@ -184,8 +184,7 @@ SCM_DEFINE (scm_gethost, "gethost", 0, 1, 0, if (!entry) scm_resolv_error (FUNC_NAME, host); - ve[0] = scm_makfromstr (entry->h_name, - (size_t) strlen (entry->h_name), 0); + ve[0] = scm_mem2string (entry->h_name, strlen (entry->h_name)); ve[1] = scm_makfromstrs (-1, entry->h_aliases); ve[2] = SCM_MAKINUM (entry->h_addrtype + 0L); ve[3] = SCM_MAKINUM (entry->h_length + 0L); @@ -257,7 +256,7 @@ SCM_DEFINE (scm_getnet, "getnet", 0, 1, 0, } if (!entry) SCM_SYSERROR_MSG ("no such network ~A", SCM_LIST1 (net), errno); - ve[0] = scm_makfromstr (entry->n_name, (size_t) strlen (entry->n_name), 0); + ve[0] = scm_mem2string (entry->n_name, strlen (entry->n_name)); ve[1] = scm_makfromstrs (-1, entry->n_aliases); ve[2] = SCM_MAKINUM (entry->n_addrtype + 0L); ve[3] = scm_ulong2num (entry->n_net + 0L); @@ -307,7 +306,7 @@ SCM_DEFINE (scm_getproto, "getproto", 0, 1, 0, } if (!entry) SCM_SYSERROR_MSG ("no such protocol ~A", SCM_LIST1 (protocol), errno); - ve[0] = scm_makfromstr (entry->p_name, (size_t) strlen (entry->p_name), 0); + ve[0] = scm_mem2string (entry->p_name, strlen (entry->p_name)); ve[1] = scm_makfromstrs (-1, entry->p_aliases); ve[2] = SCM_MAKINUM (entry->p_proto + 0L); return ans; @@ -323,10 +322,10 @@ scm_return_entry (struct servent *entry) ans = scm_c_make_vector (4, SCM_UNSPECIFIED); ve = SCM_VELTS (ans); - ve[0] = scm_makfromstr (entry->s_name, (size_t) strlen (entry->s_name), 0); + ve[0] = scm_mem2string (entry->s_name, strlen (entry->s_name)); ve[1] = scm_makfromstrs (-1, entry->s_aliases); ve[2] = SCM_MAKINUM (ntohs (entry->s_port) + 0L); - ve[3] = scm_makfromstr (entry->s_proto, (size_t) strlen (entry->s_proto), 0); + ve[3] = scm_mem2string (entry->s_proto, strlen (entry->s_proto)); return ans; } @@ -386,7 +385,7 @@ SCM_DEFINE (scm_sethost, "sethost", 0, 1, 0, if (SCM_UNBNDP (stayopen)) endhostent (); else - sethostent (SCM_NFALSEP (stayopen)); + sethostent (!SCM_FALSEP (stayopen)); return SCM_UNSPECIFIED; } #undef FUNC_NAME @@ -402,7 +401,7 @@ SCM_DEFINE (scm_setnet, "setnet", 0, 1, 0, if (SCM_UNBNDP (stayopen)) endnetent (); else - setnetent (SCM_NFALSEP (stayopen)); + setnetent (!SCM_FALSEP (stayopen)); return SCM_UNSPECIFIED; } #undef FUNC_NAME @@ -418,7 +417,7 @@ SCM_DEFINE (scm_setproto, "setproto", 0, 1, 0, if (SCM_UNBNDP (stayopen)) endprotoent (); else - setprotoent (SCM_NFALSEP (stayopen)); + setprotoent (!SCM_FALSEP (stayopen)); return SCM_UNSPECIFIED; } #undef FUNC_NAME @@ -434,7 +433,7 @@ SCM_DEFINE (scm_setserv, "setserv", 0, 1, 0, if (SCM_UNBNDP (stayopen)) endservent (); else - setservent (SCM_NFALSEP (stayopen)); + setservent (!SCM_FALSEP (stayopen)); return SCM_UNSPECIFIED; } #undef FUNC_NAME diff --git a/libguile/numbers.c b/libguile/numbers.c index b1e139d01..2c7ebf447 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -2188,12 +2188,12 @@ SCM_DEFINE (scm_number_to_string, "number->string", 1, 1, 0, if (SCM_INUMP (n)) { char num_buf [SCM_INTBUFLEN]; size_t length = scm_iint2str (SCM_INUM (n), base, num_buf); - return scm_makfromstr (num_buf, length, 0); + return scm_mem2string (num_buf, length); } else if (SCM_BIGP (n)) { return big2str (n, (unsigned int) base); } else if (SCM_INEXACTP (n)) { char num_buf [FLOBUFLEN]; - return scm_makfromstr (num_buf, iflo2str (n, num_buf), 0); + return scm_mem2string (num_buf, iflo2str (n, num_buf)); } else { SCM_WRONG_TYPE_ARG (1, n); } diff --git a/libguile/objects.c b/libguile/objects.c index 66401e194..07a46e752 100644 --- a/libguile/objects.c +++ b/libguile/objects.c @@ -491,7 +491,7 @@ SCM_DEFINE (scm_make_subclass_object, "make-subclass-object", 2, 0, 0, SCM_VALIDATE_STRING (2,layout); pl = SCM_PACK (SCM_STRUCT_DATA (class) [scm_vtable_index_layout]); /* Convert symbol->string */ - pl = scm_makfromstr (SCM_SYMBOL_CHARS (pl), SCM_SYMBOL_LENGTH (pl), 0); + pl = scm_mem2string (SCM_SYMBOL_CHARS (pl), SCM_SYMBOL_LENGTH (pl)); return scm_i_make_class_object (SCM_STRUCT_VTABLE (class), scm_string_append (SCM_LIST2 (pl, layout)), SCM_CLASS_FLAGS (class)); diff --git a/libguile/ports.c b/libguile/ports.c index 56c0b37fc..49902d7e2 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -627,7 +627,7 @@ SCM_DEFINE (scm_port_mode, "port-mode", 1, 0, 0, strcpy (modes, "w"); if (SCM_CELL_WORD_0 (port) & SCM_BUF0) strcat (modes, "0"); - return scm_makfromstr (modes, strlen (modes), 0); + return scm_mem2string (modes, strlen (modes)); } #undef FUNC_NAME @@ -664,7 +664,7 @@ SCM_DEFINE (scm_close_port, "close-port", 1, 0, 0, rv = 0; scm_remove_from_port_table (port); SCM_CLR_PORT_OPEN_FLAG (port); - return SCM_NEGATE_BOOL (rv < 0); + return SCM_BOOL (rv >= 0); } #undef FUNC_NAME @@ -760,7 +760,7 @@ SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1, int found = 0; SCM ports_ptr = ports; - while (SCM_NNULLP (ports_ptr)) + while (!SCM_NULLP (ports_ptr)) { SCM port = SCM_COERCE_OUTPORT (SCM_CAR (ports_ptr)); if (i == 0) @@ -791,9 +791,7 @@ SCM_DEFINE (scm_input_port_p, "input-port?", 1, 0, 0, "@code{port?}.") #define FUNC_NAME s_scm_input_port_p { - if (SCM_IMP (x)) - return SCM_BOOL_F; - return SCM_BOOL(SCM_INPUT_PORT_P (x)); + return SCM_BOOL (SCM_INPUT_PORT_P (x)); } #undef FUNC_NAME @@ -804,11 +802,8 @@ SCM_DEFINE (scm_output_port_p, "output-port?", 1, 0, 0, "@code{port?}.") #define FUNC_NAME s_scm_output_port_p { - if (SCM_IMP (x)) - return SCM_BOOL_F; - if (SCM_PORT_WITH_PS_P (x)) - x = SCM_PORT_WITH_PS_PORT (x); - return SCM_BOOL(SCM_OUTPUT_PORT_P (x)); + SCM_COERCE_OUTPORT (x); + return SCM_BOOL (SCM_OUTPUT_PORT_P (x)); } #undef FUNC_NAME @@ -830,7 +825,7 @@ SCM_DEFINE (scm_port_closed_p, "port-closed?", 1, 0, 0, #define FUNC_NAME s_scm_port_closed_p { SCM_VALIDATE_PORT (1,port); - return SCM_NEGATE_BOOL(SCM_OPPORTP (port)); + return SCM_BOOL (!SCM_OPPORTP (port)); } #undef FUNC_NAME diff --git a/libguile/read.c b/libguile/read.c index 5af8436c3..4dd745d67 100644 --- a/libguile/read.c +++ b/libguile/read.c @@ -380,7 +380,7 @@ tryagain_no_flush_ws: case '*': j = scm_read_token (c, tok_buf, port, 0); p = scm_istr2bve (SCM_STRING_CHARS (*tok_buf) + 1, (long) (j - 1)); - if (SCM_NFALSEP (p)) + if (!SCM_FALSEP (p)) return p; else goto unkshrp; @@ -398,7 +398,7 @@ tryagain_no_flush_ws: if (c >= '0' && c < '8') { p = scm_istr2int (SCM_STRING_CHARS (*tok_buf), (long) j, 8); - if (SCM_NFALSEP (p)) + if (!SCM_FALSEP (p)) return SCM_MAKE_CHAR (SCM_INUM (p)); } for (c = 0; c < scm_n_charnames; c++) @@ -418,7 +418,7 @@ tryagain_no_flush_ws: { SCM sharp = scm_get_hash_procedure (c); - if (SCM_NIMP (sharp)) + if (!SCM_FALSEP (sharp)) { int line = SCM_LINUM (port); int column = SCM_COL (port) - 2; @@ -484,11 +484,7 @@ tryagain_no_flush_ws: if (j == 0) return scm_nullstr; SCM_STRING_CHARS (*tok_buf)[j] = 0; - { - SCM str; - str = scm_makfromstr (SCM_STRING_CHARS (*tok_buf), j, 0); - return str; - } + return scm_mem2string (SCM_STRING_CHARS (*tok_buf), j); case'0':case '1':case '2':case '3':case '4': case '5':case '6':case '7':case '8':case '9': @@ -498,7 +494,7 @@ tryagain_no_flush_ws: num: j = scm_read_token (c, tok_buf, port, 0); p = scm_istring2number (SCM_STRING_CHARS (*tok_buf), (long) j, 10L); - if (SCM_NFALSEP (p)) + if (!SCM_FALSEP (p)) return p; if (c == '#') { @@ -749,9 +745,10 @@ SCM_DEFINE (scm_read_hash_extend, "read-hash-extend", 2, 0, 0, SCM this; SCM prev; - SCM_VALIDATE_CHAR (1,chr); - SCM_ASSERT (SCM_FALSEP (proc) || SCM_NIMP(proc), proc, SCM_ARG2, - FUNC_NAME); + SCM_VALIDATE_CHAR (1, chr); + SCM_ASSERT (SCM_FALSEP (proc) + || SCM_EQ_P (scm_procedure_p (proc), SCM_BOOL_T), + proc, SCM_ARG2, FUNC_NAME); /* Check if chr is already in the alist. */ this = *scm_read_hash_procedures; @@ -761,7 +758,7 @@ SCM_DEFINE (scm_read_hash_extend, "read-hash-extend", 2, 0, 0, if (SCM_NULLP (this)) { /* not found, so add it to the beginning. */ - if (SCM_NFALSEP (proc)) + if (!SCM_FALSEP (proc)) { *scm_read_hash_procedures = scm_cons (scm_cons (chr, proc), *scm_read_hash_procedures); diff --git a/libguile/simpos.c b/libguile/simpos.c index cfc1c9e41..882088b40 100644 --- a/libguile/simpos.c +++ b/libguile/simpos.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1997,1998, 2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -110,7 +110,7 @@ SCM_DEFINE (scm_getenv, "getenv", 1, 0, 0, SCM_VALIDATE_STRING (1, nam); SCM_STRING_COERCE_0TERMINATION_X (nam); val = getenv (SCM_STRING_CHARS (nam)); - return (val) ? scm_makfromstr(val, (size_t)strlen(val), 0) : SCM_BOOL_F; + return val ? scm_mem2string (val, strlen (val)) : SCM_BOOL_F; } #undef FUNC_NAME diff --git a/libguile/socket.c b/libguile/socket.c index 685d93277..1eacf9fe8 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -191,7 +191,7 @@ SCM_DEFINE (scm_inet_ntoa, "inet-ntoa", 1, 0, 0, SCM answer; addr.s_addr = htonl (SCM_NUM2ULONG (1, inetid)); s = inet_ntoa (addr); - answer = scm_makfromstr (s, strlen (s), 0); + answer = scm_mem2string (s, strlen (s)); return answer; } #undef FUNC_NAME @@ -960,8 +960,7 @@ scm_addr_vector (const struct sockaddr *address, const char *proc) result = scm_c_make_vector (2, SCM_UNSPECIFIED); ve = SCM_VELTS (result); ve[0] = scm_ulong2num ((unsigned long) fam); - ve[1] = scm_makfromstr (nad->sun_path, - (size_t) strlen (nad->sun_path), 0); + ve[1] = scm_mem2string (nad->sun_path, strlen (nad->sun_path)); } break; #endif diff --git a/libguile/stime.c b/libguile/stime.c index f99656da4..5db51a547 100644 --- a/libguile/stime.c +++ b/libguile/stime.c @@ -607,7 +607,7 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, SCM *velts = SCM_VELTS (stime); int have_zone = 0; - if (SCM_NFALSEP (velts[10]) && *SCM_STRING_CHARS (velts[10]) != 0) + if (!SCM_FALSEP (velts[10]) && *SCM_STRING_CHARS (velts[10]) != 0) { /* it's not required that the TZ setting be correct, just that it has the right name. so try something like TZ=EST0. @@ -647,7 +647,7 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, #endif } - result = scm_makfromstr (tbuf+1, len-1, 0); + result = scm_mem2string (tbuf + 1, len - 1); scm_must_free (tbuf); scm_must_free(myfmt); return result; diff --git a/libguile/strings.c b/libguile/strings.c index a60c03ac1..b37309b14 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -105,7 +105,7 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1, { unsigned char *data = SCM_STRING_UCHARS (result); - while (SCM_NNULLP (chrs)) + while (!SCM_NULLP (chrs)) { SCM elt = SCM_CAR (chrs); @@ -153,7 +153,7 @@ scm_makfromstrs (int argc, char **argv) if (0 > i) for (i = 0; argv[i]; i++); while (i--) - lst = scm_cons (scm_makfromstr (argv[i], (size_t) strlen (argv[i]), 0), lst); + lst = scm_cons (scm_mem2string (argv[i], strlen (argv[i])), lst); return lst; } @@ -191,8 +191,21 @@ scm_take0str (char *s) return scm_take_str (s, strlen (s)); } +#if (SCM_DEBUG_DEPRECATED == 0) + SCM scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED) +{ + scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. " + "Use `scm_mem2string' instead."); + + return scm_mem2string (src, len); +} + +#endif + +SCM +scm_mem2string (const char *src, size_t len) { SCM s = scm_allocate_string (len); char *dst = SCM_STRING_CHARS (s); @@ -206,7 +219,7 @@ SCM scm_makfrom0str (const char *src) { if (!src) return SCM_BOOL_F; - return scm_makfromstr (src, (size_t) strlen (src), 0); + return scm_mem2string (src, strlen (src)); } @@ -332,6 +345,7 @@ SCM_DEFINE (scm_substring, "substring", 2, 1, 0, { long int from; long int to; + SCM substr; SCM_VALIDATE_STRING (1, str); SCM_VALIDATE_INUM (2, start); @@ -342,7 +356,9 @@ SCM_DEFINE (scm_substring, "substring", 2, 1, 0, to = SCM_INUM (end); SCM_ASSERT_RANGE (3, end, from <= to && to <= SCM_STRING_LENGTH (str)); - return scm_makfromstr (&SCM_STRING_CHARS (str)[from], (size_t) (to - from), 0); + substr = scm_mem2string (&SCM_STRING_CHARS (str)[from], to - from); + scm_remember_upto_here_1 (str); + return substr; } #undef FUNC_NAME @@ -366,7 +382,7 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1, } res = scm_allocate_string (i); data = SCM_STRING_UCHARS (res); - for (l = args;SCM_NIMP (l);l = SCM_CDR (l)) { + for (l = args; !SCM_NULLP (l);l = SCM_CDR (l)) { s = SCM_CAR (l); for (i = 0;ilist", 1, 0, 0, static SCM string_copy (SCM str) { - return scm_makfromstr (SCM_STRING_CHARS (str), SCM_STRING_LENGTH (str), 0); + const char* chars = SCM_STRING_CHARS (str); + size_t length = SCM_STRING_LENGTH (str); + SCM new_string = scm_mem2string (chars, length); + scm_remember_upto_here_1 (str); + return new_string; } @@ -487,7 +491,7 @@ string_capitalize_x (SCM str) len = SCM_STRING_LENGTH(str); sz = SCM_STRING_CHARS (str); for(i=0; i= 0) { - res = scm_cons (scm_makfromstr (p + idx, last_idx - idx, 0), res); + res = scm_cons (scm_mem2string (p + idx, last_idx - idx), res); idx--; } } + scm_remember_upto_here_1 (str); return res; } #undef FUNC_NAME diff --git a/libguile/strports.c b/libguile/strports.c index ef4a15838..2ce941b76 100644 --- a/libguile/strports.c +++ b/libguile/strports.c @@ -305,10 +305,14 @@ scm_mkstrport (SCM pos, SCM str, long modes, const char *caller) SCM scm_strport_to_string (SCM port) { scm_t_port *pt = SCM_PTAB_ENTRY (port); + SCM str; if (pt->rw_active == SCM_PORT_WRITE) st_flush (port); - return scm_makfromstr ((char *) pt->read_buf, pt->read_buf_size, 0); + + str = scm_mem2string ((char *) pt->read_buf, pt->read_buf_size); + scm_remember_upto_here_1 (port); + return str; } SCM_DEFINE (scm_object_to_string, "object->string", 1, 1, 0, diff --git a/libguile/symbols.c b/libguile/symbols.c index 448c9d85f..7ce74a20b 100644 --- a/libguile/symbols.c +++ b/libguile/symbols.c @@ -185,8 +185,11 @@ SCM_DEFINE (scm_symbol_to_string, "symbol->string", 1, 0, 0, "@end lisp") #define FUNC_NAME s_scm_symbol_to_string { + SCM str; SCM_VALIDATE_SYMBOL (1, s); - return scm_makfromstr (SCM_SYMBOL_CHARS (s), SCM_SYMBOL_LENGTH (s), 0); + str = scm_mem2string (SCM_SYMBOL_CHARS (s), SCM_SYMBOL_LENGTH (s)); + scm_remember_upto_here_1 (s); + return str; } #undef FUNC_NAME diff --git a/libguile/validate.h b/libguile/validate.h index 5f152138c..51a9708cf 100644 --- a/libguile/validate.h +++ b/libguile/validate.h @@ -1,4 +1,4 @@ -/* $Id: validate.h,v 1.33 2001-05-26 20:51:22 cmm Exp $ */ +/* $Id: validate.h,v 1.34 2001-06-26 10:59:34 dirk Exp $ */ /* Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify @@ -180,9 +180,11 @@ SCM_VALIDATE_INUM_DEF_COPY (pos_start, start, 0, c_start);\ SCM_VALIDATE_INUM_DEF_COPY (pos_end, end, SCM_STRING_LENGTH (str), c_end);\ SCM_ASSERT_RANGE (pos_start, start,\ - 0 <= c_start && c_start <= SCM_STRING_LENGTH (str));\ + 0 <= c_start \ + && (size_t) c_start <= SCM_STRING_LENGTH (str));\ SCM_ASSERT_RANGE (pos_end, end,\ - c_start <= c_end && c_end <= SCM_STRING_LENGTH (str));\ + c_start <= c_end \ + && (size_t) c_end <= SCM_STRING_LENGTH (str));\ } while (0) #define SCM_VALIDATE_REAL(pos, z) SCM_MAKE_VALIDATE (pos, z, REALP) diff --git a/libguile/vports.c b/libguile/vports.c index 9d7fbe409..33ae23520 100644 --- a/libguile/vports.c +++ b/libguile/vports.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1998,1999, 2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1998,1999,2000,2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -101,7 +101,7 @@ sf_write (SCM port, const void *data, size_t size) SCM p = SCM_PACK (SCM_STREAM (port)); scm_apply (SCM_VELTS (p)[1], - scm_cons (scm_makfromstr ((char *) data, size, 0), SCM_EOL), + scm_cons (scm_mem2string ((char *) data, size), SCM_EOL), SCM_EOL); } diff --git a/srfi/ChangeLog b/srfi/ChangeLog index 77d97f8bf..05c1c1998 100644 --- a/srfi/ChangeLog +++ b/srfi/ChangeLog @@ -1,3 +1,13 @@ +2001-06-26 Dirk Herrmann + + * srfi-13.c (scm_string_copyS, scm_string_take, scm_string_drop, + scm_string_take_right, scm_string_drop_right, scm_string_trim, + scm_string_trim_right, scm_string_trim_both, scm_string_tokenize): + Use scm_mem2string instead of scm_makfromstr. + + (scm_reverse_list_to_string, string_titlecase_x): Prefer + !SCM_ over SCM_N. + 2001-06-25 Marius Vollmer * srfi-8.scm: Use `re-export-syntax' to correctly re-export diff --git a/srfi/srfi-13.c b/srfi/srfi-13.c index 88584caaa..af34b03e2 100644 --- a/srfi/srfi-13.c +++ b/srfi/srfi-13.c @@ -1,6 +1,6 @@ /* srfi-13.c --- SRFI-13 procedures for Guile * - * Copyright (C) 2001 Free Software Foundation, Inc. + * Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -189,7 +189,7 @@ SCM_DEFINE (scm_reverse_list_to_string, "reverse-list->string", 1, 0, 0, { unsigned char *data = SCM_STRING_UCHARS (result) + i; - while (SCM_NNULLP (chrs)) + while (!SCM_NULLP (chrs)) { SCM elt = SCM_CAR (chrs); @@ -379,7 +379,7 @@ SCM_DEFINE (scm_string_copyS, "string-copy", 1, 2, 0, SCM_VALIDATE_SUBSTRING_SPEC_COPY (1, str, cstr, 2, start, cstart, 3, end, cend); - return scm_makfromstr (cstr + cstart, cend - cstart, 0); + return scm_mem2string (cstr + cstart, cend - cstart); } #undef FUNC_NAME @@ -450,7 +450,7 @@ SCM_DEFINE (scm_string_take, "string-take", 2, 0, 0, SCM_VALIDATE_INUM_COPY (2, n, cn); SCM_ASSERT_RANGE (2, n, cn >= 0 && cn <= SCM_STRING_LENGTH (s)); - return scm_makfromstr (cstr, cn, 0); + return scm_mem2string (cstr, cn); } #undef FUNC_NAME @@ -467,7 +467,7 @@ SCM_DEFINE (scm_string_drop, "string-drop", 2, 0, 0, SCM_VALIDATE_INUM_COPY (2, n, cn); SCM_ASSERT_RANGE (2, n, cn >= 0 && cn <= SCM_STRING_LENGTH (s)); - return scm_makfromstr (cstr + cn, SCM_STRING_LENGTH (s) - cn, 0); + return scm_mem2string (cstr + cn, SCM_STRING_LENGTH (s) - cn); } #undef FUNC_NAME @@ -484,7 +484,7 @@ SCM_DEFINE (scm_string_take_right, "string-take-right", 2, 0, 0, SCM_VALIDATE_INUM_COPY (2, n, cn); SCM_ASSERT_RANGE (2, n, cn >= 0 && cn <= SCM_STRING_LENGTH (s)); - return scm_makfromstr (cstr + SCM_STRING_LENGTH (s) - cn, cn, 0); + return scm_mem2string (cstr + SCM_STRING_LENGTH (s) - cn, cn); } #undef FUNC_NAME @@ -501,7 +501,7 @@ SCM_DEFINE (scm_string_drop_right, "string-drop-right", 2, 0, 0, SCM_VALIDATE_INUM_COPY (2, n, cn); SCM_ASSERT_RANGE (2, n, cn >= 0 && cn <= SCM_STRING_LENGTH (s)); - return scm_makfromstr (cstr, SCM_STRING_LENGTH (s) - cn, 0); + return scm_mem2string (cstr, SCM_STRING_LENGTH (s) - cn); } #undef FUNC_NAME @@ -657,7 +657,7 @@ SCM_DEFINE (scm_string_trim, "string-trim", 1, 3, 0, cstart++; } } - return scm_makfromstr (cstr + cstart, cend - cstart, 0); + return scm_mem2string (cstr + cstart, cend - cstart); } #undef FUNC_NAME @@ -733,7 +733,7 @@ SCM_DEFINE (scm_string_trim_right, "string-trim-right", 1, 3, 0, cend--; } } - return scm_makfromstr (cstr + cstart, cend - cstart, 0); + return scm_mem2string (cstr + cstart, cend - cstart); } #undef FUNC_NAME @@ -837,7 +837,7 @@ SCM_DEFINE (scm_string_trim_both, "string-trim-both", 1, 3, 0, cend--; } } - return scm_makfromstr (cstr + cstart, cend - cstart, 0); + return scm_mem2string (cstr + cstart, cend - cstart); } #undef FUNC_NAME @@ -2121,7 +2121,7 @@ string_titlecase_x (SCM str, int start, int end) sz = SCM_STRING_CHARS (str); for(i = start; i < end; i++) { - if(SCM_NFALSEP(scm_char_alphabetic_p(SCM_MAKE_CHAR(sz[i])))) + if (!SCM_FALSEP (scm_char_alphabetic_p (SCM_MAKE_CHAR (sz[i])))) { if (!in_word) { @@ -2826,8 +2826,7 @@ SCM_DEFINE (scm_string_tokenize, "string-tokenize", 1, 3, 0, break; cend--; } - result = scm_cons (scm_makfromstr (cstr + cend, idx - cend, - 0), result); + result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result); } } else if (SCM_CHARSETP (token_char)) @@ -2851,8 +2850,7 @@ SCM_DEFINE (scm_string_tokenize, "string-tokenize", 1, 3, 0, break; cend--; } - result = scm_cons (scm_makfromstr (cstr + cend, idx - cend, - 0), result); + result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result); } } else @@ -2880,8 +2878,7 @@ SCM_DEFINE (scm_string_tokenize, "string-tokenize", 1, 3, 0, break; cend--; } - result = scm_cons (scm_makfromstr (cstr + cend, idx - cend, - 0), result); + result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result); } } return result; -- 2.20.1