emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] temporary Lisp_Strings


From: Dmitry Antipov
Subject: Re: [RFC] temporary Lisp_Strings
Date: Tue, 02 Sep 2014 17:47:15 +0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0

On 09/02/2014 05:21 PM, Andreas Schwab wrote:

There is none.  The stack could be in a completely different address
region that may not be suitable in non-USE_LSB_TAG configurations.

IIUC non-USE_LSB_TAG configurations are not widely used, so this is
a tier-2 problem.

+#define alloca_string(str)                                     \
+  ({ Lisp_Object string;                                       \
+     struct Lisp_String *s;                                    \
+     ptrdiff_t nchars, nbytes, size = strlen (str);            \
+     parse_str_as_multibyte ((const unsigned char *) str,      \
+                            size, &nchars, &nbytes);           \
+     s = alloca (sizeof *s + nbytes + 1);                      \
+     s->data = (unsigned char *) s + sizeof (*s);           \
+     memcpy (s->data, str, nbytes);                         \
+     s->data[size] = '\0';                                  \
+     s->intervals = NULL;                                   \
+     if (nbytes == nchars || nbytes != size)                   \
+       s->size = size, s->size_byte = -1;                        \
+     else                                                      \
+       s->size = nchars, s->size_byte = nbytes;          \
+     XSETSTRING (string, s); string; })

This will eventually fail with USE_LSB_TAG, since you don't enforce
alignment.

What about alignment guaranteed by alloca?  IIUC compilers tends
to align it enough to US_LSB_TAG:

http://msdn.microsoft.com/en-us/library/x9sx5da1.aspx
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55945

Dmitry




reply via email to

[Prev in Thread] Current Thread [Next in Thread]