From 4ebb4060f918cc15d2e7be7f37ae71ada92e9646 Mon Sep 17 00:00:00 2001 From: Andi Gutmans Date: Sun, 25 Apr 1999 19:35:44 +0000 Subject: [PATCH] * Fix a couple of thread safety issues * Add initial ISAPI support. Very very experimental. * In the thread safe version, generate php4 as a library so that we can link it with both php.exe and the ISAPI dll. We should probably consider doing that under all circumstances, under UNIX as well. The thread-unsafe version *should* be unharmed. --- main/main.c | 58 ++++- main/php.h | 2 +- output.c | 37 +--- php4ts.dsp | 602 +--------------------------------------------------- php4ts.dsw | 36 ++++ 5 files changed, 99 insertions(+), 636 deletions(-) diff --git a/main/main.c b/main/main.c index 74663ac74a..7ac337bd33 100644 --- a/main/main.c +++ b/main/main.c @@ -82,6 +82,9 @@ struct sapi_request_info *sapi_rqst; #endif #endif + +#include "SAPI.h" + #if MSVC5 || !defined(HAVE_GETOPT) #include "getopt.h" #endif @@ -107,6 +110,9 @@ void *gLock; /*mutex variable */ /* True globals (no need for thread safety) */ HashTable configuration_hash; char *php3_ini_path = NULL; +#ifdef ZTS +php_core_globals *main_core_globals; +#endif static PHP_INI_MH(OnSetPrecision) @@ -599,6 +605,36 @@ static void php_message_handler_for_zend(long message, void *data) } + +#ifndef NEW_SAPI +# if APACHE +static int zend_apache_ub_write(const char *str, uint str_length) +{ + if (php3_rqst) { + return rwrite(str, str_length, php3_rqst); + } else { + return fwrite(str, 1, str_length, stdout); + } +} + +sapi_functions_struct sapi_functions = { + zend_apache_ub_write +}; + +# elif CGI_BINARY + +static int zend_cgibin_ub_write(const char *str, uint str_length) +{ + return fwrite(str, 1, str_length, stdout); +} + +sapi_functions_struct sapi_functions = { + zend_cgibin_ub_write +}; +# endif +#endif + + int php3_request_startup(CLS_D ELS_DC PLS_DC) { zend_output_startup(); @@ -745,6 +781,14 @@ static void php3_config_ini_shutdown() } +#ifdef ZTS +static core_globals_ctor(php_core_globals *core_globals) +{ + *core_globals = *main_core_globals; +} +#endif + + int php3_module_startup() { zend_utility_functions zuf; @@ -778,8 +822,13 @@ int php3_module_startup() zend_startup(&zuf, NULL); #ifdef ZTS - core_globals_id = ts_allocate_id(sizeof(php_core_globals), NULL, NULL); + core_globals_id = ts_allocate_id(sizeof(php_core_globals), core_globals_ctor, NULL); core_globals = ts_resource(core_globals_id); + main_core_globals = core_globals; +#endif + +#ifdef NEW_SAPI + sapi_startup(); #endif #if HAVE_SETLOCALE @@ -1093,7 +1142,7 @@ void _php3_build_argv(char *s ELS_DC) #include "logos.h" -static void php3_parse(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC) +void php3_parse(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC) { zend_file_handle *prepend_file_p, *append_file_p; zend_file_handle prepend_file, append_file; @@ -1150,7 +1199,7 @@ static void php3_parse(zend_file_handle *primary_file CLS_DC ELS_DC PLS_DC) #if CGI_BINARY -static void _php3_usage(char *argv0) +void _php3_usage(char *argv0) { char *prog; @@ -1187,6 +1236,7 @@ extern flex_globals *yy_init_tls(void); extern void yy_destroy_tls(void); #endif +#ifndef ZTS int main(int argc, char *argv[]) { int cgi = 0, c, i, len; @@ -1443,6 +1493,8 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine } #endif /* CGI_BINARY */ +#endif /* ZTS */ + #if APACHE PHPAPI int apache_php3_module_main(request_rec * r, int fd, int display_source_mode) diff --git a/main/php.h b/main/php.h index 1d66a43a85..d66976e58b 100644 --- a/main/php.h +++ b/main/php.h @@ -66,7 +66,7 @@ extern unsigned char second_arg_allow_ref[]; */ -#if MSVC5 +#if WIN32 #include "config.w32.h" #include "win95nt.h" # if defined(COMPILE_DL) diff --git a/output.c b/output.c index d7e2389a90..886ba87a17 100644 --- a/output.c +++ b/output.c @@ -16,6 +16,7 @@ #include "php.h" #include "ext/standard/head.h" +#include "SAPI.h" /* output functions */ int (*zend_body_write)(const char *str, uint str_length); /* string output */ @@ -37,13 +38,6 @@ static inline void zend_ob_send(); /* HEAD support */ static int header_request; -/* wrappers */ -#if APACHE -static int zend_apache_ub_write(const char *str, uint str_length); -#elif CGI_BINARY -static int zend_cgibin_ub_write(const char *str, uint str_length); -#endif - /* * Main @@ -54,11 +48,7 @@ void zend_output_startup() ob_buffer = NULL; zend_body_write = zend_ub_body_write; header_request=0; -#if APACHE - zend_header_write = zend_apache_ub_write; -#elif CGI_BINARY - zend_header_write = zend_cgibin_ub_write; -#endif + zend_header_write = sapi_functions.ub_write; } @@ -193,29 +183,6 @@ static int zend_ub_body_write(const char *str, uint str_length) } -#if APACHE - -static int zend_apache_ub_write(const char *str, uint str_length) -{ - if (php3_rqst) { - return rwrite(str, str_length, php3_rqst); - } else { - return fwrite(str, 1, str_length, stdout); - } -} - -#elif CGI_BINARY - -static int zend_cgibin_ub_write(const char *str, uint str_length) -{ - return fwrite(str, 1, str_length, stdout); -} - - - -#endif - - /* * HEAD support */ diff --git a/php4ts.dsp b/php4ts.dsp index e2f9107923..2917e91c67 100644 --- a/php4ts.dsp +++ b/php4ts.dsp @@ -51,7 +51,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 lib44bsd95.lib resolv.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libzendts.lib tsrm.lib /nologo /version:3.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"Release_TS\php.exe" /libpath:"lib" /libpath:"\src\lib" /libpath:"d:\src\bind\lib" /libpath:"..\tsrm\release_TS" /libpath:"..\libzend\Release_TS" +# ADD LINK32 lib44bsd95.lib resolv.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libzendts.lib tsrm.lib /nologo /version:3.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"Release_TS\php.exe" /libpath:"lib" /libpath:"..\tsrm\release_TS" /libpath:"..\libzend\Release_TS" /libpath:"." !ELSEIF "$(CFG)" == "php4ts - Win32 Debug_TS" @@ -76,7 +76,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 lib44bsd95.lib resolv.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib TSRM.lib libzendts.lib /nologo /version:3.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"Debug_TS\php.exe" /pdbtype:sept /libpath:"lib" /libpath:"\src\lib" /libpath:"d:\src\bind\lib" /libpath:"..\TSRM\debug_ts" /libpath:"..\libzend\Debug_TS" +# ADD LINK32 winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib TSRM.lib libzendts.lib php4libts.lib lib44bsd95.lib resolv.lib /nologo /version:3.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"Debug_TS\php.exe" /pdbtype:sept /libpath:"lib" /libpath:"..\TSRM\debug_ts" /libpath:"..\libzend\Debug_TS" /libpath:"Debug_TS" # SUBTRACT LINK32 /pdb:none !ENDIF @@ -85,609 +85,17 @@ LINK32=link.exe # Name "php4ts - Win32 Release_TS" # Name "php4ts - Win32 Debug_TS" -# Begin Group "Core" - -# PROP Default_Filter "" # Begin Group "Source Files" -# PROP Default_Filter "" -# Begin Source File - -SOURCE=".\configuration-parser.c" -# End Source File -# Begin Source File - -SOURCE=".\configuration-scanner.c" -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\cyr_convert.c -# End Source File -# Begin Source File - -SOURCE=".\fopen-wrappers.c" -# End Source File -# Begin Source File - -SOURCE=.\getopt.c -# End Source File -# Begin Source File - -SOURCE=.\internal_functions.c -# End Source File -# Begin Source File - -SOURCE=.\main.c -# End Source File -# Begin Source File - -SOURCE=.\output.c -# End Source File -# Begin Source File - -SOURCE=.\php3_realpath.c -# End Source File -# Begin Source File - -SOURCE=.\php_ini.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\quot_print.c -# End Source File +# PROP Default_Filter ".c" # Begin Source File -SOURCE=.\request_info.c -# End Source File -# Begin Source File - -SOURCE=.\safe_mode.c +SOURCE=.\cgi_main.c # End Source File # End Group # Begin Group "Header Files" -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\config.w32.h -# End Source File -# Begin Source File - -SOURCE=".\configuration-parser.h" -# End Source File -# Begin Source File - -SOURCE=".\configuration-parser.tab.h" -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\cyr_convert.h -# End Source File -# Begin Source File - -SOURCE=.\getopt.h -# End Source File -# Begin Source File - -SOURCE=.\internal_functions_registry.h -# End Source File -# Begin Source File - -SOURCE=.\logos.h -# End Source File -# Begin Source File - -SOURCE=.\main.h -# End Source File -# Begin Source File - -SOURCE=.\output.h -# End Source File -# Begin Source File - -SOURCE=.\php.h -# End Source File -# Begin Source File - -SOURCE=.\php3_compat.h -# End Source File -# Begin Source File - -SOURCE=.\php3_realpath.h -# End Source File -# Begin Source File - -SOURCE=.\php_globals.h -# End Source File -# Begin Source File - -SOURCE=.\php_ini.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\quot_print.h -# End Source File -# Begin Source File - -SOURCE=.\request_info.h -# End Source File -# Begin Source File - -SOURCE=.\safe_mode.h -# End Source File -# Begin Source File - -SOURCE=.\win95nt.h -# End Source File -# End Group -# End Group -# Begin Group "Function Modules" - -# PROP Default_Filter "" -# Begin Group "Source Files No. 1" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\ext\apache\apache.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\base64.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\basic_functions.c -# End Source File -# Begin Source File - -SOURCE=.\ext\bcmath\bcmath.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\browscap.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\datetime.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\dir.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\dl.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\dns.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\exec.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\file.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\filestat.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\flock_compat.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\formatted_print.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\fsock.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\head.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\html.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\image.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\info.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\iptc.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\link.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\mail.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\math.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\md5.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\microtime.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\mime.c -# End Source File -# Begin Source File - -SOURCE=.\ext\bcmath\number.c -# End Source File -# Begin Source File - -SOURCE=.\ext\odbc\odbc.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\pack.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\pageinfo.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\post.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\rand.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\reg.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\soundex.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\string.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\syslog.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\type.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\uniqid.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\url.c -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\var.c -# End Source File -# End Group -# Begin Group "Header Files No. 1" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\ext\standard\base64.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\basic_functions.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\datetime.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\dl.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\dns.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\exec.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\file.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\flock_compat.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\fsock.h -# End Source File -# Begin Source File - -SOURCE=.\functions\global.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\head.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\html.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\md5.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\mime.h -# End Source File -# Begin Source File - -SOURCE=.\ext\bcmath\number.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\pageinfo.h -# End Source File -# Begin Source File - -SOURCE=.\ext\bcmath\php3_bcmath.h -# End Source File -# Begin Source File - -SOURCE=.\functions\php3_dir.h -# End Source File -# Begin Source File - -SOURCE=.\functions\php3_filestat.h -# End Source File -# Begin Source File - -SOURCE=.\functions\php3_ldap.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\php3_mail.h -# End Source File -# Begin Source File - -SOURCE=.\ext\odbc\php3_odbc.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\php3_string.h -# End Source File -# Begin Source File - -SOURCE=.\functions\php3_string.h -# End Source File -# Begin Source File - -SOURCE=.\functions\php3_syslog.h -# End Source File -# Begin Source File - -SOURCE=.\functions\phpdir.h -# End Source File -# Begin Source File - -SOURCE=.\functions\phpmath.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\post.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\reg.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\type.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\uniqid.h -# End Source File -# Begin Source File - -SOURCE=.\ext\standard\url.h -# End Source File -# End Group -# Begin Group "Regular Expressions" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\regex\regcomp.c -# End Source File -# Begin Source File - -SOURCE=.\regex\regerror.c -# End Source File -# Begin Source File - -SOURCE=.\regex\regexec.c -# End Source File -# Begin Source File - -SOURCE=.\regex\regfree.c -# End Source File -# End Group -# End Group -# Begin Group "Win32" - -# PROP Default_Filter "" -# Begin Group "Source Files No. 2" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\ext\com\COM.c -# End Source File -# Begin Source File - -SOURCE=.\win32\pwd.c -# End Source File -# Begin Source File - -SOURCE=.\win32\readdir.c -# End Source File -# Begin Source File - -SOURCE=.\win32\registry.c -# End Source File -# Begin Source File - -SOURCE=.\win32\sendmail.c -# End Source File -# Begin Source File - -SOURCE=.\win32\time.c -# End Source File -# Begin Source File - -SOURCE=.\win32\wfile.c -# End Source File -# Begin Source File - -SOURCE=.\dl\snmp\winsnmp.c -# End Source File -# Begin Source File - -SOURCE=.\win32\winutil.c -# End Source File -# Begin Source File - -SOURCE=.\win32\wsyslog.c -# End Source File -# End Group -# Begin Group "Header Files No. 2" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\win32\grp.h -# End Source File -# Begin Source File - -SOURCE=.\win32\param.h -# End Source File -# Begin Source File - -SOURCE=.\ext\com\php3_COM.h -# End Source File -# Begin Source File - -SOURCE=.\win32\php_registry.h -# End Source File -# Begin Source File - -SOURCE=.\win32\pwd.h -# End Source File -# Begin Source File - -SOURCE=.\win32\readdir.h -# End Source File -# Begin Source File - -SOURCE=.\win32\sendmail.h -# End Source File -# Begin Source File - -SOURCE=.\win32\syslog.h -# End Source File -# Begin Source File - -SOURCE=.\win32\time.h -# End Source File -# Begin Source File - -SOURCE=.\win32\unistd.h -# End Source File -# Begin Source File - -SOURCE=.\win32\wfile.h -# End Source File -# End Group -# End Group -# Begin Group "Parsers" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=".\configuration-parser.y" - -!IF "$(CFG)" == "php4ts - Win32 Release_TS" - -!ELSEIF "$(CFG)" == "php4ts - Win32 Debug_TS" - -# Begin Custom Build -InputDir=. -InputPath=".\configuration-parser.y" - -BuildCmds= \ - bison --output=configuration-parser.c -v -d -S "C:\Program Files\Cygnus\share\bison.simple" -p cfg configuration-parser.y - -"$(InputDir)\configuration-parser.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) - -"$(InputDir)\configuration-parser.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) -# End Custom Build - -!ENDIF - -# End Source File -# End Group -# Begin Group "Scanners" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=".\configuration-scanner.l" - -!IF "$(CFG)" == "php4ts - Win32 Release_TS" - -!ELSEIF "$(CFG)" == "php4ts - Win32 Debug_TS" - -# Begin Custom Build -InputPath=".\configuration-scanner.l" - -"configuration-scanner.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - flex -i -Pcfg -oconfiguration-scanner.c configuration-scanner.l - -# End Custom Build - -!ENDIF - -# End Source File +# PROP Default_Filter ".h" # End Group # End Target # End Project diff --git a/php4ts.dsw b/php4ts.dsw index 0cd8ad1862..ee8e1f2617 100644 --- a/php4ts.dsw +++ b/php4ts.dsw @@ -27,6 +27,39 @@ Package=<4> ############################################################################### +Project: "php4isapi"=.\php4isapi\php4isapi.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name libzendts + End Project Dependency + Begin Project Dependency + Project_Dep_Name php4libts + End Project Dependency + Begin Project Dependency + Project_Dep_Name TSRM + End Project Dependency +}}} + +############################################################################### + +Project: "php4libts"=.\php4libts.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "php4ts"=.\php4ts.dsp - Package Owner=<4> Package=<5> @@ -41,6 +74,9 @@ Package=<4> Begin Project Dependency Project_Dep_Name TSRM End Project Dependency + Begin Project Dependency + Project_Dep_Name php4libts + End Project Dependency }}} ############################################################################### -- 2.50.1