@@ -73,7 +73,7 @@ macro_rules! redis_module {
7373 ] ) ,* $( , ) *
7474 ] $( , ) *
7575 ) => {
76- use std:: os:: raw:: c_int;
76+ use std:: os:: raw:: { c_int, c_char } ;
7777 use std:: ffi:: CString ;
7878 use std:: slice;
7979
@@ -87,25 +87,27 @@ macro_rules! redis_module {
8787 _argv: * mut * mut raw:: RedisModuleString ,
8888 _argc: c_int,
8989 ) -> c_int {
90- {
91- // We use an explicit block here to make sure all memory allocated before we
92- // switch to the Redis allocator will be out of scope and thus deallocated.
93- let module_name = CString :: new( $module_name) . unwrap( ) ;
94- let module_version = $module_version as c_int;
9590
96- if unsafe { raw:: Export_RedisModule_Init (
97- ctx,
98- module_name. as_ptr( ) ,
99- module_version,
100- raw:: REDISMODULE_APIVER_1 as c_int,
101- ) } == raw:: Status :: Err as c_int { return raw:: Status :: Err as c_int; }
91+ // We use a statically sized buffer to avoid allocating.
92+ // This is needed since we use a custom allocator that relies on the Redis allocator,
93+ // which isn't yet ready at this point.
94+ let mut name_buffer = [ 0 ; 64 ] ;
95+ unsafe {
96+ std:: ptr:: copy(
97+ $module_name. as_ptr( ) ,
98+ name_buffer. as_mut_ptr( ) ,
99+ $module_name. len( ) ,
100+ ) ;
102101 }
103102
104- if true {
105- redis_module:: alloc:: use_redis_alloc( ) ;
106- } else {
107- eprintln!( "*** NOT USING Redis allocator ***" ) ;
108- }
103+ let module_version = $module_version as c_int;
104+
105+ if unsafe { raw:: Export_RedisModule_Init (
106+ ctx,
107+ name_buffer. as_ptr( ) as * const c_char,
108+ module_version,
109+ raw:: REDISMODULE_APIVER_1 as c_int,
110+ ) } == raw:: Status :: Err as c_int { return raw:: Status :: Err as c_int; }
109111
110112 $(
111113 if $init_func( ctx) == raw:: Status :: Err as c_int {
0 commit comments