[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Preventing stack overflows with alloca.
From: |
Kenichi Handa |
Subject: |
Re: Preventing stack overflows with alloca. |
Date: |
Sat, 19 Jun 2004 09:19:53 +0900 (JST) |
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) |
In article <address@hidden>, address@hidden (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
address@hidden