digitalmars.D.learn - DerelictVorbis and string pointer
- ANtlord (39/39) Jun 23 2018 Hello D community!
- ANtlord (2/5) Jun 23 2018 It doesn't work
- Nicholas Wilson (4/10) Jun 23 2018 Vorbis is a C library, so you need to null terminate your string
- ANtlord (2/13) Jun 23 2018 It works! Thank you!
- rikki cattermole (2/53) Jun 23 2018 So where exactly is the null byte for the C string?
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
Jun 23 2018
On Sunday, 24 June 2018 at 01:26:48 UTC, ANtlord wrote:Actually I get it worked replacing `string filepath2` by `char[] filepath2` but filepath is string still and it works correctly.It doesn't work
Jun 23 2018
On Sunday, 24 June 2018 at 01:43:41 UTC, ANtlord wrote:On Sunday, 24 June 2018 at 01:26:48 UTC, ANtlord wrote:Vorbis is a C library, so you need to null terminate your string using toStringz. The reason why the one from the command line works is because it is already null terminate.Actually I get it worked replacing `string filepath2` by `char[] filepath2` but filepath is string still and it works correctly.It doesn't work
Jun 23 2018
On Sunday, 24 June 2018 at 01:54:52 UTC, Nicholas Wilson wrote:On Sunday, 24 June 2018 at 01:43:41 UTC, ANtlord wrote:It works! Thank you!On Sunday, 24 June 2018 at 01:26:48 UTC, ANtlord wrote:Vorbis is a C library, so you need to null terminate your string using toStringz. The reason why the one from the command line works is because it is already null terminate.Actually I get it worked replacing `string filepath2` by `char[] filepath2` but filepath is string still and it works correctly.It doesn't work
Jun 23 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/DerelictVorbisSo where exactly is the null byte for the C string?
Jun 23 2018