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

Added FFI bindings to lib.rs #1

Merged
merged 13 commits into from Mar 23, 2016
6 changes: 4 additions & 2 deletions examples/tinytest/src/main.rs
Expand Up @@ -33,12 +33,13 @@ fn save_file_dialog(title: &CStr, path: &CStr,
num_patterns: c_int,
filter_pattern_one: &CStr, des: &CStr) -> *const c_char {
let filter_patterns : [&CStr; 1] = [filter_pattern_one];
let ptr_filter_patterns = filter_patterns.iter().map(|c| c.as_ptr()).collect::<Vec<*const c_char>>().as_ptr();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is still unsafe. The as_ptr() is what makes the Vec go out of scope; it should be moved to the actual argument to the function call instead.

unsafe {
let result: *const c_char = tinyfiledialogs::tinyfd_saveFileDialog(
title.as_ptr(),
path.as_ptr(),
num_patterns,
filter_patterns.iter().map(|c| c.as_ptr()).collect::<Vec<*const c_char>>().as_ptr(),
ptr_filter_patterns,
des.as_ptr());

result
Expand All @@ -49,12 +50,13 @@ fn open_file_dialog(title: &CStr, path: &CStr,
num_patterns: c_int, filter_pattern_one: &CStr,
des: &CStr, multi_select: c_int) -> *const c_char {
let filter_patterns : [&CStr; 1] = [filter_pattern_one];
let ptr_filter_patterns = filter_patterns.iter().map(|c| c.as_ptr()).collect::<Vec<*const c_char>>().as_ptr();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

unsafe {
let result: *const c_char = tinyfiledialogs::tinyfd_openFileDialog(
title.as_ptr(),
path.as_ptr(),
num_patterns,
filter_patterns.iter().map(|c| c.as_ptr()).collect::<Vec<*const c_char>>().as_ptr(),
ptr_filter_patterns,
des.as_ptr(),
multi_select);

Expand Down