Author: petdance
Date: Sat Jun 2 18:52:33 2007
New Revision: 18771
Modified:
trunk/include/parrot/string_funcs.h
trunk/src/string.c
trunk/tools/build/headerize.pl
Log:
The headerizer now properly generates nonnull attributes in the header files.
string_funcs.h has been headerized. Now I move to others.
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h (original)
+++ trunk/include/parrot/string_funcs.h Sat Jun 2 18:52:33 2007
@@ -25,10 +25,12 @@
PARROT_API STRING* Parrot_reuse_COW_reference( Interp *interp,
STRING *s /*NULLOK*/,
- STRING *d /*NN*/ );
+ STRING *d /*NN*/ )
+ __attribute__nonnull__(3);
PARROT_API const char * Parrot_string_cstring( Interp *interp,
- const STRING *str /*NN*/ );
+ const STRING *str /*NN*/ )
+ __attribute__nonnull__(2);
PARROT_API INTVAL Parrot_string_find_cclass( Interp *interp,
INTVAL flags,
@@ -57,16 +59,17 @@
INTVAL encoding_nr,
STRING *dest );
-PARROT_API void Parrot_unmake_COW( Interp *interp,
- STRING *s /*NN*/ );
+PARROT_API void Parrot_unmake_COW( Interp *interp, STRING *s /*NN*/ )
+ __attribute__nonnull__(2);
-PARROT_API STRING * const_string( Interp *interp,
- const char *buffer /*NN*/ );
+PARROT_API STRING * const_string( Interp *interp, const char *buffer /*NN*/ )
+ __attribute__nonnull__(2);
PARROT_API STRING * int_to_str( Interp *interp,
char *tc /*NN*/,
HUGEINTVAL num,
- char base );
+ char base )
+ __attribute__nonnull__(2);
PARROT_API STRING * string_append( Interp *interp,
STRING *a /*NULLOK*/,
@@ -91,55 +94,41 @@
STRING *s2,
STRING **dest );
-PARROT_API INTVAL string_bool( Interp *interp,
- const STRING *s );
-
-PARROT_API UINTVAL string_capacity( Interp *interp,
- const STRING *s /*NN*/ );
+PARROT_API INTVAL string_bool( Interp *interp, const STRING *s );
+PARROT_API UINTVAL string_capacity( Interp *interp, const STRING *s /*NN*/ )
+ __attribute__nonnull__(2);
PARROT_API STRING * string_chopn( Interp *interp,
STRING *s,
INTVAL n,
int in_place );
-PARROT_API STRING * string_chr( Interp *interp,
- UINTVAL character );
-
+PARROT_API STRING * string_chr( Interp *interp, UINTVAL character );
PARROT_API INTVAL string_compare( Interp *interp,
const STRING *s1,
const STRING *s2 );
-PARROT_API STRING * string_compose( Interp *interp,
- STRING *src );
-
-PARROT_API INTVAL string_compute_strlen( Interp *interp,
- STRING *s /*NN*/ );
+PARROT_API STRING * string_compose( Interp *interp, STRING *src );
+PARROT_API INTVAL string_compute_strlen( Interp *interp, STRING *s /*NN*/ )
+ __attribute__nonnull__(2);
PARROT_API STRING * string_concat( Interp *interp,
STRING *a /*NULLOK*/,
STRING *b /*NULLOK*/,
UINTVAL Uflags );
-PARROT_API STRING * string_copy( Interp *interp,
- STRING *s /*NULLOK*/ );
-
+PARROT_API STRING * string_copy( Interp *interp, STRING *s /*NULLOK*/ );
PARROT_API void string_cstring_free( char *p );
-
PARROT_API void string_deinit( Parrot_Interp interp );
-
-PARROT_API STRING * string_downcase( Interp *interp,
- const STRING *s );
-
+PARROT_API STRING * string_downcase( Interp *interp, const STRING *s );
PARROT_API void string_downcase_inplace( Interp *interp,
- STRING *s );
+ STRING *s /*NULLOK*/ );
PARROT_API INTVAL string_equal( Interp *interp,
const STRING *s1,
const STRING *s2 );
-PARROT_API STRING * string_escape_string( Interp *interp,
- const STRING *src );
-
+PARROT_API STRING * string_escape_string( Interp *interp, const STRING *src );
PARROT_API STRING * string_escape_string_delimited( Interp *interp,
const STRING *src,
UINTVAL limit );
@@ -152,41 +141,25 @@
const char *buffer /*NULLOK*/,
UINTVAL len );
-PARROT_API STRING * string_from_int( Interp *interp,
- INTVAL i );
-
-PARROT_API STRING * string_from_num( Interp *interp,
- FLOATVAL f );
-
+PARROT_API STRING * string_from_int( Interp *interp, INTVAL i );
+PARROT_API STRING * string_from_num( Interp *interp, FLOATVAL f );
PARROT_API STRING * string_grow( Interp * interp,
- STRING * s /*NN*/,
- INTVAL addlen );
-
-PARROT_API size_t string_hash( Interp *interp,
- STRING *s,
- size_t seed );
-
-PARROT_API STRING * string_increment( Interp *interp,
- const STRING *s );
-
-PARROT_API INTVAL string_index( Interp *interp,
- const STRING *s,
- UINTVAL idx );
-
+ STRING *s /*NN*/,
+ INTVAL addlen )
+ __attribute__nonnull__(2);
+
+PARROT_API size_t string_hash( Interp *interp, STRING *s, size_t seed );
+PARROT_API STRING * string_increment( Interp *interp, const STRING *s );
+PARROT_API INTVAL string_index( Interp *interp, const STRING *s, UINTVAL idx );
PARROT_API void string_init( Parrot_Interp interp );
-
-PARROT_API STRING* string_join( Interp *interp,
- STRING *j,
- PMC *ar );
-
-PARROT_API UINTVAL string_length( Interp *interp,
- const STRING *s /*NULLOK*/ );
-
+PARROT_API STRING* string_join( Interp *interp, STRING *j, PMC *ar );
+PARROT_API UINTVAL string_length( Interp *interp, const STRING *s /*NULLOK*/ );
PARROT_API STRING * string_make( Interp *interp,
const char *buffer /*NN*/,
UINTVAL len,
- const char *charset_name /*NN*/,
- UINTVAL flags );
+ const char *charset_name /*NULLOK*/,
+ UINTVAL flags )
+ __attribute__nonnull__(2);
PARROT_API STRING * string_make_direct( Interp *interp,
const char *buffer /*NULLOK*/,
@@ -209,24 +182,19 @@
const char *format,
... );
-PARROT_API INTVAL string_ord( Interp *interp,
- const STRING *s,
- INTVAL idx );
-
-PARROT_API void string_pin( Interp *interp,
- STRING * s );
-
+PARROT_API INTVAL string_ord( Interp *interp, const STRING *s, INTVAL idx );
+PARROT_API void string_pin( Interp *interp, STRING * s );
PARROT_API const char* string_primary_encoding_for_representation( Interp
*interp,
parrot_string_representation_t representation );
-PARROT_API STRING* string_printf( Interp *interp,
- const char *format,
- ... );
-
+PARROT_API STRING* string_printf( Interp *interp, const char *format, ... );
PARROT_API CHARSET * string_rep_compatible( Interp *interp,
const STRING *a /*NN*/,
const STRING *b /*NN*/,
- ENCODING **e /*NN*/ );
+ ENCODING **e /*NN*/ )
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ __attribute__nonnull__(4);
PARROT_API STRING * string_repeat( Interp *interp,
const STRING *s,
@@ -244,10 +212,7 @@
STRING *dest /*NULLOK*/,
STRING *src /*NULLOK*/ );
-PARROT_API PMC* string_split( Interp *interp,
- STRING *delim,
- STRING *str );
-
+PARROT_API PMC* string_split( Interp *interp, STRING *delim, STRING *str );
PARROT_API INTVAL string_str_index( Interp *interp,
const STRING *s,
const STRING *s2,
@@ -260,40 +225,27 @@
STRING **d,
int replace_dest );
-PARROT_API STRING * string_titlecase( Interp *interp,
- const STRING *s );
-
-PARROT_API void string_titlecase_inplace( Interp *interp,
- STRING *s );
-
+PARROT_API STRING * string_titlecase( Interp *interp, const STRING *s );
+PARROT_API void string_titlecase_inplace( Interp *interp, STRING *s );
PARROT_API char * string_to_cstring( Interp *interp,
const STRING * const s /* NULLOK */ );
-PARROT_API INTVAL string_to_int( Interp *interp,
- const STRING *s );
-
-PARROT_API FLOATVAL string_to_num( Interp *interp,
- const STRING *s );
-
+PARROT_API INTVAL string_to_int( Interp *interp, const STRING *s );
+PARROT_API FLOATVAL string_to_num( Interp *interp, const STRING *s );
PARROT_API STRING * string_unescape_cstring( Interp *interp,
const char *cstring,
char delimiter,
const char *enc_char );
-PARROT_API void string_unpin( Interp *interp,
- STRING * s );
-
-PARROT_API STRING * string_upcase( Interp *interp,
- const STRING *s );
-
-PARROT_API void string_upcase_inplace( Interp *interp,
- STRING *s );
-
+PARROT_API void string_unpin( Interp *interp, STRING * s );
+PARROT_API STRING * string_upcase( Interp *interp, const STRING *s );
+PARROT_API void string_upcase_inplace( Interp *interp, STRING *s );
PARROT_API STRING* uint_to_str( Interp *interp,
char *tc /*NN*/,
UHUGEINTVAL num,
char base,
- int minus );
+ int minus )
+ __attribute__nonnull__(2);
/* HEADERIZER END: src/string.c */
/* HEADERIZER BEGIN: src/string_primitives.c */
PARROT_API UINTVAL Parrot_char_digit_value( Interp *interp,
@@ -306,7 +258,6 @@
STRING *s );
PARROT_API void string_set_data_directory( const char *dir );
-
PARROT_API Parrot_UInt4 string_unescape_one( Interp *interp,
UINTVAL *offset,
STRING *string );
Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c (original)
+++ trunk/src/string.c Sat Jun 2 18:52:33 2007
@@ -576,7 +576,7 @@
STRING *
string_make(Interp *interp, const char *buffer /*NN*/,
- UINTVAL len, const char *charset_name /*NN*/, UINTVAL flags)
+ UINTVAL len, const char *charset_name /*NULLOK*/, UINTVAL flags)
{
ENCODING *encoding;
CHARSET *charset;
@@ -651,7 +651,7 @@
*/
STRING *
-string_grow(Interp * interp, STRING * s /*NN*/, INTVAL addlen)
+string_grow(Interp * interp, STRING *s /*NN*/, INTVAL addlen)
{
Parrot_unmake_COW(interp,s);
@@ -2261,7 +2261,7 @@
*/
void
-string_downcase_inplace(Interp *interp, STRING *s)
+string_downcase_inplace(Interp *interp, STRING *s /*NULLOK*/)
{
if (!s)
return;
Modified: trunk/tools/build/headerize.pl
==============================================================================
--- trunk/tools/build/headerize.pl (original)
+++ trunk/tools/build/headerize.pl Sat Jun 2 18:52:33 2007
@@ -59,7 +59,6 @@
=cut
-use Data::Dumper;
use Getopt::Long;
use lib qw( lib );
use Parrot::Config;
@@ -152,6 +151,22 @@
return [ $static, $returntype, $funcname, @parms ];
}
+sub attrs_from_args {
+ my @args = @_;
+
+ my @attrs = ();
+
+ my $n = 0;
+ for my $arg ( @args ) {
+ ++$n;
+ if ( $arg =~ m{/\*\s*NN\s*\*/} ) {
+ push( @attrs, "__attribute__nonnull__($n)" );
+ }
+ }
+
+ return @attrs;
+}
+
sub make_function_decls {
my @funcs = @_;
@@ -160,10 +175,32 @@
my ($static, $ret_type, $funcname, @args) = @{$func};
next if $static;
- push( @decls,
- sprintf "PARROT_API %s %s( %s );\n",
- $ret_type, $funcname, join( ",\n ", @args ),
- );
+ my $multiline = 0;
+
+ my $decl = sprintf( "PARROT_API %s %s(", $ret_type, $funcname );
+
+ my @attrs = attrs_from_args( @args );
+ my $argline = join( ", ", @args );
+ if ( length($decl.$argline) <= 75 ) {
+ $decl = "$decl $argline )";
+ }
+ else {
+ if ( $args[0] =~ /^Interp\b/ ) {
+ $decl .= " " . (shift @args);
+ $decl .= "," if @args;
+ }
+ $argline = join( ",", map { "\n\t$_" } @args );
+ $decl = "$decl$argline )";
+ $multiline = 1;
+ }
+ my $attrs = join( "", map { "\n\t\t$_" } @attrs );
+ if ( $attrs ) {
+ $decl .= $attrs;
+ $multiline = 1;
+ }
+ $decl .= $multiline ? ";\n" : ";";
+ $decl =~ s/\t/ /g;
+ push( @decls, $decl );
}
return @decls;
@@ -207,7 +244,6 @@
}
} # for @cfiles
my $nfiles = scalar keys %files;
- print Dumper( \%files ) if $opt{verbose};
print "$nfuncs funcs in $nfiles files\n";
for my $hfile ( sort keys %files ) {