some compilers can't handle structures with no elements. Generate
authorAndrew Tridgell <tridge@samba.org>
Tue, 16 Dec 2003 03:44:32 +0000 (03:44 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 16 Dec 2003 03:44:32 +0000 (03:44 +0000)
dummy elements if need be.

source/build/pidl/header.pm

index f7072633b90277550a17ec33f4a106350b5b775f..507455d1a177cfcae538d4a4adb7cfb0e4ffc2d1 100644 (file)
@@ -194,6 +194,20 @@ sub HeaderFunctionInOut($$)
     }
 }
 
+#####################################################################
+# determine if we need an "in" or "out" section
+sub HeaderFunctionInOut_needed($$)
+{
+    my($fn) = shift;
+    my($prop) = shift;
+    foreach my $e (@{$fn->{DATA}}) {
+           if (util::has_property($e, $prop)) {
+                   return 1;
+           }
+    }
+    return undef;
+}
+
 
 #####################################################################
 # parse a function
@@ -202,24 +216,40 @@ sub HeaderFunction($)
     my($fn) = shift;
     $res .= "\nstruct $fn->{NAME} {\n";
     $tab_depth++;
-    tabs();
-    $res .= "struct {\n";
-    $tab_depth++;
-    HeaderFunctionInOut($fn, "in");
-    $tab_depth--;
-    tabs();
-    $res .= "} in;\n\n";
-    tabs();
-    $res .= "struct {\n";
-    $tab_depth++;
-    HeaderFunctionInOut($fn, "out");
-    if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
+    my $needed = 0;
+
+    if (HeaderFunctionInOut_needed($fn, "in")) {
            tabs();
-           $res .= "$fn->{RETURN_TYPE} result;\n";
+           $res .= "struct {\n";
+           $tab_depth++;
+           HeaderFunctionInOut($fn, "in");
+           $tab_depth--;
+           tabs();
+           $res .= "} in;\n\n";
+           $needed++;
     }
-    $tab_depth--;
-    tabs();
-    $res .= "} out;\n\n";
+
+    if (HeaderFunctionInOut_needed($fn, "out")) {
+           tabs();
+           $res .= "struct {\n";
+           $tab_depth++;
+           HeaderFunctionInOut($fn, "out");
+           if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
+                   tabs();
+                   $res .= "$fn->{RETURN_TYPE} result;\n";
+           }
+           $tab_depth--;
+           tabs();
+           $res .= "} out;\n\n";
+           $needed++;
+    }
+
+    if (! $needed) {
+           # sigh - some compilers don't like empty structures
+           tabs();
+           $res .= "int _dummy_element;\n";
+    }
+
     $tab_depth--;
     $res .= "};\n\n";
 }