digitalmars.D.learn - The reason for SIGSEGV function pointer problem
- Russel Winder via Digitalmars-d-learn (28/28) Jun 07 2017 OK, so I have narrowed down my SIGSEGV problem to having no real idea
- Paolo Invernizzi (3/6) Jun 07 2017 You should remove the pointer here...
- ag0aep6g (3/4) Jun 07 2017 It's a thing of type `check_frontend_t`, which is a function pointer
- Mike Wey (13/14) Jun 07 2017 AFAIK, you would usually translate:
- Russel Winder via Digitalmars-d-learn (22/41) Jun 08 2017 Thanks also to Paolo Invernizzi=C2=A0and ag0aep6g for answering with a
OK, so I have narrowed down my SIGSEGV problem to having no real idea how to do C function pointers in D code. So I have a callback function that will be called from C library code. It currently has signature: extern(C) int checkFrontend(void* _arguments, dvb_v5_fe_parms* frontendParameters) because of the extern(C) I believe you have to use a type alias in order to specify the type in function definitions. Hence: alias check_frontend_t = extern(C) int function (void* args, dvb_v5_fe_parms* parms); In the constructor of an object to abstract the result of a call to the C library code, the parameter is: check_frontend_t* cf in the creation of the object using the constructor, I am using the argument: &checkFrontend However. This gives me a type error: extern (C) int function(void*, dvb_v5_fe_parms*)* cf is not callable using argument type: extern (C) int function(void*, dvb_v5_fe_parms*) all the other arguments/parameters types match exactly, this is the only difference. So why isn't &checkFrontend a thing of type check_frontend_t*? -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jun 07 2017
On Wednesday, 7 June 2017 at 16:50:26 UTC, Russel Winder wrote:In the constructor of an object to abstract the result of a call to the C library code, the parameter is: check_frontend_t* cfYou should remove the pointer here... /Paolo
Jun 07 2017
On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote:So why isn't &checkFrontend a thing of type check_frontend_t*?It's a thing of type `check_frontend_t`, which is a function pointer already. When you add an asterisk, you get a pointer to a function pointer.
Jun 07 2017
On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote:So why isn't &checkFrontend a thing of type check_frontend_t*AFAIK, you would usually translate: typedef int (check_frontend_t*)(void *args, struct dvb_v5_fe_parms *parms); into: alias check_frontend_t = extern(C) int function (void* args, dvb_v5_fe_parms* parms); The problem there is that libdvdv5 defines it as (check_frontend_t) and not (check_frontend_t*). To get around that you can ommit the * in the declaration of dvb_scan_transponder, and then you should be able to pass &checkFrontend to it. -- Mike Wey
Jun 07 2017
Thanks also to Paolo Invernizzi=C2=A0and ag0aep6g for answering with a similar response. Using Mike's response as it has extra detail. On Wed, 2017-06-07 at 20:00 +0200, Mike Wey via Digitalmars-d-learn wrote:On 06/07/2017 06:50 PM, Russel Winder via Digitalmars-d-learn wrote:The C code in dvb-scan.h is actually: typedef int (check_frontend_t)(void *args, struct dvb_v5_fe_parms *parms);So why isn't &checkFrontend a thing of type check_frontend_t*=20 AFAIK, you would usually translate: =20 =20 typedef int (check_frontend_t*)(void *args, struct dvb_v5_fe_parms *parms);into: =20 alias check_frontend_t =3D extern(C) int function (void* args,=C2=A0 dvb_v5_fe_parms* parms);I can't remember what DStep produced initially, but the above is what I have in dvb_scan.d. Per se it seems consistent, but then functions in D, and their signatures, may be totally different to functions in C.The problem there is that libdvdv5 defines it as (check_frontend_t) and=C2=A0 not (check_frontend_t*). To get around that you can ommit the * in the declaration of=C2=A0 dvb_scan_transponder, and then you should be able to pass &checkFrontend=C2=A0 to it.I am now at the stage of wondering if I remember C semantics, C++ semantics, and D semantics for "pointers to functions". There may also be an issue of there being a bug in DStep=E2=80=A6 --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jun 08 2017