@@ -30,7 +30,7 @@ impl Clone for MatPolyOverZ {
3030 // we can unwrap since we know, that the number of rows and columns is positive and fits into an [`i64`]
3131 let mut clone = MatPolyOverZ :: new ( self . get_num_rows ( ) , self . get_num_columns ( ) ) ;
3232
33- unsafe { fmpz_poly_mat_set ( & mut clone. matrix , & mut self . matrix . to_owned ( ) ) }
33+ unsafe { fmpz_poly_mat_set ( & mut clone. matrix , & self . matrix ) }
3434
3535 clone
3636 }
@@ -78,20 +78,26 @@ mod test_clone {
7878 // an i64, both should be a pointer and their values should differ
7979 unsafe {
8080 assert_ne ! (
81- ( * ( * poly_1. matrix. entries) . coeffs. offset( 0 ) ) . 0 ,
82- ( * ( * poly_2. matrix. entries) . coeffs. offset( 0 ) ) . 0
81+ ( * ( * poly_1. matrix. entries) . coeffs. offset( 0 ) ) ,
82+ ( * ( * poly_2. matrix. entries) . coeffs. offset( 0 ) )
8383 ) ;
8484 }
8585 unsafe {
8686 assert_ne ! (
87- ( * ( * poly_1. matrix. entries) . coeffs. offset( 1 ) ) . 0 ,
88- ( * ( * poly_2. matrix. entries) . coeffs. offset( 1 ) ) . 0
87+ ( * ( * poly_1. matrix. entries) . coeffs. offset( 1 ) ) ,
88+ ( * ( * poly_2. matrix. entries) . coeffs. offset( 1 ) )
8989 ) ;
9090 }
9191
9292 // check if length of polynomial is correctly cloned
93- assert_eq ! ( unsafe { * poly_1. matrix. entries. offset( 0 ) } . length, 2 ) ;
94- assert_eq ! ( unsafe { * poly_2. matrix. entries. offset( 0 ) } . length, 2 ) ;
93+ assert_eq ! (
94+ unsafe { std:: ptr:: read( poly_1. matrix. entries. offset( 0 ) ) } . length,
95+ 2
96+ ) ;
97+ assert_eq ! (
98+ unsafe { std:: ptr:: read( poly_2. matrix. entries. offset( 0 ) ) } . length,
99+ 2
100+ ) ;
95101
96102 assert_eq ! ( poly_1, poly_2) ;
97103 }
@@ -110,20 +116,26 @@ mod test_clone {
110116 // both should be stored directly on stack and their values should be equal
111117 unsafe {
112118 assert_eq ! (
113- ( * ( * poly_1. matrix. entries) . coeffs. offset( 0 ) ) . 0 ,
114- ( * ( * poly_2. matrix. entries) . coeffs. offset( 0 ) ) . 0
119+ ( * ( * poly_1. matrix. entries) . coeffs. offset( 0 ) ) ,
120+ ( * ( * poly_2. matrix. entries) . coeffs. offset( 0 ) )
115121 ) ;
116122 }
117123 unsafe {
118124 assert_eq ! (
119- ( * ( * poly_1. matrix. entries) . coeffs. offset( 1 ) ) . 0 ,
120- ( * ( * poly_2. matrix. entries) . coeffs. offset( 1 ) ) . 0
125+ ( * ( * poly_1. matrix. entries) . coeffs. offset( 1 ) ) ,
126+ ( * ( * poly_2. matrix. entries) . coeffs. offset( 1 ) )
121127 ) ;
122128 }
123129
124130 // check if length of polynomial is correctly cloned
125- assert_eq ! ( unsafe { * poly_1. matrix. entries. offset( 0 ) } . length, 2 ) ;
126- assert_eq ! ( unsafe { * poly_2. matrix. entries. offset( 0 ) } . length, 2 ) ;
131+ assert_eq ! (
132+ unsafe { std:: ptr:: read( poly_1. matrix. entries. offset( 0 ) ) } . length,
133+ 2
134+ ) ;
135+ assert_eq ! (
136+ unsafe { std:: ptr:: read( poly_2. matrix. entries. offset( 0 ) ) } . length,
137+ 2
138+ ) ;
127139
128140 assert_eq ! ( poly_1, poly_2) ;
129141 }
@@ -151,7 +163,7 @@ mod test_drop {
151163 /// Creates and drops a [`MatPolyOverZ`], and returns the storage points in memory
152164 fn create_and_drop_poly_over_z ( ) -> i64 {
153165 let a = MatPolyOverZ :: from_str ( & format ! ( "[[1 {}]]" , u64 :: MAX ) ) . unwrap ( ) ;
154- unsafe { * ( * a. matrix . entries ) . coeffs . offset ( 0 ) } . 0
166+ unsafe { * ( * a. matrix . entries ) . coeffs . offset ( 0 ) }
155167 }
156168
157169 /// Check whether freed memory is reused afterwards
@@ -166,13 +178,12 @@ mod test_drop {
166178 assert ! ( set. capacity( ) < 5 ) ;
167179
168180 let a = MatPolyOverZ :: from_str ( & format ! ( "[[2 {} {}]]" , u64 :: MAX - 1 , u64 :: MAX ) ) . unwrap ( ) ;
169- let storage_point = unsafe { * ( * a. matrix . entries ) . coeffs . offset ( 0 ) } . 0 ;
181+ let storage_point = unsafe { * ( * a. matrix . entries ) . coeffs . offset ( 0 ) } ;
170182
171183 // memory slots differ due to previously created large integer
172184 let d = MatPolyOverZ :: from_str ( & format ! ( "[[2 {} {}]]" , u64 :: MAX - 1 , u64 :: MAX ) ) . unwrap ( ) ;
173- assert_ne ! (
174- storage_point,
175- unsafe { * ( * d. matrix. entries) . coeffs. offset( 0 ) } . 0
176- ) ;
185+ assert_ne ! ( storage_point, unsafe {
186+ * ( * d. matrix. entries) . coeffs. offset( 0 )
187+ } ) ;
177188 }
178189}
0 commit comments