Get value of PPChar ?

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Get value of PPChar ?

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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

Free Pascal - General mailing list
On 04/16/2017 10:58 AM, fredvs wrote:

> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

Christo Crause
In reply to this post by fredvs

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

On 16 Apr 2017 4:58 PM, "fredvs" <[hidden email]> wrote:
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 archive at Nabble.com.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
In reply to this post by Free Pascal - General mailing list
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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

Free Pascal - General mailing list
In reply to this post by fredvs
On 16.04.2017 16:58, fredvs wrote:

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
In reply to this post by Christo Crause
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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
In reply to this post by Free Pascal - General mailing list
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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

Bart-48
On 4/16/17, fredvs <[hidden email]> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
In reply to this post by Free Pascal - General mailing list
>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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

Free Pascal - General mailing list
In reply to this post by fredvs
On 16.04.2017 18:52, fredvs wrote:

> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

Free Pascal - General mailing list

Am 17.04.2017 00:47 schrieb "fredvs" <[hidden email]>:
>
> 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 ;-)

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

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
This post was updated on .
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 list of great contributors ?

Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

fredvs
Hello.

For those who are interested, Thomas Orgis (the creator of mpg123) did answer: --->

https://sourceforge.net/p/mpg123/bugs/248/

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Get value of PPChar ?

Jürgen Hestermann
In reply to this post by fredvs
Am 2017-04-16 um 19:45 schrieb fredvs:
 >> 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...

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal