Ariel Scolnicov <[EMAIL PROTECTED]> writes:

> David Coppit <[EMAIL PROTECTED]> writes:
> 
> > On Sun, 3 Jun 2001, Brian Ingerson wrote:
> > 
> > > Fixed David Coppit's postamble problem. (Just deleted a bunch of lines
> > > :)
> > 
> > This version (and maybe 0.41-TRIAL1--I didn't check) has trouble
> > compiling my module, whereas 0.40 didn't. If I delete the function
> > declaration for the problem function, it works okay:
> 
> [...]
> 
> > int _ends_with_include(char *email_boundary);
> 
> [...]
> 
> > int _ends_with_include(char *email_boundary)
> 
> [...]
> 
> Ouch!  Mea culpa!  Somebody shoot me, please.
> 
> 
> What's going on is that Inline is wrapping both the declaration AND
> the definition.  Evidently I'll have to do some better hack on the
> grammar.

OK, here's the deal.  No matter how many times you declare a function,
you only want to wrap it once (declarations are "idempotent" that way
in C: you can say "double erf(double); double erf(double x); double
erf(double y);" in your code with no problems.  Of course, all
declarations must be *consistent* (unlike C++, which lets you overload
your functions) and definitions may only appear *once*.

The following patch to C/grammar/grammar.pm (against 0.41-TRIAL1) only
generates wrapper code *once*, fixing the above problem.  It *doesn't*
check for consistency of multiple declarations or of the declarations
with a definition (the compiler does that for us), or that a
definition appear (it might come from a library; the linker checks
that for us).

Test it by saying e.g.

    perl -le 'use Inline C => q{ int add(int a, int b) { return a+b; } int 
add(int,int); }; print add(3,4)'

You can put the declaration several times, before and after the
definition, and all is well; the wrapper only gets written once.


Sorry (especially to David, who received a complimentary copy every
time), the Inline mailing list server refuses to send attachments
(even text/plain).  So here's the patch, between dots, in glorious
ASCII:

................................................................
*** Inline-0.41-TRIAL1/C/grammar/grammar.pm     Sun Jun  3 05:22:45 2001
--- Inline-0.41-TRIAL1.work/C/grammar/grammar.pm        Mon Jun  4 21:32:12 2001
***************
*** 13,37 ****
        | function_definition
        {
         my $function = $item[1]->[0];
!        push @{$thisparser->{data}->{functions}}, $function;
!        $thisparser->{data}->{function}->{$function}->{return_type} = 
!              $item[1]->[1];
!        $thisparser->{data}->{function}->{$function}->{arg_types} = 
!              [map {ref $_ ? $_->[0] : '...'} @{$item[1]->[2]}];
!        $thisparser->{data}->{function}->{$function}->{arg_names} = 
!              [map {ref $_ ? $_->[1] : '...'} @{$item[1]->[2]}];
        }
        | function_declaration
        {
         my $function = $item[1]->[0];
           my $dummy = 'arg1';
!        push @{$thisparser->{data}->{functions}}, $function;
!        $thisparser->{data}->{function}->{$function}->{return_type} = 
!              $item[1]->[1];
!          $thisparser->{data}->{function}->{$function}->{arg_types} = 
!              [map {ref $_ ? $_->[0] : '...'} @{$item[1]->[2]}];
!        $thisparser->{data}->{function}->{$function}->{arg_names} = 
!              [map {ref $_ ? ($_->[1] || $dummy++) : '...'} @{$item[1]->[2]}];
        }
        | anything_else
  
--- 13,45 ----
        | function_definition
        {
         my $function = $item[1]->[0];
!          if (! exists $thisparser->{data}->{wrapped_funcs}->{$function}) {
!              $thisparser->{data}->{wrapped_funcs}->{$function} = 1;
!            push @{$thisparser->{data}->{functions}}, $function;
!            $thisparser->{data}->{function}->{$function}->{return_type} = 
!                  $item[1]->[1];
!            $thisparser->{data}->{function}->{$function}->{arg_types} = 
!                  [map {ref $_ ? $_->[0] : '...'} @{$item[1]->[2]}];
!            $thisparser->{data}->{function}->{$function}->{arg_names} = 
!                  [map {ref $_ ? $_->[1] : '...'} @{$item[1]->[2]}];
!          }
!          1;
        }
        | function_declaration
        {
         my $function = $item[1]->[0];
           my $dummy = 'arg1';
!          if (! exists $thisparser->{data}->{wrapped_funcs}->{$function}) {
!              $thisparser->{data}->{wrapped_funcs}->{$function} = 1;
!            push @{$thisparser->{data}->{functions}}, $function;
!            $thisparser->{data}->{function}->{$function}->{return_type} = 
!                  $item[1]->[1];
!              $thisparser->{data}->{function}->{$function}->{arg_types} = 
!                  [map {ref $_ ? $_->[0] : '...'} @{$item[1]->[2]}];
!            $thisparser->{data}->{function}->{$function}->{arg_names} = 
!                  [map {ref $_ ? ($_->[1] || $dummy++) : '...'} @{$item[1]->[2]}];
!          }
!          1;
        }
        | anything_else
  
................................................................

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | [EMAIL PROTECTED]
Compugen Ltd.          |Tel: +972-2-5713025 (Jerusalem) \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658117 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels

Reply via email to