unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Kenichi Handa <handa@m17n.org>
Cc: emacs-devel@gnu.org
Subject: Re: Preventing stack overflows with alloca.
Date: Sat, 19 Jun 2004 09:19:53 +0900 (JST)	[thread overview]
Message-ID: <200406190019.JAA04897@etlken.m17n.org> (raw)
In-Reply-To: <m3k6y5xefb.fsf@kfs-l.imdomain.dk> (storm@cua.dk)

In article <m3k6y5xefb.fsf@kfs-l.imdomain.dk>, 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

  reply	other threads:[~2004-06-19  0:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-18 10:14 Preventing stack overflows with alloca Kim F. Storm
2004-06-18 11:13 ` Kenichi Handa
2004-06-18 12:02   ` Kim F. Storm
2004-06-19  0:19     ` Kenichi Handa [this message]
2004-06-19  3:19     ` Richard Stallman
2004-06-20 18:56       ` Kim F. Storm
2004-06-21 22:01       ` Kim F. Storm
2004-06-22 23:17         ` Richard Stallman
2004-10-25 17:11   ` Yoichi NAKAYAMA
2004-10-26 14:04     ` Kim F. Storm
2004-10-27 17:34       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200406190019.JAA04897@etlken.m17n.org \
    --to=handa@m17n.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).