Skip to content

Commit 3f6595d

Browse files
authored
Merge pull request #566 from extphprs/chore/bump-edition-2024
2 parents 866660b + 4778c3c commit 3f6595d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+406
-221
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [
1111
"Xenira <[email protected]>",
1212
"David Cole <[email protected]>",
1313
]
14-
edition = "2021"
14+
edition = "2024"
1515
categories = ["api-bindings"]
1616
exclude = ["/.github", "/.crates"]
1717
autotests = false

build.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{
1616
str::FromStr,
1717
};
1818

19-
use anyhow::{anyhow, bail, Context, Error, Result};
19+
use anyhow::{Context, Error, Result, anyhow, bail};
2020
use bindgen::RustTarget;
2121
use impl_::Provider;
2222

@@ -332,17 +332,25 @@ impl TryFrom<u32> for ApiVersion {
332332

333333
fn try_from(version: u32) -> Result<Self, Self::Error> {
334334
match version {
335-
x if ((ApiVersion::Php80 as u32)..(ApiVersion::Php81 as u32)).contains(&x) => Ok(ApiVersion::Php80),
336-
x if ((ApiVersion::Php81 as u32)..(ApiVersion::Php82 as u32)).contains(&x) => Ok(ApiVersion::Php81),
337-
x if ((ApiVersion::Php82 as u32)..(ApiVersion::Php83 as u32)).contains(&x) => Ok(ApiVersion::Php82),
338-
x if ((ApiVersion::Php83 as u32)..(ApiVersion::Php84 as u32)).contains(&x) => Ok(ApiVersion::Php83),
335+
x if ((ApiVersion::Php80 as u32)..(ApiVersion::Php81 as u32)).contains(&x) => {
336+
Ok(ApiVersion::Php80)
337+
}
338+
x if ((ApiVersion::Php81 as u32)..(ApiVersion::Php82 as u32)).contains(&x) => {
339+
Ok(ApiVersion::Php81)
340+
}
341+
x if ((ApiVersion::Php82 as u32)..(ApiVersion::Php83 as u32)).contains(&x) => {
342+
Ok(ApiVersion::Php82)
343+
}
344+
x if ((ApiVersion::Php83 as u32)..(ApiVersion::Php84 as u32)).contains(&x) => {
345+
Ok(ApiVersion::Php83)
346+
}
339347
x if (ApiVersion::Php84 as u32) == x => Ok(ApiVersion::Php84),
340348
version => Err(anyhow!(
341-
"The current version of PHP is not supported. Current PHP API version: {}, requires a version between {} and {}",
342-
version,
343-
ApiVersion::min() as u32,
344-
ApiVersion::max() as u32
345-
))
349+
"The current version of PHP is not supported. Current PHP API version: {}, requires a version between {} and {}",
350+
version,
351+
ApiVersion::min() as u32,
352+
ApiVersion::max() as u32
353+
)),
346354
}
347355
}
348356
}
@@ -367,7 +375,9 @@ fn check_php_version(info: &PHPInfo) -> Result<()> {
367375
);
368376

369377
if version == ApiVersion::Php80 {
370-
println!("cargo:warning=PHP 8.0 is EOL and is no longer supported. Please upgrade to a supported version of PHP. See https://www.php.net/supported-versions.php for information on version support timelines.");
378+
println!(
379+
"cargo:warning=PHP 8.0 is EOL and is no longer supported. Please upgrade to a supported version of PHP. See https://www.php.net/supported-versions.php for information on version support timelines."
380+
);
371381
}
372382

