File tree Expand file tree Collapse file tree 3 files changed +10
-23
lines changed
Expand file tree Collapse file tree 3 files changed +10
-23
lines changed Original file line number Diff line number Diff line change 11use std:: alloc:: { GlobalAlloc , Layout } ;
22use std:: os:: raw:: c_void;
3- use std:: sync:: atomic:: { AtomicBool , Ordering :: SeqCst } ;
43
54use crate :: raw;
65
76pub struct RedisAlloc ;
87
9- static USE_REDIS_ALLOC : AtomicBool = AtomicBool :: new ( false ) ;
10-
118unsafe impl GlobalAlloc for RedisAlloc {
129 unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
1310 let size = ( layout. size ( ) + layout. align ( ) - 1 ) & ( !( layout. align ( ) - 1 ) ) ;
@@ -18,8 +15,3 @@ unsafe impl GlobalAlloc for RedisAlloc {
1815 return raw:: RedisModule_Free . unwrap ( ) ( ptr as * mut c_void ) ;
1916 }
2017}
21-
22- pub fn use_redis_alloc ( ) {
23- USE_REDIS_ALLOC . store ( true , SeqCst ) ;
24- eprintln ! ( "Now using Redis allocator" ) ;
25- }
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ mod key;
2828pub use crate :: context:: Context ;
2929pub use crate :: redismodule:: * ;
3030
31+ #[ cfg( not( test) ) ]
3132#[ global_allocator]
3233static ALLOC : crate :: alloc:: RedisAlloc = crate :: alloc:: RedisAlloc ;
3334
Original file line number Diff line number Diff line change @@ -95,22 +95,16 @@ macro_rules! redis_module {
9595 dest = dest. add( 1 ) ;
9696 }
9797 }
98- // We use an explicit block here to make sure all memory allocated before we
99- // switch to the Redis allocator will be out of scope and thus deallocated.
100- let module_version = $module_version as c_int;
98+ // We use an explicit block here to make sure all memory allocated before we
99+ // switch to the Redis allocator will be out of scope and thus deallocated.
100+ let module_version = $module_version as c_int;
101101
102- if unsafe { raw:: Export_RedisModule_Init (
103- ctx,
104- name_buffer. as_ptr( ) as * const std:: os:: raw:: c_char,
105- module_version,
106- raw:: REDISMODULE_APIVER_1 as c_int,
107- ) } == raw:: Status :: Err as c_int { return raw:: Status :: Err as c_int; }
108-
109- if true {
110- redis_module:: alloc:: use_redis_alloc( ) ;
111- } else {
112- eprintln!( "*** NOT USING Redis allocator ***" ) ;
113- }
102+ if unsafe { raw:: Export_RedisModule_Init (
103+ ctx,
104+ name_buffer. as_ptr( ) as * const std:: os:: raw:: c_char,
105+ module_version,
106+ raw:: REDISMODULE_APIVER_1 as c_int,
107+ ) } == raw:: Status :: Err as c_int { return raw:: Status :: Err as c_int; }
114108
115109 $(
116110 if $init_func( ctx) == raw:: Status :: Err as c_int {
You can’t perform that action at this time.
0 commit comments