Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2003-02

h2pas bug

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jeff Pohlmeyer
This is legal in a C header:
  struct foo;

- But it causes a seg fault in h2pas when it tries to read the fields from the undefined structure.

There may be a better place to test for this,
but the patch below seems to work:

[PATCH]
--- h2pas-old/h2pas.pas	Thu Feb 13 15:20:44 2003
+++ h2pas-new/h2pas.pas	Thu Feb 13 15:06:49 2003
@@ -1386,6 +1386,7 @@
          end;
          shift(3);
          (* write new type name *)
+         if ( yyv[yysp-1]^.p2   nil ) then begin
          TN:=TypeName(yyv[yysp-1]^.p2^.p);
          PN:=PointerName(yyv[yysp-1]^.p2^.p);
          (* define a Pointer type also for structs *)
@@ -1407,7 +1408,17 @@
          write_packed_fields_info(outfile,hp,TN);
          if assigned(hp) then
          dispose(hp,done);
-
+         end else
+         begin
+           TN:=TypeName(yyv[yysp-1]^.str);
+           PN:=PointerName(yyv[yysp-1]^.str);
+           if UsePPointers then writeln(outfile,aktspace,PN,' = ^',TN,';');
+           writeln(outfile, aktspace, TN, ' = record');
+           writeln(outfile, aktspace, '    {undefined structure}');
+           writeln(outfile, aktspace, '  end;');
+           writeln(outfile);
+           popshift;
+         end;
        end;
   23 : begin
[/PATCH]

...This will make h2pas print something like:

  type
     Pfoo = ^Tfoo;
     Tfoo = record
         {undefined structure}
       end;

__________________________________________________ Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com

Reply by email

Unknown author
to Jeff Pohlmeyer
Jeff Pohlmeyer wrote 9 lines
This is legal in a C header: struct foo; - But it causes a seg fault in h2pas when it tries to read the fields from the undefined structure. There may be a better place to test for this, but the patch below seems to work:

I applied it in the h2pas.y yacc sources. The h2pas.pas is generated from that. Tested and it works.

Thanks !

Michael.

Reply by email