chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] Fix compilation warnings and a runtime segfaul


From: Peter Bex
Subject: [Chicken-hackers] [PATCH] Fix compilation warnings and a runtime segfault with C++
Date: Sat, 4 Nov 2017 19:17:33 +0100
User-agent: NeoMutt/20170113 (1.7.2)

Hi all,

I was working with some C++ code and I got lots and lots of warnings on
my terminal like this:

test.cpp:175:58: warning: ISO C++ forbids converting a string constant to 
‘char*’ [-Wwrite-strings]
 lf[4]=C_h_intern(&lf[4],25,"\003sysimplicit-exit-handler");
                                                          ^
test.cpp: At global scope:
test.cpp:191:12: warning: ISO C++ forbids converting a string constant to 
‘char*’ [-Wwrite-strings]
 {NULL,NULL}};
            ^
test.cpp:191:12: warning: ISO C++ forbids converting a string constant to 
‘char*’ [-Wwrite-strings]
test.cpp:191:12: warning: ISO C++ forbids converting a string constant to 
‘char*’ [-Wwrite-strings]
test.cpp:191:12: warning: ISO C++ forbids converting a string constant to 
‘char*’ [-Wwrite-strings]
test.cpp:191:12: warning: ISO C++ forbids converting a string constant to 
‘char*’ [-Wwrite-strings]

This is quite noisy and annoying, causing real issues to disappear.
It's easily fixed by wrapping all the strings in C_text() calls, so that
they're casted to char *, even though that's not really a "proper" fix
we do that everywhere.  And trying to get everything const-correct is
a hell of a job, not to mention a breaking API change (if there are any
takers who want fix this in CHICKEN 5, now's the time!)

After having fixed those warnings, I got a runtime error (segfault) due
to a symbol being undefined (though with CHICKEN 5 I got a linking error),
the function C_register_debug_info was added at the top of the chicken.h
file, where it wasn't wrapped in extern "C" { ... }, so it gets
name-mangled by the C++ compiler.  I just moved it down to the rest of the
function prototypes, which are wrapped in such a block (via C_BEGIN_C_DECLS).
This error happens only when compiling with -debug-info, BTW.

This is something that I encountered with CHICKEN 4 while working on an
actual project, so I think it's definitely worth fixing in both branches,
so I attached two patches.

I might've missed a few string constants; I don't really know how to
easily find them, except by accidentally writing code which happens to
trigger generated C that emits such warnings.

Cheers,
Peter

Attachment: 0001-Fix-several-C-compilation-issues.chicken-5.patch
Description: Text Data

Attachment: 0001-Fix-several-C-compilation-issues.master.patch
Description: Text Data

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]