I am looking at the C code for Emacs as of Emacs 26.1, file charset.c
, defun char-charset
(around line 2040), and file charset.h
, macro CHAR_CHARSET
(around line 380). I don't understand how in the world this might work. How does this not recurse without bound if ch >= 0x80
and restriction == Qnil
??
Asked
Active
Viewed 60 times
1

Dan
- 32,980
- 7
- 102
- 169

q.undertow
- 324
- 1
- 10
1 Answers
3
This isn't recursive, because there are actually three bits of code in play. First there is the Lisp function char-charset
, then there is the CHAR_CHARSET macro, and finally there is the C function char_charset
. All three are distinct. The Lisp function char-charset
is also given the name Fchar_charset inside the Emacs binary's symbol table, although there are no calls to it by that name. (The metadata used by the Lisp interpreter when it examines this function is stored in the static global variable Schar_charset.)
It doesn't recurse because the macro calls the function char_charset
, not Fchar_charset
. But certainly the Hamming distance between these names is not very great, so it is an easy mistake to make.

db48x
- 17,977
- 1
- 22
- 28
CHAR_CHARSET
is a macro and it either expands to theCHARSET_FROM_ID
macro or thechar_charset
function. Which isn't the same as the macro and doesn't use recursion either, just expansions ofCHARSET_FROM_ID
. – wasamasa Jul 27 '20 at 19:33char_charset
, which calls the macro, which calls the function , ... – q.undertow Jul 27 '20 at 20:32debugging
tag applies? I am not saying this is a bug, and when I execute the function withS-M-:
it does not in fact loop. I am just looking at the code trying to undestand how it can possibly work. – q.undertow Jul 27 '20 at 20:38