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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//! # libperl-sys
//!
//!
//! The function signatures, `PL_*` globals, and `Sv*` / `Av*` / `Hv*`
//! helpers documented below reflect this specific Perl. Different
//! Perl versions may have minor signature differences (added /
//! removed functions, changed integer widths, threading-mode
//! variations). Use the [`PERL_VERSION`] / [`PERL_THREADED`] /
//! [`PERL_ARCHNAME`] constants for runtime identification.
//!
//! Low-level, raw FFI declarations for the Perl 5 C API (`libperl`).
//! Generated at build time by `bindgen` (regular C declarations) plus
//! [`libperl-macrogen`](https://docs.rs/libperl-macrogen) (the C
//! macros and `static inline` functions that `bindgen` skips).
//!
//! This crate is the unsafe foundation under
//! [`libperl-rs`](https://docs.rs/libperl-rs); most users want that
//! safer wrapper. Reach for `libperl-sys` directly when you need an
//! API element that hasn't been wrapped yet, or when you're writing
//! a sibling crate at the same layer.
//!
//! ## What you get
//!
//! Re-exported at the crate root:
//!
//! - `Perl_*` extern functions and `PL_*` mutable statics (from
//! bindgen),
//! - `Sv*` / `Av*` / `Hv*` / `PL_xxx!()` macro helpers and inline
//! wrappers (from libperl-macrogen) — these unify the threaded vs
//! non-threaded calling conventions so the same source builds
//! against both `MULTIPLICITY` modes,
//! - `PL_xxx_ptr!()` pointer accessors (read *and write* the
//! interpreter variables through one primitive) and the [`thx`]
//! calling-convention shim module — together they let downstream
//! crates touch raw interpreter state without `cfg`-forking on the
//! threading mode (GH-20),
//! - opcode → name lookup table ([`conv_opcode`]) and per-function
//! signature dictionary ([`sigdb`]) for downstream codegen.
//!
//! ## Safety
//!
//! Every public item here is `unsafe` to use. Even reading a `PL_*`
//! global requires the right interpreter context, and Perl's API
//! uses raw `*mut` pointers ubiquitously.
//!
//! ## Build requirements
//!
//! - A working Perl 5 install with development headers
//! (`Perl.h`, `EXTERN.h`, ...). Typical packages: `perl-dev`,
//! `perl-devel`.
//! - LLVM / libclang (for `bindgen`).
//! - Internet access at first build (libperl-macrogen downloads a
//! pre-extracted apidoc snapshot from GitHub Releases).
//!
//! Threaded vs non-threaded Perl is auto-detected — no feature flag
//! to set.
pub use *;
/// Threaded-style calling-convention shims (GH-20).
///
/// Every function here takes `my_perl: *mut PerlInterpreter` first.
/// The argument is forwarded when the wrapped function wants a context
/// and silently dropped when it does not — which covers both
/// non-threaded builds (no function takes a context) and the handful of
/// context-free functions on threaded builds. Downstream code can
/// therefore call `sys::thx::Perl_foo(my_perl, ...)` uniformly and
/// compile against both `MULTIPLICITY` modes unchanged.
///
/// Wraps both the bindgen externs (bindings.rs) and the
/// libperl-macrogen-generated inline functions (macro_bindings.rs) —
/// the latter also change signature with the threading mode. C variadic
/// functions (e.g. `Perl_croak`) cannot be wrapped in stable Rust and
/// are omitted; call them through the crate root with an explicit
/// `#[cfg(perl_useithreads)]` branch if you need them.
/// Perl version this binding was generated against (e.g. `"5.38.4"`).
pub const PERL_VERSION: &str = env!;
/// `"threaded"` if the target Perl was built with `useithreads`,
/// `"non-threaded"` otherwise. Threading mode determines whether
/// most Perl C API functions take a leading `my_perl: *mut PerlInterpreter`
/// parameter.
pub const PERL_THREADED: &str = env!;
/// Perl `archname` (e.g. `"x86_64-linux-thread-multi"` or
/// `"x86_64-linux-gnu"`). Mostly informational; the more useful
/// invariants are in [`PERL_VERSION`] and [`PERL_THREADED`].
pub const PERL_ARCHNAME: &str = env!;
use CStr;
// use std::os::raw::{c_char, c_int /*, c_void, c_schar*/};