@@ -326,83 +326,53 @@ impl<T: Clone> Clone for CVecTempl<T> {
326
326
327
327
#[ repr( C ) ]
328
328
pub struct C2TupleTempl < A , B > {
329
- pub a : * mut A ,
330
- pub b : * mut B ,
329
+ pub a : A ,
330
+ pub b : B ,
331
331
}
332
332
impl < A , B > From < ( A , B ) > for C2TupleTempl < A , B > {
333
333
fn from ( tup : ( A , B ) ) -> Self {
334
334
Self {
335
- a : Box :: into_raw ( Box :: new ( tup. 0 ) ) ,
336
- b : Box :: into_raw ( Box :: new ( tup. 1 ) ) ,
335
+ a : tup. 0 ,
336
+ b : tup. 1 ,
337
337
}
338
338
}
339
339
}
340
340
impl < A , B > C2TupleTempl < A , B > {
341
341
pub ( crate ) fn to_rust ( mut self ) -> ( A , B ) {
342
- let res = ( unsafe { * Box :: from_raw ( self . a ) } , unsafe { * Box :: from_raw ( self . b ) } ) ;
343
- self . a = std:: ptr:: null_mut ( ) ;
344
- self . b = std:: ptr:: null_mut ( ) ;
345
- res
342
+ ( self . a , self . b )
346
343
}
347
344
}
348
345
pub extern "C" fn C2TupleTempl_free < A , B > ( _res : C2TupleTempl < A , B > ) { }
349
- impl < A , B > Drop for C2TupleTempl < A , B > {
350
- fn drop ( & mut self ) {
351
- if !self . a . is_null ( ) {
352
- unsafe { Box :: from_raw ( self . a ) } ;
353
- }
354
- if !self . b . is_null ( ) {
355
- unsafe { Box :: from_raw ( self . b ) } ;
356
- }
357
- }
358
- }
359
346
impl < A : Clone , B : Clone > Clone for C2TupleTempl < A , B > {
360
347
fn clone ( & self ) -> Self {
361
348
Self {
362
- a : Box :: into_raw ( Box :: new ( unsafe { & * self . a } . clone ( ) ) ) ,
363
- b : Box :: into_raw ( Box :: new ( unsafe { & * self . b } . clone ( ) ) )
349
+ a : self . a . clone ( ) ,
350
+ b : self . b . clone ( )
364
351
}
365
352
}
366
353
}
367
354
368
355
#[ repr( C ) ]
369
356
pub struct C3TupleTempl < A , B , C > {
370
- pub a : * mut A ,
371
- pub b : * mut B ,
372
- pub c : * mut C ,
357
+ pub a : A ,
358
+ pub b : B ,
359
+ pub c : C ,
373
360
}
374
361
impl < A , B , C > From < ( A , B , C ) > for C3TupleTempl < A , B , C > {
375
362
fn from ( tup : ( A , B , C ) ) -> Self {
376
363
Self {
377
- a : Box :: into_raw ( Box :: new ( tup. 0 ) ) ,
378
- b : Box :: into_raw ( Box :: new ( tup. 1 ) ) ,
379
- c : Box :: into_raw ( Box :: new ( tup. 2 ) ) ,
364
+ a : tup. 0 ,
365
+ b : tup. 1 ,
366
+ c : tup. 2 ,
380
367
}
381
368
}
382
369
}
383
370
impl < A , B , C > C3TupleTempl < A , B , C > {
384
371
pub ( crate ) fn to_rust ( mut self ) -> ( A , B , C ) {
385
- let res = ( unsafe { * Box :: from_raw ( self . a ) } , unsafe { * Box :: from_raw ( self . b ) } , unsafe { * Box :: from_raw ( self . c ) } ) ;
386
- self . a = std:: ptr:: null_mut ( ) ;
387
- self . b = std:: ptr:: null_mut ( ) ;
388
- self . c = std:: ptr:: null_mut ( ) ;
389
- res
372
+ ( self . a , self . b , self . c )
390
373
}
391
374
}
392
375
pub extern "C" fn C3TupleTempl_free < A , B , C > ( _res : C3TupleTempl < A , B , C > ) { }
393
- impl < A , B , C > Drop for C3TupleTempl < A , B , C > {
394
- fn drop ( & mut self ) {
395
- if !self . a . is_null ( ) {
396
- unsafe { Box :: from_raw ( self . a ) } ;
397
- }
398
- if !self . b . is_null ( ) {
399
- unsafe { Box :: from_raw ( self . b ) } ;
400
- }
401
- if !self . c . is_null ( ) {
402
- unsafe { Box :: from_raw ( self . c ) } ;
403
- }
404
- }
405
- }
406
376
407
377
/// Utility to make it easy to set a pointer to null and get its original value in line.
408
378
pub ( crate ) trait TakePointer < T > {
0 commit comments