File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ fn main() {
101
101
. clang_args ( includes. split ( ' ' ) )
102
102
. parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) )
103
103
. rustfmt_bindings ( true )
104
- . no_copy ( "_zend_value " )
104
+ . no_copy ( "_zval_struct " )
105
105
. no_copy ( "_zend_string" )
106
106
. no_copy ( "_zend_array" )
107
107
. layout_tests ( env:: var ( "EXT_PHP_RS_TEST" ) . is_ok ( ) ) ;
Original file line number Diff line number Diff line change @@ -500,6 +500,38 @@ impl Zval {
500
500
{
501
501
FromZval :: from_zval ( self )
502
502
}
503
+
504
+ /// Creates a shallow clone of the [`Zval`].
505
+ ///
506
+ /// This copies the contents of the [`Zval`], and increments the reference
507
+ /// counter of the underlying value (if it is reference counted).
508
+ ///
509
+ /// For example, if the zval contains a long, it will simply copy the value.
510
+ /// However, if the zval contains an object, the new zval will point to the
511
+ /// same object, and the objects reference counter will be incremented.
512
+ ///
513
+ /// # Returns
514
+ ///
515
+ /// The cloned zval.
516
+ pub fn shallow_clone ( & self ) -> Zval {
517
+ let mut new = Zval :: new ( ) ;
518
+ new. u1 = self . u1 ;
519
+ new. value = self . value ;
520
+
521
+ // SAFETY: `u1` union is only used for easier bitmasking. It is valid to read
522
+ // from either of the variants.
523
+ //
524
+ // SAFETY: If the value if refcounted (`self.u1.type_info & Z_TYPE_FLAGS_MASK`)
525
+ // then it is valid to dereference `self.value.counted`.
526
+ unsafe {
527
+ let flags = ZvalTypeFlags :: from_bits_unchecked ( self . u1 . type_info ) ;
528
+ if flags. contains ( ZvalTypeFlags :: RefCounted ) {
529
+ ( * self . value . counted ) . gc . refcount += 1 ;
530
+ }
531
+ }
532
+
533
+ new
534
+ }
503
535
}
504
536
505
537
impl Debug for Zval {
You can’t perform that action at this time.
0 commit comments