-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
DateTimePicker raises a segmentation fault #9
Comments
The following example of date_picker often raises a segmentation fault.
require 'libui'
UI = LibUI
UI.init
vbox = UI.new_vertical_box
date_time_picker = UI.new_date_picker
time = UI::FFI::TM.malloc
@hoge = proc do
UI.date_time_picker_time(date_time_picker, time)
# p sec: time.tm_sec,
# min: time.tm_min,
# hour: time.tm_hour,
# mday: time.tm_mday,
# mon: time.tm_mon,
# year: time.tm_year,
# wday: time.tm_wday,
# yday: time.tm_yday,
# isdst: time.tm_isdst
end
UI.date_time_picker_on_changed(date_time_picker, @hoge)
UI.box_append(vbox, date_time_picker, 1)
main_window = UI.new_window('Date Time Pickers', 300, 200, 1)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
end
UI.window_set_child(main_window, vbox)
UI.control_show(main_window)
UI.main
UI.quit Errors
|
An example of an error log.
|
Finally, @kou's investigation revealed the cause.
diff --git a/lib/libui/ffi.rb b/lib/libui/ffi.rb
index e85f265..36c998d 100644
--- a/lib/libui/ffi.rb
+++ b/lib/libui/ffi.rb
@@ -223,7 +223,9 @@ module LibUI
'int tm_year',
'int tm_wday',
'int tm_yday',
- 'int tm_isdst'
+ 'int tm_isdst',
+ 'long __tm_gmtoff',
+ 'const char *__tm_zone',
] https://stackoverflow.com/questions/13969210/size-of-struct-tm |
One idea would be to create a C extension library and add #include "tmsize.h"
void
Init_tmsize(void)
{
struct tm tm;
rb_require("fiddle");
ID sym_mFiddle = rb_intern("Fiddle");
VALUE rb_mFiddle = rb_const_get(rb_cObject, sym_mFiddle);
rb_define_const(rb_mFiddle, "SIZEOF_STRUCT_TM", INT2FIX(sizeof(s)));
} This is used in the following way. require 'tmsize'
ptr = FiddlePointer.new(Fiddle::SIZEOF_STRUCT_TM)
tm = LibUI::FFI::TM.new(ptr) But I don't want to use the C extension. I would like libui to work even if the C development environment is not installed. |
I decided to change the size of the structure only when using Windows. If you find any problems, please report them to me. # time.h
TM = if Fiddle::WINDOWS
struct [
'int tm_sec',
'int tm_min',
'int tm_hour',
'int tm_mday',
'int tm_mon',
'int tm_year',
'int tm_wday',
'int tm_yday',
'int tm_isdst'
]
else # The GNU C Library (glibc)
struct [
'int tm_sec',
'int tm_min',
'int tm_hour',
'int tm_mday',
'int tm_mon',
'int tm_year',
'int tm_wday',
'int tm_yday',
'int tm_isdst',
'long tm_gmtoff',
'const char *tm_zone'
]
end |
The DateTimePicker sample generates a segmentation fault and does not work as expected.
I don't know why, but it is possible that access to the memory of the LibUI::FFI::TM structure is happening after it has been released.
The text was updated successfully, but these errors were encountered: