Skip to content

Commit 2ebb9c1

Browse files
authored
Merge pull request #1089 from DataDog/sammyk/observer-api
PHP 8: Observer API
2 parents a3e6fa4 + b643746 commit 2ebb9c1

33 files changed

+575
-670
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ workflows:
11871187
- php:7.2-fpm-alpine
11881188
- php:7.3-fpm-alpine
11891189
- php:7.4-fpm-alpine
1190-
- php:8.0.0RC3-fpm-alpine
1190+
- php:8.0.0RC4-fpm-alpine # Add RC5 when available
11911191
- pecl_tests:
11921192
requires: [ "Build PECL" ]
11931193
name: "PHP 54 PECL tests"

dockerfiles/ci/alpine/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ services:
1313
context: ./php-8.0
1414
args:
1515
phpVersion: 8.0
16-
phpTarGzUrl: https://github.com/SammyK/php-src/archive/sammyk/php8.0.0-pre-rc5.tar.gz
17-
phpSha256Hash: 9597c3497f6afa05e13db1e69e86e53bcfc19ad9581c30384be0f7f8f55c3eae
16+
phpTarGzUrl: https://github.com/php/php-src/archive/php-8.0.0RC5.tar.gz
17+
phpSha256Hash: ec5836f816e17fd8a281f671bb247b4c420f8de23fb425d599877cd911a54230

dockerfiles/ci/buster/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ services:
1313
context: ./php-8.0
1414
args:
1515
phpVersion: 8.0
16-
phpTarGzUrl: https://github.com/SammyK/php-src/archive/sammyk/php8.0.0-pre-rc5.tar.gz
17-
phpSha256Hash: 9597c3497f6afa05e13db1e69e86e53bcfc19ad9581c30384be0f7f8f55c3eae
16+
phpTarGzUrl: https://github.com/php/php-src/archive/php-8.0.0RC5.tar.gz
17+
phpSha256Hash: ec5836f816e17fd8a281f671bb247b4c420f8de23fb425d599877cd911a54230
1818

1919
php-master:
2020
image: datadog/dd-trace-ci:php-master_buster

dockerfiles/ci/centos/6/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ services:
1111
context: ./php-8.0
1212
args:
1313
phpVersion: 8.0
14-
phpTarGzUrl: https://github.com/SammyK/php-src/archive/sammyk/php8.0.0-pre-rc5.tar.gz
15-
phpSha256Hash: 9597c3497f6afa05e13db1e69e86e53bcfc19ad9581c30384be0f7f8f55c3eae
14+
phpTarGzUrl: https://github.com/php/php-src/archive/php-8.0.0RC5.tar.gz
15+
phpSha256Hash: ec5836f816e17fd8a281f671bb247b4c420f8de23fb425d599877cd911a54230
1616
image: 'datadog/dd-trace-ci:php-8.0_centos-6'

dockerfiles/compile_extension/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ services:
112112
context: .
113113
dockerfile: Dockerfile_alpine
114114
args:
115-
php_version: 8.0.0RC3
116-
php_url: https://downloads.php.net/~carusogabriel/php-8.0.0RC3.tar.gz
117-
php_sha: c651a10058840abd44f99a8aed0446f102291d1408f2299790b919634689b5cd
115+
php_version: 8.0.0RC5
116+
php_url: https://github.com/php/php-src/archive/php-8.0.0RC5.tar.gz
117+
php_sha: ec5836f816e17fd8a281f671bb247b4c420f8de23fb425d599877cd911a54230
118118
php_api: 20200930
119119
command: build-dd-trace-php
120120
volumes:

dockerfiles/compile_extension/install-php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -xe
66
PHP_TAR_FILE=php.tar.gz
77
apk add --no-cache --virtual .php-build-deps \
88
autoconf \
9+
bison \
910
ca-certificates \
1011
coreutils \
1112
g++ \
@@ -32,6 +33,7 @@ CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS"
3233
PHP_CONFIG_ARGS=""
3334

3435
# Installing PHP
36+
./buildconf --force
3537
./configure \
3638
--prefix="${PHP_INSTALL_DIR}" \
3739
--with-config-file-path="${PHP_INI_DIR}" \

