#if defined (ENABLE_CHECKING) && USE_STACK_LISP_OBJECTS
-/* Debugging check whether STR is ASCII-only. */
-
-const char *
-verify_ascii (const char *str)
-{
- const unsigned char *ptr = (unsigned char *) str, *end = ptr + strlen (str);
- while (ptr < end)
- {
- int c = STRING_CHAR_ADVANCE (ptr);
- if (!ASCII_CHAR_P (c))
- emacs_abort ();
- }
- return str;
-}
-
/* Stress alloca with inconveniently sized requests and check
whether all allocated areas may be used for Lisp_Object. */
Lisp_Object
from_unicode_buffer (const wchar_t *wstr)
{
- return from_unicode (
- make_unibyte_string (
- (char *) wstr,
- /* we get one of the two final 0 bytes for free. */
- 1 + sizeof (wchar_t) * wcslen (wstr)));
+ /* We get one of the two final null bytes for free. */
+ prtdiff_t len = 1 + sizeof (wchar_t) * wcslen (wstr);
+ AUTO_STRING_WITH_LEN (str, (char *) wstr, len);
+ return from_unicode (str);
}
wchar_t *
char *buf = buffer;
ptrdiff_t size = sizeof buffer;
size_t len;
- Lisp_Object bufstring;
int ns = t.tv_nsec;
USE_SAFE_ALLOCA;
}
xtzfree (tz);
- bufstring = make_unibyte_string (buf, len);
+ AUTO_STRING_WITH_LEN (bufstring, buf, len);
+ Lisp_Object result = code_convert_string_norecord (bufstring,
+ Vlocale_coding_system, 0);
SAFE_FREE ();
- return code_convert_string_norecord (bufstring, Vlocale_coding_system, 0);
+ return result;
}
DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 2, 0,
envptr->data = data;
Lisp_Object envobj = make_save_ptr (envptr);
- Lisp_Object doc
- = (documentation
- ? code_convert_string_norecord (build_unibyte_string (documentation),
- Qutf_8, false)
- : Qnil);
+ Lisp_Object doc = Qnil;
+ if (documentation)
+ {
+ AUTO_STRING (unibyte_doc, documentation);
+ doc = code_convert_string_norecord (unibyte_doc, Qutf_8, false);
+ }
+
/* FIXME: Use a bytecompiled object, or even better a subr. */
Lisp_Object ret = list4 (Qlambda,
list2 (Qand_rest, Qargs),
module_make_string (emacs_env *env, const char *str, ptrdiff_t length)
{
MODULE_FUNCTION_BEGIN (module_nil);
- Lisp_Object lstr = make_unibyte_string (str, length);
+ AUTO_STRING_WITH_LEN (lstr, str, length);
return lisp_to_value (code_convert_string_norecord (lstr, Qutf_8, false));
}
? exprintf (&buf, &bufsize, buffer, -1,
"#<module function %s from %s>", sym, path)
: sprintf (buffer, noaddr_format, env->subr));
- Lisp_Object unibyte_result = make_unibyte_string (buffer, size);
+ AUTO_STRING_WITH_LEN (unibyte_result, buffer, size);
+ Lisp_Object result = code_convert_string_norecord (unibyte_result,
+ Qutf_8, false);
if (buf != buffer)
xfree (buf);
- return code_convert_string_norecord (unibyte_result, Qutf_8, false);
+ return result;
}
\f
Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name);
synchronize_system_messages_locale ();
char *str = strerror (errorno);
+ AUTO_STRING (unibyte_str, str);
Lisp_Object errstring
- = code_convert_string_norecord (build_unibyte_string (str),
- Vlocale_coding_system, 0);
+ = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0);
Lisp_Object errdata = Fcons (errstring, data);
if (errorno == EEXIST)
Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name);
synchronize_system_messages_locale ();
char *str = strerror (errno);
+ AUTO_STRING (unibyte_str, str);
Lisp_Object errstring
- = code_convert_string_norecord (build_unibyte_string (str),
- Vlocale_coding_system, 0);
+ = code_convert_string_norecord (unibyte_str, Vlocale_coding_system, 0);
Lisp_Object errdata = Fcons (errstring, data);
xsignal (Qfile_notify_error, Fcons (build_string (string), errdata));
/* Drive must be set, so this is okay. */
if (strcmp (nm - 2, SSDATA (name)) != 0)
{
- char temp[] = " :";
-
name = make_specified_string (nm, -1, p - nm, multibyte);
- temp[0] = DRIVE_LETTER (drive);
- AUTO_STRING (drive_prefix, temp);
+ char temp[] = { DRIVE_LETTER (drive), ':', 0 };
+ AUTO_STRING_WITH_LEN (drive_prefix, temp, 2);
name = concat2 (drive_prefix, name);
}
#ifdef WINDOWSNT
{
char *str = NULL;
#ifdef HAVE_LANGINFO_CODESET
- Lisp_Object val;
if (EQ (item, Qcodeset))
{
str = nl_langinfo (CODESET);
for (i = 0; i < 7; i++)
{
str = nl_langinfo (days[i]);
- val = build_unibyte_string (str);
+ AUTO_STRING (val, str);
/* Fixme: Is this coding system necessarily right, even if
it is consistent with CODESET? If not, what to do? */
ASET (v, i, code_convert_string_norecord (val, Vlocale_coding_system,
for (i = 0; i < 12; i++)
{
str = nl_langinfo (months[i]);
- val = build_unibyte_string (str);
+ AUTO_STRING (val, str);
ASET (v, i, code_convert_string_norecord (val, Vlocale_coding_system,
0));
}
p1 = strchr (p0, '-');
if (! p1)
{
- AUTO_STRING (extra, (&"*-*"[len && p0[len - 1] == '*']));
+ bool asterisk = len && p0[len - 1] == '*';
+ AUTO_STRING_WITH_LEN (extra, &"*-*"[asterisk], 3 - asterisk);
registry = concat2 (registry, extra);
}
registry = Fdowncase (registry);
char *str = SSDATA (SYMBOL_NAME (registry));
USE_SAFE_ALLOCA;
char *re = SAFE_ALLOCA (SBYTES (SYMBOL_NAME (registry)) * 2 + 1);
- Lisp_Object regexp;
int i, j;
for (i = j = 0; i < SBYTES (SYMBOL_NAME (registry)); i++, j++)
re[j] = '.';
}
re[j] = '\0';
- regexp = make_unibyte_string (re, j);
- SAFE_FREE ();
+ AUTO_STRING_WITH_LEN (regexp, re, j);
for (i = 0; fc_charset_table[i].name; i++)
if (fast_c_string_match_ignore_case
(regexp, fc_charset_table[i].name,
strlen (fc_charset_table[i].name)) >= 0)
break;
+ SAFE_FREE ();
if (! fc_charset_table[i].name)
return -1;
if (! fc_charset_table[i].fc_charset)
*p = 0;
c = reorder_modifiers (c);
- AUTO_STRING (new_mods_string, new_mods);
+ AUTO_STRING_WITH_LEN (new_mods_string, new_mods, p - new_mods);
keystring = concat2 (new_mods_string, XCDR (assoc));
error ("To bind the key %s, use [?%s], not [%s]",
STACK_CONS (d, Qnil)))) \
: list4 (a, b, c, d))
-/* Check whether stack-allocated strings are ASCII-only. */
+/* Declare NAME as an auto Lisp string if possible, a GC-based one if not.
+ Take its unibyte value from the null-terminated string STR,
+ an expression that should not have side effects.
+ STR's value is not necessarily copied. The resulting Lisp string
+ should not be modified or made visible to user code. */
-#if defined (ENABLE_CHECKING) && USE_STACK_LISP_OBJECTS
-extern const char *verify_ascii (const char *);
-#else
-# define verify_ascii(str) (str)
-#endif
+#define AUTO_STRING(name, str) \
+ AUTO_STRING_WITH_LEN (name, str, strlen (str))
/* Declare NAME as an auto Lisp string if possible, a GC-based one if not.
- Take its value from STR. STR is not necessarily copied and should
- contain only ASCII characters. The resulting Lisp string should
- not be modified or made visible to user code. */
+ Take its unibyte value from the null-terminated string STR with length LEN.
+ STR may have side effects and may contain null bytes.
+ STR's value is not necessarily copied. The resulting Lisp string
+ should not be modified or made visible to user code. */
-#define AUTO_STRING(name, str) \
+#define AUTO_STRING_WITH_LEN(name, str, len) \
Lisp_Object name = \
(USE_STACK_STRING \
? (make_lisp_ptr \
((&(union Aligned_String) \
- {{strlen (str), -1, 0, (unsigned char *) verify_ascii (str)}}.s), \
- Lisp_String)) \
- : build_string (verify_ascii (str)))
+ {{len, -1, 0, (unsigned char *) (str)}}.s), \
+ Lisp_String)) \
+ : make_unibyte_string (str, len))
/* Loop over all tails of a list, checking for cycles.
FIXME: Make tortoise and n internal declarations.
if (prefix)
{
- AUTO_STRING (prefix_obj, prefix);
+ AUTO_STRING_WITH_LEN (prefix_obj, prefix, 4);
item_string = concat2 (prefix_obj, item_string);
}
}
struct timespec tnow, tstart, tboot, telapsed, us_time;
double pcpu, pmem;
Lisp_Object attrs = Qnil;
- Lisp_Object cmd_str, decoded_cmd;
+ Lisp_Object decoded_cmd;
ptrdiff_t count;
CHECK_NUMBER_OR_FLOAT (pid);
else
q = NULL;
/* Command name is encoded in locale-coding-system; decode it. */
- cmd_str = make_unibyte_string (cmd, cmdsize);
+ AUTO_STRING_WITH_LEN (cmd_str, cmd, cmdsize);
decoded_cmd = code_convert_string_norecord (cmd_str,
Vlocale_coding_system, 0);
attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
sprintf (cmdline, "[%.*s]", cmdsize, cmd);
}
/* Command line is encoded in locale-coding-system; decode it. */
- cmd_str = make_unibyte_string (q, nread);
+ AUTO_STRING_WITH_LEN (cmd_str, q, nread);
decoded_cmd = code_convert_string_norecord (cmd_str,
Vlocale_coding_system, 0);
unbind_to (count, Qnil);
make_float (100.0 / 0x8000 * pinfo.pr_pctmem)),
attrs);
- decoded_cmd = (code_convert_string_norecord
- (build_unibyte_string (pinfo.pr_fname),
- Vlocale_coding_system, 0));
+ AUTO_STRING (fname, pinfo.pr_fname);
+ decoded_cmd = code_convert_string_norecord (fname,
+ Vlocale_coding_system, 0);
attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
- decoded_cmd = (code_convert_string_norecord
- (build_unibyte_string (pinfo.pr_psargs),
- Vlocale_coding_system, 0));
+ AUTO_STRING (psargs, pinfo.pr_psargs);
+ decoded_cmd = code_convert_string_norecord (psargs,
+ Vlocale_coding_system, 0);
attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
}
unbind_to (count, Qnil);
if (gr)
attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
- decoded_comm = (code_convert_string_norecord
- (build_unibyte_string (proc.ki_comm),
- Vlocale_coding_system, 0));
+ AUTO_STRING (comm, proc.ki_comm);
+ decoded_comm = code_convert_string_norecord (comm, Vlocale_coding_system, 0);
attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
{
args[i] = ' ';
}
- decoded_comm =
- (code_convert_string_norecord
- (build_unibyte_string (args),
- Vlocale_coding_system, 0));
+ AUTO_STRING (comm, args);
+ decoded_comm = code_convert_string_norecord (comm,
+ Vlocale_coding_system, 0);
attrs = Fcons (Fcons (Qargs, decoded_comm), attrs);
}