This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
remove most 'a' flags from embed.fnc
From: http://nntp.perl.org/group/perl.perl5.porters/237910:
In embed.fnc, we mark about 80 functions with the a flag, which we
document as meaning:
: a Allocates memory a la malloc/calloc. Also implies "R":
:
: proto.h: add __attribute__malloc__
Now, the current gcc docs for the malloc attribute states:
This tells the compiler that a function is malloc-like, i.e., that the
pointer P returned by the function cannot alias any other pointer
valid when the function returns, and moreover no pointers to valid
objects occur in any storage addressed by P.
Using this attribute can improve optimization. Functions like malloc
and calloc have this property because they return a pointer to
uninitialized or zeroed-out storage. However, functions like realloc
do not have this property, as they can return a pointer to storage
containing pointers.
This implies to me that we should only flag functions as 'a' if both:
1) it returns a pointer to memory that isn't pointed to from elsewhere;
2) that the block of memory itself contains no pointers.
I think we are failing condition (2) for many 'a' functions; for example
the op.c newXXXOP() functions return an alloced op struct (condition 1
probably satisfied), but which contain pointers (condition 2 fails).