Disable serialization and unserialization on classes (#105)

* Disable serialization and unserialization on classes

Classes that have associated Rust types cannot be serialized for
obvious reasons so these need to be disabled. Disabling these actions
changes in PHP 8.1 to use a flag, so that will need to be solved with
PHP 8.1 support. Closes #97

* update docs stubs
This commit is contained in:
David Cole 2021-10-19 02:10:02 +13:00 committed by GitHub
parent b92202c89b
commit 88b84b9a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 14 deletions

View File

@ -328,4 +328,6 @@ const ALLOWED_BINDINGS: &[&str] = &[
"zend_std_has_property",
"zend_objects_new",
"zend_standard_class_def",
"zend_class_serialize_deny",
"zend_class_unserialize_deny",
];

View File

@ -1,17 +1,5 @@
/* automatically generated by rust-bindgen 0.59.1 */
/// This file is used to build the documentation for `ext-php-rs` when being
/// built on docs.rs runners. As these runners do not have PHP 8.0 installed,
/// they are unable to generate the bindings to the PHP APIs.
/// This file was generated under the following conditions:
///
/// PHP 8.0.10 (cli) (built: Sep 2 2021 13:52:33) ( NTS DEBUG )
/// Copyright (c) The PHP Group
/// Zend Engine v4.0.10, Copyright (c) Zend Technologies
///
/// Arch Linux 2021.09.01 - Linux 5.10.43.3-microsoft-standard-WSL2 x86_64
pub const ZEND_DEBUG: u32 = 1;
pub const ZEND_MM_ALIGNMENT: u32 = 8;
pub const _ZEND_TYPE_NAME_BIT: u32 = 8388608;
@ -1361,6 +1349,23 @@ extern "C" {
extern "C" {
pub fn zend_do_implement_interface(ce: *mut zend_class_entry, iface: *mut zend_class_entry);
}
extern "C" {
pub fn zend_class_serialize_deny(
object: *mut zval,
buffer: *mut *mut ::std::os::raw::c_uchar,
buf_len: *mut size_t,
data: *mut zend_serialize_data,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn zend_class_unserialize_deny(
object: *mut zval,
ce: *mut zend_class_entry,
buf: *const ::std::os::raw::c_uchar,
buf_len: size_t,
data: *mut zend_unserialize_data,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn ext_php_rs_zend_string_init(
str_: *const ::std::os::raw::c_char,

View File

@ -7,8 +7,8 @@ use crate::{
error::{Error, Result},
exception::PhpException,
ffi::{
zend_declare_class_constant, zend_declare_property, zend_do_implement_interface,
zend_register_internal_class_ex,
zend_class_serialize_deny, zend_class_unserialize_deny, zend_declare_class_constant,
zend_declare_property, zend_do_implement_interface, zend_register_internal_class_ex,
},
flags::{ClassFlags, MethodFlags, PropertyFlags},
types::{ZendClassObject, ZendObject, ZendStr, Zval},
@ -243,6 +243,15 @@ impl ClassBuilder {
.ok_or(Error::InvalidPointer)?
};
// disable serialization if the class has an associated object
//
// TODO(david): change to support PHP 8.1 - uses a flag instead of the
// serializable/deserializable properties
if self.object_override.is_some() {
class.serialize = Some(zend_class_serialize_deny);
class.unserialize = Some(zend_class_unserialize_deny);
}
for iface in self.interfaces {
unsafe { zend_do_implement_interface(class, std::mem::transmute(iface)) };
}

View File

@ -2,6 +2,7 @@
#include "ext/standard/info.h"
#include "zend_exceptions.h"
#include "zend_inheritance.h"
#include "zend_interfaces.h"
zend_string *ext_php_rs_zend_string_init(const char *str, size_t len, bool persistent);
void ext_php_rs_zend_string_release(zend_string *zs);