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:55:57 +0400 Message-ID: <5405BE5D.1090003@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030306010402090100080404" X-Trace: ger.gmane.org 1409662599 28606 80.91.229.3 (2 Sep 2014 12:56:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Sep 2014 12:56:39 +0000 (UTC) To: Emacs development discussions Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 02 14:56:33 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 1XOndR-0004tT-7X for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 14:56:33 +0200 Original-Received: from localhost ([::1]:37899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOndQ-0005nM-Qu for ged-emacs-devel@m.gmane.org; Tue, 02 Sep 2014 08:56:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOnd9-0005Qx-Oz for emacs-devel@gnu.org; Tue, 02 Sep 2014 08:56:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOnd0-0008R8-BX for emacs-devel@gnu.org; Tue, 02 Sep 2014 08:56:15 -0400 Original-Received: from forward3l.mail.yandex.net ([84.201.143.136]:36741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOncz-0008PJ-4o for emacs-devel@gnu.org; Tue, 02 Sep 2014 08:56:05 -0400 Original-Received: from smtp18.mail.yandex.net (smtp18.mail.yandex.net [95.108.252.18]) by forward3l.mail.yandex.net (Yandex) with ESMTP id BC63C1500CD8 for ; Tue, 2 Sep 2014 16:55:58 +0400 (MSK) Original-Received: from smtp18.mail.yandex.net (localhost [127.0.0.1]) by smtp18.mail.yandex.net (Yandex) with ESMTP id 5856418A003D for ; Tue, 2 Sep 2014 16:55:58 +0400 (MSK) Original-Received: from unknown (unknown [37.139.80.10]) by smtp18.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id NPCOlDaKpx-tvIqM6pa; Tue, 2 Sep 2014 16:55:57 +0400 (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) X-Yandex-Uniq: fd4d07e8-eae7-4d8e-9d78-fd02be4c9000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1409662557; bh=A7UQE3YzWFl6x3bigcYxv0ePishFwsRe6OZaTITB2js=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type; b=CnRSL38Nglfh1JnnNVx6gbhn0NVDNuSqyZn06vf4jfxjhyxSRALpoP38/E8LOS3NW 51l4xKkQ4uXykuqXas46oBkyPZs0IloZ1qprd5cz0egDImGeZk4GXkJUEUQfmz++y5 9Cnq8BhTTzMvsde3/IBffGq/TWx8D5P4J3inwDgc= Authentication-Results: smtp18.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:173946 Archived-At: This is a multi-part message in MIME format. --------------030306010402090100080404 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 --------------030306010402090100080404 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); --------------030306010402090100080404--