Skip to content

Commit 181175e

Browse files
committed
sapi/was: new WAS frontend
1 parent d2e90f2 commit 181175e

File tree

7 files changed

+832
-2
lines changed

7 files changed

+832
-2
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,7 @@ static inline int accel_find_sapi(void)
29272927
"uwsgi",
29282928
"fuzzer",
29292929
"frankenphp",
2930+
"was",
29302931
NULL
29312932
};
29322933
const char **sapi_name;

main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ static PHP_INI_DISP(display_errors_mode)
475475
mode = php_get_display_errors_mode(temporary_value);
476476

477477
/* Display 'On' for other SAPIs instead of STDOUT or STDERR */
478-
cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg"));
478+
cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "was") || !strcmp(sapi_module.name, "phpdbg"));
479479

480480
switch (mode) {
481481
case PHP_DISPLAY_ERRORS_STDERR:
@@ -1354,7 +1354,7 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
13541354
}
13551355
} else {
13561356
/* Write CLI/CGI errors to stderr if display_errors = "stderr" */
1357-
if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg")) &&
1357+
if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "was") || !strcmp(sapi_module.name, "phpdbg")) &&
13581358
PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
13591359
) {
13601360
fprintf(stderr, "%s: %s in %s on line %" PRIu32 "\n", error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno);

sapi/was/Makefile.frag

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
was: $(SAPI_WAS_PATH)
2+
3+
$(SAPI_WAS_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_WAS_OBJS)
4+
$(BUILD_WAS)
5+
6+
install-was: $(SAPI_WAS_PATH)
7+
@echo "Installing PHP WAS binary: $(INSTALL_ROOT)$(bindir)/"
8+
@$(mkinstalldirs) $(INSTALL_ROOT)$(bindir)
9+
@$(INSTALL) -m 0755 $(SAPI_WAS_PATH) $(INSTALL_ROOT)$(bindir)/$(program_prefix)php-was$(program_suffix)

sapi/was/ScopeExit.hxx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (C) 2015 Max Kellermann <[email protected]>
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20+
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27+
* OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
#ifndef SCOPE_EXIT_HXX
31+
#define SCOPE_EXIT_HXX
32+
33+
#include <utility>
34+
35+
/**
36+
* Internal class. Do not use directly.
37+
*/
38+
template<typename F>
39+
class ScopeExitGuard : F {
40+
bool enabled = true;
41+
42+
public:
43+
explicit ScopeExitGuard(F &&f):F(std::forward<F>(f)) {}
44+
45+
ScopeExitGuard(ScopeExitGuard &&src)
46+
:F(std::move(src)), enabled(src.enabled) {
47+
src.enabled = false;
48+
}
49+
50+
~ScopeExitGuard() {
51+
if (enabled)
52+
F::operator()();
53+
}
54+
55+
ScopeExitGuard(const ScopeExitGuard &) = delete;
56+
ScopeExitGuard &operator=(const ScopeExitGuard &) = delete;
57+
};
58+
59+
/**
60+
* Internal class. Do not use directly.
61+
*/
62+
struct ScopeExitTag {
63+
/* this operator is a trick so we don't need to close
64+
parantheses at the end of the expression AtScopeExit()
65+
call */
66+
template<typename F>
67+
ScopeExitGuard<F> operator+(F &&f) {
68+
return ScopeExitGuard<F>(std::forward<F>(f));
69+
}
70+
};
71+
72+
#define ScopeExitCat(a, b) a ## b
73+
#define ScopeExitName(line) ScopeExitCat(at_scope_exit_, line)
74+
75+
/**
76+
* Call the block after this macro at the end of the current scope.
77+
* Parameters are lambda captures.
78+
*
79+
* This is exception-safe, however the given code block must not throw
80+
* exceptions.
81+
*
82+
* This attempts to be a better boost/scope_exit.hpp, without all of
83+
* Boost's compile-time and runtime bloat.
84+
*/
85+
#define AtScopeExit(...) auto ScopeExitName(__LINE__) = ScopeExitTag() + [__VA_ARGS__]()
86+
87+
#endif

sapi/was/config.m4

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
AC_MSG_CHECKING(for WAS support)
2+
3+
PHP_ARG_ENABLE([was],,
4+
[AS_HELP_STRING([--enable-was],
5+
[Build PHP as WAS application])],
6+
[no])
7+
8+
if test "$PHP_WAS" != "no"; then
9+
PKG_CHECK_MODULES([LIBWAS], [libcm4all-was-simple >= 1.24],, [AC_MSG_ERROR([libwas not found])])
10+
PHP_EVAL_LIBLINE($LIBWAS_LIBS)
11+
PHP_EVAL_INCLINE($LIBWAS_CFLAGS)
12+
13+
PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/was/Makefile.frag,$abs_srcdir/sapi/was,sapi/was)
14+
SAPI_WAS_PATH=sapi/was/php
15+
PHP_SELECT_SAPI(was, program, was_main.c, "", '$(SAPI_WAS_PATH)')
16+
case $host_alias in
17+
*darwin*)
18+
BUILD_WAS="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_BINARY_OBJS:.lo=.o) \$(PHP_WAS_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_WAS_PATH)"
19+
;;
20+
*cygwin*)
21+
SAPI_WAS_PATH=sapi/was/php.exe
22+
BUILD_WAS="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_WAS_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_WAS_PATH)"
23+
;;
24+
*)
25+
BUILD_WAS="\$(LIBTOOL) --mode=link \$(CXX) -export-dynamic \$(CXXFLAGS_CLEAN) \$(EXTRA_CXXFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_WAS_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_WAS_PATH)"
26+
;;
27+
esac
28+
29+
PHP_SUBST(SAPI_WAS_PATH)
30+
PHP_SUBST(BUILD_WAS)
31+
fi
32+
33+
AC_MSG_RESULT($PHP_WAS)

0 commit comments

Comments
 (0)