Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
172 user(s) are online (152 user(s) are browsing Forums)

Members: 3
Guests: 169

NinjaCyborg, Amigafreak02, Mr_byte, more...

Support us!

Headlines

 
  Register To Post  

RawDoFmt() handling over SDI + VA_ARGS & Co
Home away from home
Home away from home


See User information
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 *bufferchar *stringAPTR data)
{
    
void *stuffchar "\x16\xc0\x4e\x75"// MOVE.B D0,(A3)+ | RTS
#if defined(__amigaos4__)
    
stuffchar NULL;
#endif
    
RawDoFmt(stringdataNULLbuffer);
}

void VARARGS68K lsprintf(char *bufchar *fmt, ...)
{
    
void *stuffchar "\x16\xc0\x4e\x75"// MOVE.B D0,(A3)+ | RTS
#if defined(__amigaos4__)
    
stuffchar NULL;
#endif
    
VA_LIST args;

    
VA_START(argsfmt);
    
RawDoFmt(fmtVA_ARG(argsvoid *), stuffcharbuf);
    
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 function


But 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 out


Can 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
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Home away from home
Home away from home


See User information
@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.


Go to top
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Home away from home
Home away from home


See User information
@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() function


Should 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.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Just can't stay away
Just can't stay away


See User information
@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

Go to top
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Home away from home
Home away from home


See User information
@Fredrik
Quote:

Make sure that <amiga_compiler.h> is included before any SDI includes.

Yeah, that helps, thanks !

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Home away from home
Home away from home


See User information
@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(argstag1);
        
GT_SetGadgetAttrsA(gad,win,NULL,VA_ARG(argsstruct TagItem *));
        
VA_END(args);
}

void VARARGS68K L_SetGadgetAttrs(
        
struct Gadget *gad,
        
struct Window *win,
        
Tag tag,...)
{
        
VA_LIST args;
        
VA_START(argstag);
        
SetGadgetAttrsA(gad,win,NULL,VA_ARG(argsstruct 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.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI (i.e.VA_ARGS & Co)
Just can't stay away
Just can't stay away


See User information
@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(argswin); 
        
GT_SetGadgetAttrsA(gad,win,NULL,VA_ARG(argsstruct TagItem *)); 
        
VA_END(args); 


void VARARGS68K L_SetGadgetAttrs
        
struct Gadget *gad
        
struct Window *win
        ...) 

        
VA_LIST args
        
VA_START(argswin); 
        
SetGadgetAttrsA(gad,win,NULL,VA_ARG(argsstruct TagItem *)); 
        
VA_END(args); 
}

Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Home away from home
Home away from home


See User information
@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.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Just can't stay away
Just can't stay away


See User information
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.

Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Home away from home
Home away from home


See User information
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 (packetDisplayBeep(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;
}


Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Just can't stay away
Just can't stay away


See User information
// 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(argsbuttons);
    
error->window=BuildEasyRequestArgs(parent,&easy,0,VA_ARG(argsAPTR));
    
VA_END(args);
    
// Display error 
    
if (!error->window
    { 
        
// Failed 
        
if (packetDisplayBeep(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
}

Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Home away from home
Home away from home


See User information
@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_codeREG(d1LaunchPacket *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
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Just can't stay away
Just can't stay away


See User information
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)) {
...
}

Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Home away from home
Home away from home


See User information
@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
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: RawDoFmt() handling over SDI + VA_ARGS & Co
Home away from home
Home away from home


See User information
That quote from itix is particularly important for hook functions.

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project