1

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 ??

  • I don't understand your confusion. CHAR_CHARSET is a macro and it either expands to the CHARSET_FROM_ID macro or the char_charset function. Which isn't the same as the macro and doesn't use recursion either, just expansions of CHARSET_FROM_ID. – wasamasa Jul 27 at 19:33
  • @wasamasa: the macro calls back the function char_charset, which calls the macro, which calls the function , ... – q.undertow Jul 27 at 20:32
  • @Drew: are you sure the debugging tag applies? I am not saying this is a bug, and when I execute the function with S-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 at 20:38
  • Perhaps if there were a "code archeology" tag, that would fit better than "debugging" – db48x Jul 27 at 20:43
  • I've removed it. I added it in the sense that you wanted to find out what was going on. But I agree that's not really about debugging. – Drew Jul 27 at 21:42
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.