@@ -180,28 +180,42 @@ impl PropertyInfo {
180
180
}
181
181
}
182
182
183
- /// Consumes self, moving the values into `sys::GDExtensionPropertyInfo` pointer.
183
+ /// Properly frees a `sys::GDExtensionPropertyInfo` created by [`into_owned_property_sys`](Self::into_owned_property_sys).
184
+ ///
185
+ /// # Safety
186
+ ///
187
+ /// * Must only be used on a struct returned from a call to `into_owned_property_sys`, without modification.
188
+ /// * Must not be called more than once on a `sys::GDExtensionPropertyInfo` struct.
189
+ pub ( crate ) unsafe fn free_owned_property_sys ( info : sys:: GDExtensionPropertyInfo ) {
190
+ // SAFETY: This function was called on a pointer returned from `into_owned_property_sys`, thus both `info.name` and
191
+ // `info.hint_string` were created from calls to `into_owned_string_sys` on their respective types.
192
+ // Additionally, this function isn't called more than once on a struct containing the same `name` or `hint_string` pointers.
193
+ unsafe {
194
+ let _name = StringName :: from_owned_string_sys ( info. name ) ;
195
+ let _hint_string = GString :: from_owned_string_sys ( info. hint_string ) ;
196
+ }
197
+ }
198
+ /// Moves its values into given `GDExtensionPropertyInfo`, dropping previous values if necessary.
184
199
///
185
200
/// # Safety
186
201
///
187
202
/// * `property_info_ptr` must be valid.
203
+ ///
188
204
pub ( crate ) unsafe fn move_into_property_info_ptr (
189
205
self ,
190
206
property_info_ptr : * mut sys:: GDExtensionPropertyInfo ,
191
207
) {
192
- ( * property_info_ptr) . type_ = self . variant_type . sys ( ) ;
208
+ ( * property_info_ptr) . usage = u32 :: try_from ( self . usage . ord ( ) ) . expect ( "usage.ord()" ) ;
193
209
( * property_info_ptr) . hint = u32:: try_from ( self . hint_info . hint . ord ( ) ) . expect ( "hint.ord()" ) ;
210
+ ( * property_info_ptr) . type_ = self . variant_type . sys ( ) ;
194
211
195
- self . hint_info
196
- . hint_string
197
- . move_into_string_ptr ( ( * property_info_ptr) . hint_string ) ;
198
- self . property_name
199
- . move_into_string_ptr ( ( * property_info_ptr) . name ) ;
212
+ let ptr = * property_info_ptr;
200
213
201
- ( * property_info_ptr) . usage = u32:: try_from ( self . usage . ord ( ) ) . expect ( "usage.ord()" ) ;
214
+ * StringName :: borrow_string_sys_mut ( ptr. name ) = self . property_name ;
215
+ * GString :: borrow_string_sys_mut ( ptr. hint_string ) = self . hint_info . hint_string ;
202
216
203
217
if self . class_name != ClassName :: none ( ) {
204
- ( * property_info_ptr ) . class_name = sys :: SysPtr :: force_mut ( self . class_name . string_sys ( ) ) ;
218
+ * StringName :: borrow_string_sys_mut ( ptr . class_name ) = self . class_name . to_string_name ( ) ;
205
219
}
206
220
}
207
221
@@ -213,34 +227,15 @@ impl PropertyInfo {
213
227
pub ( crate ) unsafe fn new_from_sys (
214
228
property_info_ptr : * mut sys:: GDExtensionPropertyInfo ,
215
229
) -> Self {
216
- let variant_type = VariantType :: from_sys ( ( * property_info_ptr) . type_ ) ;
217
- let property_name = StringName :: new_from_string_sys ( ( * property_info_ptr) . name ) ;
218
- let hint_string = GString :: new_from_string_sys ( ( * property_info_ptr) . hint_string ) ;
219
- let hint = PropertyHint :: from_ord ( ( * property_info_ptr) . hint . to_owned ( ) as i32 ) ;
220
- let usage = PropertyUsageFlags :: from_ord ( ( * property_info_ptr) . usage as u64 ) ;
221
-
222
230
Self {
223
- variant_type,
231
+ variant_type : VariantType :: from_sys ( ( * property_info_ptr ) . type_ ) ,
224
232
class_name : ClassName :: none ( ) ,
225
- property_name,
226
- hint_info : PropertyHintInfo { hint, hint_string } ,
227
- usage,
228
- }
229
- }
230
-
231
- /// Properly frees a `sys::GDExtensionPropertyInfo` created by [`into_owned_property_sys`](Self::into_owned_property_sys).
232
- ///
233
- /// # Safety
234
- ///
235
- /// * Must only be used on a struct returned from a call to `into_owned_property_sys`, without modification.
236
- /// * Must not be called more than once on a `sys::GDExtensionPropertyInfo` struct.
237
- pub ( crate ) unsafe fn free_owned_property_sys ( info : sys:: GDExtensionPropertyInfo ) {
238
- // SAFETY: This function was called on a pointer returned from `into_owned_property_sys`, thus both `info.name` and
239
- // `info.hint_string` were created from calls to `into_owned_string_sys` on their respective types.
240
- // Additionally, this function isn't called more than once on a struct containing the same `name` or `hint_string` pointers.
241
- unsafe {
242
- let _name = StringName :: from_owned_string_sys ( info. name ) ;
243
- let _hint_string = GString :: from_owned_string_sys ( info. hint_string ) ;
233
+ property_name : StringName :: new_from_string_sys ( ( * property_info_ptr) . name ) ,
234
+ hint_info : PropertyHintInfo {
235
+ hint : PropertyHint :: from_ord ( ( * property_info_ptr) . hint . to_owned ( ) as i32 ) ,
236
+ hint_string : GString :: new_from_string_sys ( ( * property_info_ptr) . hint_string ) ,
237
+ } ,
238
+ usage : PropertyUsageFlags :: from_ord ( ( * property_info_ptr) . usage as u64 ) ,
244
239
}
245
240
}
246
241
}
0 commit comments