Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-04

Get value of PPChar ?

16 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

fredvs

Hello.

A C method is defined like this:

MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta);

and translated in Pascal with this:

function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PPChar): integer;
cdecl;

OK, the function seems to work because the result = 0 (no error).

But how to retrieve the data icy_meta (PPChar) ?

var
theicytag : PPChar;
resu : integer;
...
resu := mpg123_icy(ahandle, theicytag);
if resu = 0 then writeln(theicytag^); --> raise exception + crash
resu := mpg123_icy(ahandle, theicytag);
if resu = 0 then writeln(theicytag^^); --> also raise exception + crash

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277.html Sent from the Free Pascal - General mailing list .

Reply by email

Andrew Haines
to fredvs
fredvs wrote 14 lines
K, the function seems to work because the result = 0 (no error). But how to retrieve the data icy_meta (PPChar) ? var theicytag : PPChar; resu : integer; ... resu := mpg123_icy(ahandle, theicytag); if resu = 0 then writeln(theicytag^); --> raise exception + crash resu := mpg123_icy(ahandle, theicytag); if resu = 0 then writeln(theicytag^^); --> also raise exception + crash

You haven't checked if theicytag is nil. The call to mpg123_icy may succeed but still the tag may be nil.

resu := mpg123_icy(ahandle, theicytag);
if (resu = 0) and Assigned(theicytag) and Assigned(theicytag^)
then writeln(theicytag^);

Regards,

Andrew

Reply by email

Christo Crause
to fredvs: Hello. A C method is defined like this: MPG123_EXPORT int mpg123_icy(mpg123_handle *mh,…

I suppose you have to allocate memory and create a pointer to a pointer to this memory which you pass to the function.

"fredvs" wrote 41 lines
Hello. A C method is defined like this: MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta); and translated in Pascal with this: function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PPChar): integer; cdecl; OK, the function seems to work because the result = 0 (no error). But how to retrieve the data icy_meta (PPChar) ? var theicytag : PPChar; resu : integer; ... resu := mpg123_icy(ahandle, theicytag); if resu = 0 then writeln(theicytag^); --> raise exception + crash resu := mpg123_icy(ahandle, theicytag); if resu = 0 then writeln(theicytag^^); --> also raise exception + crash Fre;D ----- Many thanks ;-) -- View this message in context: http://free-pascal-general. 1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277.html Sent from the Free Pascal - General mailing list . _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

fredvs
to Andrew Haines: You haven't checked if theicytag is nil. The call to mpg123_icy may succeed but still the…

Free Pascal - General mailing list wrote

resu := mpg123_icy(ahandle, theicytag); if (resu = 0) and Assigned(theicytag) and Assigned(theicytag^) then writeln(theicytag^);

Hello and thanks for answer.

Indeed, that way no more crash but also nothing from writeln(theicytag^).

I did a check with this:

resu := mpg123_icy(ahandle, theicytag);

if (resu = 0) then writeln('resu = ' + inttostr(resu)); ---> OK

if Assigned(theicytag) then writeln('theicytag = assigned') else writeln('theicytag NOT assigned') ; ---> theicytag NOT assigned

if Assigned(theicytag^) then writeln('theicytag^ = assigned') else writeln('theicytag^ NOT assigned') ; ---> raise exception + crash

?

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277p5728280.html Sent from the Free Pascal - General mailing list .

Reply by email

Sven Barth
to fredvs: Hello. A C method is defined like this: MPG123_EXPORT int mpg123_icy(mpg123_handle *mh,…
fredvs wrote 10 lines
Hello. A C method is defined like this: MPG123_EXPORT int mpg123_icy(mpg123_handle *mh, char **icy_meta); and translated in Pascal with this: function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PPChar): integer; cdecl;

This is wrong. "var" essentially results in a "char***".

What you want is either

function mpg123_icy(mh: Tmpg123_handle; icy_meta: PPChar): integer; cdecl;

or

function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PChar): Integer;
cdecl;

And how you'll need to use it will depend upon the function's documentation: if the function will allocate the buffer then you simply need to pass in a PChar variable (second case) or a pointer to one (first case). If you need to allocate the buffer yourself then you first need to do a GetMem with an appropriate size before you do the same.

Regards,
Sven

Reply by email

fredvs
to Christo Crause: I suppose you have to allocate memory and create a pointer to a pointer to this memory…

Christo Crause wrote

I suppose you have to allocate memory and create a pointer to a pointer to this memory which you pass to the function.

Hello and thanks for answer.

Huh, ok, but how do you do this by code ?

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277p5728282.html Sent from the Free Pascal - General mailing list .

Reply by email

fredvs
to Sven Barth: This is wrong. "var" essentially results in a "char***". What you want is either function…

Free Pascal - General mailing list wrote

function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PChar): Integer; cdecl;

