@@ -3,7 +3,7 @@ use crate::error::{Result, StorageError};
33use crate :: ffi:: {
44 free_c_string, storage_close, storage_destroy, storage_new, storage_peer_id, storage_repo,
55 storage_revision, storage_spr, storage_start, storage_stop, storage_version,
6- string_to_c_string,
6+ string_to_c_string, SendSafePtr ,
77} ;
88use crate :: node:: config:: StorageConfig ;
99use libc:: c_void;
@@ -55,13 +55,10 @@ impl StorageNode {
5555 let c_json_config = string_to_c_string ( & json_config) ;
5656
5757 let future = CallbackFuture :: new ( ) ;
58+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
5859
5960 let node_ctx = with_libstorage_lock ( || unsafe {
60- let node_ctx = storage_new (
61- c_json_config,
62- Some ( c_callback) ,
63- future. context_ptr ( ) as * mut c_void ,
64- ) ;
61+ let node_ctx = storage_new ( c_json_config, Some ( c_callback) , context_ptr. as_ptr ( ) ) ;
6562
6663 free_c_string ( c_json_config) ;
6764
@@ -120,14 +117,14 @@ impl StorageNode {
120117 }
121118
122119 let future = CallbackFuture :: new ( ) ;
120+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
123121
124122 let ctx = {
125123 let inner = node. inner . lock ( ) . unwrap ( ) ;
126124 inner. ctx as * mut _
127125 } ;
128126
129- let result =
130- unsafe { storage_start ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
127+ let result = unsafe { storage_start ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
131128
132129 if result != 0 {
133130 return Err ( StorageError :: node_error ( "start" , "Failed to start node" ) ) ;
@@ -163,14 +160,14 @@ impl StorageNode {
163160 }
164161
165162 let future = CallbackFuture :: new ( ) ;
163+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
166164
167165 let ctx = {
168166 let inner = node. inner . lock ( ) . unwrap ( ) ;
169167 inner. ctx as * mut _
170168 } ;
171169
172- let result =
173- unsafe { storage_stop ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
170+ let result = unsafe { storage_stop ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
174171
175172 if result != 0 {
176173 return Err ( StorageError :: node_error ( "stop" , "Failed to stop node" ) ) ;
@@ -212,14 +209,14 @@ impl StorageNode {
212209 }
213210
214211 let future = CallbackFuture :: new ( ) ;
212+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
215213
216214 let ctx = {
217215 let inner = node. inner . lock ( ) . unwrap ( ) ;
218216 inner. ctx as * mut _
219217 } ;
220218
221- let result =
222- unsafe { storage_close ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
219+ let result = unsafe { storage_close ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
223220
224221 if result != 0 {
225222 return Err ( StorageError :: node_error ( "close" , "Failed to close node" ) ) ;
@@ -259,14 +256,14 @@ impl StorageNode {
259256 }
260257
261258 let future = CallbackFuture :: new ( ) ;
259+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
262260
263261 let ctx = {
264262 let inner = self . inner . lock ( ) . unwrap ( ) ;
265263 inner. ctx as * mut _
266264 } ;
267265
268- let result =
269- unsafe { storage_close ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
266+ let result = unsafe { storage_close ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
270267
271268 if result != 0 {
272269 return Err ( StorageError :: node_error ( "destroy" , "Failed to close node" ) ) ;
@@ -314,14 +311,14 @@ impl StorageNode {
314311 pub async fn version ( & self ) -> Result < String > {
315312 let node = self . clone ( ) ;
316313 let future = CallbackFuture :: new ( ) ;
314+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
317315
318316 let ctx = {
319317 let inner = node. inner . lock ( ) . unwrap ( ) ;
320318 inner. ctx as * mut _
321319 } ;
322320
323- let result =
324- unsafe { storage_version ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
321+ let result = unsafe { storage_version ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
325322
326323 if result != 0 {
327324 return Err ( StorageError :: node_error ( "version" , "Failed to get version" ) ) ;
@@ -334,14 +331,14 @@ impl StorageNode {
334331 pub async fn revision ( & self ) -> Result < String > {
335332 let node = self . clone ( ) ;
336333 let future = CallbackFuture :: new ( ) ;
334+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
337335
338336 let ctx = {
339337 let inner = node. inner . lock ( ) . unwrap ( ) ;
340338 inner. ctx as * mut _
341339 } ;
342340
343- let result =
344- unsafe { storage_revision ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
341+ let result = unsafe { storage_revision ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
345342
346343 if result != 0 {
347344 return Err ( StorageError :: node_error (
@@ -357,14 +354,14 @@ impl StorageNode {
357354 pub async fn repo ( & self ) -> Result < String > {
358355 let node = self . clone ( ) ;
359356 let future = CallbackFuture :: new ( ) ;
357+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
360358
361359 let ctx = {
362360 let inner = node. inner . lock ( ) . unwrap ( ) ;
363361 inner. ctx as * mut _
364362 } ;
365363
366- let result =
367- unsafe { storage_repo ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
364+ let result = unsafe { storage_repo ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
368365
369366 if result != 0 {
370367 return Err ( StorageError :: node_error ( "repo" , "Failed to get repo path" ) ) ;
@@ -377,14 +374,14 @@ impl StorageNode {
377374 pub async fn spr ( & self ) -> Result < String > {
378375 let node = self . clone ( ) ;
379376 let future = CallbackFuture :: new ( ) ;
377+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
380378
381379 let ctx = {
382380 let inner = node. inner . lock ( ) . unwrap ( ) ;
383381 inner. ctx as * mut _
384382 } ;
385383
386- let result =
387- unsafe { storage_spr ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
384+ let result = unsafe { storage_spr ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
388385
389386 if result != 0 {
390387 return Err ( StorageError :: node_error ( "spr" , "Failed to get SPR" ) ) ;
@@ -419,14 +416,14 @@ impl StorageNode {
419416 pub async fn peer_id ( & self ) -> Result < String > {
420417 let node = self . clone ( ) ;
421418 let future = CallbackFuture :: new ( ) ;
419+ let context_ptr = unsafe { SendSafePtr :: new ( future. context_ptr ( ) as * mut c_void ) } ;
422420
423421 let ctx = {
424422 let inner = node. inner . lock ( ) . unwrap ( ) ;
425423 inner. ctx as * mut _
426424 } ;
427425
428- let result =
429- unsafe { storage_peer_id ( ctx, Some ( c_callback) , future. context_ptr ( ) as * mut c_void ) } ;
426+ let result = unsafe { storage_peer_id ( ctx, Some ( c_callback) , context_ptr. as_ptr ( ) ) } ;
430427
431428 if result != 0 {
432429 return Err ( StorageError :: node_error ( "peer_id" , "Failed to get peer ID" ) ) ;
0 commit comments