Skip to content
This repository was archived by the owner on Jul 11, 2021. It is now read-only.

Commit 1ee9152

Browse files
author
Simone Mosciatti
committed
make the PRO part also clippy complainat
1 parent fb73d5a commit 1ee9152

5 files changed

Lines changed: 80 additions & 38 deletions

File tree

engine_pro

Submodule engine_pro updated from b41382e to 093a4f8

redisql_lib/build.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ fn main() {
4949
}
5050
}
5151

52-
let engine_pro = if cfg!(features = "pro") {
53-
"-DENGINE_PRO=1"
54-
} else {
55-
"-DENGINE_PRO=0"
56-
};
52+
// let engine_pro = "-DENGINE_PRO=1";
53+
let engine_pro = "-DENGINE_PRO=0";
5754

5855
let bindings =
5956
bindgen::Builder::default()

redisql_lib/src/redis.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@ pub unsafe fn write_rdb_to_file(f: &mut File,
904904
let slice = slice::from_raw_parts(c_str_ptr.ptr as *mut u8,
905905
dimension);
906906
let y = f.write_all(slice);
907-
// mem::forget(slice);
908907
if let Err(e) = y {
909908
return Err(e);
910909
}
@@ -991,10 +990,11 @@ fn remove_statement(db: &Arc<Mutex<sql::RawConnection>>,
991990
.or_else(|e| Err(err::RediSQLError::from(e)))
992991
}
993992

994-
pub fn replicate(_ctx: *mut rm::ffi::RedisModuleCtx,
995-
_command: String,
996-
_argv: *mut *mut rm::ffi::RedisModuleString,
997-
_argc: std::os::raw::c_int) {
993+
#[allow(non_snake_case)]
994+
pub unsafe fn Replicate(_ctx: rm::Context,
995+
_command: &str,
996+
_argv: *mut *mut rm::ffi::RedisModuleString,
997+
_argc: std::os::raw::c_int) {
998998
}
999999

10001000
pub fn register_function(

redisql_lib/src/redis_type.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::os::raw::c_char;
1+
use std::os::raw::{c_char, c_int};
22

33
use std::ffi::CString;
44

@@ -35,7 +35,7 @@ impl From<Context> for *mut ffi::RedisModuleCtx {
3535
}
3636

3737
pub struct RMString {
38-
pub ptr: *mut ffi::RedisModuleString,
38+
ptr: *mut ffi::RedisModuleString,
3939
ctx: Context,
4040
}
4141

@@ -49,13 +49,16 @@ impl RMString {
4949
};
5050
RMString { ptr, ctx }
5151
}
52+
pub fn as_ptr(&self) -> *mut ffi::RedisModuleString {
53+
self.ptr
54+
}
5255
}
5356

5457
impl Drop for RMString {
5558
fn drop(&mut self) {
5659
unsafe {
5760
ffi::RedisModule_FreeString.unwrap()(self.ctx.as_ptr(),
58-
self.ptr);
61+
self.as_ptr());
5962
}
6063
}
6164
}
@@ -91,6 +94,21 @@ pub fn ReplicateVerbatim(ctx: Context) -> i32 {
9194
}
9295
}
9396

97+
#[allow(non_snake_case)]
98+
pub unsafe fn Replicate(ctx: Context,
99+
command: &str,
100+
argv: *mut *mut ffi::RedisModuleString,
101+
argc: c_int)
102+
-> i32 {
103+
let command = CString::new(command).unwrap();
104+
let v = CString::new("v").unwrap();
105+
ffi::RedisModule_Replicate.unwrap()(ctx.as_ptr(),
106+
command.as_ptr(),
107+
v.as_ptr(),
108+
argv.offset(1),
109+
argc - 1)
110+
}
111+
94112
#[allow(non_snake_case)]
95113
pub fn ReplyWithError(ctx: Context, error: &str) -> i32 {
96114
unsafe {
@@ -169,3 +187,29 @@ pub fn ReplyWithStringBuffer(ctx: Context, buffer: &[u8]) -> i32 {
169187
len)
170188
}
171189
}
190+
191+
pub struct AOF {
192+
aof: *mut ffi::RedisModuleIO,
193+
}
194+
195+
impl AOF {
196+
pub fn new(aof: *mut ffi::RedisModuleIO) -> AOF {
197+
AOF { aof }
198+
}
199+
pub fn as_ptr(&self) -> *mut ffi::RedisModuleIO {
200+
self.aof
201+
}
202+
}
203+
204+
#[allow(non_snake_case)]
205+
pub unsafe fn EmitAOF(aof: &AOF,
206+
command: &str,
207+
specifier: &str,
208+
key: *mut ffi::RedisModuleString,
209+
data: &str) {
210+
ffi::RedisModule_EmitAOF.unwrap()(aof.as_ptr(),
211+
command.as_ptr() as *const i8,
212+
specifier.as_ptr() as *const i8,
213+
key,
214+
data.as_ptr())
215+
}

