Skip to content

Commit

Permalink
Refactor to generate init section before the code.
Browse files Browse the repository at this point in the history
Prerequisite to address issue #360, feature request of adding extension version.
This change has been taken from Sources/Modules/php.cxx - PHP7 Backend.
  • Loading branch information
nihal95 committed May 7, 2017
1 parent fcde570 commit 3adf88e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Source/Modules/php5.cxx
Expand Up @@ -294,7 +294,7 @@ class PHP5 : public Language {
f_runtime = NewStringEmpty();

/* sections of the output file */
s_init = NewString("/* init section */\n");
s_init = NewStringEmpty();
r_init = NewString("/* rinit section */\n");
s_shutdown = NewString("/* shutdown section */\n");
r_shutdown = NewString("/* rshutdown section */\n");
Expand Down Expand Up @@ -528,7 +528,14 @@ class PHP5 : public Language {
Printf(s_entry, "/* Every non-class user visible function must have an entry here */\n");
Printf(s_entry, "static zend_function_entry %s_functions[] = {\n", module);

/* Emit all of the code */
Language::top(n);

SwigPHP_emit_resource_registrations();

/* start the init section */
String * s_init_old = s_init;
s_init = NewString("/* init section */\n");
Append(s_init, "#if ZEND_MODULE_API_NO <= 20090626\n");
Append(s_init, "#undef ZEND_MODULE_BUILD_ID\n");
Append(s_init, "#define ZEND_MODULE_BUILD_ID (char*)\"API\" ZEND_TOSTR(ZEND_MODULE_API_NO) ZEND_BUILD_TS ZEND_BUILD_DEBUG ZEND_BUILD_SYSTEM ZEND_BUILD_EXTRA\n");
Expand Down Expand Up @@ -562,11 +569,9 @@ class PHP5 : public Language {
* things are being called in the wrong order
*/
Printf(s_init, "#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n", module);
Printv(s_init, s_init_old, NIL);
Delete(s_init_old);

/* Emit all of the code */
Language::top(n);

SwigPHP_emit_resource_registrations();
// Printv(s_init,s_resourcetypes,NIL);
/* We need this after all classes written out by ::top */
Printf(s_oinit, "CG(active_class_entry) = NULL;\n");
Expand Down

0 comments on commit 3adf88e

Please sign in to comment.