28 February 2022, 07:55 | #1 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
fd2pragma inline entry for function that returns pointer to another function
In my dynamic library I have added a function that returns a pointer to another function. The function to be returned has the following signature;
Code:
int func(int,int) Code:
int (*getMyFunction())(int,int); Code:
int (*)(int,int) __getFunction(__reg("a6") struct Library *)="\tjsr\t-36(a6)"; #define getFunction() __getFunction(MyLibBase) Code:
int (*__getFunction(__reg("a6") struct Library *))(int,int)="\tjsr\t-36(a6)"; #define getFunction() __getFunction(MyLibBase) |
28 February 2022, 14:19 | #2 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,564
|
This is certainly a bug in fd2pragma, but not trivial to fix.
Usually such function pointer types are avoided in dynamic libraries. Or simply replaced by APTR. I would suggest to define the function pointer return value type with a typedefin your clib header: Code:
typedef int (*MYFUNCTYPE)(int,int); Code:
MYFUNCTYPE getFunction(void); |
28 February 2022, 14:49 | #3 | |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
Using typedef is the first thing that I tried. However it seems fd2pragma does not support that as it gave me an error. Reading the documentation I found the following;
"fd2pragma knows all standard parameter types defined in exec/types.h and dos/dos.h, all structures and some more types. All other #typedef's bring a warning. Do not use them in prototypes files!" This is why I then took the other approach. Quote:
|
|
28 February 2022, 18:12 | #4 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,564
|
|
28 February 2022, 19:56 | #5 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
No it doesn't
It gives a warning and says it is going to handle the typedefs as int and then says it cannot find the prototype functions and finally says empty or partial file deleted. In short the inline file is not generated. I tried add the following to fd2pragma.types "MYFUNCTYPE : int (*)(int,int)" It does not seem to have worked. To be honest not a big fan of this solution as that would mean having to edit fd2pragma.types each time if trying to build on a new environment (at the moment placed it in C). |
28 February 2022, 21:41 | #6 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
|
01 March 2022, 10:49 | #7 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,564
|
Quote:
Quote:
Now I was curious and tried to reproduce it. Using the following clib header and FD file: Code:
frank@nerthus cat clib/my_protos.h typedef int (*MYFUNCTYPE)(int,int); MYFUNCTYPE GetFunction(void); frank@nerthus cat my_lib.fd ##base _MyBase ##bias 30 ##public GetFunction()() ##end Code:
frank@nerthus fd2pragma -s 38 -c clib/my_protos.h -i my_lib.fd SourceFile: my_lib.fd Warning 46 : Missing the types definition file. Using internal defaults. Warning 80 in line 1 of clib file: Unknown type of return value (typedef) handled as int. Warning 79 in line 1 of clib file: Unknown type of argument 1 (MYFUNCTYPE) handled as int. ResultFile: my.h frank@nerthus cat my.h #ifndef _PROTO_MY_H #define _PROTO_MY_H #ifndef EXEC_TYPES_H #include <exec/types.h> #endif #if !defined(CLIB_MY_PROTOS_H) && !defined(__GNUC__) #pragma stdargs-on #include <clib/my_protos.h> #pragma stdargs-off #endif #ifndef __NOLIBBASE__ extern struct Library *MyBase; #endif #ifdef __GNUC__ #ifdef __AROS__ #include <defines/my.h> #else #include <inline/my.h> #endif #elif defined(__VBCC__) #ifndef _NO_INLINE #include <inline/my_protos.h> #endif #else #include <pragma/my_lib.h> #endif #endif /* _PROTO_MY_H */ Code:
frank@nerthus fd2pragma -s 70 --voidbase -c clib/my_protos.h -i my_lib.fd SourceFile: my_lib.fd Warning 46 : Missing the types definition file. Using internal defaults. Warning 80 in line 1 of clib file: Unknown type of return value (typedef) handled as int. Warning 79 in line 1 of clib file: Unknown type of argument 1 (MYFUNCTYPE) handled as int. ResultFile: my_protos.h frank@nerthus cat my_protos.h #ifndef _VBCCINLINE_MY_H #define _VBCCINLINE_MY_H #ifndef EXEC_TYPES_H #include <exec/types.h> #endif MYFUNCTYPE __GetFunction(__reg("a6") void *)="\tjsr\t-30(a6)"; #define GetFunction() __GetFunction(MyBase) #endif /* _VBCCINLINE_MY_H */ |
||
01 March 2022, 11:55 | #8 |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 683
|
Maybe you could switch to sfdc and provide sfd files...
Code:
==base FooBase ==basetype struct Library * ==libname foo.library ==bias 42 ==public * Functions... void * foo(void (*fx)(int, int *)) (a1) Code:
#define foo(___fx) \ LP1FP(0x2a, void *, foo , __fpt, ___fx, a1,\ , FOO_BASE_NAME, void (*__fpt)(int,int * )) Code:
void * foo(void (* fx)(int,int * )); |
01 March 2022, 14:00 | #9 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,564
|
|
01 March 2022, 16:10 | #10 | |
bye
Join Date: Jun 2016
Location: Some / Where
Posts: 683
|
Quote:
oh, ok... projects/sfdc/sfdc --target=m68kvbcc-amigaos --mode=macros x.sfd Code:
#ifndef _INLINE_FOO_H #define _INLINE_FOO_H #ifndef _SFDC_VARARG_DEFINED #define _SFDC_VARARG_DEFINED #ifdef __HAVE_IPTR_ATTR__ typedef APTR _sfdc_vararg __attribute__((iptr)); #else typedef ULONG _sfdc_vararg; #endif /* __HAVE_IPTR_ATTR__ */ #endif /* _SFDC_VARARG_DEFINED */ void * __foo(__reg("a6") struct Library * , __reg("a1") void (* fx)(int,int * ) ) = "\tjsr\t-42(a6)"; #define foo(fx) __foo(FooBase, (fx)) void * __faa(__reg("a6") struct Library * , __reg("d0") int x , __reg("a1") void (* fx)(int,int * ) , __reg("a2") char * p ) = "\tjsr\t-48(a6)"; #define faa(x, fx, p) __faa(FooBase, (x), (fx), (p)) #endif /* !_INLINE_FOO_H */ |
|
01 March 2022, 22:13 | #11 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
|
02 March 2022, 10:38 | #12 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,564
|
Wow... that's new, isn't it?
So there is an alternative! Nice. Quote:
Code:
Ram Disk:> fd2pragma special 38 clib clib/my_protos.h my_lib.fd SourceFile: my_lib.fd Warning 80 in line 1 of clib file: Unknown type of return value (typedef) handled as int. Warning 79 in line 1 of clib file: Unknown type of argument 1 (MYFUNCTYPE) handled as int. ResultFile: my.h http://phoenix.owl.de/fd2pragma.tar.gz Or alternatively from the recent vbcc V0.9h binary archive. You can also try sfdc, as we learned from Bebbo, in case you have a cross-compiling environment with Perl installed somewhere. Nowadays you should prefer SFD files over FD anyway. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Function Vs Statement? | AF2013 | Coders. Blitz Basic | 6 | 11 December 2020 23:42 |
need help with modeid-function | Ratte | Coders. General | 6 | 17 August 2009 00:57 |
Mouse Master-function | sittingduck | request.UAE Wishlist | 8 | 26 February 2006 19:16 |
Snapshot function | Eny- | support.Apps | 4 | 16 July 2004 08:52 |
|
|