Skip to content

Commit cf8824e

Browse files
committed
try to ruby-asan test
1 parent 297adfa commit cf8824e

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Ubuntu
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
ruby: ['asan']
19+
duckdb: ['1.1.3', '1.1.1', '1.0.0']
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Ruby
25+
uses: ruby/setup-ruby@v1
26+
with:
27+
ruby-version: ${{ matrix.ruby }}
28+
29+
- name: duckdb cache
30+
id: duckdb-cache
31+
uses: actions/cache@v4
32+
with:
33+
path: duckdb-v${{ matrix.duckdb }}
34+
key: ${{ runner.os }}-duckdb-v${{ matrix.duckdb }}
35+
36+
- name: Build duckdb ${{ matrix.duckdb }}
37+
env:
38+
DUCKDB_VERSION: ${{ matrix.duckdb }}
39+
if: steps.duckdb-cache.outputs.cache-hit != 'true'
40+
run: |
41+
git clone -b v$DUCKDB_VERSION https://github.com/cwida/duckdb.git duckdb-tmp-v$DUCKDB_VERSION
42+
cd duckdb-tmp-v$DUCKDB_VERSION && make && cd ..
43+
rm -rf duckdb-v$DUCKDB_VERSION
44+
mkdir -p duckdb-v$DUCKDB_VERSION/build/release/src duckdb-v$DUCKDB_VERSION/src
45+
cp -rip duckdb-tmp-v$DUCKDB_VERSION/build/release/src/*.so duckdb-v$DUCKDB_VERSION/build/release/src
46+
cp -rip duckdb-tmp-v$DUCKDB_VERSION/src/include duckdb-v$DUCKDB_VERSION/src/
47+
48+
- name: bundle install with Ruby ${{ matrix.ruby }}
49+
env:
50+
DUCKDB_VERSION: ${{ matrix.duckdb }}
51+
run: |
52+
bundle install --jobs 4 --retry 3
53+
54+
- name: Build test with DUCKDB_API_NO_DEPRECATED and Ruby ${{ matrix.ruby }}
55+
env:
56+
DUCKDB_VERSION: ${{ matrix.duckdb }}
57+
run: |
58+
env DUCKDB_API_NO_DEPRECATED=1 bundle exec rake build -- --with-duckdb-include=${GITHUB_WORKSPACE}/duckdb-v${DUCKDB_VERSION}/src/include --with-duckdb-lib=${GITHUB_WORKSPACE}/duckdb-v${DUCKDB_VERSION}/build/release/src/
59+
bundle exec rake clean
60+
61+
- name: Build with Ruby ${{ matrix.ruby }}
62+
env:
63+
DUCKDB_VERSION: ${{ matrix.duckdb }}
64+
run: |
65+
bundle exec rake build -- --with-duckdb-include=${GITHUB_WORKSPACE}/duckdb-v${DUCKDB_VERSION}/src/include --with-duckdb-lib=${GITHUB_WORKSPACE}/duckdb-v${DUCKDB_VERSION}/build/release/src/
66+
67+
- name: test with Ruby ${{ matrix.ruby }}
68+
env:
69+
DUCKDB_VERSION: ${{ matrix.duckdb }}
70+
run: |
71+
env RUBYOPT=-W:deprecated ruby -Ilib test/duckdb_test/ruby_asan_test.rb

ext/duckdb/prepared_statement.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,20 @@ static VALUE duckdb_prepared_statement_initialize(VALUE self, VALUE con, VALUE q
8282
rubyDuckDBConnection *ctxcon;
8383
rubyDuckDBPreparedStatement *ctx;
8484

85+
duckdb_prepared_statement prepared_statement;
86+
8587
if (!rb_obj_is_kind_of(con, cDuckDBConnection)) {
8688
rb_raise(rb_eTypeError, "1st argument should be instance of DackDB::Connection");
8789
}
8890

8991
TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
9092
ctxcon = get_struct_connection(con);
9193

92-
if (duckdb_prepare(ctxcon->con, StringValuePtr(query), &(ctx->prepared_statement)) == DuckDBError) {
93-
const char *error = duckdb_prepare_error(ctx->prepared_statement);
94+
if (duckdb_prepare(ctxcon->con, StringValuePtr(query), &(prepared_statement)) == DuckDBError) {
95+
const char *error = duckdb_prepare_error(prepared_statement);
9496
rb_raise(eDuckDBError, "%s", error ? error : "Failed to prepare statement(Database connection closed?).");
9597
}
98+
ctx->prepared_statement = prepared_statement;
9699
return self;
97100
}
98101

test/duckdb_test/ruby_asan_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
require 'duckdb'
3+
4+
def run_duckdb_asan_test
5+
db = DuckDB::Database.open
6+
con = db.connect
7+
stmt = DuckDB::PreparedStatement.new(con, 'INSERT INTO test VALUES (?, "hello")')
8+
rescue Exception => e
9+
p e
10+
end
11+
12+
run_duckdb_asan_test

0 commit comments

Comments
 (0)