2017-09-18 12:35:50 +00:00
|
|
|
#!/usr/bin/env perl
|
2011-05-06 13:11:32 +00:00
|
|
|
#
|
|
|
|
# Generate code for an XDR protocol, optionally applying
|
|
|
|
# fixups to the glibc rpcgen code so that it compiles
|
2007-06-11 11:36:17 +00:00
|
|
|
# with warnings turned on.
|
|
|
|
#
|
|
|
|
# This code is evil. Arguably better would be just to compile
|
|
|
|
# without -Werror. Update: The IXDR_PUT_LONG replacements are
|
|
|
|
# actually fixes for 64 bit, so this file is necessary. Arguably
|
|
|
|
# so is the type-punning fix.
|
|
|
|
#
|
2013-05-14 23:42:12 +00:00
|
|
|
# Copyright (C) 2007, 2011-2013 Red Hat, Inc.
|
2007-06-11 11:36:17 +00:00
|
|
|
#
|
2013-05-14 23:42:12 +00:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library. If not, see
|
|
|
|
# <http://www.gnu.org/licenses/>.
|
2007-06-11 11:36:17 +00:00
|
|
|
#
|
|
|
|
# Richard Jones <rjones@redhat.com>
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $in_function = 0;
|
|
|
|
my @function = ();
|
|
|
|
|
2011-05-06 13:11:32 +00:00
|
|
|
my $rpcgen = shift;
|
|
|
|
my $mode = shift;
|
|
|
|
my $xdrdef = shift;
|
|
|
|
my $target = shift;
|
|
|
|
|
|
|
|
unlink $target;
|
|
|
|
|
2015-07-08 11:29:23 +00:00
|
|
|
if ($rpcgen =~ /portable-rpcgen/) {
|
|
|
|
$rpcgen = "$rpcgen -o -";
|
|
|
|
}
|
|
|
|
open RPCGEN, "-|", "$rpcgen $mode $xdrdef"
|
2011-05-06 13:11:32 +00:00
|
|
|
or die "cannot run $rpcgen $mode $xdrdef: $!";
|
|
|
|
open TARGET, ">$target"
|
|
|
|
or die "cannot create $target: $!";
|
|
|
|
|
2016-11-19 17:40:27 +00:00
|
|
|
my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd" || $^O eq "darwin";
|
2011-05-06 13:11:32 +00:00
|
|
|
|
|
|
|
if ($mode eq "-c") {
|
|
|
|
print TARGET "#include <config.h>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
while (<RPCGEN>) {
|
|
|
|
# We only want to fixup the GLibc rpcgen output
|
|
|
|
# So just print data unchanged, if non-Linux
|
|
|
|
unless ($fixup) {
|
2012-07-27 12:51:28 +00:00
|
|
|
print TARGET;
|
|
|
|
next;
|
2011-05-06 13:11:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-11 11:36:17 +00:00
|
|
|
if (m/^{/) {
|
2012-07-27 12:51:28 +00:00
|
|
|
$in_function = 1;
|
|
|
|
print TARGET;
|
|
|
|
next;
|
2007-06-11 11:36:17 +00:00
|
|
|
}
|
|
|
|
|
2008-05-22 15:20:25 +00:00
|
|
|
s/\t/ /g;
|
|
|
|
|
2012-03-06 20:49:53 +00:00
|
|
|
# Fix VPATH builds
|
|
|
|
s,#include ".*/([^/]+)protocol\.h",#include "${1}protocol.h",;
|
|
|
|
|
2009-01-28 21:33:56 +00:00
|
|
|
# Portability for Solaris RPC
|
|
|
|
s/u_quad_t/uint64_t/g;
|
|
|
|
s/quad_t/int64_t/g;
|
|
|
|
s/xdr_u_quad_t/xdr_uint64_t/g;
|
|
|
|
s/xdr_quad_t/xdr_int64_t/g;
|
2010-04-25 11:31:31 +00:00
|
|
|
s/(?<!IXDR_GET_INT32 )IXDR_GET_LONG/IXDR_GET_INT32/g;
|
2009-01-28 21:33:56 +00:00
|
|
|
|
2007-06-11 11:36:17 +00:00
|
|
|
if (m/^}/) {
|
2012-07-27 12:51:28 +00:00
|
|
|
$in_function = 0;
|
|
|
|
|
|
|
|
# Note: The body of the function is in @function.
|
|
|
|
|
|
|
|
# Remove decl of buf, if buf isn't used in the function.
|
|
|
|
my @uses = grep /[^.>]\bbuf\b/, @function;
|
|
|
|
@function = grep !/[^.>]\bbuf\b/, @function if @uses == 1;
|
|
|
|
|
|
|
|
# Remove decl of i, if i isn't used in the function.
|
|
|
|
@uses = grep /[^.>]\bi\b/, @function;
|
|
|
|
@function = grep !/[^.>]\bi\b/, @function if @uses == 1;
|
|
|
|
|
|
|
|
# (char **)&objp->... gives:
|
|
|
|
# warning: dereferencing type-punned pointer will break
|
|
|
|
# strict-aliasing rules
|
|
|
|
# so rewrite it.
|
|
|
|
my %uses = ();
|
|
|
|
my $i = 0;
|
|
|
|
foreach (@function) {
|
|
|
|
$uses{$1} = $i++ if m/\(char \*\*\)\&(objp->[a-z_.]+_val)/i;
|
|
|
|
}
|
|
|
|
if (keys %uses >= 1) {
|
|
|
|
my $i = 1;
|
|
|
|
|
|
|
|
foreach (keys %uses) {
|
|
|
|
$i = $uses{$_};
|
|
|
|
unshift @function,
|
|
|
|
(" char **objp_cpp$i = (char **) (void *) &$_;\n");
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
@function =
|
|
|
|
map { s{\(char \*\*\)\&(objp->[a-z_.]+_val)}
|
|
|
|
{objp_cpp$uses{$1}}gi; $_ } @function;
|
|
|
|
}
|
|
|
|
|
|
|
|
# The code uses 'IXDR_PUT_{U_,}LONG' but it's wrong in two
|
|
|
|
# ways: Firstly these functions are deprecated and don't
|
|
|
|
# work on 64 bit platforms. Secondly the return value should
|
|
|
|
# be ignored. Correct both these mistakes.
|
|
|
|
@function =
|
|
|
|
map { s/\bIXDR_PUT_((U_)?)LONG\b/(void)IXDR_PUT_$1INT32/; $_ }
|
|
|
|
map { s/\bXDR_INLINE\b/(int32_t*)XDR_INLINE/; $_ }
|
|
|
|
@function;
|
|
|
|
|
|
|
|
print TARGET (join ("", @function));
|
|
|
|
@function = ();
|
2007-06-11 11:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unless ($in_function) {
|
2012-07-27 12:51:28 +00:00
|
|
|
print TARGET;
|
2007-06-11 11:36:17 +00:00
|
|
|
} else {
|
2012-07-27 12:51:28 +00:00
|
|
|
push @function, $_;
|
2007-06-11 11:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-06 13:11:32 +00:00
|
|
|
|
|
|
|
close TARGET
|
|
|
|
or die "cannot save $target: $!";
|
|
|
|
close RPCGEN
|
|
|
|
or die "cannot shutdown $rpcgen: $!";
|
|
|
|
|
|
|
|
chmod 0444, $target
|
|
|
|
or die "cannot set $target readonly: $!";
|