Skip to content

Commit ab1c7be

Browse files
committed
Merge branch 'master' into docs_content
2 parents 14573f1 + e4e20aa commit ab1c7be

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@
99

1010
# Generated by Cargo
1111
/target/
12-
13-
# Generated by bindgen
14-
src/arrayfire.rs
12+
Cargo.lock

Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
[package]
22
name = "arrayfire"
3-
version = "3.0.0"
4-
authors = ["Jason Ramapuram <jason.ramapuram@gmail.com>"]
3+
version = "3.1.2"
4+
authors = ["Pradeep Garigipati <pradeep@arrayfire.com>",
5+
"Jason Ramapuram <jason.ramapuram@gmail.com>"]
56
build = "build.rs"
67

78
[dependencies]
8-
libc = "*"
9-
num = "*"
10-
time = "*"
9+
libc = "0.1.10"
10+
num = "0.1.27"
11+
time = "0.1.32"
1112

1213
[build-dependencies.rustc-serialize]
13-
rustc-serialize = "*"
14+
rustc-serialize = "0.3.16"
1415

1516
[lib]
1617
name = "arrayfire"

arrayfire

Submodule arrayfire updated 356 files

src/graphics.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ extern crate libc;
33
use array::Array;
44
use defines::AfError;
55
use defines::ColorMap;
6-
use self::libc::{c_int, c_uint, c_double};
6+
use self::libc::{c_int, c_uint, c_double, c_char};
7+
use std::ffi::CString;
78

89
type MutWndHandle = *mut self::libc::c_ulonglong;
910
type WndHandle = self::libc::c_ulonglong;
10-
type AfArray = self::libc::c_longlong;
11+
type AfArray = self::libc::c_longlong;
1112
type CellPtr = *const self::libc::c_void;
1213

1314
#[allow(dead_code)]
1415
extern {
15-
fn af_create_window(out: MutWndHandle, w: c_int, h: c_int, title: *const u8) -> c_int;
16+
fn af_create_window(out: MutWndHandle, w: c_int, h: c_int, title: *const c_char) -> c_int;
1617
fn af_set_position(wnd: WndHandle, x: c_uint, y: c_uint) -> c_int;
17-
fn af_set_title(wnd: WndHandle, title: *const u8) -> c_int;
18+
fn af_set_title(wnd: WndHandle, title: *const c_char) -> c_int;
1819
fn af_draw_image(wnd: WndHandle, arr: AfArray, props: CellPtr) -> c_int;
1920
fn af_draw_plot(wnd: WndHandle, x: AfArray, y: AfArray, props: CellPtr) -> c_int;
2021
fn af_grid(wnd: WndHandle, rows: c_int, cols: c_int) -> c_int;
2122
fn af_show(wnd: WndHandle) -> c_int;
2223
fn af_is_window_closed(out: *mut c_int, wnd: WndHandle) -> c_int;
2324
fn af_destroy_window(wnd: WndHandle) -> c_int;
24-
2525
fn af_draw_hist(wnd: WndHandle, x: AfArray,
2626
minval: c_double, maxval: c_double, props: CellPtr) -> c_int;
2727
}
@@ -102,12 +102,18 @@ impl Window {
102102
pub fn new(width: i32, height: i32, title: String) -> Result<Window, AfError> {
103103
unsafe {
104104
let mut temp: u64 = 0;
105-
let err_val = af_create_window(&mut temp as MutWndHandle,
106-
width as c_int, height as c_int,
107-
title.clone().as_bytes().as_ptr() as *const u8);
108-
match err_val {
109-
0 => Ok(Window::from(temp)),
110-
_ => Err(AfError::from(err_val)),
105+
let cstr_ret = CString::new(title.as_bytes());
106+
match cstr_ret {
107+
Ok(cstr) => {
108+
let err_val = af_create_window(&mut temp as MutWndHandle
109+
, width as c_int, height as c_int
110+
, cstr.to_bytes_with_nul().as_ptr() as *const c_char);
111+
match err_val {
112+
0 => Ok(Window::from(temp)),
113+
_ => Err(AfError::from(err_val)),
114+
}
115+
},
116+
Err(_) => Err(AfError::ERR_INTERNAL),
111117
}
112118
}
113119
}
@@ -126,11 +132,17 @@ impl Window {
126132
/// Set window title
127133
pub fn set_title(&self, title: String) -> Result<(), AfError> {
128134
unsafe {
129-
let err_val = af_set_title(self.handle as WndHandle,
130-
title.clone().as_bytes().as_ptr() as *const u8);
131-
match err_val {
132-
0 => Ok(()),
133-
_ => Err(AfError::from(err_val)),
135+
let cstr_ret = CString::new(title.as_bytes());
136+
match cstr_ret {
137+
Ok(cstr) => {
138+
let err_val = af_set_title(self.handle as WndHandle
139+
, cstr.to_bytes_with_nul().as_ptr() as *const c_char);
140+
match err_val {
141+
0 => Ok(()),
142+
_ => Err(AfError::from(err_val)),
143+
}
144+
},
145+
Err(_) => Err(AfError::ERR_INTERNAL),
134146
}
135147
}
136148
}

0 commit comments

Comments
 (0)