Skip to content

Commit 11b6a8d

Browse files
authored
feat(globals): add CompilerGlobals
Refs: #445
1 parent 1db8863 commit 11b6a8d

File tree

5 files changed

+245
-11
lines changed

5 files changed

+245
-11
lines changed

allowed_bindings.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bind! {
2828
_efree,
2929
_emalloc,
3030
_zend_executor_globals,
31+
_zend_compiler_globals,
3132
_sapi_globals_struct,
3233
_sapi_module_struct,
3334
_zend_expected_type,
@@ -43,6 +44,7 @@ bind! {
4344
_zval_struct__bindgen_ty_2,
4445
_zend_known_string_id,
4546
// ext_php_rs_executor_globals,
47+
// ext_php_rs_compiler_globals,
4648
// ext_php_rs_php_build_id,
4749
// ext_php_rs_zend_object_alloc,
4850
// ext_php_rs_zend_object_release,
@@ -254,6 +256,7 @@ bind! {
254256
zend_class_serialize_deny,
255257
zend_class_unserialize_deny,
256258
zend_executor_globals,
259+
zend_compiler_globals,
257260
sapi_module_struct,
258261
zend_objects_store_del,
259262
zend_hash_move_forward_ex,
@@ -265,6 +268,7 @@ bind! {
265268
gc_possible_root,
266269
ZEND_ACC_NOT_SERIALIZABLE,
267270
executor_globals,
271+
compiler_globals,
268272
php_core_globals,
269273
core_globals,
270274
sapi_globals_struct,
@@ -274,6 +278,7 @@ bind! {
274278
__zend_malloc,
275279
tsrm_get_ls_cache,
276280
executor_globals_offset,
281+
compiler_globals_offset,
277282
core_globals_offset,
278283
sapi_globals_offset,
279284
php_file_globals,

docsrs_bindings.rs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ pub type zend_object = _zend_object;
293293
pub type zend_resource = _zend_resource;
294294
pub type zend_reference = _zend_reference;
295295
pub type zend_ast_ref = _zend_ast_ref;
296+
pub type zend_ast = _zend_ast;
296297
pub type dtor_func_t = ::std::option::Option<unsafe extern "C" fn(pDest: *mut zval)>;
297298
#[repr(C)]
298299
#[derive(Debug, Copy, Clone)]
@@ -697,6 +698,16 @@ extern "C" {
697698
len: usize,
698699
) -> *mut ::std::os::raw::c_void;
699700
}
701+
pub type zend_ast_kind = u16;
702+
pub type zend_ast_attr = u16;
703+
#[repr(C)]
704+
#[derive(Debug, Copy, Clone)]
705+
pub struct _zend_ast {
706+
pub kind: zend_ast_kind,
707+
pub attr: zend_ast_attr,
708+
pub lineno: u32,
709+
pub child: [*mut zend_ast; 1usize],
710+
}
700711
extern "C" {
701712
pub fn gc_possible_root(ref_: *mut zend_refcounted);
702713
}
@@ -1266,6 +1277,24 @@ pub union _znode_op {
12661277
}
12671278
pub type znode_op = _znode_op;
12681279
#[repr(C)]
1280+
#[derive(Debug, Copy, Clone)]
1281+
pub struct _zend_declarables {
1282+
pub ticks: zend_long,
1283+
}
1284+
pub type zend_declarables = _zend_declarables;
1285+
#[repr(C)]
1286+
pub struct _zend_file_context {
1287+
pub declarables: zend_declarables,
1288+
pub current_namespace: *mut zend_string,
1289+
pub in_namespace: bool,
1290+
pub has_bracketed_namespaces: bool,
1291+
pub imports: *mut HashTable,
1292+
pub imports_function: *mut HashTable,
1293+
pub imports_const: *mut HashTable,
1294+
pub seen_symbols: HashTable,
1295+
}
1296+
pub type zend_file_context = _zend_file_context;
1297+
#[repr(C)]
12691298
#[derive(Copy, Clone)]
12701299
pub struct _zend_op {
12711300
pub handler: *const ::std::os::raw::c_void,
@@ -1281,6 +1310,16 @@ pub struct _zend_op {
12811310
}
12821311
#[repr(C)]
12831312
#[derive(Debug, Copy, Clone)]
1313+
pub struct _zend_brk_cont_element {
1314+
pub start: ::std::os::raw::c_int,
1315+
pub cont: ::std::os::raw::c_int,
1316+
pub brk: ::std::os::raw::c_int,
1317+
pub parent: ::std::os::raw::c_int,
1318+
pub is_switch: bool,
1319+
}
1320+
pub type zend_brk_cont_element = _zend_brk_cont_element;
1321+
#[repr(C)]
1322+
#[derive(Debug, Copy, Clone)]
12841323
pub struct _zend_try_catch_element {
12851324
pub try_op: u32,
12861325
pub catch_op: u32,
@@ -1298,6 +1337,20 @@ pub struct _zend_live_range {
12981337
pub type zend_live_range = _zend_live_range;
12991338
#[repr(C)]
13001339
#[derive(Debug, Copy, Clone)]
1340+
pub struct _zend_oparray_context {
1341+
pub opcodes_size: u32,
1342+
pub vars_size: ::std::os::raw::c_int,
1343+
pub literals_size: ::std::os::raw::c_int,
1344+
pub fast_call_var: u32,
1345+
pub try_catch_offset: u32,
1346+
pub current_brk_cont: ::std::os::raw::c_int,
1347+
pub last_brk_cont: ::std::os::raw::c_int,
1348+
pub brk_cont_array: *mut zend_brk_cont_element,
1349+
pub labels: *mut HashTable,
1350+
}
1351+
pub type zend_oparray_context = _zend_oparray_context;
1352+
#[repr(C)]
1353+
#[derive(Debug, Copy, Clone)]
13011354
pub struct _zend_property_info {
13021355
pub offset: u32,
13031356
pub flags: u32,
@@ -1429,7 +1482,60 @@ pub struct __jmp_buf_tag {
14291482
pub __saved_mask: __sigset_t,
14301483
}
14311484
pub type jmp_buf = [__jmp_buf_tag; 1usize];
1485+
pub type zend_compiler_globals = _zend_compiler_globals;
14321486
pub type zend_executor_globals = _zend_executor_globals;
1487+
#[repr(C)]
1488+
pub struct _zend_compiler_globals {
1489+
pub loop_var_stack: zend_stack,
1490+
pub active_class_entry: *mut zend_class_entry,
1491+
pub compiled_filename: *mut zend_string,
1492+
pub zend_lineno: ::std::os::raw::c_int,
1493+
pub active_op_array: *mut zend_op_array,
1494+
pub function_table: *mut HashTable,
1495+
pub class_table: *mut HashTable,
1496+
pub auto_globals: *mut HashTable,
1497+
pub parse_error: u8,
1498+
pub in_compilation: bool,
1499+
pub short_tags: bool,
1500+
pub unclean_shutdown: bool,
1501+
pub ini_parser_unbuffered_errors: bool,
1502+
pub open_files: zend_llist,
1503+
pub ini_parser_param: *mut _zend_ini_parser_param,
1504+
pub skip_shebang: bool,
1505+
pub increment_lineno: bool,
1506+
pub variable_width_locale: bool,
1507+
pub ascii_compatible_locale: bool,
1508+
pub doc_comment: *mut zend_string,
1509+
pub extra_fn_flags: u32,
1510+
pub compiler_options: u32,
1511+
pub context: zend_oparray_context,
1512+
pub file_context: zend_file_context,
1513+
pub arena: *mut zend_arena,
1514+
pub interned_strings: HashTable,
1515+
pub script_encoding_list: *mut *const zend_encoding,
1516+
pub script_encoding_list_size: usize,
1517+
pub multibyte: bool,
1518+
pub detect_unicode: bool,
1519+
pub encoding_declared: bool,
1520+
pub ast: *mut zend_ast,
1521+
pub ast_arena: *mut zend_arena,
1522+
pub delayed_oplines_stack: zend_stack,
1523+
pub memoized_exprs: *mut HashTable,
1524+
pub memoize_mode: zend_memoize_mode,
1525+
pub map_ptr_real_base: *mut ::std::os::raw::c_void,
1526+
pub map_ptr_base: *mut ::std::os::raw::c_void,
1527+
pub map_ptr_size: usize,
1528+
pub map_ptr_last: usize,
1529+
pub delayed_variance_obligations: *mut HashTable,
1530+
pub delayed_autoloads: *mut HashTable,
1531+
pub unlinked_uses: *mut HashTable,
1532+
pub current_linking_class: *mut zend_class_entry,
1533+
pub rtd_key_counter: u32,
1534+
pub short_circuiting_opnums: zend_stack,
1535+
}
1536+
extern "C" {
1537+
pub static mut compiler_globals: _zend_compiler_globals;
1538+
}
14331539
extern "C" {
14341540
pub static mut executor_globals: zend_executor_globals;
14351541
}
@@ -1477,6 +1583,20 @@ extern "C" {
14771583
}
14781584
#[repr(C)]
14791585
#[derive(Debug, Copy, Clone)]
1586+
pub struct _zend_encoding {
1587+
_unused: [u8; 0],
1588+
}
1589+
pub type zend_encoding = _zend_encoding;
1590+
pub type zend_arena = _zend_arena;
1591+
#[repr(C)]
1592+
#[derive(Debug, Copy, Clone)]
1593+
pub struct _zend_arena {
1594+
pub ptr: *mut ::std::os::raw::c_char,
1595+
pub end: *mut ::std::os::raw::c_char,
1596+
pub prev: *mut zend_arena,
1597+
}
1598+
#[repr(C)]
1599+
#[derive(Debug, Copy, Clone)]
14801600
pub struct _zend_call_stack {
14811601
pub base: *mut ::std::os::raw::c_void,
14821602
pub max_size: usize,
@@ -1496,6 +1616,10 @@ pub struct _zend_fiber {
14961616
_unused: [u8; 0],
14971617
}
14981618
pub type zend_fiber = _zend_fiber;
1619+
pub const zend_memoize_mode_ZEND_MEMOIZE_NONE: zend_memoize_mode = 0;
1620+
pub const zend_memoize_mode_ZEND_MEMOIZE_COMPILE: zend_memoize_mode = 1;
1621+
pub const zend_memoize_mode_ZEND_MEMOIZE_FETCH: zend_memoize_mode = 2;
1622+
pub type zend_memoize_mode = ::std::os::raw::c_uint;
14991623
#[repr(C)]
15001624
pub struct _zend_executor_globals {
15011625
pub uninitialized_zval: zval,
@@ -2391,6 +2515,21 @@ extern "C" {
23912515
module_number: ::std::os::raw::c_int,
23922516
) -> zend_result;
23932517
}
2518+
pub type zend_ini_parser_cb_t = ::std::option::Option<
2519+
unsafe extern "C" fn(
2520+
arg1: *mut zval,
2521+
arg2: *mut zval,
2522+
arg3: *mut zval,
2523+
callback_type: ::std::os::raw::c_int,
2524+
arg: *mut ::std::os::raw::c_void,
2525+
),
2526+
>;
2527+
#[repr(C)]
2528+
#[derive(Debug, Copy, Clone)]
2529+
pub struct _zend_ini_parser_param {
2530+
pub ini_parser_cb: zend_ini_parser_cb_t,
2531+
pub arg: *mut ::std::os::raw::c_void,
2532+
}
23942533
extern "C" {
23952534
pub fn zend_register_bool_constant(
23962535
name: *const ::std::os::raw::c_char,

src/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626
pub fn ext_php_rs_zend_object_alloc(obj_size: usize, ce: *mut zend_class_entry) -> *mut c_void;
2727
pub fn ext_php_rs_zend_object_release(obj: *mut zend_object);
2828
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
29+
pub fn ext_php_rs_compiler_globals() -> *mut zend_compiler_globals;
2930
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
3031
pub fn ext_php_rs_sapi_globals() -> *mut sapi_globals_struct;
3132
pub fn ext_php_rs_file_globals() -> *mut php_file_globals;

src/wrapper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ zend_executor_globals *ext_php_rs_executor_globals() {
4040
#endif
4141
}
4242

43+
zend_compiler_globals *ext_php_rs_compiler_globals() {
44+
#ifdef ZTS
45+
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
46+
return TSRMG_FAST_BULK_STATIC(compiler_globals_offset, zend_compiler_globals);
47+
#else
48+
return TSRMG_FAST_BULK(compiler_globals_offset, zend_compiler_globals *);
49+
#endif
50+
#else
51+
return &compiler_globals;
52+
#endif
53+
}
54+
4355
php_core_globals *ext_php_rs_process_globals() {
4456
#ifdef ZTS
4557
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE

0 commit comments

Comments
 (0)