diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 52bedf87f..7d3d33ac1 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -820,6 +820,15 @@ Results in the following in "example.php" echo "example.php execution\n"; +
+The version pragma can be used to add version to generated PHP extension module. The version is inserted in the zend_module_entry block. +
+ ++%module example +%pragma(php) version="1.5" +
The include pragma is a short cut to add include statements to the example.php file. diff --git a/Examples/php/pragmas/example.i b/Examples/php/pragmas/example.i index c7e8bf303..f9307a663 100644 --- a/Examples/php/pragmas/example.i +++ b/Examples/php/pragmas/example.i @@ -27,5 +27,6 @@ # This code is inserted into example.php echo \"this was php code\\n\"; " +%pragma(php) version="1.5" %pragma(php) phpinfo="php_info_print_table_start();" diff --git a/Examples/php/pragmas/runme.php b/Examples/php/pragmas/runme.php index 538548b6f..b99cf37a4 100644 --- a/Examples/php/pragmas/runme.php +++ b/Examples/php/pragmas/runme.php @@ -2,4 +2,5 @@ require "example.php"; +echo "Version - " . ((new ReflectionExtension('example'))->getVersion()); ?> diff --git a/Examples/php5/pragmas/example.i b/Examples/php5/pragmas/example.i index c7e8bf303..f9307a663 100644 --- a/Examples/php5/pragmas/example.i +++ b/Examples/php5/pragmas/example.i @@ -27,5 +27,6 @@ # This code is inserted into example.php echo \"this was php code\\n\"; " +%pragma(php) version="1.5" %pragma(php) phpinfo="php_info_print_table_start();" diff --git a/Examples/php5/pragmas/runme.php b/Examples/php5/pragmas/runme.php index 538548b6f..b99cf37a4 100644 --- a/Examples/php5/pragmas/runme.php +++ b/Examples/php5/pragmas/runme.php @@ -2,4 +2,5 @@ require "example.php"; +echo "Version - " . ((new ReflectionExtension('example'))->getVersion()); ?> diff --git a/Examples/test-suite/php/Makefile.in b/Examples/test-suite/php/Makefile.in index c554e2b17..64f0d1f9d 100644 --- a/Examples/test-suite/php/Makefile.in +++ b/Examples/test-suite/php/Makefile.in @@ -14,6 +14,7 @@ CPP_TEST_CASES += \ li_factory \ php_iterator \ php_namewarn_rename \ + php_pragma \ include $(srcdir)/../common.mk diff --git a/Examples/test-suite/php/php_pragma_runme.php b/Examples/test-suite/php/php_pragma_runme.php new file mode 100644 index 000000000..ae92f6818 --- /dev/null +++ b/Examples/test-suite/php/php_pragma_runme.php @@ -0,0 +1,12 @@ +getVersion(),"1.5==version(php_pragma)"); + +check::done(); + +?> + diff --git a/Examples/test-suite/php5/Makefile.in b/Examples/test-suite/php5/Makefile.in index 391ca2c53..179ce59d6 100644 --- a/Examples/test-suite/php5/Makefile.in +++ b/Examples/test-suite/php5/Makefile.in @@ -14,6 +14,7 @@ CPP_TEST_CASES += \ li_factory \ php_iterator \ php_namewarn_rename \ + php_pragma \ include $(srcdir)/../common.mk diff --git a/Examples/test-suite/php5/php_pragma_runme.php b/Examples/test-suite/php5/php_pragma_runme.php new file mode 100644 index 000000000..ae92f6818 --- /dev/null +++ b/Examples/test-suite/php5/php_pragma_runme.php @@ -0,0 +1,12 @@ +getVersion(),"1.5==version(php_pragma)"); + +check::done(); + +?> + diff --git a/Examples/test-suite/php_pragma.i b/Examples/test-suite/php_pragma.i new file mode 100644 index 000000000..4d14f1357 --- /dev/null +++ b/Examples/test-suite/php_pragma.i @@ -0,0 +1,6 @@ +// Test pragma of php - pragma version. + +%module php_pragma + +%pragma(php) version= "1.5" + diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index e6fbf47d7..0ab792863 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -96,6 +96,7 @@ static String *all_cs_entry; static String *pragma_incl; static String *pragma_code; static String *pragma_phpinfo; +static String *pragma_version; static String *s_oowrappers; static String *s_fakeoowrappers; static String *s_phpclasses; @@ -359,6 +360,7 @@ public: /* sub-sections of the php file */ pragma_code = NewStringEmpty(); pragma_incl = NewStringEmpty(); + pragma_version = NULL; /* Initialize the rest of the module */ @@ -515,7 +517,11 @@ public: } else { Printf(s_init, " NULL, /* No MINFO code */\n"); } - Printf(s_init, " NO_VERSION_YET,\n"); + if (Len(pragma_version) > 0) { + Printf(s_init, " \"%s\",\n", pragma_version); + } else { + Printf(s_init, " NO_VERSION_YET,\n"); + } Printf(s_init, " STANDARD_MODULE_PROPERTIES\n"); Printf(s_init, "};\n"); Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module); @@ -2007,6 +2013,10 @@ done: if (value) { Printf(pragma_phpinfo, "%s\n", value); } + } else if (Strcmp(type, "version") == 0) { + if (value) { + pragma_version = value; + } } else { Swig_warning(WARN_PHP_UNKNOWN_PRAGMA, input_file, line_number, "Unrecognized pragma <%s>.\n", type); } diff --git a/Source/Modules/php5.cxx b/Source/Modules/php5.cxx index 59d928c21..bf5664c3c 100644 --- a/Source/Modules/php5.cxx +++ b/Source/Modules/php5.cxx @@ -96,6 +96,7 @@ static String *all_cs_entry; static String *pragma_incl; static String *pragma_code; static String *pragma_phpinfo; +static String *pragma_version; static String *s_oowrappers; static String *s_fakeoowrappers; static String *s_phpclasses; @@ -294,7 +295,7 @@ public: 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"); @@ -391,6 +392,7 @@ public: /* sub-sections of the php file */ pragma_code = NewStringEmpty(); pragma_incl = NewStringEmpty(); + pragma_version = NULL; /* Initialize the rest of the module */ @@ -528,7 +530,14 @@ public: 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"); @@ -542,7 +551,11 @@ public: Printf(s_init, " PHP_RINIT(%s),\n", module); Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module); Printf(s_init, " PHP_MINFO(%s),\n", module); - Printf(s_init, " NO_VERSION_YET,\n"); + if (Len(pragma_version) > 0) { + Printf(s_init, " \"%s\",\n", pragma_version); + } else { + Printf(s_init, " NO_VERSION_YET,\n"); + } Printf(s_init, " STANDARD_MODULE_PROPERTIES\n"); Printf(s_init, "};\n"); Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module); @@ -562,11 +575,9 @@ public: * 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"); @@ -1988,6 +1999,10 @@ done: if (value) { Printf(pragma_phpinfo, "%s\n", value); } + } else if (Strcmp(type, "version") == 0) { + if (value) { + pragma_version = value; + } } else { Swig_warning(WARN_PHP_UNKNOWN_PRAGMA, input_file, line_number, "Unrecognized pragma <%s>.\n", type); }