@@ -6,6 +6,7 @@ use defines::{ColorMap, MarkerType};
66use error:: HANDLE_ERROR ;
77use self :: libc:: { c_int, c_uint, c_float, c_double, c_char} ;
88use std:: ffi:: CString ;
9+ use std:: ptr;
910
1011type MutWndHandle = * mut self :: libc:: c_ulonglong ;
1112type WndHandle = self :: libc:: c_ulonglong ;
@@ -73,7 +74,7 @@ extern {
7374pub struct Cell {
7475 pub row : i32 ,
7576 pub col : i32 ,
76- pub title : String ,
77+ pub title : * const c_char ,
7778 pub cmap : ColorMap ,
7879}
7980
@@ -148,12 +149,12 @@ impl Window {
148149 pub fn new ( width : i32 , height : i32 , title : String ) -> Window {
149150 unsafe {
150151 let mut temp: u64 = 0 ;
151- let cstr_ret = CString :: new ( title. as_bytes ( ) ) ;
152+ let cstr_ret = CString :: new ( title) ;
152153 match cstr_ret {
153154 Ok ( cstr) => {
154155 let err_val = af_create_window ( & mut temp as MutWndHandle ,
155156 width as c_int , height as c_int ,
156- cstr. to_bytes_with_nul ( ) . as_ptr ( ) as * const c_char ) ;
157+ cstr. as_ptr ( ) ) ;
157158 HANDLE_ERROR ( AfError :: from ( err_val) ) ;
158159 Window :: from ( temp)
159160 } ,
@@ -182,11 +183,11 @@ impl Window {
182183 /// - `title` is the string to be displayed on window title bar
183184 pub fn set_title ( & self , title : String ) {
184185 unsafe {
185- let cstr_ret = CString :: new ( title. as_bytes ( ) ) ;
186+ let cstr_ret = CString :: new ( title) ;
186187 match cstr_ret {
187188 Ok ( cstr) => {
188189 let err_val = af_set_title ( self . handle as WndHandle ,
189- cstr. to_bytes_with_nul ( ) . as_ptr ( ) as * const c_char ) ;
190+ cstr. as_ptr ( ) ) ;
190191 HANDLE_ERROR ( AfError :: from ( err_val) ) ;
191192 } ,
192193 Err ( _) => HANDLE_ERROR ( AfError :: ERR_INTERNAL ) ,
@@ -284,15 +285,15 @@ impl Window {
284285 /// - `ylabel` is y axis title
285286 /// - `zlabel` is z axis title
286287 pub fn set_axes_titles ( & mut self , xlabel : String , ylabel : String , zlabel : String ) {
287- let cprops = & Cell { row : self . row , col : self . col , title : String :: from ( "" ) , cmap : self . cmap } ;
288- let xstr = CString :: new ( xlabel. as_bytes ( ) ) . unwrap ( ) ;
289- let ystr = CString :: new ( ylabel. as_bytes ( ) ) . unwrap ( ) ;
290- let zstr = CString :: new ( zlabel. as_bytes ( ) ) . unwrap ( ) ;
288+ let cprops = & Cell { row : self . row , col : self . col , title : ptr :: null ( ) , cmap : self . cmap } ;
289+ let xstr = CString :: new ( xlabel) . unwrap ( ) ;
290+ let ystr = CString :: new ( ylabel) . unwrap ( ) ;
291+ let zstr = CString :: new ( zlabel) . unwrap ( ) ;
291292 unsafe {
292293 let err_val = af_set_axes_titles ( self . handle as WndHandle ,
293- xstr. to_bytes_with_nul ( ) . as_ptr ( ) as * const c_char ,
294- ystr. to_bytes_with_nul ( ) . as_ptr ( ) as * const c_char ,
295- zstr. to_bytes_with_nul ( ) . as_ptr ( ) as * const c_char ,
294+ xstr. as_ptr ( ) ,
295+ ystr. as_ptr ( ) ,
296+ zstr. as_ptr ( ) ,
296297 cprops as * const Cell as CellPtr ) ;
297298 HANDLE_ERROR ( AfError :: from ( err_val) ) ;
298299 }
@@ -314,7 +315,7 @@ impl Window {
314315 /// to next power of 2 and the magnitude remains the same.
315316 pub fn set_axes_limits_compute ( & mut self , xrange : & Array , yrange : & Array ,
316317 zrange : Option < & Array > , exact : bool ) {
317- let cprops = & Cell { row : self . row , col : self . col , title : String :: from ( "" ) , cmap : self . cmap } ;
318+ let cprops = & Cell { row : self . row , col : self . col , title : ptr :: null ( ) , cmap : self . cmap } ;
318319 unsafe {
319320 let err_val = af_set_axes_limits_compute ( self . handle as WndHandle ,
320321 xrange. get ( ) as AfArray ,
@@ -343,7 +344,7 @@ impl Window {
343344 /// are to extracted. If exact is false then the most significant digit is rounded up
344345 /// to next power of 2 and the magnitude remains the same.
345346 pub fn set_axes_limits_2d ( & mut self , xmin : f32 , xmax : f32 , ymin : f32 , ymax : f32 , exact : bool ) {
346- let cprops = & Cell { row : self . row , col : self . col , title : String :: from ( "" ) , cmap : self . cmap } ;
347+ let cprops = & Cell { row : self . row , col : self . col , title : ptr :: null ( ) , cmap : self . cmap } ;
347348 unsafe {
348349 let err_val = af_set_axes_limits_2d ( self . handle as WndHandle , xmin as c_float ,
349350 xmax as c_float , ymin as c_float , ymax as c_float ,
@@ -370,7 +371,7 @@ impl Window {
370371 /// to next power of 2 and the magnitude remains the same.
371372 pub fn set_axes_limits_3d ( & mut self , xmin : f32 , xmax : f32 , ymin : f32 , ymax : f32 ,
372373 zmin : f32 , zmax : f32 , exact : bool ) {
373- let cprops = & Cell { row : self . row , col : self . col , title : String :: from ( "" ) , cmap : self . cmap } ;
374+ let cprops = & Cell { row : self . row , col : self . col , title : ptr :: null ( ) , cmap : self . cmap } ;
374375 unsafe {
375376 let err_val = af_set_axes_limits_3d ( self . handle as WndHandle , xmin as c_float ,
376377 xmax as c_float , ymin as c_float , ymax as c_float ,
@@ -392,7 +393,8 @@ impl Window {
392393 Some ( s) => s,
393394 None => format ! ( "Cell({},{}))" , self . col, self . row)
394395 } ;
395- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
396+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
397+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
396398 unsafe {
397399 let err_val = af_draw_image ( self . handle as WndHandle , input. get ( ) as AfArray ,
398400 cprops as * const Cell as CellPtr ) ;
@@ -413,7 +415,8 @@ impl Window {
413415 Some ( s) => s,
414416 None => format ! ( "Cell({},{}))" , self . col, self . row)
415417 } ;
416- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
418+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
419+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
417420 unsafe {
418421 let err_val = af_draw_plot_2d ( self . handle as WndHandle ,
419422 x. get ( ) as AfArray , y. get ( ) as AfArray ,
@@ -436,7 +439,8 @@ impl Window {
436439 Some ( s) => s,
437440 None => format ! ( "Cell({},{}))" , self . col, self . row)
438441 } ;
439- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
442+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
443+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
440444 unsafe {
441445 let err_val = af_draw_plot_3d ( self . handle as WndHandle ,
442446 x. get ( ) as AfArray , y. get ( ) as AfArray , z. get ( ) as AfArray ,
@@ -457,7 +461,8 @@ impl Window {
457461 Some ( s) => s,
458462 None => format ! ( "Cell({},{}))" , self . col, self . row)
459463 } ;
460- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
464+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
465+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
461466 unsafe {
462467 let err_val = af_draw_plot_nd ( self . handle as WndHandle , points. get ( ) as AfArray ,
463468 cprops as * const Cell as CellPtr ) ;
@@ -479,7 +484,8 @@ impl Window {
479484 Some ( s) => s,
480485 None => format ! ( "Cell({},{}))" , self . col, self . row)
481486 } ;
482- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
487+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
488+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
483489 unsafe {
484490 let err_val = af_draw_hist ( self . handle as WndHandle , hst. get ( ) as AfArray ,
485491 minval as c_double , maxval as c_double ,
@@ -502,7 +508,8 @@ impl Window {
502508 Some ( s) => s,
503509 None => format ! ( "Cell({},{}))" , self . col, self . row)
504510 } ;
505- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
511+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
512+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
506513 unsafe {
507514 let err_val = af_draw_surface ( self . handle as WndHandle ,
508515 xvals. get ( ) as AfArray ,
@@ -528,7 +535,8 @@ impl Window {
528535 Some ( s) => s,
529536 None => format ! ( "Cell({},{}))" , self . col, self . row)
530537 } ;
531- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
538+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
539+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
532540 unsafe {
533541 let err_val = af_draw_scatter_2d ( self . handle as WndHandle ,
534542 xvals. get ( ) as AfArray , yvals. get ( ) as AfArray ,
@@ -553,7 +561,8 @@ impl Window {
553561 Some ( s) => s,
554562 None => format ! ( "Cell({},{}))" , self . col, self . row)
555563 } ;
556- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
564+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
565+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
557566 unsafe {
558567 let err_val = af_draw_scatter_3d ( self . handle as WndHandle , xvals. get ( ) as AfArray ,
559568 yvals. get ( ) as AfArray , zvals. get ( ) as AfArray ,
@@ -575,7 +584,8 @@ impl Window {
575584 Some ( s) => s,
576585 None => format ! ( "Cell({},{}))" , self . col, self . row)
577586 } ;
578- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
587+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
588+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
579589 unsafe {
580590 let err_val = af_draw_scatter_nd ( self . handle as WndHandle , vals. get ( ) as AfArray ,
581591 marker as c_int , cprops as * const Cell as CellPtr ) ;
@@ -599,7 +609,8 @@ impl Window {
599609 Some ( s) => s,
600610 None => format ! ( "Cell({},{}))" , self . col, self . row)
601611 } ;
602- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
612+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
613+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
603614 unsafe {
604615 let err_val = af_draw_vector_field_2d ( self . handle as WndHandle ,
605616 xpnts. get ( ) as AfArray , ypnts. get ( ) as AfArray ,
@@ -628,7 +639,8 @@ impl Window {
628639 Some ( s) => s,
629640 None => format ! ( "Cell({},{}))" , self . col, self . row)
630641 } ;
631- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
642+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
643+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
632644 unsafe {
633645 let err_val = af_draw_vector_field_3d ( self . handle as WndHandle , xpnts. get ( ) as AfArray ,
634646 ypnts. get ( ) as AfArray , zpnts. get ( ) as AfArray ,
@@ -653,7 +665,8 @@ impl Window {
653665 Some ( s) => s,
654666 None => format ! ( "Cell({},{}))" , self . col, self . row)
655667 } ;
656- let cprops = & Cell { row : self . row , col : self . col , title : tstr. clone ( ) , cmap : self . cmap } ;
668+ let tstr = CString :: new ( tstr) . unwrap ( ) ;
669+ let cprops = & Cell { row : self . row , col : self . col , title : tstr. as_ptr ( ) , cmap : self . cmap } ;
657670 unsafe {
658671 let err_val = af_draw_vector_field_nd ( self . handle as WndHandle ,
659672 points. get ( ) as AfArray , directions. get ( ) as AfArray ,
0 commit comments