Opened 17 years ago

Last modified 17 years ago

#2021 closed defect

INCLUDE is only parsed in the first mapfile — at Version 4

Reported by: johan.vandewauw@… Owned by: sdlime
Priority: high Milestone: 5.0 release
Component: MapServer C Library Version: 4.10
Severity: normal Keywords:
Cc:

Description (last modified by dmorissette)

When I use a script where different mapfiles are parsed, it seems like the
INCLUDE directive is not followed in the second mapfile and therefore it
generates an error.

The following script, with two valid mapfiles with include directives generates
the following error:
Script:
<?php
dl("php_mapscript.so");
$map1 = ms_newMapObj("/home/johan/rwanda/start.map");
$map2 = ms_newMapObj("/home/johan/rwanda/start3.map");
?>
Error:
Warning: [MapServer Error]: msLoadMap(): in /home/johan/public_html/test.php on
line 5

Warning: Failed to open map file /home/johan/rwanda/start3.map in
/home/johan/public_html/test.php on line 5

Some information on my mapscript version:
MapServer version 4.10.0 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP
OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER INPUT=EPPL7
INPUT=JPEG INPUT=POSTGIS INPUT=SHAPEFILE
PHP MapScript Version 	($Revision: 1.260 $ $Date: 2006/09/06 16:42:36 $)

-------------
The script also fails when using the cvs-version (same error):
MapServer version 4.99 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=SVG
SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER INPUT=EPPL7 INPUT=JPEG
INPUT=POSTGIS INPUT=SHAPEFILE

Change History (4)

comment:1 by dmorissette, 17 years ago

Cc: steve.lime@… added
This is probably not specific to PHP. Adding Steve to CC.

comment:2 by sdlime, 17 years ago

Component: MapScript-PHPMapServer C Library
Status: newassigned
That's a test case that I never tried. I'm not sure why it wouldn't work but I 
imagine there is some state information that needs to be reset between runs of 
the tokenizer. Switching component to the main C library...

Steve

comment:3 by dmorissette, 17 years ago

Milestone: 5.0 release

comment:4 by dmorissette, 17 years ago

Description: modified (diff)
Owner: changed from mapserverbugs to sdlime
Status: assignednew

Steve,

I was able to reproduce this with 5.0-beta2 and stepped through it in the debugger. It turns out that the issue seems to be caused by include_stack_ptr being left to a value of -1 after we hit EOF on the first mapfile.

Then the second parse starts with include_stack_ptr=-1 and never returns an "unexpected EOF" error.

The following patch seems to fix the issue, but I'm not sure if that's the best way to go. I think forcing include_stack_ptr=0 in some initialization code might be better so that in case of errors during parsing of an included file we still start up clean, but I didn't look for or find the right location to do it. I'll leave that to you.

--- maplexer.l  (revision 6436)
+++ maplexer.l  (working copy)
@@ -521,9 +521,10 @@
 <INITIAL>\n                                     { msyylineno++; }

 <INITIAL><<EOF>>                                {
-                                                  if( --include_stack_ptr < 0 )
+                                                  if( --include_stack_ptr < 0 ) {
+                                                    include_stack_ptr = 0;
                                                     return(EOF); /* end of main file */
-                                                  else {
+                                                  } else {
                                                     fclose(YY_CURRENT_BUFFER->yy_input_file);
                                                     msyy_delete_buffer( YY_CURRENT_BUFFER );
                                                     msyy_switch_to_buffer(include_stack[include_stack_ptr]);
Note: See TracTickets for help on using tickets.