Page 1 of 2

AllocVecTags

Posted: Sun Oct 09, 2011 12:28 pm
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.

Re: AllocVecTags

Posted: Sun Oct 09, 2011 6:56 pm
by ZeroG
Read the autodoc: only MEMF_PRIVATE, MEMF_SHARED or MEMF_EXECUTABLE is allowed for AVT_Type.

Re: AllocVecTags

Posted: Mon Oct 10, 2011 3:39 pm
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.

Re: AllocVecTags

Posted: Mon Oct 10, 2011 6:28 pm
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:

Re: AllocVecTags

Posted: Tue Oct 11, 2011 4:49 am
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.

Re: AllocVecTags

Posted: Tue Oct 11, 2011 9:12 am
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.

Re: AllocVecTags

Posted: Tue Oct 11, 2011 9:29 am
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

Re: AllocVecTags

Posted: Tue Oct 11, 2011 10:01 am
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.

Re: AllocVecTags

Posted: Tue Oct 11, 2011 10:15 am
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.

Re: AllocVecTags

Posted: Tue Oct 25, 2011 11:09 am
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.