Skip to content

Commit

Permalink
ref: taos-sys remove warnings
Browse files Browse the repository at this point in the history
1.Use camel case instead of underscores for type names 2.for functions and variables never used comment out 3.for field never be read or enum never be constructed add underscore 4.there is another warning which is 'unnecessary `unsafe` block' seems like a Incorrect warning: rust-lang/rust#49112
  • Loading branch information
lispQin committed Feb 17, 2023
1 parent a0671ed commit f6ee8f0
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 147 deletions.
2 changes: 1 addition & 1 deletion taos-sys/src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl RawTaos {
pub fn query_a<'a, S: IntoCStr<'a>>(
&self,
sql: S,
fp: taos_async_query_cb,
fp: TaosAsyncQueryCb,
param: *mut c_void,
) {
unsafe { taos_query_a(self.as_ptr(), sql.into_c_str().as_ptr(), fp, param) }
Expand Down
128 changes: 64 additions & 64 deletions taos-sys/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use taos_macros::c_cfg;
use crate::types::*;

pub type TAOS = c_void;
pub type TAOS_STMT = c_void;
pub type TAOS_RES = c_void;
pub type TAOS_STREAM = c_void;
pub type TAOS_SUB = c_void;
pub type TAOS_ROW = *mut *mut c_void;
pub type TaosStmt = c_void;
pub type TaosRes = c_void;
pub type TaosStream = c_void;
pub type TaosSub = c_void;
pub type TaosRow = *mut *mut c_void;

pub type taos_subscribe_cb =
unsafe extern "C" fn(sub: *mut TAOS_SUB, res: *mut TAOS_RES, param: *mut c_void, code: c_int);
pub type TaosSubscribeCb =
unsafe extern "C" fn(sub: *mut TaosSub, res: *mut TaosRes, param: *mut c_void, code: c_int);

pub type taos_stream_cb =
unsafe extern "C" fn(param: *mut c_void, res: *mut TAOS_RES, row: TAOS_ROW);
pub type TaosStreamCb =
unsafe extern "C" fn(param: *mut c_void, res: *mut TaosRes, row: TaosRow);

pub type taos_stream_close_cb = unsafe extern "C" fn(param: *mut c_void);
pub type TaosStreamCloseCb = unsafe extern "C" fn(param: *mut c_void);

extern "C" {
pub fn taos_cleanup();
Expand Down Expand Up @@ -60,154 +60,154 @@ extern "C" {

}

pub type taos_async_fetch_cb =
pub type TaosAsyncFetchCb =
unsafe extern "C" fn(param: *mut c_void, res: *mut c_void, rows: c_int);

pub type taos_async_query_cb =
pub type TaosAsyncQueryCb =
unsafe extern "C" fn(param: *mut c_void, res: *mut c_void, code: c_int);

extern "C" {
pub fn taos_fetch_rows_a(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void);
pub fn taos_fetch_rows_a(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void);

pub fn taos_query_a(
taos: *mut TAOS,
sql: *const c_char,
fp: taos_async_query_cb,
fp: TaosAsyncQueryCb,
param: *mut c_void,
);
}

extern "C" {
pub fn taos_load_table_info(taos: *mut TAOS, tableNameList: *const c_char) -> c_int;

pub fn taos_stmt_init(taos: *mut TAOS) -> *mut TAOS_STMT;
pub fn taos_stmt_init(taos: *mut TAOS) -> *mut TaosStmt;

pub fn taos_stmt_prepare(stmt: *mut TAOS_STMT, sql: *const c_char, length: c_ulong) -> c_int;
pub fn taos_stmt_prepare(stmt: *mut TaosStmt, sql: *const c_char, length: c_ulong) -> c_int;

pub fn taos_stmt_set_tbname_tags(
stmt: *mut TAOS_STMT,
stmt: *mut TaosStmt,
name: *const c_char,
tags: *mut TaosBind,
) -> c_int;

pub fn taos_stmt_set_tbname(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int;
pub fn taos_stmt_set_tbname(stmt: *mut TaosStmt, name: *const c_char) -> c_int;

pub fn taos_stmt_set_tags(stmt: *mut TAOS_STMT, tags: *mut TaosBind) -> c_int;
pub fn taos_stmt_set_tags(stmt: *mut TaosStmt, tags: *mut TaosBind) -> c_int;

pub fn taos_stmt_set_sub_tbname(stmt: *mut TAOS_STMT, name: *const c_char) -> c_int;
pub fn taos_stmt_set_sub_tbname(stmt: *mut TaosStmt, name: *const c_char) -> c_int;

pub fn taos_stmt_is_insert(stmt: *mut TAOS_STMT, insert: *mut c_int) -> c_int;
pub fn taos_stmt_is_insert(stmt: *mut TaosStmt, insert: *mut c_int) -> c_int;

pub fn taos_stmt_num_params(stmt: *mut TAOS_STMT, nums: *mut c_int) -> c_int;
pub fn taos_stmt_num_params(stmt: *mut TaosStmt, nums: *mut c_int) -> c_int;

pub fn taos_stmt_get_param(
stmt: *mut TAOS_STMT,
stmt: *mut TaosStmt,
idx: c_int,
type_: *mut c_int,
bytes: *mut c_int,
) -> c_int;

pub fn taos_stmt_bind_param(stmt: *mut TAOS_STMT, bind: *const TaosBind) -> c_int;
pub fn taos_stmt_bind_param(stmt: *mut TaosStmt, bind: *const TaosBind) -> c_int;

pub fn taos_stmt_bind_param_batch(stmt: *mut TAOS_STMT, bind: *const TaosMultiBind) -> c_int;
pub fn taos_stmt_bind_param_batch(stmt: *mut TaosStmt, bind: *const TaosMultiBind) -> c_int;

pub fn taos_stmt_bind_single_param_batch(
stmt: *mut TAOS_STMT,
stmt: *mut TaosStmt,
bind: *const TaosMultiBind,
colIdx: c_int,
) -> c_int;

pub fn taos_stmt_add_batch(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_add_batch(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_execute(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_execute(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_affected_rows(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_affected_rows(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_use_result(stmt: *mut TAOS_STMT) -> *mut TAOS_RES;
pub fn taos_stmt_use_result(stmt: *mut TaosStmt) -> *mut TaosRes;

pub fn taos_stmt_close(stmt: *mut TAOS_STMT) -> c_int;
pub fn taos_stmt_close(stmt: *mut TaosStmt) -> c_int;

pub fn taos_stmt_errstr(stmt: *mut TAOS_STMT) -> *const c_char;
pub fn taos_stmt_errstr(stmt: *mut TaosStmt) -> *const c_char;
}

extern "C" {
pub fn taos_query(taos: *mut TAOS, sql: *const c_char) -> *mut TAOS_RES;
pub fn taos_query(taos: *mut TAOS, sql: *const c_char) -> *mut TaosRes;

pub fn taos_fetch_row(res: *mut TAOS_RES) -> TAOS_ROW;
pub fn taos_fetch_row(res: *mut TaosRes) -> TaosRow;

pub fn taos_result_precision(res: *mut TAOS_RES) -> c_int;
pub fn taos_result_precision(res: *mut TaosRes) -> c_int;

pub fn taos_free_result(res: *mut TAOS_RES);
pub fn taos_free_result(res: *mut TaosRes);

pub fn taos_field_count(res: *mut TAOS_RES) -> c_int;
pub fn taos_field_count(res: *mut TaosRes) -> c_int;

pub fn taos_affected_rows(res: *mut TAOS_RES) -> c_int;
pub fn taos_affected_rows(res: *mut TaosRes) -> c_int;

pub fn taos_fetch_fields(res: *mut TAOS_RES) -> *mut TAOS_FIELD;
pub fn taos_fetch_fields(res: *mut TaosRes) -> *mut TAOS_FIELD;

pub fn taos_select_db(taos: *mut TAOS, db: *const c_char) -> c_int;

pub fn taos_print_row(
str_: *mut c_char,
row: TAOS_ROW,
row: TaosRow,
fields: *mut TAOS_FIELD,
num_fields: c_int,
) -> c_int;

pub fn taos_stop_query(res: *mut TAOS_RES);
pub fn taos_stop_query(res: *mut TaosRes);

pub fn taos_is_null(res: *mut TAOS_RES, row: i32, col: i32) -> bool;
pub fn taos_is_null(res: *mut TaosRes, row: i32, col: i32) -> bool;

pub fn taos_is_update_query(res: *mut TAOS_RES) -> bool;
pub fn taos_is_update_query(res: *mut TaosRes) -> bool;

pub fn taos_fetch_block(res: *mut TAOS_RES, rows: *mut TAOS_ROW) -> c_int;
pub fn taos_fetch_block(res: *mut TaosRes, rows: *mut TaosRow) -> c_int;

pub fn taos_fetch_lengths(res: *mut TAOS_RES) -> *mut c_int;
pub fn taos_fetch_lengths(res: *mut TaosRes) -> *mut c_int;

pub fn taos_validate_sql(taos: *mut TAOS, sql: *const c_char) -> c_int;

pub fn taos_reset_current_db(taos: *mut TAOS);

pub fn taos_get_server_info(taos: *mut TAOS) -> *mut c_char;

pub fn taos_errstr(tres: *mut TAOS_RES) -> *mut c_char;
pub fn taos_errstr(tres: *mut TaosRes) -> *mut c_char;

pub fn taos_errno(tres: *mut TAOS_RES) -> c_int;
pub fn taos_errno(tres: *mut TaosRes) -> c_int;

}

#[c_cfg(taos_v3)]
extern "C" {
pub fn taos_get_column_data_offset(res: *mut TAOS_RES, col: i32) -> *mut i32;
pub fn taos_get_column_data_offset(res: *mut TaosRes, col: i32) -> *mut i32;

pub fn taos_fetch_raw_block(res: *mut TAOS_RES, num: *mut i32, data: *mut *mut c_void)
pub fn taos_fetch_raw_block(res: *mut TaosRes, num: *mut i32, data: *mut *mut c_void)
-> c_int;

pub fn taos_fetch_raw_block_a(res: *mut TAOS_RES, fp: taos_async_fetch_cb, param: *mut c_void);
pub fn taos_fetch_raw_block_a(res: *mut TaosRes, fp: TaosAsyncFetchCb, param: *mut c_void);

pub fn taos_get_raw_block(taos: *mut TAOS_RES) -> *mut c_void;
pub fn taos_get_raw_block(taos: *mut TaosRes) -> *mut c_void;
}

#[c_cfg(taos_result_block)]
extern "C" {
pub fn taos_result_block(res: *mut TAOS_RES) -> *mut TAOS_ROW;
pub fn taos_result_block(res: *mut TaosRes) -> *mut TaosRow;
}

#[cfg(taos_fetch_block_s)]
extern "C" {
pub fn taos_fetch_block_s(
res: *mut TAOS_RES,
res: *mut TaosRes,
num_of_rows: *mut c_int,
rows: *mut TAOS_ROW,
rows: *mut TaosRow,
) -> c_int;
}

#[cfg(not(taos_fetch_block_s))]
#[no_mangle]
pub unsafe extern "C" fn taos_fetch_block_s(
res: *mut TAOS_RES,
res: *mut TaosRes,
num_of_rows: *mut c_int,
rows: *mut TAOS_ROW,
rows: *mut TaosRow,
) -> c_int {
*num_of_rows = taos_fetch_block(res, rows);
return 0;
Expand All @@ -219,25 +219,25 @@ extern "C" {
restart: c_int,
topic: *const c_char,
sql: *const c_char,
fp: Option<taos_subscribe_cb>,
fp: Option<TaosSubscribeCb>,
param: *mut c_void,
interval: c_int,
) -> *mut TAOS_SUB;
) -> *mut TaosSub;

pub fn taos_consume(tsub: *mut TAOS_SUB) -> *mut TAOS_RES;
pub fn taos_consume(tsub: *mut TaosSub) -> *mut TaosRes;

pub fn taos_unsubscribe(tsub: *mut TAOS_SUB, keep_progress: c_int);
pub fn taos_unsubscribe(tsub: *mut TaosSub, keep_progress: c_int);
}

extern "C" {
pub fn taos_open_stream(
taos: *mut TAOS,
sql: *const c_char,
fp: Option<taos_stream_cb>,
fp: Option<TaosStreamCb>,
stime: i64,
param: *mut c_void,
callback: Option<taos_stream_close_cb>,
) -> *mut TAOS_STREAM;
callback: Option<TaosStreamCloseCb>,
) -> *mut TaosStream;

pub fn taos_close_stream(stream: *mut TAOS_STREAM);
pub fn taos_close_stream(stream: *mut TaosStream);
}
4 changes: 2 additions & 2 deletions taos-sys/src/query/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::Stream;
use taos_query::common::{Field, Precision, RawBlock};
use taos_query::prelude::RawError as Error;

use crate::ffi::{taos_get_raw_block, TAOS_RES};
use crate::ffi::{taos_get_raw_block, TaosRes};

use super::raw_res::RawRes;

Expand Down Expand Up @@ -90,7 +90,7 @@ impl Stream for Blocks {
let param = Box::new((&self.shared_state, cx.waker().clone()));
unsafe extern "C" fn async_fetch_callback(
param: *mut c_void,
res: *mut TAOS_RES,
res: *mut TaosRes,
num_of_rows: c_int,
) {
let param = param as *mut (&UnsafeCell<SharedState>, Waker);
Expand Down
6 changes: 3 additions & 3 deletions taos-sys/src/query/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::os::raw::{c_int, c_void};
use std::pin::Pin;
use std::task::{Context, Poll, Waker};

use crate::ffi::TAOS_RES;
use crate::ffi::TaosRes;
use crate::into_c_str::IntoCStr;
use crate::{RawRes, RawTaos};
use taos_query::prelude::RawError;
Expand All @@ -20,7 +20,7 @@ pub struct QueryFuture<'a> {

/// Shared state between the future and the waiting thread
struct State {
result: *mut TAOS_RES,
result: *mut TaosRes,
code: i32,
}

Expand All @@ -38,7 +38,7 @@ impl<'a> Future for QueryFuture<'a> {
} else {
unsafe extern "C" fn async_query_callback(
param: *mut c_void,
res: *mut TAOS_RES,
res: *mut TaosRes,
code: c_int,
) {
let state = Box::from_raw(param as *mut (&UnsafeCell<State>, Waker));
Expand Down
14 changes: 7 additions & 7 deletions taos-sys/src/query/old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use taos_query::common::{Field, Precision, RawData};
use crate::{
ffi::{
taos_errstr, taos_fetch_fields, taos_fetch_raw_block, taos_fetch_raw_block_a,
taos_field_count, taos_get_raw_block, taos_result_precision, TAOS_RES,
taos_field_count, taos_get_raw_block, taos_result_precision, TaosRes,
},
tmq_get_db_name, tmq_get_json_meta, tmq_get_res_type, tmq_get_table_name, tmq_res_t,
};
Expand All @@ -24,7 +24,7 @@ pub struct BlockStream {
precision: Precision,
fields: *const Field,
cols: usize,
res: *mut TAOS_RES,
res: *mut TaosRes,
shared_state: UnsafeCell<SharedState>,
}

Expand Down Expand Up @@ -149,7 +149,7 @@ impl BlockStream {
let param = Box::new((&self.shared_state, cx.waker().clone()));
unsafe extern "C" fn async_fetch_callback(
param: *mut c_void,
res: *mut TAOS_RES,
res: *mut TaosRes,
num_of_rows: c_int,
) {
let param = param as *mut (&UnsafeCell<SharedState>, Waker);
Expand Down Expand Up @@ -203,8 +203,8 @@ impl Stream for BlockStream {

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match self.msg_type {
tmq_res_t::TMQ_RES_DATA => self.poll_next_tmq_data(cx),
tmq_res_t::TMQ_RES_TABLE_META => self.poll_next_tmq_meta(cx),
tmq_res_t::TmqResData => self.poll_next_tmq_data(cx),
tmq_res_t::TmqResTableMeta => self.poll_next_tmq_meta(cx),
_ => self.poll_next_query_data(cx),
}
}
Expand All @@ -214,7 +214,7 @@ impl BlockStream {
/// Create a new `TimerFuture` which will complete after the provided
/// timeout.
#[inline(always)]
pub fn new(res: *mut TAOS_RES, fields: &[Field], precision: Precision) -> Self {
pub fn new(res: *mut TaosRes, fields: &[Field], precision: Precision) -> Self {
let shared_state = UnsafeCell::new(SharedState {
done: false,
block: std::ptr::null_mut(),
Expand All @@ -223,7 +223,7 @@ impl BlockStream {
});

let msg_type = unsafe { tmq_get_res_type(res) };
// let msg_type = tmq_res_t::TMQ_RES_INVALID;
// let msg_type = tmq_res_t::TmqResInvalid;
BlockStream {
res,
msg_type,
Expand Down
Loading

0 comments on commit f6ee8f0

Please sign in to comment.