summaryrefslogtreecommitdiff
path: root/embed.pl
diff options
context:
space:
mode:
Diffstat (limited to 'embed.pl')
-rwxr-xr-xembed.pl28
1 files changed, 21 insertions, 7 deletions
diff --git a/embed.pl b/embed.pl
index 50ec17faf3..9cdef0782a 100755
--- a/embed.pl
+++ b/embed.pl
@@ -201,23 +201,37 @@ sub write_protos {
$ret .= "void" if !$has_context;
}
$ret .= ")";
- $ret .= " __attribute__((noreturn))" if $flags =~ /r/;
- $ret .= "\n\t\t\t__attribute__((malloc)) __attribute__((warn_unused_result))" if $flags =~ /a/;
- $ret .= "\n\t\t\t__attribute__((pure))" if $flags =~ /P/;
+ my @attrs;
+ if ( $flags =~ /r/ ) {
+ push @attrs, "__attribute__((noreturn))";
+ }
+ if ( $flags =~ /a/ ) {
+ push @attrs, "__attribute__((malloc))";
+ $flags .= "R"; # All allocing must check return value
+ }
+ if ( $flags =~ /R/ ) {
+ push @attrs, "__attribute__((warn_unused_result))";
+ }
+ if ( $flags =~ /P/ ) {
+ push @attrs, "__attribute__((pure))";
+ }
if( $flags =~ /f/ ) {
my $prefix = $has_context ? 'pTHX_' : '';
my $args = scalar @args;
- $ret .= sprintf "\n\t\t\t__attribute__format__(__printf__,%s%d,%s%d)",
+ push @attrs, sprintf "__attribute__format__(__printf__,%s%d,%s%d)",
$prefix, $args - 1, $prefix, $args;
}
- $ret .= "\n\t\t\t__attribute__((nonnull))" if $flags =~ /N/;
if ( @nonnull ) {
my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull;
- $ret .= sprintf( "\n\t\t\t__attribute__((nonnull(%s)))", join( ",", @pos ) );
+ push @attrs, sprintf( "__attribute__((nonnull(%s)))", join( ",", @pos ) );
+ }
+ if ( @attrs ) {
+ $ret .= "\n";
+ $ret .= join( "\n", map { "\t\t\t$_" } @attrs );
}
$ret .= ";";
$ret .= ' */' if $flags =~ /m/;
- $ret .= "\n";
+ $ret .= @attrs ? "\n\n" : "\n";
}
$ret;
}