ext/php8/ddtrace.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,9 @@ STD_PHP_INI_ENTRY("ddtrace.request_init_hook", "", PHP_INI_SYSTEM, OnUpdateStrin
7171
PHP_INI_END()
7272

7373
static int ddtrace_startup(struct _zend_extension *extension) {
74-
#if PHP_VERSION_ID < 80000
75-
ddtrace_resource = zend_get_resource_handle(extension);
76-
#if PHP_VERSION_ID >= 70400
77-
ddtrace_op_array_extension = zend_get_op_array_extension_handle();
78-
#endif
79-
#else
8074
UNUSED(extension);
8175
ddtrace_resource = zend_get_resource_handle(PHP_DDTRACE_EXTNAME);
8276
ddtrace_op_array_extension = zend_get_op_array_extension_handle(PHP_DDTRACE_EXTNAME);
83-
#endif
8477

8578
ddtrace_excluded_modules_startup();
8679
ddtrace_internal_handlers_startup();
@@ -433,10 +426,6 @@ static PHP_RINIT_FUNCTION(ddtrace) {
433426
ddtrace_distributed_tracing_rinit(TSRMLS_C);
434427
DDTRACE_G(disable_in_current_request) = 0;
435428

436-
// This allows us to hook the ZEND_HANDLE_EXCEPTION pseudo opcode
437-
ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
438-
EG(exception_op)->opcode = ZEND_HANDLE_EXCEPTION;
439-
440429
ddtrace_dogstatsd_client_rinit(TSRMLS_C);
441430

442431
ddtrace_seed_prng(TSRMLS_C);
@@ -1114,15 +1103,9 @@ static PHP_FUNCTION(dd_trace_disable_in_request) {
11141103
}
11151104

11161105
static PHP_FUNCTION(dd_trace_reset) {
1117-
PHP5_UNUSED(return_value_used, this_ptr, return_value_ptr, ht);
1118-
PHP7_UNUSED(execute_data);
1119-
1120-
if (DDTRACE_G(disable)) {
1121-
RETURN_BOOL(0);
1122-
}
1123-
1124-
ddtrace_dispatch_reset(TSRMLS_C);
1125-
RETURN_BOOL(1);
1106+
UNUSED(execute_data);
1107+
ddtrace_log_debug("Cannot reset traced functions on PHP 8+");
1108+
RETURN_BOOL(0);
11261109
}
11271110

11281111
/* {{{ proto string dd_trace_serialize_msgpack(array trace_array) */

ext/php8/dispatch.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ void ddtrace_dispatch_destroy(TSRMLS_D) {
108108
}
109109
}
110110

111-
void ddtrace_dispatch_reset(TSRMLS_D) {
112-
if (DDTRACE_G(class_lookup)) {
113-
zend_hash_clean(DDTRACE_G(class_lookup));
114-
}
115-
if (DDTRACE_G(function_lookup)) {
116-
zend_hash_clean(DDTRACE_G(function_lookup));
117-
}
118-
}
119-
120111
static HashTable *_get_lookup_for_target(zval *class_name TSRMLS_DC) {
121112
HashTable *overridable_lookup = NULL;
122113
if (class_name && DDTRACE_G(class_lookup)) {

ext/php8/dispatch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ inline void ddtrace_dispatch_release(ddtrace_dispatch_t *dispatch) {
6363

6464
void ddtrace_dispatch_init(TSRMLS_D);
6565
void ddtrace_dispatch_destroy(TSRMLS_D);
66-
void ddtrace_dispatch_reset(TSRMLS_D);
6766

6867
#if PHP_VERSION_ID < 70000
6968

ext/php8/engine_hooks.c

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,28 @@
11
#include "engine_hooks.h"
22

3+
#include <Zend/zend_observer.h>
34
#include <php.h>
45
#include <time.h>
5-
#if PHP_VERSION_ID >= 80000
6-
#include <Zend/zend_observer.h>
7-
#endif
86

97
#include "configuration.h"
108
#include "ddtrace.h"
119
#include "span.h"
1210

1311
ZEND_EXTERN_MODULE_GLOBALS(ddtrace);
1412

15-
static zend_op_array *(*_prev_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
16-
#if PHP_VERSION_ID < 80000
17-
void (*ddtrace_prev_error_cb)(DDTRACE_ERROR_CB_PARAMETERS);
18-
#endif
19-
20-
void ddtrace_execute_internal_minit(void);
21-
void ddtrace_execute_internal_mshutdown(void);
13+
static zend_op_array *(*_prev_compile_file)(zend_file_handle *file_handle, int type);
2214

2315
static void _compile_minit(void);
2416
static void _compile_mshutdown(void);
2517

26-
void ddtrace_opcode_minit(void);
27-
void ddtrace_opcode_mshutdown(void);
28-
2918
void ddtrace_engine_hooks_minit(void) {
30-
ddtrace_execute_internal_minit();
31-
ddtrace_opcode_minit();
3219
_compile_minit();
3320

34-
#if PHP_VERSION_ID >= 50500 && PHP_VERSION_ID < 80000
35-
ddtrace_prev_error_cb = zend_error_cb;
36-
zend_error_cb = ddtrace_error_cb;
37-
#endif
38-
39-
#if PHP_VERSION_ID >= 80000
21+
zend_observer_fcall_register(ddtrace_observer_fcall_init);
4022
zend_observer_error_register(ddtrace_observer_error_cb);
41-
#endif
4223
}
4324

44-
void ddtrace_engine_hooks_mshutdown(void) {
45-
#if PHP_VERSION_ID < 80000
46-
if (ddtrace_prev_error_cb == ddtrace_error_cb) {
47-
zend_error_cb = ddtrace_prev_error_cb;
48-
}
49-
#endif
50-
51-
_compile_mshutdown();
52-
ddtrace_opcode_mshutdown();
53-
ddtrace_execute_internal_mshutdown();
54-
}
25+
void ddtrace_engine_hooks_mshutdown(void) { _compile_mshutdown(); }
5526

5627
static uint64_t _get_microseconds() {
5728
struct timespec time;
@@ -61,10 +32,10 @@ static uint64_t _get_microseconds() {
6132
return 0U;
6233
}
6334

64-
static zend_op_array *_dd_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) {
35+
static zend_op_array *_dd_compile_file(zend_file_handle *file_handle, int type) {
6536
zend_op_array *res;
6637
uint64_t start = _get_microseconds();
67-
res = _prev_compile_file(file_handle, type TSRMLS_CC);
38+
res = _prev_compile_file(file_handle, type);
6839
DDTRACE_G(compile_time_microseconds) += (int64_t)(_get_microseconds() - start);
6940
return res;
7041
}
@@ -82,14 +53,12 @@ static void _compile_mshutdown(void) {
8253
}
8354
}
8455

85-
void ddtrace_compile_time_reset(TSRMLS_D) { DDTRACE_G(compile_time_microseconds) = 0; }
56+
void ddtrace_compile_time_reset(void) { DDTRACE_G(compile_time_microseconds) = 0; }
8657

87-
int64_t ddtrace_compile_time_get(TSRMLS_D) { return DDTRACE_G(compile_time_microseconds); }
58+
int64_t ddtrace_compile_time_get(void) { return DDTRACE_G(compile_time_microseconds); }
59+
60+
extern inline void ddtrace_backup_error_handling(ddtrace_error_handling *eh, zend_error_handling_t mode);
8861

89-
extern inline void ddtrace_backup_error_handling(ddtrace_error_handling *eh, zend_error_handling_t mode TSRMLS_DC);
90-
#if PHP_VERSION_ID < 80000
91-
extern inline void ddtrace_restore_error_handling(ddtrace_error_handling *eh TSRMLS_DC);
92-
#else
9362
void ddtrace_restore_error_handling(ddtrace_error_handling *eh) {
9463
if (PG(last_error_message)) {
9564
if (PG(last_error_message) != eh->message) {
@@ -99,21 +68,15 @@ void ddtrace_restore_error_handling(ddtrace_error_handling *eh) {
9968
free(PG(last_error_file));
10069
}
10170
}
102-
zend_restore_error_handling(&eh->error_handling TSRMLS_CC);
71+
zend_restore_error_handling(&eh->error_handling);
10372
PG(last_error_type) = eh->type;
10473
PG(last_error_message) = eh->message;
10574
PG(last_error_file) = eh->file;
10675
PG(last_error_lineno) = eh->lineno;
10776
EG(error_reporting) = eh->error_reporting;
10877
}
109-
#endif
78+
11079
extern inline void ddtrace_sandbox_end(ddtrace_sandbox_backup *backup TSRMLS_DC);
111-
#if PHP_VERSION_ID < 70000
112-
extern inline ddtrace_sandbox_backup ddtrace_sandbox_begin(zend_op *opline_before_exception TSRMLS_DC);
113-
extern inline void ddtrace_maybe_clear_exception(TSRMLS_D);
114-
extern inline zval *ddtrace_exception_get_entry(zval *object, char *name, int name_len TSRMLS_DC);
115-
#else
11680
extern inline ddtrace_sandbox_backup ddtrace_sandbox_begin(void);
11781
extern inline void ddtrace_maybe_clear_exception(void);
11882
extern inline zend_class_entry *ddtrace_get_exception_base(zval *object);
119-
#endif

0 commit comments

Comments
 (0)