Thanks for your answer.

I did try with this but :

 res := mpg123_icy(mph,theicytag);
if (res = 0) then writeln('resu = ' + inttostr(res));  // OK = 0
if Assigned(theicytag) then writeln('theicytag = assigned')
else writeln('theicytag NOT assigned') ; /// always theicytag NOT assigned

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277p5728283.html Sent from the Free Pascal - General mailing list .

Reply by email

Bart
to fredvs
fredvs wrote
if (res = 0) then writeln('resu = ' + inttostr(res)); // OK = 0

That just creams my corn!

If you know that res equals 0, then a simple writeln('resu = 0'); would suffice. Second, there is no need do an inttostr(res) inside write(ln). Write(ln) is perfectly capable of writing integers (as it has been from the very first start).

Bart

Reply by email

fredvs
to Bart

Bart-48 wrote

If you know that res equals 0, then a simple writeln('resu = 0'); would suffice. Second, there is no need do an inttostr(res) inside write(ln). Write(ln) is perfectly capable of writing integers (as it has been

Huh, of course I know all this, sorry, I just mixed copy paste of some code.

So the problem remain, why icydata is never assigned ? (even with a result = 0).

Should it by assigned before, .(assigning memory) ?

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277p5728285.html Sent from the Free Pascal - General mailing list .

Reply by email

fredvs
to Sven Barth: This is wrong. "var" essentially results in a "char***". What you want is either function…
And how you'll need to use it will depend upon the function's documentation

Huh, you did not know ?

With audio libraries there is a law: NO doc (other that the C header) and NO demos.

So you must guess and explore all by your self.

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277p5728286.html Sent from the Free Pascal - General mailing list .

Reply by email

Sven Barth
to fredvs: Free Pascal - General mailing list wrote Thanks for your answer. I did try with this but :
fredvs wrote 14 lines
Free Pascal - General mailing list wrote > function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PChar): Integer; > cdecl; Thanks for your answer. I did try with this but : res := mpg123_icy(mph,theicytag); if (res = 0) then writeln('resu = ' + inttostr(res)); // OK = 0 if Assigned(theicytag) then writeln('theicytag = assigned') else writeln('theicytag NOT assigned') ; /// always theicytag NOT assigned

According to the code it also returns 0 with icy_meta being Nil if there is no corresponding data:
https://github.com/georgi/mpg123/blob/master/src/libmpg123/libmpg123.c#L1384

Regards,
Sven

Reply by email

fredvs
to Sven Barth

Free Pascal - General mailing list wrote

According to the code it also returns 0 with icy_meta being Nil if there is no corresponding data: https://github.com/georgi/mpg123/blob/master/src/libmpg123/libmpg123.c#L1384

Ha, nice, you did find the only doc available : the source code (that contains no comment, of course ;-) )

Yep, this would solve everything.
In fact solve nothing because the code was ok then ;-)

OK, I keep the doubt that this web-radio is not sending ivy like they say:

http://stream-uk1.radioparadise.com/mp3-128

Thanks Sven.

Fre;D

PS: If somebody knows a web-radio that really sent ivy-data, you are welcome to give the url (to test it).

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277p5728288.html Sent from the Free Pascal - General mailing list .

Reply by email

Sven Barth
"fredvs" wrote 5 lines
Free Pascal - General mailing list wrote > According to the code it also returns 0 with icy_meta being Nil if there > is no corresponding data: >

https://github.com/georgi/mpg123/blob/master/src/libmpg123/libmpg123.c#L1384

Show quoted text 6 lines
Ha, nice, you did find the only doc available : the source code (that contains no comment, of course ;-) ) Yep, this would solve everything. In fact solve nothing because the code was ok then ;-)

No, your "var PPChar" was still wrong. It's either "var PChar" or "PPChar" and nothing else.

Regards,
Sven

Reply by email

fredvs
to Sven Barth

Free Pascal - General mailing list wrote

No, your "var PPChar" was still wrong. It's either "var PChar" or "PPChar" and nothing else.

Huh, in last commit (5e680a4 10 hours ago) --->

https://github.com/fredvs/uos/blob/master/src/uos_mpg123.pas#L673

Fre;D

PS: Do you agree if I add you to the great contributors ?

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Get-value-of-PPChar-tp5728277p5728290.html Sent from the Free Pascal - General mailing list .

Reply by email

Jürgen Hestermann
to fredvs: Huh, you did not know ? With audio libraries there is a law: NO doc (other that the C…
fredvs wrote
> And how you'll need to use it will depend upon the function's documentation With audio libraries there is a law: NO doc (other that the C header) and NO demos. So you must guess and explore all by your self.

Now that's a useful working mode!
No bugs will ever exist because no code
behaviour can violate the documentation!

How programming has degraded...

Reply by email