[phc-internals] [phc] r3300 committed - Extensions didn't really
work well (beyond "hello world") as the impor...
codesite-noreply at google.com
codesite-noreply at google.com
Thu Oct 1 13:17:04 IST 2009
Revision: 3300
Author: paul.biggar
Date: Thu Oct 1 05:16:08 2009
Log: Extensions didn't really work well (beyond "hello world") as the
important initializations and finalizations weren't taking place.
Hopefully this solves that (based on a patch by Martijn Bogaard).
http://code.google.com/p/phc/source/detail?r=3300
Modified:
/trunk/src/codegen/Generate_C.cpp
=======================================
--- /trunk/src/codegen/Generate_C.cpp Mon May 4 08:48:00 2009
+++ /trunk/src/codegen/Generate_C.cpp Thu Oct 1 05:16:08 2009
@@ -73,6 +73,14 @@
// we need access to the pass manager in compile_static_value
extern Pass_manager* pm;
+
+/* While its tough to remove these, we can at least limit them so that they
+ * arent usable from patterns. */
+static stringstream prologue;
+static stringstream initializations;
+static stringstream embed_initializations;
+static stringstream finalizations;
+
/*
* Helper functions
*/
@@ -977,6 +985,11 @@
<< " saved_refcount = (*return_value_ptr)->refcount;\n"
;
}
+
+ if (*signature->method_name->value == "__MAIN__")
+ {
+ buf << finalizations.str ();
+ }
buf << "}\n" ;
}
@@ -2614,11 +2627,6 @@
out << read_file (filename);
}
-/* While its tough to remove these, we can at least limit them so that they
- * arent usable from patterns. */
-static stringstream prologue;
-static stringstream initializations;
-static stringstream finalizations;
void Generate_C::pre_php_script(PHP_script* in)
{
micg.add_macro_def (read_file
(s("templates/templates_new.c")), "templates/templates_new.c");
@@ -2670,7 +2678,7 @@
foreach (String* key, *PHP::get_altered_ini_entries ())
{
String* value = PHP::get_ini_entry (key);
- initializations
+ embed_initializations
<< "zend_alter_ini_entry ("
<< "\"" << *key << "\", "
<< (key->size () + 1) << ", " // include NULL byte
@@ -2701,11 +2709,38 @@
os << body.str();
// MINIT
- os << "// Module initialization\n";
- os << "PHP_MINIT_FUNCTION(" << *extension_name << ")\n{\n";
- os << minit.str();
- os << "return SUCCESS;";
- os << "}";
+ os << "// Module initialization\n"
+ << "PHP_MINIT_FUNCTION(" << *extension_name << ")\n{\n"
+
+ << " // initialize the phc runtime\n"
+ << " init_runtime();\n"
+ << "\n"
+ << " // initialize the module\n"
+ << minit.str()
+ << "\n"
+ << " // initialize the stats\n"
+ << init_stats ()
+ << "\n"
+ << " // Other initializations\n"
+ << initializations.str ()
+ << "\n"
+ << "return SUCCESS;\n"
+ << "}\n";
+
+ // MSHUTDOWN
+ os << "// Module finalization\n"
+ << "PHP_MSHUTDOWN_FUNCTION(" << *extension_name << ")\n{\n"
+ << "\n"
+ << " // Other finalizations occur at the end of __MAIN__\n"
+ << "\n"
+ << " // finalize the stats\n"
+ << finalize_stats ()
+ << "\n"
+ << " // Finalize the runtime\n"
+ << " finalize_runtime();\n"
+ << "\n"
+ << "return SUCCESS;\n"
+ << "}";
function_declaration_block(os,
in->attrs->get_list<Signature>("phc.codegen.compiled_functions"),
extension_name);
@@ -2717,7 +2752,7 @@
<< "\"" << *extension_name << "\",\n"
<< *extension_name << "_functions,\n"
<< "PHP_MINIT(" << *extension_name << "), /* MINIT */\n"
- << "NULL, /* MSHUTDOWN */\n"
+ << "PHP_MSHUTDOWN(" << *extension_name << "), /* MSHUTDOWN */\n"
<< "NULL, /* RINIT */\n"
<< "NULL, /* RSHUTDOWN */\n"
<< "NULL, /* MINFO */\n"
@@ -2765,13 +2800,10 @@
" signal(SIGSEGV, sighandler);\n"
"\n"
" TSRMLS_D;\n"
- " int dealloc_pools = 1;\n"
" php_embed_init (argc, argv PTSRMLS_CC);\n"
" zend_first_try\n"
" {\n"
"\n"
- " // initialize the phc runtime\n"
- " init_runtime();\n"
"\n"
" // load the compiled extension\n"
" zend_startup_module (&" << *extension_name << "_module_entry);\n"
@@ -2785,9 +2817,7 @@
" zend_alter_ini_entry (\"report_zend_debug\",
sizeof(\"report_zend_debug\"), \"0\", sizeof(\"0\") - 1, PHP_INI_ALL,
PHP_INI_STAGE_RUNTIME);\n"
" zend_alter_ini_entry (\"display_startup_errors\",
sizeof(\"display_startup_errors\"), \"1\", sizeof(\"1\") - 1, PHP_INI_ALL,
PHP_INI_STAGE_RUNTIME);\n"
"\n"
- << init_stats () <<
- " // initialize all the constants\n"
- << initializations.str () << // TODO put this in __MAIN__, or else
extensions cant use it.
+ << embed_initializations.str () <<
"\n"
" // call __MAIN__\n"
" int success = call_user_function( \n"
@@ -2801,20 +2831,12 @@
"\n"
" assert (success == SUCCESS);\n"
"\n"
- << finalize_stats () <<
- " // finalize the runtime\n"
- " finalize_runtime();\n"
"\n"
" }\n"
" zend_catch\n"
" {\n"
- " dealloc_pools = 0;\n"
" }\n"
" zend_end_try ();\n"
- " if (dealloc_pools)\n"
- " {\n"
- << finalizations.str () <<
- " }\n"
" phc_exit_status = EG(exit_status);\n"
" php_embed_shutdown (TSRMLS_C);\n"
"\n"
More information about the phc-internals
mailing list