DerelictVorbis and string pointer

rikki cattermole rikki at cattermole.co.nz
Sun Jun 24 01:55:00 UTC 2018


On 24/06/2018 1:26 PM, ANtlord wrote:
> Hello D community!
> 
> I'm developing an application that must work on audio especially 
> playback Ogg files. So I took library DerelictVorbis [0] testing basic 
> functions like `ov_fopen`. The tests were successful so I decided to 
> implement core components of the application using D and Derelict 
> libraries.
> 
> Today I encountered a problem, the `ov_fopen` returns -1 instead of 0. 
> It means that something goes wrong and the file that is pointed by a 
> string is not opened. I figured out it so there is the error is not 
> occurred when a file path is pointed by a string variable from CLI input 
> arguments but it is occurred when the path is pointed by a string 
> variable filled dynamically (for example file path is read from another 
> file).
> 
> Here code goes
> 
> public import derelict.vorbis;
> public import derelict.vorbis.file;
> 
> void main(string[] args) {
>      DerelictVorbis.load();
>      DerelictVorbisFile.load();
>      OggVorbis_File _ovFile;
> 
>      immutable filepath = args[1];
> 
> 
>      import std.file;
>      import std.string;
>      string filepath2 = "./name.txt".readText.strip;
>      assert(filepath2 == filepath);
>      int res = ov_fopen(filepath2.ptr, &_ovFile); // res == -1
>      // int res = ov_fopen(filepath.ptr, &_ovFile); // res == 0
>      assert(res == 0, "ov_fopen returns %d".format(res));
> }
> 
> Actually I get it worked replacing `string filepath2` by `char[] 
> filepath2` but filepath is string still and it works correctly.
> 
> So what detail The devil is in? Is there an issue in DerelictVorbis or 
> in compiler. Don't I know something about implementation of strings or 
> pointers in D?
> 
> Thanks in advance!
> 
> DMD 2.080
> DerelictVorbis 2.0.0-beta.2
> 
> [0] https://github.com/DerelictOrg/DerelictVorbis

So where exactly is the null byte for the C string?


More information about the Digitalmars-d-learn mailing list