AllocVecTags

This forum is for general developer support questions.
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

AllocVecTags

Post by JosDuchIt »

Cleaning up the Gui4Cli source i replaced in a working version just one line:
if (p = (UBYTE *)AllocVec(strlen(val)+2, ANYMEM))
with
if (p = (UBYTE *)AllocVecTags(strlen(val)+2, AVT_TYPE, MEMF_ANY, TAG_DONE))

p is used in allocating a directory filter attribute.
(AllocVec is mentioned as "obsolete use AllocVecTaglist")
When i load a gui(script) with the Gui4Cli interpreter using such attribute i get an immediate and very unhelpfull crash.
I don't get it how this simple substitution can have this effect.
User avatar
ZeroG
Posts: 124
Joined: Sat Jun 18, 2011 11:31 am
Location: Germany

Re: AllocVecTags

Post by ZeroG »

Read the autodoc: only MEMF_PRIVATE, MEMF_SHARED or MEMF_EXECUTABLE is allowed for AVT_Type.
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: AllocVecTags

Post by JosDuchIt »

@ZeroG,
thanks, i was convinced i did check the autodoc about this a week before.
The crash was immediate, and i had introduced a lot of other changes that i did check before writing to this forum
I am rather disappointed thet the compiler does not give any warning, error or undefined reference in this case.
Maybe this thread should go to the SDK section.
User avatar
abalaban
Beta Tester
Beta Tester
Posts: 456
Joined: Mon Dec 20, 2010 2:09 pm
Location: France
Contact:

Re: AllocVecTags

Post by abalaban »

JosDuchIt wrote: I am rather disappointed thet the compiler does not give any warning, error or undefined reference in this case.
Maybe this thread should go to the SDK section.
You are disappointed that the compiler didn't tell you you were passing wrong value to a function, aren't you?
If that's the case then it would be similar to be disappointed because the compiler didn't throw anything for

Code: Select all

printf("age=%ld\n", nWeight);
while it's obvious you were implying to display the age and not the weight... :roll:
AmigaOne X1000 running AOS 4 beta
AmigaOne XE/G4
Amiga 1200/PPC 603e + BVision PPC
User avatar
ssolie
Beta Tester
Beta Tester
Posts: 1010
Joined: Mon Dec 20, 2010 8:51 pm
Location: Canada
Contact:

Re: AllocVecTags

Post by ssolie »

JosDuchIt wrote:I am rather disappointed thet the compiler does not give any warning, error or undefined reference in this case.
That is impossible because tag IDs and tag data are all uint32 types. There are no types for the compiler to check.
ExecSG Team Lead
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: AllocVecTags

Post by JosDuchIt »

It seems to me that as the set of acceptable values is (very) limited, there should be no problem in giving an error when a not acceptable value is proposed.
User avatar
abalaban
Beta Tester
Beta Tester
Posts: 456
Joined: Mon Dec 20, 2010 2:09 pm
Location: France
Contact:

Re: AllocVecTags

Post by abalaban »

JosDuchIt wrote:It seems to me that as the set of acceptable values is (very) limited, there should be no problem in giving an error when a not acceptable value is proposed.
It seems to me you didn't realized that the compiler has no idea what AllocVecTags is actually doing (that's the job of the OS). Nonetheless what the compiler *does* know is that it takes variable number of integer arguments and that it can check (and do it), nothing more. Unless you want to build the AmigaOS API into GCC it will never be able to do what you are saying (see my sample above what you want is at the same level).

This is the drawback of the flexibility given by TagItems: in the end it's only an array of 32bits integers...

EDIT: typo
Last edited by abalaban on Tue Oct 11, 2011 9:10 am, edited 1 time in total.
AmigaOne X1000 running AOS 4 beta
AmigaOne XE/G4
Amiga 1200/PPC 603e + BVision PPC
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 5:47 pm
Contact:

Re: AllocVecTags

Post by JosDuchIt »

It seems to me you didn't realized that the compiler as no idea what AllocVecTags is actually doing (that's the job of the OS). Nonetheless what the compiler *does* know is that it takes variable number of integer arguments and that it can check (and do it), nothing more. Unless you want to build the AmigaOS API into GCC it will never be able to do what you are saying (see my sample above what you want is at the same level).
It did not seem to you: you are quite right. I am not pretendig to be a compiler expert or even a C expert, Far from that. I can't but rephrase that i am rather disappointed that "the SDK does not provide more in detecting wong input to functions with a limited number of acceptable parameter values" If the easiest solution to this means that such library functions should be rewritten to fail more gracefully and provide help info, i am all for it.
If all this is unrealistic, so be it.
User avatar
abalaban
Beta Tester
Beta Tester
Posts: 456
Joined: Mon Dec 20, 2010 2:09 pm
Location: France
Contact:

Re: AllocVecTags

Post by abalaban »

JosDuchIt wrote:If the easiest solution to this means that such library functions should be rewritten to fail more gracefully and provide help info, i am all for it.
I agree with you that such a vital function AllocVecTags() could be more error tolerant providing at least a graceful return with adequate error code, either a fallback value for such error.
AmigaOne X1000 running AOS 4 beta
AmigaOne XE/G4
Amiga 1200/PPC 603e + BVision PPC
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: AllocVecTags

Post by tonyw »

It is vital that you check for and handle the failure return (which is NULL in this case). You will also get a NULL return if you ask it for a zero length allocation, so for instance if your string is "", you will get a failure return.

Also, you should have had a warning from gcc about using the assignment "p = xxx" as a truth value. It would have suggested putting parentheses around the expression. If you don't have warnings enabled in your makefile (and abort on error if any warnings reported), you are running a real risk of compiling code with built-in problems.
cheers
tony
Post Reply