Re: std.conv.to!string refuses to convert a char* to string.

2017-12-09 Thread Venkat via Digitalmars-d-learn
Thank you, core.runtime.Runtime.initialize() fixed the issue. I 
am now able to use to!string as well. I found your posts and Ali 
Çehreli's posts on this subject. I think I have some 
understanding now.


Re: std.conv.to!string refuses to convert a char* to string.

2017-12-09 Thread Mike Parker via Digitalmars-d-learn

On Saturday, 9 December 2017 at 06:14:36 UTC, Venkat wrote:
Thanks for the quick response. std.string.fromStringz did the 
trick. I am not sure what was the deal with to!string.


Be careful with fromStringz. It doesn't allocate a new string, so 
the returned string can easily become corrupted if the C string 
it's referencing falls off the stack.


As for your problem with to!string, it isn't actually to!string 
that's the issue. It appears to have something to do with the 
memory allocated from the GC. I assume this is a shared library. 
Random thoughts -- Have you initialized DRuntime? Have you 
registered the calling thread with the GC?


Re: std.conv.to!string refuses to convert a char* to string.

2017-12-08 Thread Venkat via Digitalmars-d-learn
Thanks for the quick response. std.string.fromStringz did the 
trick. I am not sure what was the deal with to!string.


Re: std.conv.to!string refuses to convert a char* to string.

2017-12-08 Thread Neia Neutuladh via Digitalmars-d-learn

On Saturday, 9 December 2017 at 05:55:21 UTC, Venkat wrote:
I am trying out the DJni library 
(https://github.com/Monnoroch/DJni). For some reason 
std.conv.to!string doesn't want to convert a char* to a 
string.The lines below are taken from the log. I see that the 
last frame is at gc_qalloc. I am not sure why it failed there. 
Can anybody elaborate on what is going on here ? Thanks in 
advance.


I've got no idea, but can you verify that you can print it with 
printf? Can you allocate other GC memory? Can you try using 
fromStringz instead of to!string and see what that does?


Just shots in the dark...