373383
for supported_version in version.supported_apis() {

crates/cli/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ keywords = ["php", "ffi", "zend"]
88
version = "0.1.13"
99
authors = [
1010
"Xenira <[email protected]>",
11-
"David Cole <[email protected]>"
11+
"David Cole <[email protected]>",
12+
"Pierre Tondereau <[email protected]>",
1213
]
13-
edition = "2018"
14+
edition = "2024"
1415
categories = ["api-bindings", "command-line-interface"]
1516

1617
[dependencies]

crates/cli/src/lib.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#[cfg(not(windows))]
44
mod ext;
55

6-
use anyhow::{bail, Context, Result as AResult};
7-
use cargo_metadata::{camino::Utf8PathBuf, CrateType, Target};
6+
use anyhow::{Context, Result as AResult, bail};
7+
use cargo_metadata::{CrateType, Target, camino::Utf8PathBuf};
88
use clap::Parser;
99
use dialoguer::{Confirm, Select};
1010

@@ -27,7 +27,7 @@ macro_rules! stub_symbols {
2727
(@INTERNAL; $s: ident) => {
2828
#[allow(non_upper_case_globals)]
2929
#[allow(missing_docs)]
30-
#[no_mangle]
30+
#[unsafe(no_mangle)]
3131
pub static mut $s: *mut () = ::std::ptr::null_mut();
3232
};
3333
}
@@ -221,9 +221,9 @@ impl Install {
221221
ext_dir.push(ext_name);
222222
}
223223

224-
std::fs::copy(&ext_path, &ext_dir).with_context(|| {
225-
"Failed to copy extension from target directory to extension directory"
226-
})?;
224+
std::fs::copy(&ext_path, &ext_dir).with_context(
225+
|| "Failed to copy extension from target directory to extension directory",
226+
)?;
227227

228228
if let Some(php_ini) = php_ini {
229229
let mut file = OpenOptions::new()
@@ -408,15 +408,17 @@ impl Stubs {
408408
let result = ext.describe();
409409

410410
// Ensure extension and CLI `ext-php-rs` versions are compatible.
411-
let cli_version = semver::VersionReq::from_str(ext_php_rs::VERSION).with_context(|| {
412-
"Failed to parse `ext-php-rs` version that `cargo php` was compiled with"
413-
})?;
414-
let ext_version = semver::Version::from_str(result.version).with_context(|| {
415-
"Failed to parse `ext-php-rs` version that your extension was compiled with"
416-
})?;
411+
let cli_version = semver::VersionReq::from_str(ext_php_rs::VERSION).with_context(
412+
|| "Failed to parse `ext-php-rs` version that `cargo php` was compiled with",
413+
)?;
414+
let ext_version = semver::Version::from_str(result.version).with_context(
415+
|| "Failed to parse `ext-php-rs` version that your extension was compiled with",
416+
)?;
417417

418418
if !cli_version.matches(&ext_version) {
419-
bail!("Extension was compiled with an incompatible version of `ext-php-rs` - Extension: {ext_version}, CLI: {cli_version}");
419+
bail!(
420+
"Extension was compiled with an incompatible version of `ext-php-rs` - Extension: {ext_version}, CLI: {cli_version}"
421+
);
420422
}
421423

422424
let stubs = result

crates/macros/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ license = "MIT OR Apache-2.0"
77
version = "0.11.4"
88
authors = [
99
"Xenira <[email protected]>",
10-
"David Cole <[email protected]>"
10+
"David Cole <[email protected]>",
11+
"Pierre Tondereau <[email protected]>",
1112
]
12-
edition = "2021"
13+
edition = "2024"
1314

1415
[lib]
1516
proc-macro = true

crates/macros/src/enum_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::convert::TryFrom;
22

3-
use darling::{util::Flag, FromAttributes};
3+
use darling::{FromAttributes, util::Flag};
44
use itertools::Itertools;
55
use proc_macro2::TokenStream;
6-
use quote::{quote, ToTokens};
6+
use quote::{ToTokens, quote};
77
use syn::{Fields, Ident, ItemEnum, Lit};
88

99
use crate::{

crates/macros/src/extern_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use proc_macro2::TokenStream;
22
use quote::quote;
33
use syn::{
4-
punctuated::Punctuated, spanned::Spanned as _, token::Unsafe, ForeignItemFn, ItemForeignMod,
5-
ReturnType, Signature, Token,
4+
ForeignItemFn, ItemForeignMod, ReturnType, Signature, Token, punctuated::Punctuated,
5+
spanned::Spanned as _, token::Unsafe,
66
};
77

88
use crate::prelude::*;

crates/macros/src/function.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ impl<'a> Function<'a> {
218218
let required_arg_names: Vec<_> = required.iter().map(|arg| arg.name).collect();
219219
let not_required_arg_names: Vec<_> = not_required.iter().map(|arg| arg.name).collect();
220220

221+
let variadic_bindings = self.args.typed.iter().filter_map(|arg| {
222+
if arg.variadic {
223+
let name = arg.name;
224+
let variadic_name = format_ident!("__variadic_{}", name);
225+
let clean_ty = arg.clean_ty();
226+
Some(quote! {
227+
let #variadic_name = #name.variadic_vals::<#clean_ty>();
228+
})
229+
} else {
230+
None
231+
}
232+
});
233+
221234
let arg_accessors = self.args.typed.iter().map(|arg| {
222235
arg.accessor(|e| {
223236
quote! {
@@ -237,6 +250,7 @@ impl<'a> Function<'a> {
237250
if parse.is_err() {
238251
return;
239252
}
253+
#(#variadic_bindings)*
240254

241255
#ident(#({#arg_accessors}),*)
242256
},
@@ -277,6 +291,7 @@ impl<'a> Function<'a> {
277291
if parse_result.is_err() {
278292
return;
279293
}
294+
#(#variadic_bindings)*
280295

281296
#call
282297
}
@@ -332,6 +347,18 @@ impl<'a> Function<'a> {
332347
.iter()
333348
.map(TypedArg::arg_declaration)
334349
.collect::<Vec<_>>();
350+
let variadic_bindings = self.args.typed.iter().filter_map(|arg| {
351+
if arg.variadic {
352+
let name = arg.name;
353+
let variadic_name = format_ident!("__variadic_{}", name);
354+
let clean_ty = arg.clean_ty();
355+
Some(quote! {
356+
let #variadic_name = #name.variadic_vals::<#clean_ty>();
357+
})
358+
} else {
359+
None
360+
}
361+
});
335362
let arg_accessors = self.args.typed.iter().map(|arg| {
336363
arg.accessor(
337364
|e| quote! { return ::ext_php_rs::class::ConstructorResult::Exception(#e); },
@@ -359,6 +386,7 @@ impl<'a> Function<'a> {
359386
if parse.is_err() {
360387
return ::ext_php_rs::class::ConstructorResult::ArgError;
361388
}
389+
#(#variadic_bindings)*
362390
#class::#ident(#({#arg_accessors}),*).into()
363391
}
364392
inner
@@ -535,7 +563,7 @@ impl TypedArg<'_> {
535563
let mut ty = self.ty.clone();
536564
ty.drop_lifetimes();
537565

538-
// Variadic arguments are passed as slices, so we need to extract the
566+
// Variadic arguments are passed as &[&Zval], so we need to extract the
539567
// inner type.
540568
if self.variadic {
541569
let Type::Reference(reference) = &ty else {
@@ -599,8 +627,9 @@ impl TypedArg<'_> {
599627
#name.val().unwrap_or(#default.into())
600628
}
601629
} else if self.variadic {
630+
let variadic_name = format_ident!("__variadic_{}", name);
602631
quote! {
603-
&#name.variadic_vals()
632+
#variadic_name.as_slice()
604633
}
605634
} else if self.nullable {
606635
// Originally I thought we could just use the below case for `null` options, as

crates/macros/src/impl_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use darling::util::Flag;
21
use darling::FromAttributes;
2+
use darling::util::Flag;
33
use proc_macro2::TokenStream;
44
use quote::quote;
55
use std::collections::{HashMap, HashSet};

crates/macros/src/module.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub fn parser(input: ItemFn) -> Result<TokenStream> {
2525

2626
Ok(quote! {
2727
#[doc(hidden)]
28-
#[no_mangle]
28+
#[unsafe(no_mangle)]
2929
extern "C" fn get_module() -> *mut ::ext_php_rs::zend::ModuleEntry {
3030
static __EXT_PHP_RS_MODULE_STARTUP: ::ext_php_rs::internal::ModuleStartupMutex =
3131
::ext_php_rs::internal::MODULE_STARTUP_INIT;
3232

3333
extern "C" fn ext_php_rs_startup(ty: i32, mod_num: i32) -> i32 {
34-
let a = #startup;
34+
let a = unsafe { #startup };
3535
let b = __EXT_PHP_RS_MODULE_STARTUP
3636
.lock()
3737
.take()
@@ -64,7 +64,7 @@ pub fn parser(input: ItemFn) -> Result<TokenStream> {
6464
}
6565

6666
#[cfg(debug_assertions)]
67-
#[no_mangle]
67+
#[unsafe(no_mangle)]
6868
pub extern "C" fn ext_php_rs_describe_module() -> ::ext_php_rs::describe::Description {
6969
use ::ext_php_rs::describe::*;
7070

0 commit comments

Comments
 (0)