Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLib] Use Cast() instead of CastTo() #39225

Closed
llama90 opened this issue Dec 14, 2023 · 10 comments · Fixed by #39228
Closed

[GLib] Use Cast() instead of CastTo() #39225

llama90 opened this issue Dec 14, 2023 · 10 comments · Fixed by #39228

Comments

@llama90
Copy link
Contributor

llama90 commented Dec 14, 2023

Describe the enhancement requested

This is a sub-issue of the issue mentioned below.

I found this through the ARROW_SUPPRESS_DEPRECATION_WARNING macro.

auto arrow_casted_scalar_result = arrow_scalar->CastTo(arrow_data_type);

Component(s)

GLib

@llama90
Copy link
Contributor Author

llama90 commented Dec 14, 2023

Progress Update

Removing the Legacy Cast broke the tests.

terminate called after throwing an instance of 'std::bad_cast'

@kou
Copy link
Member

kou commented Dec 14, 2023

Our C++ API should not throw any exception.
We should use arrow::Status (or arrow::Result) instead of exception on error.

Could you find where the exception was thrown? Or I can try it on local later.

@llama90
Copy link
Contributor Author

llama90 commented Jan 2, 2024

Progress Update

I have identified the test case that causes the error.

def test_cast
buffer = Arrow::Buffer.new("-10")
scalar = Arrow::StringScalar.new(buffer)
assert_equal(Arrow::Int8Scalar.new(-10),
scalar.cast(Arrow::Int8DataType.new))
end

@kou
Copy link
Member

kou commented Jan 2, 2024

Could you get a backtrace by C++ debugger (gdb or lldb)?
GDB="lldb --" BUNDLE_GEMFILE=../c_glib/Gemfile bundle exec ../c_glib/test/run-test.sh -n test_cast will run the test on C++ debugger.

@llama90
Copy link
Contributor Author

llama90 commented Jan 2, 2024

Is it correct?

$ GDB="lldb --" BUNDLE_GEMFILE=../c_glib/Gemfile bundle exec ../c_glib/test/run-test.sh -n test_cast
[17/26] Generating parquet-glib/Parquet-1.0.gir with a custom command (wrapped by meson to set env)
Package 'arrow', required by 'arrow-glib-uninstalled', not found

[19/26] Generating arrow-flight-glib/ArrowFlight-1.0.gir with a custom command (wrapped by meson to set env)
Package 'arrow', required by 'arrow-glib-uninstalled', not found

[21/26] Generating gandiva-glib/Gandiva-1.0.gir with a custom command (wrapped by meson to set env)
Package 'arrow', required by 'arrow-glib-uninstalled', not found

[22/26] Generating arrow-dataset-glib/ArrowDataset-1.0.gir with a custom command (wrapped by meson to set env)
Package 'arrow', required by 'arrow-glib-uninstalled', not found

[25/26] Generating arrow-flight-sql-glib/ArrowFlightSQL-1.0.gir with a custom command (wrapped by meson to set env)
Package 'arrow', required by 'arrow-glib-uninstalled', not found

[26/26] Generating arrow-flight-sql-glib/ArrowFlightSQL-1.0.typelib with a custom command
(lldb) target create "/Users/lama/.rbenv/versions/3.3.0/bin/ruby"
Current executable set to '/Users/lama/.rbenv/versions/3.3.0/bin/ruby' (arm64).
(lldb) settings set -- target.run-args  "/Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb" "-n" "test_cast"
(lldb) r
Process 47659 launched: '/Users/lama/.rbenv/versions/3.3.0/bin/ruby' (arm64)
(null)-WARNING **: Failed to load shared library 'libarrow-glib.1500.dylib' referenced by the typelib: dlopen(libarrow-glib.1500.dylib, 0x0009): tried: 'libarrow-glib.1500.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibarrow-glib.1500.dylib' (no such file), '/usr/lib/libarrow-glib.1500.dylib' (no such file, not in dyld cache), 'libarrow-glib.1500.dylib' (no such file), '/usr/local/lib/libarrow-glib.1500.dylib' (no such file), '/usr/lib/libarrow-glib.1500.dylib' (no such file, not in dyld cache)
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/loader.rb:606:in `load_interface_info'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/loader.rb:75:in `load_info'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/loader.rb:44:in `block (2 levels) in load'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/repository.rb:34:in `block (2 levels) in each'
	from <internal:numeric>:237:in `times'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/repository.rb:33:in `block in each'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/repository.rb:32:in `each'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/repository.rb:32:in `each'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/loader.rb:43:in `block in load'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/loader.rb:636:in `prepare_class'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection/loader.rb:41:in `load'
	from /Users/lama/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection.rb:44:in `load'
	from /Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb:33:in `<main>'
/Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb:44:in `alias_method': undefined method `value?' for class `Arrow::BooleanScalar' (NameError)

    alias_method :value, :value?
    ^^^^^^^^^^^^
	from /Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb:44:in `<class:BooleanScalar>'
	from /Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb:43:in `<module:Arrow>'
	from /Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb:34:in `<main>'
Process 47659 exited with status = 1 (0x00000001)

@kou
Copy link
Member

kou commented Jan 2, 2024

Oh... It didn't work...

Does this work?

diff --git a/c_glib/test/run-test.sh b/c_glib/test/run-test.sh
index 33e9fbf85d..c7bc6edca5 100755
--- a/c_glib/test/run-test.sh
+++ b/c_glib/test/run-test.sh
@@ -34,14 +34,14 @@ for module in "${modules[@]}"; do
   module_build_dir="${build_dir}/${module}"
   if [ -d "${module_build_dir}" ]; then
     LD_LIBRARY_PATH="${module_build_dir}:${LD_LIBRARY_PATH}"
+    DYLD_LIBRARY_PATH="${module_build_dir}:${DYLD_LIBRARY_PATH}"
   fi
 done
 export LD_LIBRARY_PATH
+export DYLD_LIBRARY_PATH
 
 if [ "${BUILD}" != "no" ]; then
-  if [ -f "Makefile" ]; then
-    make -j8 > /dev/null || exit $?
-  elif [ -f "build.ninja" ]; then
+  if [ -f "build.ninja" ]; then
     ninja || exit $?
   fi
 fi
@@ -59,4 +59,19 @@ for module in "${modules[@]}"; do
 done
 export GI_TYPELIB_PATH
 
-${GDB} ruby ${test_dir}/run-test.rb "$@"
+if type rbenv > /dev/null 2>&1; then
+  RUBY="$(rbenv which ruby)"
+else
+  RUBY=ruby
+fi
+DEBUGGER_ARGS=()
+case "${DEBUGGER}" in
+  "gdb")
+    DEBUGGER_ARGS+=(--args)
+    ;;
+  "lldb")
+    DEBUGGER_ARGS+=(--one-line "env DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
+    DEBUGGER_ARGS+=(--)
+    ;;
+esac
+${DEBUGGER} "${DEBUGGER_ARGS[@]}" "${RUBY}" ${test_dir}/run-test.rb "$@"
$ DEBUGGER=lldb BUNDLE_GEMFILE=../c_glib/Gemfile bundle exec ../c_glib/test/run-test.sh -n test_cast

@llama90
Copy link
Contributor Author

llama90 commented Jan 2, 2024

I retried.

DEBUGGER=lldb BUNDLE_GEMFILE=../c_glib/Gemfile bundle exec ../c_glib/test/run-test.sh -n test_cast
ninja: no work to do.
(lldb) target create "/Users/lama/.rbenv/versions/3.3.0/bin/ruby"
Current executable set to '/Users/lama/.rbenv/versions/3.3.0/bin/ruby' (arm64).
(lldb) settings set -- target.run-args  "/Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb" "-n" "test_cast"
(lldb) env DYLD_LIBRARY_PATH=/Users/lama/workspace/arrow-latest/c_glib.build/parquet-glib:/Users/lama/workspace/arrow-latest/c_glib.build/gandiva-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-flight-sql-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-flight-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-dataset-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-glib:
(lldb) r
Process 51041 launched: '/Users/lama/.rbenv/versions/3.3.0/bin/ruby' (arm64)
Loaded suite test
Started
libc++abi: terminating due to uncaught exception of type std::bad_cast: std::bad_cast
Process 51041 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001823ee0dc libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
->  0x1823ee0dc <+8>:  b.lo   0x1823ee0fc               ; <+40>
    0x1823ee0e0 <+12>: pacibsp
    0x1823ee0e4 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1823ee0e8 <+20>: mov    x29, sp
Target 0: (ruby) stopped.

@kou
Copy link
Member

kou commented Jan 2, 2024

Could you run bt on lldb?

@llama90
Copy link
Contributor Author

llama90 commented Jan 2, 2024

Yes!

DEBUGGER=lldb BUNDLE_GEMFILE=../c_glib/Gemfile bundle exec ../c_glib/test/run-test.sh -n test_cast
ninja: no work to do.
(lldb) target create "/Users/lama/.rbenv/versions/3.3.0/bin/ruby"
Current executable set to '/Users/lama/.rbenv/versions/3.3.0/bin/ruby' (arm64).
(lldb) settings set -- target.run-args  "/Users/lama/workspace/arrow-latest/c_glib/test/run-test.rb" "-n" "test_cast"
(lldb) env DYLD_LIBRARY_PATH=/Users/lama/workspace/arrow-latest/c_glib.build/parquet-glib:/Users/lama/workspace/arrow-latest/c_glib.build/gandiva-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-flight-sql-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-flight-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-dataset-glib:/Users/lama/workspace/arrow-latest/c_glib.build/arrow-glib:
(lldb) r
Process 53265 launched: '/Users/lama/.rbenv/versions/3.3.0/bin/ruby' (arm64)
Loaded suite test
Started
libc++abi: terminating due to uncaught exception of type std::bad_cast: std::bad_cast
Process 53265 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001823ee0dc libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
->  0x1823ee0dc <+8>:  b.lo   0x1823ee0fc               ; <+40>
    0x1823ee0e0 <+12>: pacibsp
    0x1823ee0e4 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1823ee0e8 <+20>: mov    x29, sp
Target 0: (ruby) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00000001823ee0dc libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x0000000182425cc0 libsystem_pthread.dylib`pthread_kill + 288
    frame #2: 0x0000000182331a40 libsystem_c.dylib`abort + 180
    frame #3: 0x00000001823dd070 libc++abi.dylib`abort_message + 132
    frame #4: 0x00000001823cd110 libc++abi.dylib`demangling_terminate_handler() + 320
    frame #5: 0x000000018207399c libobjc.A.dylib`_objc_terminate() + 160
    frame #6: 0x00000001823dc434 libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x00000001823df520 libc++abi.dylib`__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 88
    frame #8: 0x00000001823df464 libc++abi.dylib`__cxa_throw + 308
    frame #9: 0x00000001823ccf68 libc++abi.dylib`__cxa_bad_cast + 52
    frame #10: 0x000000017013ab80 libarrow.1500.0.0.dylib`arrow::BaseBinaryScalar const& arrow::internal::checked_cast<arrow::BaseBinaryScalar const&, arrow::Scalar const&>(value=0x00006000025fd0a8) at checked_cast.h:38:10
    frame #11: 0x0000000170139950 libarrow.1500.0.0.dylib`arrow::ArraySpan::FillFromScalar(this=0x0000600003413960, value=0x00006000025fd0a8) at data.cc:372:26
    frame #12: 0x0000000170a3c300 libarrow.1500.0.0.dylib`arrow::compute::detail::(anonymous namespace)::PromoteExecSpanScalars(span=0x000000016fdfbe10) at exec.cc:326:20
    frame #13: 0x0000000170a3bf1c libarrow.1500.0.0.dylib`arrow::compute::detail::ExecSpanIterator::Next(this=0x0000600003db5988, span=0x000000016fdfbe10) at exec.cc:442:7
    frame #14: 0x0000000170a468fc libarrow.1500.0.0.dylib`arrow::compute::detail::(anonymous namespace)::ScalarExecutor::ExecuteSpans(this=0x0000600003db5930, listener=0x000000016fdfc240) at exec.cc:856:29
    frame #15: 0x0000000170a45490 libarrow.1500.0.0.dylib`arrow::compute::detail::(anonymous namespace)::ScalarExecutor::Execute(this=0x0000600003db5930, batch=0x000000016fdfc1f8, listener=0x000000016fdfc240) at exec.cc:808:14
    frame #16: 0x0000000170a90e5c libarrow.1500.0.0.dylib`arrow::compute::detail::FunctionExecutorImpl::Execute(this=0x000060000280a818, args=size=1, passed_length=-1) at function.cc:277:5
    frame #17: 0x0000000170a87040 libarrow.1500.0.0.dylib`arrow::compute::(anonymous namespace)::ExecuteInternal(func=0x00006000039d5788, args=size=1, passed_length=-1, options=0x000000016fdfcb28, ctx=0x00000001737ed5e0) at function.cc:342:21
    frame #18: 0x0000000170a86c84 libarrow.1500.0.0.dylib`arrow::compute::Function::Execute(this=0x00006000039d5788, args=size=1, options=0x000000016fdfcb28, ctx=0x00000001737ed5e0) const at function.cc:349:10
    frame #19: 0x0000000170a325b4 libarrow.1500.0.0.dylib`arrow::compute::internal::(anonymous namespace)::CastMetaFunction::ExecuteImpl(this=0x000060000339ae98, args=size=1, options=0x000000016fdfcb28, ctx=0x00000001737ed5e0) const at cast.cc:124:23
    frame #20: 0x0000000170a889a8 libarrow.1500.0.0.dylib`arrow::compute::MetaFunction::Execute(this=0x000060000339ae98, args=size=1, options=0x000000016fdfcb28, ctx=0x00000001737ed5e0) const at function.cc:482:10
    frame #21: 0x0000000170a3d954 libarrow.1500.0.0.dylib`arrow::compute::CallFunction(func_name="cast", args=size=1, options=0x000000016fdfcb28, ctx=0x00000001737ed5e0) at exec.cc:1369:16
    frame #22: 0x0000000170a27c1c libarrow.1500.0.0.dylib`arrow::compute::Cast(value=0x000000016fdfcc88, options=0x000000016fdfcb28, ctx=0x0000000000000000) at cast.cc:239:10
    frame #23: 0x0000000170a27dc8 libarrow.1500.0.0.dylib`arrow::compute::Cast(value=0x000000016fdfcc88, to_type=0x000000016fdfcc70, options=0x000000016fdfcc30, ctx=0x0000000000000000) at cast.cc:246:10
    frame #24: 0x000000011d517348 libarrow-glib.1500.dylib`::garrow_scalar_cast(scalar=0x0000600002668c60, data_type=0x00006000009831f0, options=0x0000000000000000, error=0x000000016fdfcf10) at scalar.cpp:390:37
    frame #25: 0x0000000192f9a050 libffi.dylib`ffi_call_SYSV + 80
    frame #26: 0x0000000192fa2adc libffi.dylib`ffi_call_int + 1208
    frame #27: 0x000000011b871744 libgirepository-1.0.1.dylib`g_callable_info_invoke + 860
    frame #28: 0x000000011b872a68 libgirepository-1.0.1.dylib`g_function_info_invoke + 252
    frame #29: 0x000000011b7c2984 gobject_introspection.bundle`rb_gi_function_info_invoke_raw + 212
    frame #30: 0x000000011b7c4244 gobject_introspection.bundle`rg_invoke + 64
    frame #31: 0x0000000100b84dfc libruby.3.3.dylib`vm_call_cfunc_with_frame_ + 240
    frame #32: 0x0000000100b6ab64 libruby.3.3.dylib`vm_exec_core + 7688
    frame #33: 0x0000000100b67d28 libruby.3.3.dylib`rb_vm_exec + 320
    frame #34: 0x0000000100b8c4f4 libruby.3.3.dylib`invoke_block_from_c_bh + 872
    frame #35: 0x0000000100b8bc64 libruby.3.3.dylib`catch_i + 108
    frame #36: 0x0000000100b77df4 libruby.3.3.dylib`vm_catch_protect + 232
    frame #37: 0x0000000100b78678 libruby.3.3.dylib`rb_f_catch + 112
    frame #38: 0x0000000100b84dfc libruby.3.3.dylib`vm_call_cfunc_with_frame_ + 240
    frame #39: 0x0000000100b6ab64 libruby.3.3.dylib`vm_exec_core + 7688
    frame #40: 0x0000000100b67d28 libruby.3.3.dylib`rb_vm_exec + 320
    frame #41: 0x0000000100b8c4f4 libruby.3.3.dylib`invoke_block_from_c_bh + 872
    frame #42: 0x0000000100b8bc64 libruby.3.3.dylib`catch_i + 108
    frame #43: 0x0000000100b77df4 libruby.3.3.dylib`vm_catch_protect + 232
    frame #44: 0x0000000100b78678 libruby.3.3.dylib`rb_f_catch + 112
    frame #45: 0x0000000100b84dfc libruby.3.3.dylib`vm_call_cfunc_with_frame_ + 240
    frame #46: 0x0000000100b6ab64 libruby.3.3.dylib`vm_exec_core + 7688
    frame #47: 0x0000000100b67dec libruby.3.3.dylib`rb_vm_exec + 516
    frame #48: 0x00000001009e0830 libruby.3.3.dylib`rb_ec_exec_node + 160
    frame #49: 0x00000001009e0728 libruby.3.3.dylib`ruby_run_node + 96
    frame #50: 0x0000000100003f34 ruby`main + 104
    frame #51: 0x00000001820a50e0 dyld`start + 2360

