Narrowing in on source of "<filename.scad>" bug

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Narrowing in on source of "<filename.scad>" bug

clothbot
Hi Clifford,

I've found a way to make "<filename.scad>" includes work for me, but  
this probably isn't the proper way to fix things:

--snip--

svn diff lexer.l
Index: lexer.l
===================================================================
--- lexer.l (revision 141)
+++ lexer.l (working copy)
@@ -73,8 +73,8 @@
}

<<EOF>> {
- if (yyin)
- fclose(yyin);
+// if (yyin)
+// fclose(yyin);
        yypop_buffer_state();
        if (!YY_CURRENT_BUFFER)
                yyterminate();

--end-snip--

If I comment out the fclose(yyin); in lexer.l then file includes work  
for me.  I can see why it's there, to match the fopen() operation, but  
I suspect there's a mismatched number of "fclose()" operations when  
Compile is run for the second time.

Andrew.

--

"The future is already here.  It's just not very evenly distributed"  
-- William Gibson




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Narrowing in on source of "<filename.scad>" bug

clothbot
Here's a cleaner fix using a "filecount" int to track the number of  
calls to fopen:

--snip--

svn diff lexer.l
Index: lexer.l
===================================================================
--- lexer.l (revision 141)
+++ lexer.l (working copy)
@@ -23,6 +23,8 @@
  #include "openscad.h"
  #include "parser_yacc.h"

+int filecount=0;
+
  int lexerget_lineno(void);
  #ifdef __GNUC__
  static void yyunput(int, char*) __attribute__((unused));
@@ -66,6 +68,7 @@
  if (!yyin) {
  PRINTF("WARNING: Can't open input file `%s'.", filename);
  } else {
+ filecount++;
  yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));
  BEGIN(INITIAL);
  }
@@ -73,8 +76,10 @@
  }

  <<EOF>> {
- if (yyin)
+ if (yyin && filecount>0) {
  fclose(yyin);
+ filecount--;
+ }
  yypop_buffer_state();
  if (!YY_CURRENT_BUFFER)
  yyterminate();

--end-snip--

Andrew.

--

"The future is already here.  It's just not very evenly distributed"  
-- William Gibson




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Narrowing in on source of "<filename.scad>" bug

Clifford Wolf
In reply to this post by clothbot
Hi Andrew,

On Wed, Dec 02, 2009 at 01:03:14PM -0500, Andrew Plumb wrote:
> I've found a way to make "<filename.scad>" includes work for me, but  
> this probably isn't the proper way to fix things:

thans for your effort with debugging this issue.

after I have seen your patches it was totally clear to me what went wrong.
The following patch (applied already to subversion trunk) solves the
problem:

--snip--
Index: lexer.l
===================================================================
--- lexer.l     (revision 141)
+++ lexer.l     (revision 142)
@@ -73,7 +73,7 @@
 }

 <<EOF>> {
-       if (yyin)
+       if (yyin && yyin != stdin)
                fclose(yyin);
        yypop_buffer_state();
        if (!YY_CURRENT_BUFFER)
--snap--

yours,
 - clifford

--
"Premature optimization is the root of all evil." - Donald Knuth

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Narrowing in on source of "<filename.scad>" bug

clothbot
Got distracted with the other threads. :-)

Confirmed that your fix works in my local build-from-svn.

Thanks!

Andrew.

On 4-Dec-09, at 2:35 AM, Clifford Wolf wrote:

> Hi Andrew,
>
> On Wed, Dec 02, 2009 at 01:03:14PM -0500, Andrew Plumb wrote:
>> I've found a way to make "<filename.scad>" includes work for me, but
>> this probably isn't the proper way to fix things:
>
> thans for your effort with debugging this issue.
>
> after I have seen your patches it was totally clear to me what went  
> wrong.
> The following patch (applied already to subversion trunk) solves the
> problem:
>
> --snip--
> Index: lexer.l
> ===================================================================
> --- lexer.l     (revision 141)
> +++ lexer.l     (revision 142)
> @@ -73,7 +73,7 @@
> }
>
> <<EOF>> {
> -       if (yyin)
> +       if (yyin && yyin != stdin)
>                fclose(yyin);
>        yypop_buffer_state();
>        if (!YY_CURRENT_BUFFER)
> --snap--
>
> yours,
> - clifford
>
> --
> "Premature optimization is the root of all evil." - Donald Knuth
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad

--

"The future is already here.  It's just not very evenly distributed"  
-- William Gibson




Loading...