From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Antipov Newsgroups: gmane.emacs.devel Subject: [RFC] temporary Lisp_Strings Date: Tue, 02 Sep 2014 16:56:05 +0400 Message-ID: <5405BE65.6040404@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040301050600040600010905" X-Trace: ger.gmane.org 1409662655 29362 80.91.229.3 (2 Sep 2014 12:57:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Sep 2014 12:57:35 +0000 (UTC) To: Emacs development discussions Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 02 14:57:29 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 1XOneC-0005Lr-Bx for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 14:57:20 +0200 Original-Received: from localhost ([::1]:37905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOneC-0006gn-2O for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 08:57:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOndF-0005YR-1Q for emacs-devel@gnu.org; Tue, 02 Sep 2014 08:56:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOnd3-0008Ts-Ib for emacs-devel@gnu.org; Tue, 02 Sep 2014 08:56:20 -0400 Original-Received: from forward3l.mail.yandex.net ([84.201.143.136]:36832) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOnd3-0008T9-7t for emacs-devel@gnu.org; Tue, 02 Sep 2014 08:56:09 -0400 Original-Received: from smtp17.mail.yandex.net (smtp17.mail.yandex.net [95.108.252.17]) by forward3l.mail.yandex.net (Yandex) with ESMTP id 859421500E62 for ; Tue, 2 Sep 2014 16:56:08 +0400 (MSK) Original-Received: from smtp17.mail.yandex.net (localhost [127.0.0.1]) by smtp17.mail.yandex.net (Yandex) with ESMTP id 2DA3B190060E for ; Tue, 2 Sep 2014 16:56:08 +0400 (MSK) Original-Received: from unknown (unknown [37.139.80.10]) by smtp17.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id wgV0sWCGPt-u7ceMXug; Tue, 2 Sep 2014 16:56:07 +0400 (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) X-Yandex-Uniq: 00668f0a-64b6-4a51-bc9d-d0450eecb5c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1409662567; bh=zzG2x6xOxr2WDy46y5lw5xrBeuD5bj7KozcZRYC+AXI=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type; b=IhITXGKM/zI7HQse9DX+aROsKyRIhzrC3y1I/knY4N2SjOlYNdN1keeCbQbq1yPqI LEu4OJ8f1U/Coc57VDrbTYu5nSNFrJlsZ2txNQ1FmSW6cXwSiD8WB9ZwMAThEkv1JP h2t1nHll2Iz6gVi4Sut7Qt4tsUwKsKH/h0FU6n5o= Authentication-Results: smtp17.mail.yandex.net; dkim=pass header.i=@yandex.ru User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 84.201.143.136 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:173947 Archived-At: This is a multi-part message in MIME format. --------------040301050600040600010905 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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? Dmitry --------------040301050600040600010905 Content-Type: text/x-patch; name="alloca_string.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="alloca_string.patch" === modified file 'src/fileio.c' --- src/fileio.c 2014-09-02 11:41:22 +0000 +++ src/fileio.c 2014-09-02 11:47:45 +0000 @@ -1179,11 +1179,11 @@ char newdir_utf8[MAX_UTF8_PATH]; filename_from_ansi (newdir, newdir_utf8); - tem = build_string (newdir_utf8); + tem = alloca_string (newdir_utf8); } else #endif - tem = build_string (newdir); + tem = alloca_string (newdir); newdirlen = SBYTES (tem); if (multibyte && !STRING_MULTIBYTE (tem)) { @@ -1215,7 +1215,7 @@ /* `getpwnam' may return a unibyte string, which will bite us since we expect the directory to be multibyte. */ - tem = build_string (newdir); + tem = alloca_string (newdir); newdirlen = SBYTES (tem); if (multibyte && !STRING_MULTIBYTE (tem)) { @@ -1249,7 +1249,7 @@ adir = NULL; else if (multibyte) { - Lisp_Object tem = build_string (adir); + Lisp_Object tem = alloca_string (adir); tem = DECODE_FILE (tem); newdirlen = SBYTES (tem); @@ -1350,7 +1350,7 @@ getcwd (adir, adir_size); if (multibyte) { - Lisp_Object tem = build_string (adir); + Lisp_Object tem = alloca_string (adir); tem = DECODE_FILE (tem); newdirlen = SBYTES (tem); === modified file 'src/lisp.h' --- src/lisp.h 2014-09-02 06:49:40 +0000 +++ src/lisp.h 2014-09-02 12:31:01 +0000 @@ -4459,6 +4459,25 @@ memcpy (alloca (SBYTES (string) + 1), \ SSDATA (string), SBYTES (string) + 1) +/* Create temporary Lisp_String. Use alloca and do not disturb GC. */ + +#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; }) + /* Set up the name of the machine we're running on. */ extern void init_system_name (void); --------------040301050600040600010905--