~ chicken-core (chicken-5) 42958bc3c9aa8bc6e195ae63ef787d70fec52032
commit 42958bc3c9aa8bc6e195ae63ef787d70fec52032
Author: Peter Bex <peter@more-magic.net>
AuthorDate: Sat Nov 4 18:40:26 2017 +0100
Commit: Evan Hanson <evhan@foldling.org>
CommitDate: Tue Nov 7 22:55:07 2017 +1300
Fix several C++ compilation issues.
- The compiler generates several calls to C functions that accept a
"char *" as type, but with string constants. Those must be wrapped
in C_text() to shut up these warnings, which get spammed like crazy:
"blah.cpp:1147:12: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]"
- When compiling a program with -debug-info or -d3, the resulting
binary will fail with a segfault due to unresolved symbols, which
are caused by name mangling: C_register_debug_info is defined
outside an extern "C" { ... } block.
- C_header_size returns a C_header, which is a C_uword. This results
in another warning from C_u_i_string_equal_p():
"chicken.h:2262:22:warning: comparison between signed and unsigned integer expressions [-Wsign-compare]"
Signed-off-by: Evan Hanson <evhan@foldling.org>
diff --git a/NEWS b/NEWS
index c849aede..d0927e58 100644
--- a/NEWS
+++ b/NEWS
@@ -145,6 +145,8 @@
- The scheduler no longer indirectly hangs on to the old thread
when switching to a new one, which caused excessive memory
consumption (#1367, thanks to "megane").
+ - C++ programs no longer fail with a symbol lookup error when
+ compiled with debugger support (-d3 or -debug-info).
- Syntax expander
- Renaming an identifier twice no longer results in an undo of the
diff --git a/c-backend.scm b/c-backend.scm
index d7b8844b..1f399de3 100644
--- a/c-backend.scm
+++ b/c-backend.scm
@@ -218,9 +218,9 @@
(cond [block
(if safe
(gen "lf[" index "]")
- (gen "C_retrieve2(lf[" index "],"
+ (gen "C_retrieve2(lf[" index "],C_text("
(c-ify-string (##sys#symbol->qualified-string
- (fourth params))) #\)) ) ]
+ (fourth params))) "))"))]
[safe (gen "*((C_word*)lf[" index "]+1)")]
[else (gen "C_fast_retrieve(lf[" index "])")] ) ) )
@@ -332,8 +332,8 @@
(set! carg (string-append "lf[" (number->string index) "]"))
(if safe
(gen "C_fast_retrieve_proc(" carg ")")
- (gen "C_retrieve2_symbol_proc(" carg ","
- (c-ify-string (##sys#symbol->qualified-string (fourth gparams))) #\)) ) )
+ (gen "C_retrieve2_symbol_proc(" carg ",C_text("
+ (c-ify-string (##sys#symbol->qualified-string (fourth gparams))) "))")))
(safe
(set! carg
(string-append "*((C_word*)lf[" (number->string index) "]+1)"))
@@ -742,15 +742,15 @@
[cstr (c-ify-string str)]
[len (##sys#size str)] )
(gen #t to "=")
- (gen "C_h_intern(&" to #\, len #\, cstr ");") ) )
+ (gen "C_h_intern(&" to #\, len ", C_text(" cstr "));")))
((null? lit)
(gen #t to "=C_SCHEME_END_OF_LIST;") )
((and (not (##sys#immediate? lit)) ; nop
(##core#inline "C_lambdainfop" lit)))
((or (fixnum? lit) (not (##sys#immediate? lit)))
- (gen #t to "=C_decode_literal(C_heaptop,")
+ (gen #t to "=C_decode_literal(C_heaptop,C_text(")
(gen-string-constant (encode-literal lit))
- (gen ");") )
+ (gen "));"))
(else (bad-literal lit))))
(define (gen-string-constant str)
@@ -959,9 +959,9 @@
(lambda (info)
(gen #t "{" (second info) ",0,")
(for-each
- (lambda (x)
- (gen "\"" (backslashify (->string x)) "\","))
- (cddr info))
+ (lambda (x)
+ (gen "C_text(\"" (backslashify (->string x)) "\"),"))
+ (cddr info))
(gen "},"))
(sort dbg-info-table (lambda (i1 i2) (< (car i1) (car i2)))))
(gen #t "{0,0,NULL,NULL}};\n"))
@@ -976,7 +976,7 @@
(lambda (p)
(let ((id (car p))
(ll (cdr p)))
- (gen #t "{\"" id #\: (string->c-identifier sf) "\",(void*)")
+ (gen #t "{C_text(\"" id #\: (string->c-identifier sf) "\"),(void*)")
(if (eq? 'toplevel id)
(gen "C_" (toplevel unit-name) "},")
(gen id "},") ) ) )
diff --git a/chicken.h b/chicken.h
index 400c80e2..dfe4bb1c 100644
--- a/chicken.h
+++ b/chicken.h
@@ -1651,10 +1651,7 @@ typedef struct C_DEBUG_INFO {
#define C_DEBUG_LISTEN 6
#define C_DEBUG_INTERRUPTED 7
-#define C_debugger(cell, c, av) (C_debugger_hook != NULL ? C_debugger_hook(cell, c, av, __FILE__, __LINE__) : C_SCHEME_UNDEFINED)
-
-C_fctexport void C_register_debug_info(C_DEBUG_INFO *);
-
+#define C_debugger(cell, c, av) (C_debugger_hook != NULL ? C_debugger_hook(cell, c, av, C_text(__FILE__), __LINE__) : C_SCHEME_UNDEFINED)
/* Variables: */
@@ -1719,6 +1716,7 @@ C_varextern C_TLS C_word (*C_get_unbound_variable_value_hook)(C_word sym);
C_BEGIN_C_DECLS
+C_fctexport void C_register_debug_info(C_DEBUG_INFO *);
C_fctexport int CHICKEN_main(int argc, char *argv[], void *toplevel);
C_fctexport int CHICKEN_initialize(int heap, int stack, int symbols, void *toplevel);
C_fctexport C_word CHICKEN_run(void *toplevel);
@@ -2577,9 +2575,7 @@ inline static C_ulong C_num_to_unsigned_long(C_word x)
inline static C_word C_u_i_string_equal_p(C_word x, C_word y)
{
- C_word n;
-
- n = C_header_size(x);
+ C_uword n = C_header_size(x);
return C_mk_bool(n == C_header_size(y)
&& !C_memcmp((char *)C_data_pointer(x), (char *)C_data_pointer(y), n));
}
Trap