From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kenichi Handa Newsgroups: gmane.emacs.devel Subject: Re: Preventing stack overflows with alloca. Date: Sat, 19 Jun 2004 09:19:53 +0900 (JST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200406190019.JAA04897@etlken.m17n.org> References: <200406181113.UAA03743@etlken.m17n.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII X-Trace: sea.gmane.org 1087604436 8493 80.91.224.253 (19 Jun 2004 00:20:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 19 Jun 2004 00:20:36 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sat Jun 19 02:20:27 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BbTat-0004dN-00 for ; Sat, 19 Jun 2004 02:20:27 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BbTas-00012z-00 for ; Sat, 19 Jun 2004 02:20:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BbTc0-0007sT-AK for emacs-devel@quimby.gnus.org; Fri, 18 Jun 2004 20:21:36 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BbTbs-0007rR-NB for emacs-devel@gnu.org; Fri, 18 Jun 2004 20:21:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BbTbr-0007rF-MX for emacs-devel@gnu.org; Fri, 18 Jun 2004 20:21:28 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BbTbr-0007rC-Fj for emacs-devel@gnu.org; Fri, 18 Jun 2004 20:21:27 -0400 Original-Received: from [192.47.44.130] (helo=tsukuba.m17n.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1BbTaX-0008Tu-6Q for emacs-devel@gnu.org; Fri, 18 Jun 2004 20:20:05 -0400 Original-Received: from fs.m17n.org (fs.m17n.org [192.47.44.2]) by tsukuba.m17n.org (8.12.3/8.12.3/Debian-6.6) with ESMTP id i5J0Jrno030678; Sat, 19 Jun 2004 09:19:54 +0900 Original-Received: from etlken.m17n.org (etlken.m17n.org [192.47.44.125]) by fs.m17n.org (8.11.6p2/8.11.6) with ESMTP id i5J0JrW16202; Sat, 19 Jun 2004 09:19:53 +0900 (JST) Original-Received: (from handa@localhost) by etlken.m17n.org (8.8.8+Sun/3.7W-2001040620) id JAA04897; Sat, 19 Jun 2004 09:19:53 +0900 (JST) Original-To: storm@cua.dk In-reply-to: (storm@cua.dk) User-Agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.3 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:25094 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:25094 In article , storm@cua.dk (Kim F. Storm) writes: > Since old_value is not a lisp object here, > we would need to fix (hack) GC like this: > for (bind = specpdl; bind != specpdl_ptr; bind++) > { > mark_object (bind->symbol); > if (bind->func != safe_alloca_unwind) > mark_object (bind->old_value); > } I now remembered why I didn't work on it further. That's because I didn't find the above simple solution! So, I was going to change `unused' of struct specbinding to void *val, make record_unwind_protect_c which accepts void * instead of Lisp_Object as ARG, make unbind_to to call func with val instead of old_value of val is not NULL, etc... and noticed that it's a too big change for the current rather simple problem. :-( > A sample use would look like this: > Lisp_Object > string_make_multibyte (string) > Lisp_Object string; > { > unsigned char *buf; > int nbytes; > Lisp_Object ret; > USE_SAFE_ALLOCA; > if (STRING_MULTIBYTE (string)) > return string; > nbytes = count_size_as_multibyte (SDATA (string), > SCHARS (string)); > /* If all the chars are ASCII, they won't need any more bytes > once converted. In that case, we can return STRING itself. */ > if (nbytes == SBYTES (string)) > return string; > SAFE_ALLOCA (buf, nbytes); > copy_text (SDATA (string), buf, SBYTES (string), > 0, 1); > ret = make_multibyte_string (buf, SCHARS (string), nbytes); > SAFE_FREE (nbytes); > return ret; > } I like it. --- Ken'ichi HANDA handa@m17n.org