From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Schwab Newsgroups: gmane.emacs.devel Subject: Re: [RFC] temporary Lisp_Strings Date: Tue, 02 Sep 2014 15:21:35 +0200 Message-ID: References: <5405BE5D.1090003@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1409664128 16268 80.91.229.3 (2 Sep 2014 13:22:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Sep 2014 13:22:08 +0000 (UTC) Cc: Emacs development discussions To: Dmitry Antipov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 02 15:22:01 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XOo1w-0003K1-GB for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 15:21:52 +0200 Original-Received: from localhost ([::1]:38120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOo1w-0004II-1v for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 09:21:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOo1n-0004Hv-FB for emacs-devel@gnu.org; Tue, 02 Sep 2014 09:21:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOo1h-0001dV-E0 for emacs-devel@gnu.org; Tue, 02 Sep 2014 09:21:43 -0400 Original-Received: from cantor2.suse.de ([195.135.220.15]:49924 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOo1h-0001dA-7r for emacs-devel@gnu.org; Tue, 02 Sep 2014 09:21:37 -0400 Original-Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B8F0FAD2C; Tue, 2 Sep 2014 13:21:35 +0000 (UTC) X-Yow: I guess it was all a DREAM.. or an episode of HAWAII FIVE-O... In-Reply-To: <5405BE5D.1090003@yandex.ru> (Dmitry Antipov's message of "Tue, 02 Sep 2014 16:55:57 +0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:173948 Archived-At: Dmitry Antipov writes: > I'm thinking about temporary Lisp_Strings on C stack (allocated with alloca). > Simple implementation (with no check whether it fits on stack) and a few use > cases attached. Among others, the question is: is there a way to make sure > that an address returned by alloca fits in Lisp_Object? There is none. The stack could be in a completely different address region that may not be suitable in non-USE_LSB_TAG configurations. > +#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. Andreas. -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."