Run error in TeXmacs 2,1.4 with guile3

I compiled the texmacs 2.1.4 on Debian 12, and the sources does not support guile3. So I compared the guile_tm.cpp and guile_tm.hpp in the branch of guile3_branch_2.1
and the 2.1.4 branch, and modified the two files of 2.1.4. The compilation successed but texmacs didn’t run well.
Here is the error information:
Installing internal plug-ins…
Welcome to TeXmacs 2.1.4
------------------------------------------------------------------------------
kpsepath works with your TeX distribution
kpsewhich works with your TeX distribution
mktextfm works with your TeX distribution
mktexpk works with your TeX distribution
texhash works with your TeX distribution
Found TeX directory /usr/share/texmf/fonts
------------------------------------------------------------------------------
Installation completed successfully !
I will now start up the editor
------------------------------------------------------------------------------
Opening display…
Screen extents: 1366 x 768
Starting server…
TeXmacs] debug-std, Evaluating /usr/local/share/TeXmacs/progs/init-texmacs.scm…
;;; note: source file /usr/local/share/TeXmacs/progs/kernel/boot/boot.scm
;;; newer than compiled /home/yibo/.cache/guile/ccache/3.0-LE-8-4.6/usr/local/share/TeXmacs/progs/kernel/boot/boot.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /usr/local/share/TeXmacs/progs/kernel/boot/boot.scm
;;; WARNING: compilation of /usr/local/share/TeXmacs/progs/kernel/boot/boot.scm failed:
;;; Syntax error:
;;; kernel/boot/boot.scm:56:4: definition in expression context, where definitions are not allowed, in form (define-syntax define-public-macro (lambda (y) #f #((macro-type . defmacro) (defmacro-args args)) (syntax-case y () ((_ . args) (let ((v (syntax->datum (syntax args)))) (datum->syntax y (apply (lambda (head . body) (quasiquote (define-public (unquote (car head)) (procedure->memoizing-macro (lambda (cmd env) (apply (lambda (unquote (cdr head)) (unquote-splicing body)) (cdr cmd))))))) v)))))))
ice-9/psyntax.scm:2813:12: In procedure syntax-violation:
Syntax error:
kernel/boot/boot.scm:56:4: definition in expression context, where definitions are not allowed, in form (define-syntax define-public-macro (lambda (y) #f #((macro-type . defmacro) (defmacro-args args)) (syntax-case y () ((_ . args) (let ((v (syntax->datum (syntax args)))) (datum->syntax y (apply (lambda (head . body) (quasiquote (define-public (unquote (car head)) (procedure->memoizing-macro (lambda (cmd env) (apply (lambda (unquote (cdr head)) (unquote-splicing body)) (cdr cmd))))))) v)))))))
TeXmacs] debug-std, Evaluating /home/yibo/.TeXmacs/progs/my-init-texmacs.scm…

Backtrace:
In ice-9/boot-9.scm:
  1752:10 19 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
          18 (apply-smob/0 #<thunk 7ff8c7711340>)
In ice-9/boot-9.scm:
  1752:10 17 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
          16 (apply-smob/0 #<thunk 7ff8c484df60>)
In ice-9/eval.scm:
   721:20 15 (primitive-eval (use-modules (convert markdown #)))
In ice-9/psyntax.scm:
  1218:36 14 (expand-top-sequence (#<syntax:my-init-texmacs.scm:1:…>) …)
  1210:19 13 (parse _ (("placeholder" placeholder)) ((top) #(# # …)) …)
   259:10 12 (parse _ (("placeholder" placeholder)) (()) _ c&e (eval) …)
In ice-9/boot-9.scm:
  3935:20 11 (process-use-modules _)
   222:17 10 (map1 (((convert markdown init-markdown))))
  3936:31  9 (_ ((convert markdown init-markdown)))
  3327:17  8 (resolve-interface (convert markdown init-markdown) # _ …)
In ice-9/threads.scm:
    390:8  7 (_ _)
In ice-9/boot-9.scm:
  3253:13  6 (_)
In ice-9/threads.scm:
    390:8  5 (_ _)
In ice-9/boot-9.scm:
  3544:20  4 (_)
   2836:4  3 (save-module-excursion #<procedure 7ff8c483a900 at ice-…>)
  3564:26  2 (_)
In unknown file:
           1 (primitive-load-path "convert/markdown/init-markdown" #)
In ice-9/boot-9.scm:
  3984:13  0 (_)

ice-9/boot-9.scm:3984:13: Unbound variable: ahash-ref
Loading welcome message...
Creating 'no name' buffer...
TeXmacs] With linked TrueType support
TeXmacs] debug-std, Redefined color dark slate
TeXmacs] debug-std, #2F4F4F replaced by #483D8B
TeXmacs] debug-std, Redefined color light slate
TeXmacs] debug-std, #778899 replaced by #8470FF
TeXmacs] debug-std, Redefined color light goldenrod
TeXmacs] debug-std, #FAFAD2 replaced by #EEDD82
TeXmacs] debug-std, Evaluating /usr/local/share/TeXmacs/progs/init-buffer.scm...
Backtrace:
In ice-9/boot-9.scm:
  1752:10  9 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
           8 (apply-smob/0 #<thunk 7ff8c7711340>)
In ice-9/boot-9.scm:
  1752:10  7 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
           6 (apply-smob/0 #<thunk 7ff8c44ac5c0>)
In ice-9/eval.scm:
   279:15  5 (_ #f)
   191:35  4 (_ #f)
   191:35  3 (_ #f)
   187:27  2 (_ _)
   223:20  1 (proc #<directory (guile-user) 7ff8c7714c80>)
In unknown file:
           0 (%resolve-variable (7 . current-buffer) #<directory (gu…>)

ERROR: In procedure %resolve-variable:
Unbound variable: current-buffer
Throwing widget should be attached
-------------------------------------------------
Error message:
  widget should be attached

System information:
  TeXmacs version  : 2.1.4
  Built by         : debian
  Building date    : 2024-03-21T22:38:48
  Operating system : linux-gnu
  Vendor           : pc
  Processor        : x86_64
  Crash date       : Thu Mar 21 11:38:55 PM CST 2024

TeXmacs does not yet have a current view
Backtrace of C++ stack:
  texmacs.bin : () + 0x26daf4
  texmacs.bin : () + 0x12a1d9
  texmacs.bin : () + 0x2647ab
  texmacs.bin : () + 0x264d2f
  texmacs.bin : () + 0x269600
  texmacs.bin : () + 0x2697b7
  texmacs.bin : () + 0xfd82a
  texmacs.bin : () + 0x14e052
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : () + 0x5565c
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : () + 0x3ef6a
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : () + 0xc64e8
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : scm_call_n() + 0x169
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : scm_call_2() + 0x1a
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : () + 0xef292
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : scm_c_catch() + 0x3f
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : scm_c_with_continuation_barrier() + 0x96
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : () + 0xc1b89
  /lib/x86_64-linux-gnu/libgc.so.1 : GC_call_with_stack_base() + 0x25
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : scm_with_guile() + 0x28
  /lib/x86_64-linux-gnu/libguile-3.0.so.1 : scm_boot_guile() + 0x25
  texmacs.bin : () + 0x14e0a7
  texmacs.bin : () + 0x1001f2
  /lib/x86_64-linux-gnu/libc.so.6 : () + 0x2724a
  /lib/x86_64-linux-gnu/libc.so.6 : __libc_start_main() + 0x85
  texmacs.bin : () + 0xf9731

-------------------------------------------------
terminate called after throwing an instance of 'string'
[1]    29375 IOT instruction  texmacs -d

I guess the string code leads this error.Here is the string code:
#ifdef GUILE_D

// Guile-2 uses proper encoding of strings...
//
//  we have to hardcode some implementation details from libguile
// since we need to peek at the internals of strings
// in order to understand if they have a wide representation
// or can be smuggled into a latin1 encoding

// situation with strings is currently quite messy since TeXmacs uses its own
// encoding while guile >1.8 want an explicit standard exconding
// so we just inject everything into a latin1 (which allow to use 8-bits)
// with this default we have the problem of scheme strings which contains
// unicode chars, for example. They do not fit in 8-bit and some conversions is needed.
// in this case we just convert them into a proper latin1


#define STRINGBUF_F_WIDE        SCM_I_STRINGBUF_F_WIDE
#define STRINGBUF_F_MUTABLE     SCM_I_STRINGBUF_F_MUTABLE

#define STRINGBUF_WIDE(buf)     (SCM_CELL_WORD_0(buf) & STRINGBUF_F_WIDE)
#define STRING_STRINGBUF(str) (SCM_CELL_OBJECT_1(str))

/* (from libguile) True if the string is 'narrow', meaning it has a 8-bit Latin-1
   encoding.  False if it is 'wide', having a 32-bit UCS-4
   encoding.  */
int
scm_i_is_narrow_string (SCM str)
{
  return !STRINGBUF_WIDE (STRING_STRINGBUF (str));
}

string
tmscm_to_string (tmscm s) {
  guile_str_size_t len_r;
  char* _r;
  
  if (scm_i_is_narrow_string(s)) {
    _r = scm_scm2str (s, &len_r);
    string r (_r, len_r);
    #ifdef OS_WIN32
      scm_must_free(_r);
    #else
      free (_r);
    #endif
    return r;
  } else {
    _r = scm_to_utf8_stringn (s, &len_r);
    string r (_r, len_r);
    string rr= utf8_to_cork (r);
    #ifdef OS_WIN32
      scm_must_free(_r);
    #else
      free (_r);
    #endif
    return rr;
  }
}
#else
string
tmscm_to_string (tmscm s) {
  guile_str_size_t len_r;
  char* _r= scm_scm2str (s, &len_r);
  string r (_r, len_r);
  #ifdef OS_WIN32
    scm_must_free(_r);
  #else
    free (_r);
  #endif
  return r;
}
#endif // #ifdef GUILE_D

Can I compile the 2.1.4 version correctly with guile3? thanks a lot.

Take a look at this. I made sure it compiles and runs on Ubuntu 22.04.4 LTS long time ago and just reconfirmed it. You figure out packages needed on debian.

1 Like

thank you. This repo works well.

1 Like