Skip to content

Commit

Permalink
changes to allow rust 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Noriebalbinot committed Aug 21, 2024
1 parent 508bf55 commit 27ed074
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 25 deletions.
4 changes: 3 additions & 1 deletion rsfbclient-core/src/ibase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
clippy::upper_case_acronyms
)]

use std::{marker::PhantomData, slice::Iter};

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / linting

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / linting

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / embedded (dynamic_loading)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / embedded (linking)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, linking)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, linking)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, linking)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, linking)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, linking)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, linking)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, dynamic_loading)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, dynamic_loading)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, dynamic_loading)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, dynamic_loading)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, dynamic_loading)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, dynamic_loading)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

Check warning on line 11 in rsfbclient-core/src/ibase.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, pure_rust)

unused imports: `marker::PhantomData` and `slice::Iter`

pub const FB_API_VER: u32 = 30;
pub const ISC_TRUE: u32 = 1;
pub const ISC_FALSE: u32 = 0;
Expand Down Expand Up @@ -2491,7 +2493,7 @@ pub struct XSQLVAR {
pub aliasname: [ISC_SCHAR; 32usize],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Clone, Copy)]
pub struct XSQLDA {
pub version: ISC_SHORT,
pub sqldaid: [ISC_SCHAR; 8usize],
Expand Down
8 changes: 4 additions & 4 deletions rsfbclient-native/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ impl<T: LinkageMarker> FirebirdClientSqlOps for NativeFbClient<T> {
// Create the column buffers and set the xsqlda conercions
let col_buffers = (0..xsqlda.sqld)
.map(|col| {
let xcol = xsqlda
.get_xsqlvar_mut(col as usize)
.ok_or_else(|| FbError::from("Error getting the xsqlvar"))?;
// let mut xcol = xsqlda
// .get_xsqlvar_mut(col as usize)
// .ok_or_else(|| FbError::from("Error getting the xsqlvar"))?;

ColumnBuffer::from_xsqlvar(xcol)
ColumnBuffer::from_xsqlvar(&mut xsqlda, col)
})
.collect::<Result<_, _>>()?;

Expand Down
16 changes: 11 additions & 5 deletions rsfbclient-native/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ impl Params {
for (col, info) in infos.into_iter().enumerate() {
buffers.push(ParamBuffer::from_parameter(
info,
xsqlda
.get_xsqlvar_mut(col)
.ok_or_else(|| FbError::from("Error getting the xsqlvar"))?,
&mut xsqlda,
col,
db_handle,
tr_handle,
ibase,
Expand Down Expand Up @@ -151,14 +150,20 @@ impl ParamBuffer {
/// Allocate a buffer from a value to use in an input (parameter) XSQLVAR
pub fn from_parameter<T: IBase>(
info: SqlType,
var: &mut ibase::XSQLVAR,
orig_var: &mut ibase::XSQLDA,
col: usize,
db: &mut ibase::isc_db_handle,
tr: &mut ibase::isc_tr_handle,
ibase: &T,
charset: &Charset,
) -> Result<Self, FbError> {
let mut null = 0;

let mut var = unsafe {
let mut sqlvar = orig_var.sqlvar.to_vec();
sqlvar.set_len(orig_var.sqln as usize);
sqlvar.as_mut_slice();
*sqlvar.get_mut(col).unwrap()
};
let (sqltype, sqlsubtype) = info.sql_type_and_subtype();
var.sqltype = sqltype as i16;
var.sqlsubtype = sqlsubtype as i16;
Expand Down Expand Up @@ -205,6 +210,7 @@ impl ParamBuffer {

var.sqldata = buffer.as_mut_ptr();
var.sqllen = size as i16;
orig_var.sqlvar = [var];

Ok(ParamBuffer {
_buffer: buffer,
Expand Down
10 changes: 8 additions & 2 deletions rsfbclient-native/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ pub struct ColumnBuffer {

impl ColumnBuffer {
/// Allocate a buffer from an output (column) XSQLVAR, coercing the data types as necessary
pub fn from_xsqlvar(var: &mut ibase::XSQLVAR) -> Result<Self, FbError> {
pub fn from_xsqlvar(orig_var: &mut ibase::XSQLDA, col: i16) -> Result<Self, FbError> {
// Remove nullable type indicator
let mut var = unsafe {
let mut sqlvar = orig_var.sqlvar.to_vec();
sqlvar.set_len(orig_var.sqln as usize);
sqlvar.as_mut_slice();
*sqlvar.get_mut(col as usize).unwrap()
};
let sqltype = var.sqltype & (!1);
let sqlsubtype = var.sqlsubtype;

Expand Down Expand Up @@ -149,7 +155,7 @@ impl ColumnBuffer {

String::from_utf8(bname)
}?;

orig_var.sqlvar = [var];
Ok(ColumnBuffer {
buffer,
nullind,
Expand Down
4 changes: 2 additions & 2 deletions rsfbclient-native/src/varchar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct InnerVarchar {
len: u16,
//changed to avoid using get_unchecked in the as_bytes() implementation
//because get_unchecked was used in a UB way.
data: Vec<u8>,
data: [u8; 0],
}

#[derive(Debug)]
Expand Down Expand Up @@ -37,7 +37,7 @@ impl Varchar {
pub fn as_bytes(&self) -> &[u8] {
let len = u16::min(self.capacity, unsafe { self.ptr.as_ref().len }) as usize;

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / linting

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / embedded (dynamic_loading)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / embedded (linking)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, linking)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, linking)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, linking)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, linking)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, linking)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, linking)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, dynamic_loading)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, dynamic_loading)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, dynamic_loading)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, dynamic_loading)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, dynamic_loading)

unused variable: `len`

Check warning on line 38 in rsfbclient-native/src/varchar.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, dynamic_loading)

unused variable: `len`

unsafe { self.ptr.as_ref().data.get(..len).unwrap() }
unsafe { &self.ptr.as_ref().data as &[u8] }
}

/// Get the pointer to the inner type
Expand Down
27 changes: 16 additions & 11 deletions rsfbclient-native/src/xsqlda.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::{
alloc,
ops::{Deref, DerefMut},
ops::{Deref, DerefMut, Index},

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / linting

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / linting

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / embedded (dynamic_loading)

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / embedded (linking)

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, linking)

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, linking)

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, linking)

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, dynamic_loading)

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, dynamic_loading)

unused import: `Index`

Check warning on line 3 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, dynamic_loading)

unused import: `Index`
ptr,
};

use rsfbclient_core::ibase::XSQLVAR;

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / linting

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / embedded (dynamic_loading)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / embedded (linking)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, linking)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, linking)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, linking)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, linking)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, linking)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, linking)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, dynamic_loading)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, dynamic_loading)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v3, dynamic_loading)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v2, dynamic_loading)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, dynamic_loading)

unused import: `rsfbclient_core::ibase::XSQLVAR`

Check warning on line 7 in rsfbclient-native/src/xsqlda.rs

View workflow job for this annotation

GitHub Actions / testing (ubuntu-20.04, v4, dynamic_loading)

unused import: `rsfbclient_core::ibase::XSQLVAR`

use crate::ibase;

pub struct XSqlDa {
Expand Down Expand Up @@ -33,16 +35,19 @@ impl XSqlDa {
xsqlda
}

/// Returns a mutable reference to a XSQLVAR
pub fn get_xsqlvar_mut(&mut self, col: usize) -> Option<&mut ibase::XSQLVAR> {
if col < self.len as usize {
let xsqlvar = unsafe { self.ptr.as_mut().sqlvar.get_mut(col as usize).unwrap() };

Some(xsqlvar)
} else {
None
}
}
// Returns a mutable reference to a XSQLVAR
// pub fn get_xsqlvar_mut(&mut self, col: usize) -> Option<ibase::XSQLVAR> {
// if col < self.len as usize {
// Some(unsafe {
// let sqlvar = &mut self.ptr.as_mut().sqlvar.to_vec();
// sqlvar.set_len(self.len as usize);
// sqlvar.as_mut_slice();
// *sqlvar.get_mut(col as usize)
// })
// } else {
// None
// }
// }
}

impl Deref for XSqlDa {
Expand Down

0 comments on commit 27ed074

Please sign in to comment.