@kou
Copy link
Member

kou commented Jan 2, 2024

Does https://github.com/apache/arrow/pull/39228/files#r1439542060 work?

@kou kou closed this as completed in #39228 Jan 6, 2024
kou pushed a commit that referenced this issue Jan 6, 2024
### Rationale for this change

Remove legacy code

### What changes are included in this PR?

* Replace the legacy scalar CastTo implementation for GLib. 

### Are these changes tested?

No.

### Are there any user-facing changes?

No.

* Closes: #39225

Authored-by: Hyunseok Seo <hsseo0501@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
@kou kou added this to the 15.0.0 milestone Jan 6, 2024
clayburn pushed a commit to clayburn/arrow that referenced this issue Jan 23, 2024
### Rationale for this change

Remove legacy code

### What changes are included in this PR?

* Replace the legacy scalar CastTo implementation for GLib. 

### Are these changes tested?

No.

### Are there any user-facing changes?

No.

* Closes: apache#39225

Authored-by: Hyunseok Seo <hsseo0501@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
dgreiss pushed a commit to dgreiss/arrow that referenced this issue Feb 19, 2024
### Rationale for this change

Remove legacy code

### What changes are included in this PR?

* Replace the legacy scalar CastTo implementation for GLib. 

### Are these changes tested?

No.

### Are there any user-facing changes?

No.

* Closes: apache#39225

Authored-by: Hyunseok Seo <hsseo0501@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
zanmato1984 pushed a commit to zanmato1984/arrow that referenced this issue Feb 28, 2024
### Rationale for this change

Remove legacy code

### What changes are included in this PR?

* Replace the legacy scalar CastTo implementation for GLib. 

### Are these changes tested?

No.

### Are there any user-facing changes?

No.

* Closes: apache#39225

Authored-by: Hyunseok Seo <hsseo0501@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants