Skip to content

Commit b54fce7

Browse files
committed
rename sapi/cli/php_cli.c::main() to do_php_cli()
export do_php_cli() without main() method in embed sapi
1 parent 449361a commit b54fce7

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

sapi/cli/cli.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#endif
2727

2828

29+
extern PHP_CLI_API int do_php_cli(int argc, char *argv[]);
30+
2931
extern PHP_CLI_API ssize_t sapi_cli_single_write(const char *str, size_t str_length);
3032

3133
typedef struct {

sapi/cli/php_cli.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,18 +1181,10 @@ static int do_cli(int argc, char **argv) /* {{{ */
11811181
}
11821182
/* }}} */
11831183

1184-
/* {{{ main */
1185-
#ifdef PHP_CLI_WIN32_NO_CONSOLE
1186-
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
1187-
#else
1188-
int main(int argc, char *argv[])
1189-
#endif
1184+
/* {{{ do_php_cli */
1185+
PHP_CLI_API int do_php_cli(int argc, char *argv[])
11901186
{
11911187
#if defined(PHP_WIN32)
1192-
# ifdef PHP_CLI_WIN32_NO_CONSOLE
1193-
int argc = __argc;
1194-
char **argv = __argv;
1195-
# endif
11961188
int num_args;
11971189
wchar_t **argv_wide;
11981190
char **argv_save = argv;
@@ -1395,6 +1387,22 @@ int main(int argc, char *argv[])
13951387
* exiting.
13961388
*/
13971389
cleanup_ps_args(argv);
1398-
exit(exit_status);
1390+
return exit_status;
1391+
}
1392+
/* }}} */
1393+
1394+
/* {{{ main */
1395+
#ifndef PHP_EMBED_SAPI
1396+
# ifdef PHP_CLI_WIN32_NO_CONSOLE
1397+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
1398+
{
1399+
exit(do_php_cli(__argc, __argv));
13991400
}
1401+
# else
1402+
int main(int argc, char *argv[])
1403+
{
1404+
exit(do_php_cli(argc, argv));
1405+
}
1406+
# endif
1407+
#endif /* PHP_EMBED_SAPI */
14001408
/* }}} */

sapi/embed/Makefile.frag

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Redirect cli source objects to sapi/embed/cli, so the version without main() doesn't conflict with cli sapis version with main()
2+
EMBED_CLI_SRCDIR = $(top_srcdir)/sapi/cli
3+
EMBED_CLI_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) -Isapi/cli/ -I$(EMBED_CLI_SRCDIR) -DPHP_EMBED_SAPI -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1
4+
5+
sapi/embed/cli/php_cli.lo: $(EMBED_CLI_SRCDIR)/php_cli.c
6+
$(EMBED_CLI_CC) -c $< -o $@
7+
8+
sapi/embed/cli/php_http_parser.lo: $(EMBED_CLI_SRCDIR)/php_http_parser.c
9+
$(EMBED_CLI_CC) -c $< -o $@
10+
11+
sapi/embed/cli/php_cli_server.lo: $(EMBED_CLI_SRCDIR)/php_cli_server.c
12+
$(EMBED_CLI_CC) -c $< -o $@
13+
14+
sapi/embed/cli/ps_title.lo: $(EMBED_CLI_SRCDIR)/ps_title.c
15+
$(EMBED_CLI_CC) -c $< -o $@
16+
17+
sapi/embed/cli/php_cli_process_title.lo: $(EMBED_CLI_SRCDIR)/php_cli_process_title.c
18+
$(EMBED_CLI_CC) -c $< -o $@

sapi/embed/config.m4

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ if test "$PHP_EMBED" != "no"; then
3232
[$PHP_EMBED_TYPE],
3333
[php_embed.c],
3434
[-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
35+
36+
dnl Include CLI sources in embed SAPI so do_php_cli() is available
37+
PHP_ADD_BUILD_DIR([sapi/embed/cli])
38+
PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/embed/Makefile.frag])
39+
PHP_SAPI_OBJS="$PHP_SAPI_OBJS sapi/embed/cli/php_cli.lo sapi/embed/cli/php_http_parser.lo sapi/embed/cli/php_cli_server.lo sapi/embed/cli/ps_title.lo sapi/embed/cli/php_cli_process_title.lo"
40+
3541
PHP_INSTALL_HEADERS([sapi/embed], [php_embed.h])
42+
PHP_INSTALL_HEADERS([sapi/cli], [cli.h])
3643
])
3744
else
3845
AC_MSG_RESULT([no])

sapi/embed/config.w32

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ var PHP_EMBED_PGO = false;
66

77
if (PHP_EMBED != "no") {
88
SAPI('embed', 'php_embed.c', 'php' + PHP_VERSION + 'embed.lib', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
9+
ADD_SOURCES("sapi/cli", "php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c", "embed", "/DPHP_EMBED_SAPI");
10+
ADD_FLAG("LIBS_EMBED", "ws2_32.lib");
11+
ADD_FLAG("LIBS_EMBED", "shell32.lib");
912
PHP_INSTALL_HEADERS("sapi/embed", "php_embed.h");
13+
PHP_INSTALL_HEADERS("sapi/cli", "cli.h");
1014
}

sapi/embed/php_embed.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ BEGIN_EXTERN_C()
4949
EMBED_SAPI_API int php_embed_init(int argc, char **argv);
5050
EMBED_SAPI_API void php_embed_shutdown(void);
5151
extern EMBED_SAPI_API sapi_module_struct php_embed_module;
52+
53+
#define HAVE_EMBED_CLI 1
54+
EMBED_SAPI_API int do_php_cli(int argc, char *argv[]);
5255
END_EXTERN_C()
5356

5457

0 commit comments

Comments
 (0)