From 2790c71a350d30593495be5314aa435608ccc353 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 21 Jul 2022 22:17:34 -0700 Subject: [PATCH] Factor out NULL_STRING macro --- src/macros.rs | 10 ++++++ src/scanner.rs | 90 +++++++++----------------------------------------- 2 files changed, 25 insertions(+), 75 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index de8fe5d..0a6faf7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,3 +1,13 @@ +macro_rules! NULL_STRING { + () => { + yaml_string_t { + start: ptr::null_mut::(), + end: ptr::null_mut::(), + pointer: ptr::null_mut::(), + } + }; +} + macro_rules! IS_BLANK_AT { ($string:expr, $offset:expr) => { *$string.pointer.wrapping_offset($offset as isize) as libc::c_int diff --git a/src/scanner.rs b/src/scanner.rs index 7c5d59d..90dfb45 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1850,11 +1850,7 @@ unsafe fn yaml_parser_scan_directive_name( name: *mut *mut yaml_char_t, ) -> libc::c_int { let current_block: u64; - let mut string = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; + let mut string = NULL_STRING!(); string.start = yaml_malloc(16_u64) as *mut yaml_char_t; if !(if !string.start.is_null() { string.pointer = string.start; @@ -2115,11 +2111,7 @@ unsafe fn yaml_parser_scan_anchor( let mut length: libc::c_int = 0_i32; let start_mark: yaml_mark_t; let end_mark: yaml_mark_t; - let mut string = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; + let mut string = NULL_STRING!(); string.start = yaml_malloc(16_u64) as *mut yaml_char_t; if !(if !string.start.is_null() { string.pointer = string.start; @@ -2389,11 +2381,7 @@ unsafe fn yaml_parser_scan_tag_handle( handle: *mut *mut yaml_char_t, ) -> libc::c_int { let mut current_block: u64; - let mut string = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; + let mut string = NULL_STRING!(); string.start = yaml_malloc(16_u64) as *mut yaml_char_t; if !(if !string.start.is_null() { string.pointer = string.start; @@ -2511,11 +2499,7 @@ unsafe fn yaml_parser_scan_tag_uri( } else { 0_u64 }; - let mut string = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; + let mut string = NULL_STRING!(); string.start = yaml_malloc(16_u64) as *mut yaml_char_t; if if !string.start.is_null() { string.pointer = string.start; @@ -2850,21 +2834,9 @@ unsafe fn yaml_parser_scan_block_scalar( let mut current_block: u64; let start_mark: yaml_mark_t; let mut end_mark: yaml_mark_t; - let mut string = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut leading_break = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut trailing_breaks = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; + let mut string = NULL_STRING!(); + let mut leading_break = NULL_STRING!(); + let mut trailing_breaks = NULL_STRING!(); let mut chomping: libc::c_int = 0_i32; let mut increment: libc::c_int = 0_i32; let mut indent: libc::c_int = 0_i32; @@ -3551,26 +3523,10 @@ unsafe fn yaml_parser_scan_flow_scalar( let current_block: u64; let start_mark: yaml_mark_t; let end_mark: yaml_mark_t; - let mut string = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut leading_break = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut trailing_breaks = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut whitespaces = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; + let mut string = NULL_STRING!(); + let mut leading_break = NULL_STRING!(); + let mut trailing_breaks = NULL_STRING!(); + let mut whitespaces = NULL_STRING!(); let mut leading_blanks: libc::c_int; string.start = yaml_malloc(16_u64) as *mut yaml_char_t; if !(if !string.start.is_null() { @@ -4407,26 +4363,10 @@ unsafe fn yaml_parser_scan_plain_scalar( let current_block: u64; let start_mark: yaml_mark_t; let mut end_mark: yaml_mark_t; - let mut string = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut leading_break = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut trailing_breaks = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; - let mut whitespaces = yaml_string_t { - start: ptr::null_mut::(), - end: ptr::null_mut::(), - pointer: ptr::null_mut::(), - }; + let mut string = NULL_STRING!(); + let mut leading_break = NULL_STRING!(); + let mut trailing_breaks = NULL_STRING!(); + let mut whitespaces = NULL_STRING!(); let mut leading_blanks: libc::c_int = 0_i32; let indent: libc::c_int = (*parser).indent + 1_i32; string.start = yaml_malloc(16_u64) as *mut yaml_char_t;