[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Accessing Lisp variables from C
From: |
Oliver Scholz |
Subject: |
Accessing Lisp variables from C |
Date: |
Thu, 04 May 2006 08:19:53 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
I decided to make a stab at porting `decode-char' to C. The better
part of it was indeed fairly trivial, but it turned out that I
obviously don't understand something very fundamental about the
interpreter. `decode-char' checks whether `utf-translate-cjk-mode' is
non-nil; if it is, it calls `utf-lookup-subst-table-for-decode'. This
one gets a translation hash table from the property
`translation-hash-table' on the symbol `utf-subst-table-for-decode'.
But before that, it checks whether the translation hash tables are
loaded, and calls `utf-translate-cjk-load-tables'.
I had the impression that in C this would look like this:
int
ucs_to_internal (ucs)
int ucs;
{
int c = 0;
Lisp_Object tmp_char;
if (! EQ (Qnil, SYMBOL_VALUE (intern ("utf-translate-cjk-mode"))))
/* cf. `utf-lookup-subst-table-for-decode' */
{
if (EQ (Qnil, SYMBOL_VALUE (intern ("utf-translate-cjk-lang-env"))))
call0 (intern ("utf-translate-cjk-load-tables"));
tmp_char = Fgethash (ucs,
Fget (intern ("utf-subst-table-for-decode"),
intern ("translation-hash-table")),
Qnil);
if (! EQ (Qnil, tmp_char))
{
CHECK_NUMBER (tmp_char);
c = XFASTINT (tmp_char);
}
}
[...]
But, oddly, this is not equivalent to what is supposed to be its Lisp
counterpart. `(utf-lookup-subst-table-for-decode #x9662)' returns a
nice Japanese character. This (alleged) C equivalent doesn't.
Besides, debugging is rather painful, since gdb insists on stepping
into `intern' and then into `oblookup' and then into `hash_string'
etc. I wonder what I am doing wrong here. The behaviour when stepping
is rather erratic, because for instance the gdb command "return"
causes a segfault when in `intern', but not when I step through it.
(The garbage collector is "mark and sweep", isn't it? Besides garbage
collection is triggered in the above only by `call0', right?)
Oliver
--
15 Floréal an 214 de la Révolution
Liberté, Egalité, Fraternité!
- Accessing Lisp variables from C,
Oliver Scholz <=