From 4e4ded2f1f24bdb1052fe45262f73e87d5f1e2bb Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 11 Dec 2022 16:55:43 -0500 Subject: [PATCH] Added test to catch #39 Update buildx context Updated buffer output text for integration Bump mariadb version in dockerfile --- .github/workflows/validation-rust.yaml | 2 + Dockerfile.examples | 2 +- udf-examples/tests/lookup.rs | 21 ++++++++++- udf/src/wrapper/debug.rs | 52 ++++++++++++++++++++++++-- udf/src/wrapper/process.rs | 10 +++-- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/.github/workflows/validation-rust.yaml b/.github/workflows/validation-rust.yaml index a43a1e3..4eb9301 100644 --- a/.github/workflows/validation-rust.yaml +++ b/.github/workflows/validation-rust.yaml @@ -130,6 +130,7 @@ jobs: file: Dockerfile.examples cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new + context: . - # Temp fix # https://github.com/docker/build-push-action/issues/252 # https://github.com/moby/buildkit/issues/1896 @@ -157,6 +158,7 @@ jobs: # Run only integration tests with `--test '*'` run: cargo test -p udf-examples --test '*' --features backend - name: Print docker logs + if: always() run: | docker logs mdb-example-container # If any critical / debug options were printed, error out diff --git a/Dockerfile.examples b/Dockerfile.examples index c0cdd35..7f0f612 100644 --- a/Dockerfile.examples +++ b/Dockerfile.examples @@ -24,6 +24,6 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ && mkdir /output \ && cp target/release/libudf_examples.so /output -FROM mariadb:10.9 +FROM mariadb:10.10 COPY --from=build /output/* /usr/lib/mysql/plugin/ diff --git a/udf-examples/tests/lookup.rs b/udf-examples/tests/lookup.rs index dbd2225..7f7b381 100644 --- a/udf-examples/tests/lookup.rs +++ b/udf-examples/tests/lookup.rs @@ -5,7 +5,7 @@ mod backend; use backend::get_db_connection; use diesel::dsl::sql; use diesel::prelude::*; -use diesel::sql_types::{Nullable, Text}; +use diesel::sql_types::{Nullable, Text, Untyped}; const SETUP: [&str; 1] = ["create or replace function lookup6 returns string @@ -43,3 +43,22 @@ fn test_nonexistant() { assert!(res.0.is_none()); } + +#[test] +fn test_sql_buffer_bug() { + // This is intended to catch a buffer problem in mysql/mariadb + // See link: https://github.com/pluots/sql-udf/issues/39 + + let conn = &mut get_db_connection(&SETUP); + + sql::<(Untyped,)>("set @testval = (select lookup6('0.0.0.0'))") + .execute(conn) + .unwrap(); + + let res: (Option,) = + sql::<(Nullable,)>("select regexp_replace(@testval,'[:.]','')") + .get_result(conn) + .expect("bad result"); + + assert_eq!(res.0.unwrap(), "ffff0000"); +} diff --git a/udf/src/wrapper/debug.rs b/udf/src/wrapper/debug.rs index 172dcbf..5d99cde 100644 --- a/udf/src/wrapper/debug.rs +++ b/udf/src/wrapper/debug.rs @@ -3,7 +3,7 @@ #![cfg(feature = "logging-debug")] use std::any::type_name; -use std::ffi::{c_char, c_uchar}; +use std::ffi::{c_char, c_uchar, c_ulong}; use cfg_if::cfg_if; use udf_sys::{UDF_ARGS, UDF_INIT}; @@ -74,7 +74,6 @@ pub unsafe fn pre_add_call( } } -#[allow(dead_code)] pub unsafe fn pre_clear_call(initid: *const UDF_INIT, error: *const c_uchar) { udf_log!(Debug: "entering clear for `{}`", type_name::()); @@ -87,7 +86,6 @@ pub unsafe fn pre_clear_call(initid: *const UDF_INIT, error: *const c_uchar) } } -#[allow(dead_code)] pub unsafe fn pre_remove_call( initid: *const UDF_INIT, args: *const UDF_ARGS, @@ -142,3 +140,51 @@ pub unsafe fn post_process_call( } } } + +pub unsafe fn pre_process_call_buf( + initid: *const UDF_INIT, + args: *const UDF_ARGS, + result: *const c_char, + length: *const c_ulong, + is_null: *const c_uchar, + error: *const c_uchar, +) { + udf_log!(Debug: "entering process for `{}`", type_name::()); + + cfg_if! { + if #[cfg(feature = "logging-debug-calls")] { + udf_log!(Debug: "Data receive state at process:"); + dbg!(&*initid); + dbg!(&*args); + dbg!(result); + dbg!(&*length); + dbg!(&*is_null); + dbg!(&*error); + } + } +} + +pub unsafe fn post_process_call_buf( + initid: *const UDF_INIT, + args: *const UDF_ARGS, + result: *const c_char, + length: *const c_ulong, + is_null: *const c_uchar, + error: *const c_uchar, + ret: *const c_char, +) { + udf_log!(Debug: "exiting process for `{}`", type_name::()); + + cfg_if! { + if #[cfg(feature = "logging-debug-calls")] { + udf_log!(Debug: "Data return state at process:"); + dbg!(&*initid); + dbg!(&*args); + dbg!(result); + dbg!(&*length); + dbg!(&*is_null); + dbg!(&*error); + dbg!(ret); + } + } +} diff --git a/udf/src/wrapper/process.rs b/udf/src/wrapper/process.rs index 26bff6b..39a47cb 100644 --- a/udf/src/wrapper/process.rs +++ b/udf/src/wrapper/process.rs @@ -60,6 +60,7 @@ unsafe fn ret_callback( /// Apply the `process` function for any implementation returning a nonbuffer type /// (`f64`, `i64`) #[inline] +#[allow(clippy::let_and_return)] pub unsafe fn wrap_process_basic( initid: *mut UDF_INIT, args: *mut UDF_ARGS, @@ -91,6 +92,7 @@ where /// Apply the `process` function for any implementation returning an optional /// nonbuffer type (`Option`, `Option`) #[inline] +#[allow(clippy::let_and_return)] pub unsafe fn wrap_process_basic_option( initid: *mut UDF_INIT, args: *mut UDF_ARGS, @@ -136,7 +138,7 @@ where for<'a> ::Returns<'a>: AsRef<[u8]>, { #[cfg(feature = "logging-debug")] - debug::pre_process_call::(initid, args, is_null, error); + debug::pre_process_call_buf::(initid, args, result, length, is_null, error); let cfg = UdfCfg::from_raw_ptr(initid); let arglist = ArgList::from_raw_ptr(args); @@ -159,7 +161,7 @@ where cfg.store_box(b); #[cfg(feature = "logging-debug")] - debug::post_process_call::(initid, args, is_null, error); + debug::post_process_call_buf::(initid, args, result, length, is_null, error, ret); ret } @@ -181,7 +183,7 @@ where B: AsRef<[u8]>, { #[cfg(feature = "logging-debug")] - debug::pre_process_call::(initid, args, is_null, error); + debug::pre_process_call_buf::(initid, args, result, length, is_null, error); let cfg = UdfCfg::from_raw_ptr(initid); let arglist = ArgList::from_raw_ptr(args); @@ -208,7 +210,7 @@ where cfg.store_box(b); #[cfg(feature = "logging-debug")] - debug::post_process_call::(initid, args, is_null, error); + debug::post_process_call_buf::(initid, args, result, length, is_null, error, ret); ret }