~ chicken-core (chicken-5) 5746f0c13a7278a5afecb690cc18df268e229d4e


commit 5746f0c13a7278a5afecb690cc18df268e229d4e
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:17:46 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 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..c3493ddb 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));
 }
Trap