From 47842ccc8b60c2c0a5215b0274985d811bdf1a51 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sat, 4 Nov 2017 18:40:26 +0100 Subject: [PATCH] Fix several C++ compilation issues. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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]" --- NEWS | 2 ++ c-backend.scm | 18 +++++++++--------- chicken.h | 10 +++------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index 397fd532..48a48402 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,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 3e742c9f..18052078 100644 --- a/c-backend.scm +++ b/c-backend.scm @@ -190,9 +190,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 "])")] ) ) ) @@ -304,8 +304,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)")) @@ -707,15 +707,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) @@ -925,7 +925,7 @@ (gen #t "{" (second info) ",0,") (for-each (lambda (x) - (gen "\"" (backslashify (->string x)) "\",")) + (gen "C_text(\"" (backslashify (->string x)) "\"),")) (cddr info)) (gen "},")) (sort dbg-info-table (lambda (i1 i2) (< (car i1) (car i2))))) @@ -939,7 +939,7 @@ #t "static C_PTABLE_ENTRY ptable[" (add1 (##sys#hash-table-size lambda-table)) "] = {") (##sys#hash-table-for-each (lambda (id ll) - (gen #t "{\"" id #\: (string->c-identifier sf) "\",(void*)") + (gen #t "{C_text(\"" id #\: (string->c-identifier sf) "\"),(void*)") (if (eq? 'toplevel id) (if unit-name (gen "C_" unit-name "_toplevel},") diff --git a/chicken.h b/chicken.h index 4ecb52cc..ef62fd4d 100644 --- a/chicken.h +++ b/chicken.h @@ -1613,10 +1613,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: */ @@ -1674,6 +1671,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); @@ -2256,9 +2254,7 @@ C_inline C_ulong C_num_to_unsigned_long(C_word x) C_inline 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)); } -- 2.11.0