-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpz.h
More file actions
107 lines (95 loc) · 3.52 KB
/
Copy pathphpz.h
File metadata and controls
107 lines (95 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef PHPZ_H
#define PHPZ_H
/*
* Workaround: skip <arm_neon.h> on aarch64.
*
* Why it's needed:
* On aarch64, `php.h` -> `Zend/zend_types.h` unconditionally includes
* <arm_neon.h>, which pulls in Clang's <arm_vector_types.h>. Those
* headers use the `__mfp8` builtin type and thousands of
* `__builtin_neon_*` intrinsics that Zig's translate-c (aro) cannot
* parse, so binding generation fails before any of our code is reached.
*
* Why it's safe:
* PHP only uses NEON inside macro bodies (e.g. HT_HASH_RESET in
* zend_types.h) and static inline functions. translate-c only parses
* top-level declarations (typedefs / structs / function prototypes),
* none of which reference NEON types. The macros are expanded later by
* the real C compiler when the extension is built, where <arm_neon.h>
* is included normally and handled by native Clang.
*
* How it works:
* Predefining the headers' own include guards makes their bodies expand
* to nothing during translate-c, while the C build still sees them
* unchanged.
*/
#if defined(__aarch64__) || defined(_M_ARM64)
#define __ARM_NEON_H
#endif
#include "php.h"
#include "Zend/zend_API.h"
#include "Zend/zend_exceptions.h"
#include "Zend/zend_enum.h"
#include "ext/standard/info.h"
#include "main/SAPI.h"
static zend_always_inline zend_executor_globals *phpz_executor_globals(void) {
#ifdef ZTS
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
return (zend_executor_globals *) (((char *) TSRMLS_CACHE) + executor_globals_offset);
#else
return (zend_executor_globals *) (((char *) tsrm_get_ls_cache()) + executor_globals_offset);
#endif
#else
return &executor_globals;
#endif
}
static zend_always_inline zend_compiler_globals *phpz_compiler_globals(void) {
#ifdef ZTS
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
return (zend_compiler_globals *) (((char *) TSRMLS_CACHE) + compiler_globals_offset);
#else
return (zend_compiler_globals *) (((char *) tsrm_get_ls_cache()) + compiler_globals_offset);
#endif
#else
return &compiler_globals;
#endif
}
static zend_always_inline php_core_globals *phpz_core_globals(void) {
#ifdef ZTS
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
return (php_core_globals *) (((char *) TSRMLS_CACHE) + core_globals_offset);
#else
return (php_core_globals *) (((char *) tsrm_get_ls_cache()) + core_globals_offset);
#endif
#else
return &core_globals;
#endif
}
static zend_always_inline sapi_globals_struct *phpz_sapi_globals(void) {
#ifdef ZTS
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
return (sapi_globals_struct *) (((char *) TSRMLS_CACHE) + sapi_globals_offset);
#else
return (sapi_globals_struct *) (((char *) tsrm_get_ls_cache()) + sapi_globals_offset);
#endif
#else
return &sapi_globals;
#endif
}
static zend_always_inline void phpz_zval_zval(zval *z, zval *src, bool copy, bool dtor_src) {
ZVAL_ZVAL(z, src, copy, dtor_src);
}
/* Bridge helpers for zend_class_entry anonymous unions.
* translate-c numbers unnamed unions (unnamed_0, unnamed_1, ...),
* which break when PHP headers change union layout. These inline
* wrappers give translate-c stable symbol names to bind against. */
static zend_always_inline void phpz_class_entry_set_create_object(zend_class_entry *ce, zend_object* (*handler)(zend_class_entry *)) {
ce->create_object = handler;
}
static zend_always_inline zend_class_entry *phpz_class_entry_get_parent(zend_class_entry *ce) {
return ce->parent;
}
static zend_always_inline zend_class_entry *phpz_class_entry_get_interface(zend_class_entry *ce, uint32_t index) {
return ce->interfaces[index];
}
#endif