Skip to content

Commit 0686740

Browse files
alejandro-colomarac000
authored andcommitted
PHP: Factored out code into a helper function.
We're going to use zend_stream_init_filename in a following commit. To reduce the diff of that change, move the current code that will be replaced, to a function that has the same interface. We use strlen(3) here to be able to use an interface without passing the length, but we will remove that call in a following code, so it has no performance issues. Co-developed-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com> Reviewed-by: Andrew Clayton <a.clayton@nginx.com> Cc: Andrei Zeliankou <zelenkov@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent 05c5639 commit 0686740

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/nxt_php_sapi.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ static nxt_int_t nxt_php_do_301(nxt_unit_request_info_t *req);
106106
static void nxt_php_request_handler(nxt_unit_request_info_t *req);
107107
static void nxt_php_dynamic_request(nxt_php_run_ctx_t *ctx,
108108
nxt_unit_request_t *r);
109+
static void nxt_zend_stream_init_filename(zend_file_handle *handle,
110+
const char *filename);
109111
static void nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r);
110112
nxt_inline void nxt_php_vcwd_chdir(nxt_unit_request_info_t *req, u_char *dir);
111113

@@ -1109,6 +1111,21 @@ nxt_php_dynamic_request(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r)
11091111
}
11101112

11111113

1114+
static void
1115+
nxt_zend_stream_init_filename(zend_file_handle *handle, const char *filename)
1116+
{
1117+
nxt_memzero(handle, sizeof(zend_file_handle));
1118+
1119+
handle->type = ZEND_HANDLE_FILENAME;
1120+
#if (PHP_VERSION_ID >= 80100)
1121+
handle->filename = zend_string_init(filename, strlen(filename), 0);
1122+
handle->primary_script = 1;
1123+
#else
1124+
handle->filename = filename;
1125+
#endif
1126+
}
1127+
1128+
11121129
static void
11131130
nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r)
11141131
{
@@ -1179,16 +1196,8 @@ nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r)
11791196
nxt_php_vcwd_chdir(ctx->req, ctx->script_dirname.start);
11801197
}
11811198

1182-
nxt_memzero(&file_handle, sizeof(file_handle));
1183-
1184-
file_handle.type = ZEND_HANDLE_FILENAME;
1185-
#if (PHP_VERSION_ID >= 80100)
1186-
file_handle.filename = zend_string_init((char *) ctx->script_filename.start,
1187-
ctx->script_filename.length, 0);
1188-
file_handle.primary_script = 1;
1189-
#else
1190-
file_handle.filename = (char *) ctx->script_filename.start;
1191-
#endif
1199+
nxt_zend_stream_init_filename(&file_handle,
1200+
(const char *) ctx->script_filename.start);
11921201

11931202
php_execute_script(&file_handle TSRMLS_CC);
11941203

0 commit comments

Comments
 (0)