src/lib.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ extern crate engine_pro;
3333
use engine_pro::{WriteAOF, register};
3434

3535
#[cfg(feature = "pro")]
36-
use engine_pro::replicate;
36+
use engine_pro::Replicate;
3737
#[cfg(not(feature = "pro"))]
38-
use redisql_lib::redis::replicate;
38+
use redisql_lib::redis::Replicate;
3939

4040
extern "C" fn reply_exec(ctx: *mut r::rm::ffi::RedisModuleCtx,
4141
_argv: *mut *mut r::rm::ffi::RedisModuleString,
@@ -122,7 +122,7 @@ extern "C" fn ExecStatement(
122122
argv: *mut *mut r::rm::ffi::RedisModuleString,
123123
argc: ::std::os::raw::c_int,
124124
) -> i32{
125-
let (_context, argvector) = r::create_argument(ctx, argv, argc);
125+
let (context, argvector) = r::create_argument(ctx, argv, argc);
126126

127127
match argvector.len() {
128128
0...2 => {
@@ -135,7 +135,7 @@ extern "C" fn ExecStatement(
135135
}
136136
}
137137
_ => {
138-
match get_db_and_loopdata_from_name(ctx, &argvector[1]) {
138+
match get_db_and_loopdata_from_name(ctx, argvector[1]) {
139139
Err(key_type) => {
140140
reply_with_error_from_key_type(ctx, key_type)
141141
}
@@ -159,7 +159,7 @@ extern "C" fn ExecStatement(
159159

160160
match ch.send(cmd) {
161161
Ok(()) => {
162-
replicate(ctx, String::from("REDISQL.EXEC_STATEMENT.NOW"), argv, argc);
162+
unsafe {Replicate(context, "REDISQL.EXEC_STATEMENT.NOW", argv, argc);}
163163
r::rm::ffi::REDISMODULE_OK
164164
}
165165
Err(_) => r::rm::ffi::REDISMODULE_OK,
@@ -189,7 +189,7 @@ extern "C" fn QueryStatement(
189189
}
190190
}
191191
_ => {
192-
match get_db_and_loopdata_from_name(ctx, &argvector[1]) {
192+
match get_db_and_loopdata_from_name(ctx, argvector[1]) {
193193
Err(key_type) => {
194194
reply_with_error_from_key_type(ctx, key_type)
195195
}
@@ -226,10 +226,10 @@ extern "C" fn Exec(ctx: *mut r::rm::ffi::RedisModuleCtx,
226226
argv: *mut *mut r::rm::ffi::RedisModuleString,
227227
argc: ::std::os::raw::c_int)
228228
-> i32 {
229-
let (_context, argvector) = r::create_argument(ctx, argv, argc);
229+
let (context, argvector) = r::create_argument(ctx, argv, argc);
230230
match argvector.len() {
231231
3 => {
232-
match get_db_channel_from_name(ctx, &argvector[1]) {
232+
match get_db_channel_from_name(ctx, argvector[1]) {
233233
Err(key_type) => {
234234
reply_with_error_from_key_type(ctx, key_type)
235235
}
@@ -251,7 +251,7 @@ extern "C" fn Exec(ctx: *mut r::rm::ffi::RedisModuleCtx,
251251
};
252252
match ch.send(cmd) {
253253
Ok(()) => {
254-
replicate(ctx, String::from("REDISQL.EXEC.NOW"), argv, argc);
254+
unsafe {Replicate(context, "REDISQL.EXEC.NOW", argv, argc);}
255255
r::rm::ffi::REDISMODULE_OK
256256
}
257257
Err(_) => r::rm::ffi::REDISMODULE_OK,
@@ -281,7 +281,7 @@ extern "C" fn Query(ctx: *mut r::rm::ffi::RedisModuleCtx,
281281
let (_context, argvector) = r::create_argument(ctx, argv, argc);
282282
match argvector.len() {
283283
3 => {
284-
match get_db_channel_from_name(ctx, &argvector[1]) {
284+
match get_db_channel_from_name(ctx, argvector[1]) {
285285
Err(key_type) => {
286286
reply_with_error_from_key_type(ctx, key_type)
287287
}
@@ -331,10 +331,10 @@ extern "C" fn CreateStatement(
331331
argv: *mut *mut r::rm::ffi::RedisModuleString,
332332
argc: ::std::os::raw::c_int,
333333
) -> i32{
334-
let (_ctx, argvector) = r::create_argument(ctx, argv, argc);
334+
let (context, argvector) = r::create_argument(ctx, argv, argc);
335335
match argvector.len() {
336336
4 => {
337-
match get_db_channel_from_name(ctx, &argvector[1]) {
337+
match get_db_channel_from_name(ctx, argvector[1]) {
338338
Err(key_type) => {
339339
reply_with_error_from_key_type(ctx, key_type)
340340
}
@@ -357,7 +357,8 @@ extern "C" fn CreateStatement(
357357

358358
match ch.send(cmd) {
359359
Ok(()) => {
360-
replicate(ctx, String::from("REDISQL.CREATE_STATEMENT.NOW"), argv, argc);
360+
unsafe {
361+
Replicate(context, "REDISQL.CREATE_STATEMENT.NOW", argv, argc);}
361362
r::rm::ffi::REDISMODULE_OK
362363
}
363364
Err(_) => r::rm::ffi::REDISMODULE_OK,
@@ -387,10 +388,10 @@ extern "C" fn UpdateStatement(
387388
argv: *mut *mut r::rm::ffi::RedisModuleString,
388389
argc: ::std::os::raw::c_int,
389390
) -> i32{
390-
let (_ctx, argvector) = r::create_argument(ctx, argv, argc);
391+
let (context, argvector) = r::create_argument(ctx, argv, argc);
391392
match argvector.len() {
392393
4 => {
393-
match get_db_channel_from_name(ctx, &argvector[1]) {
394+
match get_db_channel_from_name(ctx, argvector[1]) {
394395
Err(key_type) => {
395396
reply_with_error_from_key_type(ctx, key_type)
396397
}
@@ -414,7 +415,7 @@ extern "C" fn UpdateStatement(
414415

415416
match ch.send(cmd) {
416417
Ok(()) => {
417-
replicate(ctx, String::from("REDISQL.UPDATE_STATEMENT.NOW"), argv, argc);
418+
unsafe {Replicate(context, "REDISQL.UPDATE_STATEMENT.NOW", argv, argc);}
418419
r::rm::ffi::REDISMODULE_OK
419420
}
420421
Err(_) => r::rm::ffi::REDISMODULE_OK,
@@ -442,10 +443,10 @@ extern "C" fn DeleteStatement(
442443
argv: *mut *mut r::rm::ffi::RedisModuleString,
443444
argc: ::std::os::raw::c_int,
444445
) -> i32{
445-
let (_ctx, argvector) = r::create_argument(ctx, argv, argc);
446+
let (context, argvector) = r::create_argument(ctx, argv, argc);
446447
match argvector.len() {
447448
3 => {
448-
match get_db_channel_from_name(ctx, &argvector[1]) {
449+
match get_db_channel_from_name(ctx, argvector[1]) {
449450
Ok(ch) => {
450451
let blocked_client =
451452
r::BlockedClient {
@@ -464,7 +465,7 @@ extern "C" fn DeleteStatement(
464465
};
465466
match ch.send(cmd) {
466467
Ok(()) => {
467-
replicate(ctx, String::from("REDISQL.DELETE_STATEMENT.NOW"), argv, argc);
468+
unsafe {Replicate(context, "REDISQL.DELETE_STATEMENT.NOW", argv, argc);}
468469
r::rm::ffi::REDISMODULE_OK
469470
}
470471
Err(_) => r::rm::ffi::REDISMODULE_OK,
@@ -499,15 +500,15 @@ extern "C" fn CreateDB(ctx: *mut r::rm::ffi::RedisModuleCtx,
499500
match argvector.len() {
500501
2 | 3 => {
501502
let key_name = r::rm::RMString::new(context,
502-
&argvector[1]);
503+
argvector[1]);
503504
let key = unsafe {
504505
r::rm::ffi::Export_RedisModule_OpenKey(
505506
ctx,
506-
key_name.ptr,
507+
key_name.as_ptr(),
507508
r::rm::ffi::REDISMODULE_WRITE,
508509
)
509510
};
510-
let safe_key = r::RedisKey { key: key };
511+
let safe_key = r::RedisKey { key };
511512
match unsafe {
512513
r::rm::ffi::RedisModule_KeyType
513514
.unwrap()(safe_key.key)
@@ -516,7 +517,7 @@ extern "C" fn CreateDB(ctx: *mut r::rm::ffi::RedisModuleCtx,
516517
let (path, in_memory): (&str,
517518
bool) =
518519
match argvector.len() {
519-
3 => (&argvector[2], false),
520+
3 => (argvector[2], false),
520521
_ => (":memory:", true),
521522
};
522523
match sql::get_arc_connection(path) {
@@ -774,7 +775,7 @@ pub extern "C" fn RedisModule_OnLoad(
774775
}
775776

776777

777-
if unsafe { r::rm::ffi::DBType } == std::ptr::null_mut() {
778+
if unsafe { r::rm::ffi::DBType.is_null() } {
778779
return r::rm::ffi::REDISMODULE_ERR;
779780
}
780781

0 commit comments

Comments
 (0)