Who's Online
199 user(s) are online (
183 user(s) are browsing
Forums )
Members: 0
Guests: 199
more...
Topic options
View mode
Newest First
RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/3 16:30
#1
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
We have done such a cross-platform function just like done in example of SDI_stdargs.c:
#include <SDI_stdarg.h>
#include <proto/exec.h>
void LSprintf ( char * buffer , char * string , APTR data )
{
void * stuffchar = "\x16\xc0\x4e\x75" ; // MOVE.B D0,(A3)+ | RTS
#if defined(__amigaos4__)
stuffchar = NULL ;
#endif
RawDoFmt ( string , data , NULL , buffer );
}
void VARARGS68K lsprintf ( char * buf , char * fmt , ...)
{
void * stuffchar = "\x16\xc0\x4e\x75" ; // MOVE.B D0,(A3)+ | RTS
#if defined(__amigaos4__)
stuffchar = NULL ;
#endif
VA_LIST args ;
VA_START ( args , fmt );
RawDoFmt ( fmt , VA_ARG ( args , void *), stuffchar , buf );
VA_END ( args );
// return(strlen(buf));
}
On gcc 4.2.4 its just bring a warning
Quote:
lsprintf.c:25: warning: __builtin_getlinearva can only be used in a linearvarargs functionBut still compiles ok (line 25 is that RawDoFmt call at end).
On gcc 4.4.3 on the same code it change warning on error now, and :
Quote:
lsprintf.c:25: error: __builtin_getlinearva can only be used in a linearvarargs function lsprintf.c:25: confused by earlier errors, bailing outCan someone point out of how to make it warning/error less ?
All what i can find out its 1 link in google, where Cyborg meet with the same warning, and somehow fix it, but as code is no more available (that was Amirc), so i can see what he do. Only few links:
https://www.ohloh.net/p/amirc/commits/160123982 - problem
https://www.ohloh.net/p/amirc/commits/160123992 - kind of fix
Edited by kas1e on 2013/4/5 8:22:48
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Posted on:
2013/4/3 17:07
#2
Home away from home
Joined: 2006/12/4 23:15Last Login
: 10/14 16:04
Group:
Registered Users
@kas1e Solution 1. Check your macros particularly VARARGS68K are defined correctly for each OS (try compileing with -E option and see what is output) Solution 2. Utility the version 50 IUtility->SNPrintf() function Somthing like #define lsprintf(buffer,fmt,data, ...) SNPrintf(buffer, sizeof(buffer),fmt,__VARAGS__) That macro is wrong but you can look up simalar ones to fix it.
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Posted on:
2013/4/3 19:02
#3
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
@Andy
Quote:
Check your macros particularly VARARGS68K are defined correctly for each OS Already done by SDI, and seems ok for all other times.
Quote:
Utility the version 50 IUtility->SNPrintf() functionShould be crossplatform (i.e. SDI)
Quote:
#define lsprintf(buffer,fmt,data, ...) SNPrintf(buffer, sizeof(buffer),fmt,__VARAGS__)With defines there a lot of other problems like one function one it there, another there, everything done like it want it as function.
As i read on the Cyborg's posts, he fix it somehow by casting, but by what casting and where - dunno.
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Posted on:
2013/4/3 20:06
#4
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@kas1e Make sure that <amiga_compiler.h> is included before any SDI includes. If it's not the SDI definition of VARARGS68K will be used which IIRC is just: #ifndef VARARGS68K #define VARARGS68K #endif
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Posted on:
2013/4/4 5:23
#5
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
@Fredrik
Quote:
Make sure that <amiga_compiler.h> is included before any SDI includes.Yeah, that helps, thanks !
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Posted on:
2013/4/5 8:25
#6
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
@all
Can anyone help with STDARGS to VARARGS + SDI conversion ?
Thats what we have originally:
void STDARGS L_GT_SetGadgetAttrs ( struct Gadget * gad , struct Window * win , ULONG tag1 ,...);
void STDARGS L_SetGadgetAttrs ( struct Gadget * gad , struct Window * win , Tag tag ,...);
void STDARGS L_GT_SetGadgetAttrs (
struct Gadget * gad ,
struct Window * win ,
Tag tag1 ,...)
{
GT_SetGadgetAttrsA ( gad , win , 0 ,( struct TagItem *)& tag1 );
}
void STDARGS L_SetGadgetAttrs (
struct Gadget * gad ,
struct Window * win ,
Tag tag ,...)
{
SetGadgetAttrsA ( gad , win , 0 ,( struct TagItem *)& tag );
}
As you can see even if name of functions kind of the same as in SDks, its still different with different params, so simply redefine non-go there.
So, we do such replacement:
void VARARGS68K L_GT_SetGadgetAttrs ( struct Gadget * gad , struct Window * win , Tag tag1 ,...);
void VARARGS68K L_SetGadgetAttrs ( struct Gadget * gad , struct Window * win , Tag tag ,...);
void VARARGS68K L_GT_SetGadgetAttrs (
struct Gadget * gad ,
struct Window * win ,
Tag tag1 ,...)
{
VA_LIST args ;
VA_START ( args , tag1 );
GT_SetGadgetAttrsA ( gad , win , NULL , VA_ARG ( args , struct TagItem *));
VA_END ( args );
}
void VARARGS68K L_SetGadgetAttrs (
struct Gadget * gad ,
struct Window * win ,
Tag tag ,...)
{
VA_LIST args ;
VA_START ( args , tag );
SetGadgetAttrsA ( gad , win , NULL , VA_ARG ( args , struct TagItem *));
VA_END ( args );
}
But that didn't works. Can anyone point out how it should be done ? Should be exactly SDI to make it works on all platforms.
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Posted on:
2013/4/5 8:59
#7
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@kas1e
It doesn't work because the tag/tag1 parameter should be a part of the varargs parameter ('...') and not be defined separately.
void VARARGS68K L_GT_SetGadgetAttrs ( struct Gadget * gad , struct Window * win ,...);
void VARARGS68K L_SetGadgetAttrs ( struct Gadget * gad , struct Window * win ,...);
void VARARGS68K L_GT_SetGadgetAttrs (
struct Gadget * gad ,
struct Window * win ,
...)
{
VA_LIST args ;
VA_START ( args , win );
GT_SetGadgetAttrsA ( gad , win , NULL , VA_ARG ( args , struct TagItem *));
VA_END ( args );
}
void VARARGS68K L_SetGadgetAttrs (
struct Gadget * gad ,
struct Window * win ,
...)
{
VA_LIST args ;
VA_START ( args , win );
SetGadgetAttrsA ( gad , win , NULL , VA_ARG ( args , struct TagItem *));
VA_END ( args );
}
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 9:52
#8
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
@salas00
It works! Thanks a lot !
May i ask you please to convert also those ones (i anyway understand nothing with that varargs/stdargs crap, just will copy + paste it):
APTR STDARGS my_NewObject (Class *class, UBYTE * classid , Tag tag ,...);
APTR STDARGS L_NewObject (Class *,Class *, UBYTE *, Tag ,...);
// varargs NewObject
APTR STDARGS my_NewObject (
Class *class,
UBYTE * classid , Tag tag ,...)
{
return NewObjectA (class, classid ,( struct TagItem *)& tag );
}
// varargs NewObject
APTR STDARGS L_NewObject (
Class * cl ,
Class *class,
UBYTE * classid , Tag tag ,...)
{
return NewObjectA (class, classid ,( struct TagItem *)& tag );
}
As well as those 3 which a bit different:
struct Process * launcher_CreateNewProcTags ( struct LibData * data , Tag tag1 ,...);
LONG launcher_SystemTags ( struct LibData * data , char * command , Tag tag1 ,...);
ErrorNode * STDARGS launch_error ( struct LibData * data , LaunchPacket * packet , short , short , char * args ,...);
// varargs CreateNewProcTags
struct Process * launcher_CreateNewProcTags ( struct LibData * data , Tag tag1 ,...)
{
return CreateNewProc (( struct TagItem *)& tag1 );
}
// varargs SystemTags
LONG launcher_SystemTags ( struct LibData * data , char * command , Tag tag1 ,...)
{
return SystemTagList ( command ,( struct TagItem *)& tag1 );
}
ErrorNode * STDARGS launch_error ( struct LibData * data , LaunchPacket * packet , short msg , short buttons , char * args ,...)
{
ErrorNode * error ;
..... blablab ..
return error ;
}
Currently we replace it like this:
#define L_NewObject NewObject
#define my_NewObject NewObject
#define launcher_CreateNewProcTags(base, ...) CreateNewProcTags(__VA_ARGS__)
#define launcher_SystemTags(base, ...) SystemTags(__VA_ARGS__)
but dunno about launch_error() as well as m_newObject and L_newobject should be different, as well as "defines" looks crappy and better to do everything via VARARGS68K way so to keep the same look of sources.
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 10:48
#9
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
Since the L_NewObject() function has an unused first parameter (cl) which isn't passed on to NewObjectA() a more correct macro definition would be: #define L_NewObject(cl, ...) NewObject(__VA_ARGS__) As for launch_error() it's hard to say without knowing what the code in the '.....blablab..' part is.
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 10:51
#10
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
Quote:
As for launch_error() it's hard to say without knowing what the code in the '.....blablab..' part is.
// Signal an error
ErrorNode * STDARGS launch_error ( struct LibData * data , LaunchPacket * packet , short msg , short buttons , char * args ,...)
{
ErrorNode * error ;
struct EasyStruct easy ;
struct Window * parent = 0 ;
// No errors?
if ( packet && packet -> errors ==( struct Screen *)- 1 )
return 0 ;
// Allocate error node
if (!( error = AllocVec ( sizeof ( ErrorNode ), MEMF_CLEAR )))
return 0 ;
// Fill out requester struct
easy . es_StructSize = sizeof ( easy );
easy . es_Flags = 0 ;
easy . es_Title = "Directory Opus" ;
easy . es_TextFormat = GetString (& data -> locale , msg );
easy . es_GadgetFormat = GetString (& data -> locale , buttons );
// Get parent window
if ( packet && packet -> errors )
parent = packet -> errors -> FirstWindow ;
// Display error
if (!( error -> window = BuildEasyRequestArgs ( parent ,& easy , 0 ,& args )))
{
// Failed
if ( packet ) DisplayBeep ( packet -> errors );
FreeVec ( error );
return 0 ;
}
// Get bit to wait on
data -> error_wait |= 1 << error -> window -> UserPort -> mp_SigBit ;
// Add to error list
AddTail (( struct List *)& data -> error_list ,( struct Node *) error );
return error ;
}
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 12:25
#11
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
// Signal an error
ErrorNode * VARARGS68K launch_error ( struct LibData * data , LaunchPacket * packet , short msg , short buttons ,...)
{
ErrorNode * error ;
struct EasyStruct easy ;
struct Window * parent = 0 ;
VA_LIST args ;
// No errors?
if ( packet && packet -> errors ==( struct Screen *)- 1 )
return 0 ;
// Allocate error node
if (!( error = AllocVec ( sizeof ( ErrorNode ), MEMF_CLEAR )))
return 0 ;
// Fill out requester struct
easy . es_StructSize = sizeof ( easy );
easy . es_Flags = 0 ;
easy . es_Title = "Directory Opus" ;
easy . es_TextFormat = GetString (& data -> locale , msg );
easy . es_GadgetFormat = GetString (& data -> locale , buttons );
// Get parent window
if ( packet && packet -> errors )
parent = packet -> errors -> FirstWindow ;
VA_START ( args , buttons );
error -> window = BuildEasyRequestArgs ( parent ,& easy , 0 , VA_ARG ( args , APTR ));
VA_END ( args );
// Display error
if (! error -> window )
{
// Failed
if ( packet ) DisplayBeep ( packet -> errors );
FreeVec ( error );
return 0 ;
}
// Get bit to wait on
data -> error_wait |= 1 << error -> window -> UserPort -> mp_SigBit ;
// Add to error list
AddTail (( struct List *)& data -> error_list ,( struct Node *) error );
return error ;
}
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 12:41
#12
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
@salas00
Thanks a lot !
Now almost everything done, just a little strange moment, which maybe related to redefine of launcher_SystemTags().
I.e. once i run any programm from dopus5 (any native binary), and then exit from it, then
i have crash on the very begining of launcher_exit_code() function (i.e. stacktrace point out not even on first code-string in functino, but just on { braket.
And that laucher_exit_code used only one time when we run process over that launcher_SystemTags. Thats how that part looks like:
// Launch program
if ( launcher_SystemTags ( data ,
packet -> name ,
SYS_Input , packet -> in ,
SYS_Output , packet -> out ,
SYS_Asynch , TRUE ,
SYS_UserShell , TRUE ,
NP_Cli , TRUE ,
NP_StackSize , packet -> stack ,
NP_WindowPtr , 0 ,
( packet -> wait )? NP_ExitCode : TAG_IGNORE , launch_exit_code ,
NP_ExitData , packet ,
TAG_DONE )!=- 1 )
And launch_erro_code() is:
// Launch exit code
long SAVEDS ASM launch_exit_code ( REG ( d1 , LaunchPacket * packet ))
{ // <-- stack trace point out on that line
struct LibData * data ;
// Get library data pointer
data = packet -> data ;
.... blablabl ...
Dunno if it just something need to be added to create proc (like some PPC/OS4 flags only, like NP_Child or NP_NotifyOnDeathMessage or kind), or its just redefine of that laucher_SystemTags varags done wrong ? Maybe NP_ExitCode different somehow ..
All what i can say, is that the same 1:1 code (i.e. with all our new redefines / rewrites to VARARGS) works fine when we compile it for os3, but when just recompile it for os4, on exit we have such crash.
Edited by kas1e on 2013/4/5 12:59:27 Edited by kas1e on 2013/4/5 13:00:33 Edited by kas1e on 2013/4/5 13:16:23
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 13:44
#13
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
According to the autodocs the NP_ExitCode function should look like this: void SAVEDS ASM launch_exit_code( REG(d0, LONG return_code), REG(d1, LaunchPacket *packet)) { ... }
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 14:47
#14
Home away from home
Joined: 2007/9/11 12:31Last Login
: Today 7:13
From Russia
Group:
Registered Users
@salas00
Replaced, it works ! Yeah !
I also rebuild the with the same 2 params and for os3: works as well. What mean that when it compiles for os3, seems sdk somehow put something there ? Or why it works on os3 ? (and the same os3 version with 1 param works on os4 too, i.e. like os3 ndk/sdk do something for).
edit: answer from itix:
Quote:
It works because in OS3 parameters are explicitly placed to certain register, "REG(d1, LaunchPacket *packet)". Order of parameters wont matter. But on PPC when SysV/ABI is used it does matter because registers are allocated in order parameters are defined.so now all clear
Edited by kas1e on 2013/4/5 15:32:49
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Posted on:
2013/4/5 17:45
#15
Home away from home
Joined: 2006/12/4 23:15Last Login
: 10/14 16:04
Group:
Registered Users
That quote from itix is particularly important for hook functions.
Currently Active Users Viewing This Thread:
1
(
0 members
and 1 Anonymous Users
)