@@ -32,7 +32,6 @@ use std::ascii::AsciiExt;
3232use std:: cell:: RefCell ;
3333use std:: collections:: { HashMap , VecDeque } ;
3434use std:: default:: Default ;
35- use std:: ffi:: CString ;
3635use std:: fmt:: { self , Write } ;
3736use std:: str;
3837use syntax:: feature_gate:: UnstableFeatures ;
@@ -529,8 +528,8 @@ extern {
529528 fn hoedown_document_free ( md : * mut hoedown_document ) ;
530529
531530 fn hoedown_buffer_new ( unit : libc:: size_t ) -> * mut hoedown_buffer ;
532- fn hoedown_buffer_puts ( b : * mut hoedown_buffer , c : * const libc:: c_char ) ;
533531 fn hoedown_buffer_free ( b : * mut hoedown_buffer ) ;
532+ fn hoedown_buffer_put ( b : * mut hoedown_buffer , c : * const u8 , len : libc:: size_t ) ;
534533}
535534
536535impl hoedown_buffer {
@@ -620,8 +619,7 @@ pub fn render(w: &mut fmt::Formatter,
620619 Some ( "rust-example-rendered" ) ,
621620 None ,
622621 playground_button. as_ref ( ) . map ( String :: as_str) ) ) ;
623- let output = CString :: new ( s) . unwrap ( ) ;
624- hoedown_buffer_puts ( ob, output. as_ptr ( ) ) ;
622+ hoedown_buffer_put ( ob, s. as_ptr ( ) , s. len ( ) ) ;
625623 } )
626624 }
627625 }
@@ -630,7 +628,7 @@ pub fn render(w: &mut fmt::Formatter,
630628 level : libc:: c_int , data : * const hoedown_renderer_data ,
631629 _: libc:: size_t ) {
632630 // hoedown does this, we may as well too
633- unsafe { hoedown_buffer_puts ( ob, "\n \0 " . as_ptr ( ) as * const _ ) ; }
631+ unsafe { hoedown_buffer_put ( ob, "\n " . as_ptr ( ) , 1 ) ; }
634632
635633 // Extract the text provided
636634 let s = if text. is_null ( ) {
@@ -681,8 +679,7 @@ pub fn render(w: &mut fmt::Formatter,
681679 <a href='#{id}'>{sec}{}</a></h{lvl}>",
682680 s, lvl = level, id = id, sec = sec) ;
683681
684- let text = CString :: new ( text) . unwrap ( ) ;
685- unsafe { hoedown_buffer_puts ( ob, text. as_ptr ( ) ) }
682+ unsafe { hoedown_buffer_put ( ob, text. as_ptr ( ) , text. len ( ) ) ; }
686683 }
687684
688685 extern fn codespan (
@@ -700,8 +697,9 @@ pub fn render(w: &mut fmt::Formatter,
700697 } ;
701698
702699 let content = format ! ( "<code>{}</code>" , Escape ( & content) ) ;
703- let element = CString :: new ( content) . unwrap ( ) ;
704- unsafe { hoedown_buffer_puts ( ob, element. as_ptr ( ) ) ; }
700+ unsafe {
701+ hoedown_buffer_put ( ob, content. as_ptr ( ) , content. len ( ) ) ;
702+ }
705703 // Return anything except 0, which would mean "also print the code span verbatim".
706704 1
707705 }
0 commit comments