digitalmars.D - strange problem with typeinfo (...) in functions from other files
- clayasaurus (15/15) Jul 18 2004 Hello all. I've made a global logging system that makes use of streams a...
- clayasaurus (3/3) Jul 18 2004 oh yes. I forgot to add that I'm using linux with the latest dmd (.95).
- clayasaurus (6/6) Jul 18 2004 trying to fix the problem, I made a function called
- clayasaurus (36/36) Jul 18 2004 heres some simple example code that illustrates the problem.
Hello all. I've made a global logging system that makes use of streams and TypeInfo (...). I'm also using multiple files for my projects. In the file that I declare main(), my logger works perfectly as expected. I just call gLog.info("Whatever I want ", 4, "me"); and I look in the .log file and it is in there just fine. However, when I call gLog.info from other files that don't have main in them, I get a segmentation fault. The reason I'm blaming the typeinfo _arguments and _argptr stuff is that, even when I comment out the functionality of my log.info(...) function, i still get segmentation faults. Also, when I replace log.info(...) with log.info(char[] message), it works just fine. The program doesn't crash. So, is there something about (...) that I don't know about and causes it to crash? thx.
Jul 18 2004
oh yes. I forgot to add that I'm using linux with the latest dmd (.95). My Log is a struct, and I declare the global within the the log module. So all i have to do is import log;
Jul 18 2004
trying to fix the problem, I made a function called char[] arguments(...), which takes a set of arguments and returns them as a char[], and passed this into my log function like log.info(arguments("my cool ", 7, " args")) it works within the file that holds main(), but in other files it causes a segmentation fault.
Jul 18 2004
heres some simple example code that illustrates the problem. i use the compile line 'dmd main.d argufile.d' //////////// main.d ////////////////////////////////////////// import argufile; int main(char [][] args) { char[] message = arguments("bob is ", 7, " years old"); writefln(message); // it works here argufile.useargs(); // will crash here return 0; } // argufile.d ////////////////////////////////////////////////// import std.stdio; import std.format; import std.utf; dchar[] formatstring(TypeInfo[] arguments, void *argptr) { dchar[] message = null; void putc(dchar c) { message ~= c; } std.format.doFormat(&putc, arguments, argptr); return message; } char[] arguments(...) // turns a bunch of arguments into a formatted char[] string { return toUTF8(formatstring(_arguments, _argptr)); } void useargs() { // crashes on this line char[] crashage = arguments("why is 8 scared of 7? because", 7,8,9); writefln(crashage); }
Jul 18 2004