Branch: Tag:

2014-04-20

2014-04-20 10:02:38 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Support __INIT with C programs.

When a C program inherits Pike code, it may need to have an __INIT.
This would previously cause fatal errors as end_program() transited
to compiler pass #2 before the __INIT symbol had been added.

end_first_pass() now transits from pass #1 to pass #2 if finish
has been set, and ensures that __INIT (if needed) exists.

4012:    }    }    +  if (finish == 1) { +  if (Pike_compiler->compiler_pass == 1) { +  /* Called from end_program(). */ +  if (Pike_compiler->init_node) { +  /* Make sure that the __INIT symbol exists, so that +  * we won't get a fatal when we add the actual code +  * further down when we have entered pass 2. +  */ +  define_function(s, function_type_string, ID_PROTECTED, +  IDENTIFIER_PIKE_FUNCTION, NULL, 0); +  } +  } +  Pike_compiler->compiler_pass = 2; +  } +     /*    * Define the __INIT function, but only if there was any code    * to initialize.
4161:    */   PMOD_EXPORT struct program *debug_end_program(void)   { -  Pike_compiler->compiler_pass = 2; +     return end_first_pass(1);   }