Skip to content

Commit 2822d76

Browse files
committed
Replace all push zero operations to calling ensure_end_with_zero function.
1 parent 00caa8e commit 2822d76

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

phper/src/functions.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
sys::*,
1212
values::{ExecuteData, SetVal, Val},
1313
};
14+
use crate::utils::ensure_end_with_zero;
1415

1516
pub trait Function: Send + Sync {
1617
fn call(&self, arguments: &mut [Val], return_value: &mut Val);
@@ -61,8 +62,7 @@ pub struct FunctionEntity {
6162

6263
impl FunctionEntity {
6364
pub(crate) fn new(name: impl ToString, handler: Callable, arguments: Vec<Argument>) -> Self {
64-
let mut name = name.to_string();
65-
name.push('\0');
65+
let name = ensure_end_with_zero(name);
6666
FunctionEntity {
6767
name,
6868
handler,
@@ -111,8 +111,7 @@ pub struct Argument {
111111

112112
impl Argument {
113113
pub fn by_val(name: impl ToString) -> Self {
114-
let mut name = name.to_string();
115-
name.push('\0');
114+
let name = ensure_end_with_zero(name);
116115
Self {
117116
name,
118117
pass_by_ref: false,
@@ -121,8 +120,7 @@ impl Argument {
121120
}
122121

123122
pub fn by_ref(name: impl ToString) -> Self {
124-
let mut name = name.to_string();
125-
name.push('\0');
123+
let name = ensure_end_with_zero(name);
126124
Self {
127125
name,
128126
pass_by_ref: true,
@@ -131,8 +129,7 @@ impl Argument {
131129
}
132130

133131
pub fn by_val_optional(name: impl ToString) -> Self {
134-
let mut name = name.to_string();
135-
name.push('\0');
132+
let name = ensure_end_with_zero(name);
136133
Self {
137134
name,
138135
pass_by_ref: false,
@@ -141,8 +138,7 @@ impl Argument {
141138
}
142139

143140
pub fn by_ref_optional(name: impl ToString) -> Self {
144-
let mut name = name.to_string();
145-
name.push('\0');
141+
let name = ensure_end_with_zero(name);
146142
Self {
147143
name,
148144
pass_by_ref: true,

phper/src/modules.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::{
1616
ptr::{null, null_mut},
1717
sync::RwLock,
1818
};
19+
use crate::utils::ensure_end_with_zero;
1920

2021
static GLOBAL_MODULE: Lazy<RwLock<Module>> = Lazy::new(Default::default);
2122

@@ -105,20 +106,17 @@ impl Module {
105106
}
106107

107108
pub fn set_name(&mut self, name: impl ToString) {
108-
let mut name = name.to_string();
109-
name.push('\0');
109+
let name = ensure_end_with_zero(name);
110110
self.name = name;
111111
}
112112

113113
pub fn set_version(&mut self, version: impl ToString) {
114-
let mut version = version.to_string();
115-
version.push('\0');
114+
let version = ensure_end_with_zero(version);
116115
self.version = version;
117116
}
118117

119118
pub fn set_author(&mut self, author: impl ToString) {
120-
let mut author = author.to_string();
121-
author.push('\0');
119+
let author = ensure_end_with_zero(author);
122120
self.author = author;
123121
}
124122

phper/src/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{arrays::Array, errors::Throwable, sys::*};
22
use std::{mem::zeroed, slice::from_raw_parts, str, sync::atomic::Ordering};
3+
use crate::utils::ensure_end_with_zero;
34

45
#[repr(transparent)]
56
pub struct ExecuteData {
@@ -221,8 +222,7 @@ impl<T: SetVal, E: Throwable> SetVal for Result<T, E> {
221222
.class_entity()
222223
.as_ref()
223224
.expect("class entry is null pointer");
224-
let mut message = e.to_string();
225-
message.push('\0');
225+
let message = ensure_end_with_zero(&e);
226226
zend_throw_exception(
227227
class.entry.load(Ordering::SeqCst).cast(),
228228
message.as_ptr().cast(),

0 commit comments

Comments
 (0)