Skip to main content

libperl_sys/
perl_core.rs

1//! Auto-generated FFI declarations (bindgen + libperl-macrogen output).
2//!
3#![doc = concat!(
4    "Built against Perl ", env!("LIBPERL_SYS_PERL_VERSION"),
5    " (", env!("LIBPERL_SYS_PERL_THREADED"),
6    ", `", env!("LIBPERL_SYS_PERL_ARCHNAME"), "`).",
7)]
8//!
9//! See the [crate root](crate) for build-target details and version
10//! constants.
11#![allow(non_upper_case_globals)]
12#![allow(non_camel_case_types)]
13#![allow(non_snake_case)]
14#![allow(unnecessary_transmutes)]
15#![allow(unpredictable_function_pointer_comparisons)]
16#![allow(unused_imports)]
17#![allow(unused_mut)]
18// 5.20 の生成体 (SvSCREAM_on 族の sv_flags |= (...)) が unused_parens を
19// 3 件出す。下流が -D warnings でビルドしても生成コード起因で落ちない
20// よう、他の生成コード用 allow と同列で許容しておく。
21#![allow(unused_parens)]
22// 5.24 の生成体 (CvDEPTH デクリメント族の
23// `{ *S_CvDEPTHp(cv) -= 1; *S_CvDEPTHp(cv) }` 文) が unused_must_use を
24// 出す (CI は RUSTFLAGS=-D warnings で error 化する)。同上の理由で許容。
25#![allow(unused_must_use)]
26#![allow(unused_unsafe)]
27#![allow(unused_variables)]
28
29include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
30
31include!(concat!(env!("OUT_DIR"), "/macro_bindings.rs"));
32
33// GH-20: PERLVAR 由来の読み書き両用アクセサ `PL_xxx_ptr!` (build.rs 生成)。
34// read 専用の `PL_xxx!` (macro_bindings.rs) と同じ PERLVAR 観測が情報源。
35include!(concat!(env!("OUT_DIR"), "/perlvar_ptr_bindings.rs"));
36
37#[cfg(perlapi_ver40)]
38pub type perl_stack_size_t = isize;
39
40#[cfg(not(perlapi_ver40))]
41pub type perl_stack_size_t = i32;
42
43// Compat: `Stack_off_t` first appeared in the perl 5.40 stack refactor;
44// before that the mark stack was plain `I32`. Alias it on older perls so
45// downstream code can use `Stack_off_t` uniformly across versions
46// (bindgen emits the real typedef on 5.40+).
47#[cfg(not(perlapi_ver40))]
48pub type Stack_off_t = I32;
49
50// Compat: perl 5.31.x renamed the inline refcount helper `S_SvREFCNT_dec`
51// to `Perl_SvREFCNT_dec`, so the `Perl_` name only exists from 5.32 on.
52// Below 5.32 macrogen generates `S_SvREFCNT_dec` with the identical
53// signature (verified on 5.20-5.30 x both modes with libperl-macrogen
54// 0.1.12 / apidoc data 1.15); alias it so downstream code can call
55// `Perl_SvREFCNT_dec` uniformly across versions.
56#[cfg(not(perlapi_ver32))]
57pub use self::S_SvREFCNT_dec as Perl_SvREFCNT_dec;
58
59// Compat: the `OpSIBLING` macro first appeared in perl 5.21.2. On 5.20
60// mirror the old-world direct `op_sibling` read, with the signature
61// matching the 5.22+ macrogen output (`fn OpSIBLING(o: *mut OP) -> *mut OP`).
62#[cfg(not(perlapi_ver22))]
63pub unsafe fn OpSIBLING(o: *mut OP) -> *mut OP {
64    unsafe { (*o).op_sibling }
65}
66
67// Compat: `Perl_newXS_deffile` and `Perl_xs_boot_epilog` were both born
68// in perl 5.21.x (first release: 5.22) as part of the XS bootstrap
69// rework, and the `xs_boot!` proc-macro expansion references them. On
70// 5.20 mirror the 5.22 implementations (op.c `newXS_deffile` / perl.c
71// `xs_boot_epilog`), with signatures matching the 5.22 bindgen externs.
72#[cfg(all(not(perlapi_ver22), perl_useithreads))]
73pub unsafe fn Perl_newXS_deffile(
74    my_perl: *mut PerlInterpreter,
75    name: *const ::std::os::raw::c_char,
76    subaddr: XSUBADDR_t,
77) -> *mut CV {
78    // 5.22's newXS_deffile passes file = NULL (leaving CvFILE unset);
79    // 5.20's newXS asserts a filename, so hand it an empty string.
80    unsafe { Perl_newXS(my_perl, name, subaddr, c"".as_ptr()) }
81}
82
83#[cfg(all(not(perlapi_ver22), not(perl_useithreads)))]
84pub unsafe fn Perl_newXS_deffile(
85    name: *const ::std::os::raw::c_char,
86    subaddr: XSUBADDR_t,
87) -> *mut CV {
88    unsafe { Perl_newXS(name, subaddr, c"".as_ptr()) }
89}
90
91// 5.22 perl.c: run UNITCHECK blocks queued during boot, then
92// XSRETURN_YES (ST(0) = &PL_sv_yes; XSRETURN(1)).
93#[cfg(all(not(perlapi_ver22), perl_useithreads))]
94pub unsafe fn Perl_xs_boot_epilog(my_perl: *mut PerlInterpreter, ax: U32) {
95    unsafe {
96        if !(*my_perl).Iunitcheckav.is_null() {
97            Perl_call_list(my_perl, (*my_perl).Iscopestack_ix, (*my_perl).Iunitcheckav);
98        }
99        let slot = (*my_perl).Istack_base.add(ax as usize);
100        *slot = &raw mut (*my_perl).Isv_yes;
101        (*my_perl).Istack_sp = slot;
102    }
103}
104
105#[cfg(all(not(perlapi_ver22), not(perl_useithreads)))]
106pub unsafe fn Perl_xs_boot_epilog(ax: U32) {
107    unsafe {
108        if !PL_unitcheckav.is_null() {
109            Perl_call_list(PL_scopestack_ix, PL_unitcheckav);
110        }
111        let slot = PL_stack_base.add(ax as usize);
112        *slot = &raw mut PL_sv_yes;
113        PL_stack_sp = slot;
114    }
115}