提交 47339f61 编写于 作者: D Dr. Stephen Henson

Extensively changed the DEF file generator mkdef.pl to use a modified version

of Ulf's prototype parser, also general tidying and fixing of several problems
with the original. Its still a bit of a hack but should work.

This is the last bit of the old code that uses the K&R prototypes: after some
testing they can finally go away...
上级 a1e464f9
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
Changes between 0.9.2b and 0.9.3 Changes between 0.9.2b and 0.9.3
*) Partial rewrite of the DEF file generator to now parse the ANSI
prototypes.
[Steve Henson]
*) New Configure options --prefix=DIR and --openssldir=DIR. *) New Configure options --prefix=DIR and --openssldir=DIR.
[Ulf Möller] [Ulf Möller]
......
#!/usr/local/bin/perl #!/usr/my/bin/perl -w
# #
# generate a .def file # generate a .def file
# #
# It does this by parsing the header files and looking for the # It does this by parsing the header files and looking for the
# non-prototyped functions. # prototyped functions: it then prunes the output.
# #
$crypto_num="util/libeay.num"; $crypto_num="util/libeay.num";
$ssl_num= "util/ssleay.num"; $ssl_num= "util/ssleay.num";
my $do_update = 0;
my $do_crypto = 0;
my $do_ssl = 0;
$rsaref = 0;
$W32=1; $W32=1;
$NT=0; $NT=0;
# Set this to make typesafe STACK definitions appear in DEF # Set this to make typesafe STACK definitions appear in DEF
...@@ -26,11 +31,12 @@ foreach (@ARGV) ...@@ -26,11 +31,12 @@ foreach (@ARGV)
$do_crypto=1 if $_ eq "libeay"; $do_crypto=1 if $_ eq "libeay";
$do_crypto=1 if $_ eq "crypto"; $do_crypto=1 if $_ eq "crypto";
$do_update=1 if $_ eq "update"; $do_update=1 if $_ eq "update";
$rsaref=1 if $_ eq "rsaref";
} }
if (!$do_ssl && !$do_crypto) if (!$do_ssl && !$do_crypto)
{ {
print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n"; print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n";
exit(1); exit(1);
} }
...@@ -84,12 +90,10 @@ $crypto.=" crypto/hmac/hmac.h"; ...@@ -84,12 +90,10 @@ $crypto.=" crypto/hmac/hmac.h";
$crypto.=" crypto/comp/comp.h"; $crypto.=" crypto/comp/comp.h";
$crypto.=" crypto/tmdiff.h"; $crypto.=" crypto/tmdiff.h";
$match{'NOPROTO'}=1;
$match2{'PERL5'}=1;
@ssl_func = &do_defs("SSLEAY", $ssl); @ssl_func = &do_defs("SSLEAY", $ssl);
@crypto_func = &do_defs("LIBEAY", $crypto); @crypto_func = &do_defs("LIBEAY", $crypto);
if ($do_update) { if ($do_update) {
if ($do_ssl == 1) { if ($do_ssl == 1) {
...@@ -116,99 +120,103 @@ if($do_crypto == 1) { ...@@ -116,99 +120,103 @@ if($do_crypto == 1) {
sub do_defs sub do_defs
{ {
local($name,$files)=@_; my($name,$files)=@_;
local(@ret); my @ret;
my %funcs;
$off=-1;
foreach $file (split(/\s+/,$files)) foreach $file (split(/\s+/,$files))
{ {
# print STDERR "reading $file\n";
open(IN,"<$file") || die "unable to open $file:$!\n"; open(IN,"<$file") || die "unable to open $file:$!\n";
$depth=0;
$pr=-1; my $line = "", $def= "";
@np=""; my %tag = (
$/=undef; FreeBSD => 0,
$a=<IN>; NOPROTO => 0,
while (($i=index($a,"/*")) >= 0) WIN16 => 0,
{ PERL5 => 0,
$j=index($a,"*/"); _WINDLL => 0,
last unless ($j >= 0); NO_FP_API => 0,
$a=substr($a,0,$i).substr($a,$j+2); CONST_STRICT => 0,
# print "$i $j\n"; TRUE => 1,
);
while(<IN>) {
last if (/BEGIN ERROR CODES/);
if ($line ne '') {
$_ = $line . $_;
$line = '';
} }
foreach (split("\n",$a))
{ if (/\\$/) {
if (/^\#\s*ifndef (.*)/) $line = $_;
{ next;
}
$cpp = 1 if /^#.*ifdef.*cplusplus/;
if ($cpp) {
$cpp = 0 if /^#.*endif/;
next;
}
s/\/\*.*?\*\///gs; # ignore comments
s/{[^{}]*}//gs; # ignore {} blocks
if (/^\#\s*ifndef (.*)/) {
push(@tag,$1); push(@tag,$1);
$tag{$1}=-1; $tag{$1}=-1;
next; next;
} } elsif (/^\#\s*if !defined\(([^\)]+)\)/) {
elsif (/^\#\s*if !defined\(([^\)]+)\)/)
{
push(@tag,$1); push(@tag,$1);
$tag{$1}=-1; $tag{$1}=-1;
next; next;
} } elsif (/^\#\s*ifdef (.*)/) {
elsif (/^\#\s*ifdef (.*)/)
{
push(@tag,$1); push(@tag,$1);
$tag{$1}=1; $tag{$1}=1;
next; next;
} } elsif (/^\#\s*if defined(.*)/) {
elsif (/^\#\s*if defined(.*)/)
{
push(@tag,$1); push(@tag,$1);
$tag{$1}=1; $tag{$1}=1;
next; next;
} } elsif (/^\#\s*endif/) {
elsif (/^\#\s*endif/)
{
$tag{$tag[$#tag]}=0; $tag{$tag[$#tag]}=0;
pop(@tag); pop(@tag);
next; next;
} } elsif (/^\#\s*else/) {
elsif (/^\#\s*else/) my $t=$tag[$#tag];
{
$t=$tag[$#tag];
$tag{$t}= -$tag{$t}; $tag{$t}= -$tag{$t};
next; next;
} } elsif (/^\#\s*if\s+1/) {
#printf STDERR "$_\n%2d %2d %2d %2d %2d $W32\n", # Dummy tag
#$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'}; push(@tag,"TRUE");
$tag{"TRUE"}=1;
$t=undef; next;
if (/^extern .*;$/) } elsif (/^\#/) {
{ $t=&do_extern($name,$_); } next;
elsif ($safe_stack_def && }
/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) if ($safe_stack_def &&
{ /^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
push(@ret,"sk_${1}_new"); $funcs{"sk_${1}_new"} = 1;
push(@ret,"sk_${1}_new_null"); $funcs{"sk_${1}_new_null"} = 1;
push(@ret,"sk_${1}_free"); $funcs{"sk_${1}_free"} = 1;
push(@ret,"sk_${1}_num"); $funcs{"sk_${1}_num"} = 1;
push(@ret,"sk_${1}_value"); $funcs{"sk_${1}_value"} = 1;
push(@ret,"sk_${1}_set"); $funcs{"sk_${1}_set"} = 1;
push(@ret,"sk_${1}_zero"); $funcs{"sk_${1}_zero"} = 1;
push(@ret,"sk_${1}_push"); $funcs{"sk_${1}_push"} = 1;
push(@ret,"sk_${1}_pop"); $funcs{"sk_${1}_pop"} = 1;
push(@ret,"sk_${1}_find"); $funcs{"sk_${1}_find"} = 1;
push(@ret,"sk_${1}_delete"); $funcs{"sk_${1}_delete"} = 1;
push(@ret,"sk_${1}_delete_ptr"); $funcs{"sk_${1}_delete_ptr"} = 1;
push(@ret,"sk_${1}_set_cmp_func"); $funcs{"sk_${1}_set_cmp_func"} = 1;
push(@ret,"sk_${1}_dup"); $funcs{"sk_${1}_dup"} = 1;
push(@ret,"sk_${1}_pop_free"); $funcs{"sk_${1}_pop_free"} = 1;
push(@ret,"sk_${1}_shift"); $funcs{"sk_${1}_shift"} = 1;
} } elsif ($safe_stack_def &&
elsif ($safe_stack_def && /^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) $funcs{"d2i_ASN1_SET_OF_${1}"} = 1;
{ $funcs{"i2d_ASN1_SET_OF_${1}"} = 1;
push(@ret,"d2i_ASN1_SET_OF_${1}"); } elsif (
push(@ret,"i2d_ASN1_SET_OF_${1}");
}
elsif (($tag{'NOPROTO'} == 1) &&
($tag{'FreeBSD'} != 1) && ($tag{'FreeBSD'} != 1) &&
($tag{'CONST_STRICT'} != 1) &&
(($W32 && ($tag{'WIN16'} != 1)) || (($W32 && ($tag{'WIN16'} != 1)) ||
(!$W32 && ($tag{'WIN16'} != -1))) && (!$W32 && ($tag{'WIN16'} != -1))) &&
($tag{'PERL5'} != 1) && ($tag{'PERL5'} != 1) &&
...@@ -217,80 +225,71 @@ sub do_defs ...@@ -217,80 +225,71 @@ sub do_defs
($W32 && $tag{'_WINDLL'} != 1)) && ($W32 && $tag{'_WINDLL'} != 1)) &&
((($tag{'NO_FP_API'} != 1) && $W32) || ((($tag{'NO_FP_API'} != 1) && $W32) ||
(($tag{'NO_FP_API'} != -1) && !$W32))) (($tag{'NO_FP_API'} != -1) && !$W32)))
{ $t=&do_line($name,$_); }
else
{ $t=undef; }
if (($t ne undef) && (!$done{$name,$t}))
{ {
$done{$name,$t}++; if (/{|\/\*/) { # }
push(@ret,$t); $line = $_;
#printf STDERR "one:$t\n" if $t =~ /BIO_/; } else {
$def .= $_;
}
} }
} }
close(IN); close(IN);
foreach (split /;/, $def) {
s/^[\n\s]*//g;
s/[\n\s]*$//g;
next if(/typedef\W/);
if (/\(\*(\w*)\([^\)]+/) {
$funcs{$1} = 1;
} elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) {
# K&R C
next;
} elsif (/\w+\W+\w+\W*\(.*\)$/s) {
while (not /\(\)$/s) {
s/[^\(\)]*\)$/\)/s;
s/\([^\(\)]*\)\)$/\)/s;
}
s/\(void\)//;
/(\w+)\W*\(\)/s;
$funcs{$1} = 1;
} elsif (/\(/ and not (/=/)) {
print STDERR "File $file: cannot parse: $_;\n";
}
} }
return(@ret);
} }
sub do_line # Prune the returned functions
{
local($file,$_)=@_; delete $funcs{"SSL_add_dir_cert_subjects_to_stack"};
local($n); delete $funcs{"des_crypt"};
delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref;
return(undef) if /^$/;
return(undef) if /^\s/; if($W32) {
#printf STDERR "two:$_\n" if $_ =~ /BIO_/; delete $funcs{"BIO_s_file_internal"};
if (/(CRYPTO_get_locking_callback)/) delete $funcs{"BIO_new_file_internal"};
{ return($1); } delete $funcs{"BIO_new_fp_internal"};
elsif (/(CRYPTO_get_id_callback)/) } else {
{ return($1); } if(exists $funcs{"ERR_load_CRYPTO_strings"}) {
elsif (/(CRYPTO_get_add_lock_callback)/) delete $funcs{"ERR_load_CRYPTO_strings"};
{ return($1); } $funcs{"ERR_load_CRYPTOlib_strings"} = 1;
elsif (/(SSL_CTX_get_verify_callback)/)
{ return($1); }
elsif (/(SSL_get_info_callback)/)
{ return($1); }
elsif ((!$W32) && /(ERR_load_CRYPTO_strings)/)
{ return("ERR_load_CRYPTOlib_strings"); }
elsif (!$W32 && /BIO_s_file/)
{ return(undef); }
elsif (!$W32 && /BIO_new_file/)
{ return(undef); }
elsif (!$W32 && /BIO_new_fp/)
{ return(undef); }
elsif ($W32 && /BIO_s_file_internal/)
{ return(undef); }
elsif ($W32 && /BIO_new_file_internal/)
{ return(undef); }
elsif ($W32 && /BIO_new_fp_internal/)
{ return(undef); }
elsif (/SSL_add_dir_cert_subjects_to_stack/)
{ return(undef); }
elsif (!$NT && /BIO_s_log/)
{ return(undef); }
else
{
/\s\**(\S+)\s*\(/;
$_ = $1;
tr/()*//d;
#print STDERR "$1 : $_\n";
return($_);
} }
delete $funcs{"BIO_s_file"};
delete $funcs{"BIO_new_file"};
delete $funcs{"BIO_new_fp"};
}
if (!$NT) {
delete $funcs{"BIO_s_log"};
} }
sub do_extern push @ret, keys %funcs;
{
local($file,$_)=@_;
local($n);
/\s\**(\S+);$/; return(@ret);
return($1); }
}
sub print_def_file sub print_def_file
{ {
local(*OUT,$name,*nums,@functions)=@_; (*OUT,my $name,*nums,@functions)=@_;
local($n)=1; my $n =1;
if ($W32) if ($W32)
{ $name.="32"; } { $name.="32"; }
...@@ -308,8 +307,7 @@ DESCRIPTION 'OpenSSL $name - http://www.openssl.org/' ...@@ -308,8 +307,7 @@ DESCRIPTION 'OpenSSL $name - http://www.openssl.org/'
EOF EOF
if (!$W32) if (!$W32) {
{
print <<"EOF"; print <<"EOF";
CODE PRELOAD MOVEABLE CODE PRELOAD MOVEABLE
DATA PRELOAD MOVEABLE SINGLE DATA PRELOAD MOVEABLE SINGLE
...@@ -320,7 +318,7 @@ HEAPSIZE 4096 ...@@ -320,7 +318,7 @@ HEAPSIZE 4096
STACKSIZE 8192 STACKSIZE 8192
EOF EOF
} }
print "EXPORTS\n"; print "EXPORTS\n";
...@@ -329,59 +327,52 @@ EOF ...@@ -329,59 +327,52 @@ EOF
(@r)=grep(!/^SSLeay/,@functions); (@r)=grep(!/^SSLeay/,@functions);
@functions=((sort @e),(sort @r)); @functions=((sort @e),(sort @r));
foreach $func (@functions) foreach $func (@functions) {
{ if (!defined($nums{$func})) {
if (!defined($nums{$func}))
{
printf STDERR "$func does not have a number assigned\n" printf STDERR "$func does not have a number assigned\n"
if(!$do_update); if(!$do_update);
} } else {
else
{
$n=$nums{$func}; $n=$nums{$func};
printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n; printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n;
}
} }
printf OUT "\n";
} }
printf OUT "\n";
}
sub load_numbers sub load_numbers
{ {
local($name)=@_; my($name)=@_;
local($j,@a,%ret); my(@a,%ret);
$max_num = 0; $max_num = 0;
open(IN,"<$name") || die "unable to open $name:$!\n"; open(IN,"<$name") || die "unable to open $name:$!\n";
while (<IN>) while (<IN>) {
{
chop; chop;
s/#.*$//; s/#.*$//;
next if /^\s*$/; next if /^\s*$/;
@a=split; @a=split;
$ret{$a[0]}=$a[1]; $ret{$a[0]}=$a[1];
$max_num = $a[1] if $a[1] > $max_num; $max_num = $a[1] if $a[1] > $max_num;
} }
close(IN); close(IN);
return(%ret); return(%ret);
} }
sub update_numbers sub update_numbers
{ {
local(*OUT,$name,*nums,$start_num, @functions)=@_; (*OUT,$name,*nums,my $start_num, my @functions)=@_;
my $new_funcs = 0; my $new_funcs = 0;
print STDERR "Updating $name\n"; print STDERR "Updating $name\n";
foreach $func (@functions) foreach $func (@functions) {
{ if (!exists $nums{$func}) {
if (!defined($nums{$func}))
{
$new_funcs++; $new_funcs++;
printf OUT "%s%-40s%d\n","",$func, ++$start_num; printf OUT "%s%-40s%d\n","",$func, ++$start_num;
}
} }
}
if($new_funcs) { if($new_funcs) {
print STDERR "$new_funcs New Functions added\n"; print STDERR "$new_funcs New Functions added\n";
} else { } else {
print STDERR "No New Functions Added\n"; print STDERR "No New Functions Added\n";
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册