Factor out STACK_DEL macro

This commit is contained in:
David Tolnay 2022-07-22 15:20:04 -07:00
parent 8974a256ed
commit ee70411948
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
5 changed files with 39 additions and 190 deletions

View file

@ -245,41 +245,11 @@ pub unsafe fn yaml_parser_initialize(parser: *mut yaml_parser_t) -> libc::c_int
*fresh35 = *fresh34; *fresh35 = *fresh34;
let fresh36 = addr_of_mut!((*parser).tokens.start); let fresh36 = addr_of_mut!((*parser).tokens.start);
*fresh36 = *fresh35; *fresh36 = *fresh35;
yaml_free((*parser).indents.start as *mut libc::c_void); STACK_DEL!((*parser).indents);
let fresh37 = addr_of_mut!((*parser).indents.end); STACK_DEL!((*parser).simple_keys);
*fresh37 = ptr::null_mut::<libc::c_int>(); STACK_DEL!((*parser).states);
let fresh38 = addr_of_mut!((*parser).indents.top); STACK_DEL!((*parser).marks);
*fresh38 = *fresh37; STACK_DEL!((*parser).tag_directives);
let fresh39 = addr_of_mut!((*parser).indents.start);
*fresh39 = *fresh38;
yaml_free((*parser).simple_keys.start as *mut libc::c_void);
let fresh40 = addr_of_mut!((*parser).simple_keys.end);
*fresh40 = ptr::null_mut::<yaml_simple_key_t>();
let fresh41 = addr_of_mut!((*parser).simple_keys.top);
*fresh41 = *fresh40;
let fresh42 = addr_of_mut!((*parser).simple_keys.start);
*fresh42 = *fresh41;
yaml_free((*parser).states.start as *mut libc::c_void);
let fresh43 = addr_of_mut!((*parser).states.end);
*fresh43 = ptr::null_mut::<yaml_parser_state_t>();
let fresh44 = addr_of_mut!((*parser).states.top);
*fresh44 = *fresh43;
let fresh45 = addr_of_mut!((*parser).states.start);
*fresh45 = *fresh44;
yaml_free((*parser).marks.start as *mut libc::c_void);
let fresh46 = addr_of_mut!((*parser).marks.end);
*fresh46 = ptr::null_mut::<yaml_mark_t>();
let fresh47 = addr_of_mut!((*parser).marks.top);
*fresh47 = *fresh46;
let fresh48 = addr_of_mut!((*parser).marks.start);
*fresh48 = *fresh47;
yaml_free((*parser).tag_directives.start as *mut libc::c_void);
let fresh49 = addr_of_mut!((*parser).tag_directives.end);
*fresh49 = ptr::null_mut::<yaml_tag_directive_t>();
let fresh50 = addr_of_mut!((*parser).tag_directives.top);
*fresh50 = *fresh49;
let fresh51 = addr_of_mut!((*parser).tag_directives.start);
*fresh51 = *fresh50;
0_i32 0_i32
} }
@ -300,34 +270,10 @@ pub unsafe fn yaml_parser_delete(parser: *mut yaml_parser_t) {
*fresh62 = *fresh61; *fresh62 = *fresh61;
let fresh63 = addr_of_mut!((*parser).tokens.start); let fresh63 = addr_of_mut!((*parser).tokens.start);
*fresh63 = *fresh62; *fresh63 = *fresh62;
yaml_free((*parser).indents.start as *mut libc::c_void); STACK_DEL!((*parser).indents);
let fresh64 = addr_of_mut!((*parser).indents.end); STACK_DEL!((*parser).simple_keys);
*fresh64 = ptr::null_mut::<libc::c_int>(); STACK_DEL!((*parser).states);
let fresh65 = addr_of_mut!((*parser).indents.top); STACK_DEL!((*parser).marks);
*fresh65 = *fresh64;
let fresh66 = addr_of_mut!((*parser).indents.start);
*fresh66 = *fresh65;
yaml_free((*parser).simple_keys.start as *mut libc::c_void);
let fresh67 = addr_of_mut!((*parser).simple_keys.end);
*fresh67 = ptr::null_mut::<yaml_simple_key_t>();
let fresh68 = addr_of_mut!((*parser).simple_keys.top);
*fresh68 = *fresh67;
let fresh69 = addr_of_mut!((*parser).simple_keys.start);
*fresh69 = *fresh68;
yaml_free((*parser).states.start as *mut libc::c_void);
let fresh70 = addr_of_mut!((*parser).states.end);
*fresh70 = ptr::null_mut::<yaml_parser_state_t>();
let fresh71 = addr_of_mut!((*parser).states.top);
*fresh71 = *fresh70;
let fresh72 = addr_of_mut!((*parser).states.start);
*fresh72 = *fresh71;
yaml_free((*parser).marks.start as *mut libc::c_void);
let fresh73 = addr_of_mut!((*parser).marks.end);
*fresh73 = ptr::null_mut::<yaml_mark_t>();
let fresh74 = addr_of_mut!((*parser).marks.top);
*fresh74 = *fresh73;
let fresh75 = addr_of_mut!((*parser).marks.start);
*fresh75 = *fresh74;
while !((*parser).tag_directives.start == (*parser).tag_directives.top) { while !((*parser).tag_directives.start == (*parser).tag_directives.top) {
let fresh76 = addr_of_mut!((*parser).tag_directives.top); let fresh76 = addr_of_mut!((*parser).tag_directives.top);
*fresh76 = (*fresh76).wrapping_offset(-1); *fresh76 = (*fresh76).wrapping_offset(-1);
@ -335,13 +281,7 @@ pub unsafe fn yaml_parser_delete(parser: *mut yaml_parser_t) {
yaml_free(tag_directive.handle as *mut libc::c_void); yaml_free(tag_directive.handle as *mut libc::c_void);
yaml_free(tag_directive.prefix as *mut libc::c_void); yaml_free(tag_directive.prefix as *mut libc::c_void);
} }
yaml_free((*parser).tag_directives.start as *mut libc::c_void); STACK_DEL!((*parser).tag_directives);
let fresh77 = addr_of_mut!((*parser).tag_directives.end);
*fresh77 = ptr::null_mut::<yaml_tag_directive_t>();
let fresh78 = addr_of_mut!((*parser).tag_directives.top);
*fresh78 = *fresh77;
let fresh79 = addr_of_mut!((*parser).tag_directives.start);
*fresh79 = *fresh78;
memset( memset(
parser as *mut libc::c_void, parser as *mut libc::c_void,
0_i32, 0_i32,
@ -459,13 +399,7 @@ pub unsafe fn yaml_emitter_initialize(mut emitter: *mut yaml_emitter_t) -> libc:
} }
BUFFER_DEL!((*emitter).buffer); BUFFER_DEL!((*emitter).buffer);
BUFFER_DEL!((*emitter).raw_buffer); BUFFER_DEL!((*emitter).raw_buffer);
yaml_free((*emitter).states.start as *mut libc::c_void); STACK_DEL!((*emitter).states);
let fresh118 = addr_of_mut!((*emitter).states.end);
*fresh118 = ptr::null_mut::<yaml_emitter_state_t>();
let fresh119 = addr_of_mut!((*emitter).states.top);
*fresh119 = *fresh118;
let fresh120 = addr_of_mut!((*emitter).states.start);
*fresh120 = *fresh119;
yaml_free((*emitter).events.start as *mut libc::c_void); yaml_free((*emitter).events.start as *mut libc::c_void);
let fresh121 = addr_of_mut!((*emitter).events.end); let fresh121 = addr_of_mut!((*emitter).events.end);
*fresh121 = ptr::null_mut::<yaml_event_t>(); *fresh121 = ptr::null_mut::<yaml_event_t>();
@ -475,20 +409,8 @@ pub unsafe fn yaml_emitter_initialize(mut emitter: *mut yaml_emitter_t) -> libc:
*fresh123 = *fresh122; *fresh123 = *fresh122;
let fresh124 = addr_of_mut!((*emitter).events.start); let fresh124 = addr_of_mut!((*emitter).events.start);
*fresh124 = *fresh123; *fresh124 = *fresh123;
yaml_free((*emitter).indents.start as *mut libc::c_void); STACK_DEL!((*emitter).indents);
let fresh125 = addr_of_mut!((*emitter).indents.end); STACK_DEL!((*emitter).tag_directives);
*fresh125 = ptr::null_mut::<libc::c_int>();
let fresh126 = addr_of_mut!((*emitter).indents.top);
*fresh126 = *fresh125;
let fresh127 = addr_of_mut!((*emitter).indents.start);
*fresh127 = *fresh126;
yaml_free((*emitter).tag_directives.start as *mut libc::c_void);
let fresh128 = addr_of_mut!((*emitter).tag_directives.end);
*fresh128 = ptr::null_mut::<yaml_tag_directive_t>();
let fresh129 = addr_of_mut!((*emitter).tag_directives.top);
*fresh129 = *fresh128;
let fresh130 = addr_of_mut!((*emitter).tag_directives.start);
*fresh130 = *fresh129;
0_i32 0_i32
} }
@ -497,13 +419,7 @@ pub unsafe fn yaml_emitter_delete(emitter: *mut yaml_emitter_t) {
__assert!(!emitter.is_null()); __assert!(!emitter.is_null());
BUFFER_DEL!((*emitter).buffer); BUFFER_DEL!((*emitter).buffer);
BUFFER_DEL!((*emitter).raw_buffer); BUFFER_DEL!((*emitter).raw_buffer);
yaml_free((*emitter).states.start as *mut libc::c_void); STACK_DEL!((*emitter).states);
let fresh137 = addr_of_mut!((*emitter).states.end);
*fresh137 = ptr::null_mut::<yaml_emitter_state_t>();
let fresh138 = addr_of_mut!((*emitter).states.top);
*fresh138 = *fresh137;
let fresh139 = addr_of_mut!((*emitter).states.start);
*fresh139 = *fresh138;
while !((*emitter).events.head == (*emitter).events.tail) { while !((*emitter).events.head == (*emitter).events.tail) {
yaml_event_delete(addr_of_mut!(DEQUEUE!((*emitter).events))); yaml_event_delete(addr_of_mut!(DEQUEUE!((*emitter).events)));
} }
@ -516,13 +432,7 @@ pub unsafe fn yaml_emitter_delete(emitter: *mut yaml_emitter_t) {
*fresh144 = *fresh143; *fresh144 = *fresh143;
let fresh145 = addr_of_mut!((*emitter).events.start); let fresh145 = addr_of_mut!((*emitter).events.start);
*fresh145 = *fresh144; *fresh145 = *fresh144;
yaml_free((*emitter).indents.start as *mut libc::c_void); STACK_DEL!((*emitter).indents);
let fresh146 = addr_of_mut!((*emitter).indents.end);
*fresh146 = ptr::null_mut::<libc::c_int>();
let fresh147 = addr_of_mut!((*emitter).indents.top);
*fresh147 = *fresh146;
let fresh148 = addr_of_mut!((*emitter).indents.start);
*fresh148 = *fresh147;
while !((*emitter).tag_directives.start == (*emitter).tag_directives.top) { while !((*emitter).tag_directives.start == (*emitter).tag_directives.top) {
let fresh149 = addr_of_mut!((*emitter).tag_directives.top); let fresh149 = addr_of_mut!((*emitter).tag_directives.top);
*fresh149 = (*fresh149).wrapping_offset(-1); *fresh149 = (*fresh149).wrapping_offset(-1);
@ -530,13 +440,7 @@ pub unsafe fn yaml_emitter_delete(emitter: *mut yaml_emitter_t) {
yaml_free(tag_directive.handle as *mut libc::c_void); yaml_free(tag_directive.handle as *mut libc::c_void);
yaml_free(tag_directive.prefix as *mut libc::c_void); yaml_free(tag_directive.prefix as *mut libc::c_void);
} }
yaml_free((*emitter).tag_directives.start as *mut libc::c_void); STACK_DEL!((*emitter).tag_directives);
let fresh150 = addr_of_mut!((*emitter).tag_directives.end);
*fresh150 = ptr::null_mut::<yaml_tag_directive_t>();
let fresh151 = addr_of_mut!((*emitter).tag_directives.top);
*fresh151 = *fresh150;
let fresh152 = addr_of_mut!((*emitter).tag_directives.start);
*fresh152 = *fresh151;
yaml_free((*emitter).anchors as *mut libc::c_void); yaml_free((*emitter).anchors as *mut libc::c_void);
memset( memset(
emitter as *mut libc::c_void, emitter as *mut libc::c_void,
@ -942,10 +846,7 @@ pub unsafe fn yaml_document_start_event_initialize(
yaml_free(value_0.handle as *mut libc::c_void); yaml_free(value_0.handle as *mut libc::c_void);
yaml_free(value_0.prefix as *mut libc::c_void); yaml_free(value_0.prefix as *mut libc::c_void);
} }
yaml_free(tag_directives_copy.start as *mut libc::c_void); STACK_DEL!(tag_directives_copy);
tag_directives_copy.end = ptr::null_mut::<yaml_tag_directive_t>();
tag_directives_copy.top = tag_directives_copy.end;
tag_directives_copy.start = tag_directives_copy.top;
yaml_free(value.handle as *mut libc::c_void); yaml_free(value.handle as *mut libc::c_void);
yaml_free(value.prefix as *mut libc::c_void); yaml_free(value.prefix as *mut libc::c_void);
0_i32 0_i32
@ -1523,10 +1424,7 @@ pub unsafe fn yaml_document_initialize(
} }
} }
} }
yaml_free(nodes.start as *mut libc::c_void); STACK_DEL!(nodes);
nodes.end = ptr::null_mut::<yaml_node_t>();
nodes.top = nodes.end;
nodes.start = nodes.top;
yaml_free(version_directive_copy as *mut libc::c_void); yaml_free(version_directive_copy as *mut libc::c_void);
while !(tag_directives_copy.start == tag_directives_copy.top) { while !(tag_directives_copy.start == tag_directives_copy.top) {
tag_directives_copy.top = tag_directives_copy.top.wrapping_offset(-1); tag_directives_copy.top = tag_directives_copy.top.wrapping_offset(-1);
@ -1534,10 +1432,7 @@ pub unsafe fn yaml_document_initialize(
yaml_free(value_0.handle as *mut libc::c_void); yaml_free(value_0.handle as *mut libc::c_void);
yaml_free(value_0.prefix as *mut libc::c_void); yaml_free(value_0.prefix as *mut libc::c_void);
} }
yaml_free(tag_directives_copy.start as *mut libc::c_void); STACK_DEL!(tag_directives_copy);
tag_directives_copy.end = ptr::null_mut::<yaml_tag_directive_t>();
tag_directives_copy.top = tag_directives_copy.end;
tag_directives_copy.start = tag_directives_copy.top;
yaml_free(value.handle as *mut libc::c_void); yaml_free(value.handle as *mut libc::c_void);
yaml_free(value.prefix as *mut libc::c_void); yaml_free(value.prefix as *mut libc::c_void);
0_i32 0_i32
@ -1557,29 +1452,17 @@ pub unsafe fn yaml_document_delete(document: *mut yaml_document_t) {
yaml_free(node.data.scalar.value as *mut libc::c_void); yaml_free(node.data.scalar.value as *mut libc::c_void);
} }
2 => { 2 => {
yaml_free(node.data.sequence.items.start as *mut libc::c_void); STACK_DEL!(node.data.sequence.items);
node.data.sequence.items.end = ptr::null_mut::<yaml_node_item_t>();
node.data.sequence.items.top = node.data.sequence.items.end;
node.data.sequence.items.start = node.data.sequence.items.top;
} }
3 => { 3 => {
yaml_free(node.data.mapping.pairs.start as *mut libc::c_void); STACK_DEL!(node.data.mapping.pairs);
node.data.mapping.pairs.end = ptr::null_mut::<yaml_node_pair_t>();
node.data.mapping.pairs.top = node.data.mapping.pairs.end;
node.data.mapping.pairs.start = node.data.mapping.pairs.top;
} }
_ => { _ => {
__assert!(false); __assert!(false);
} }
} }
} }
yaml_free((*document).nodes.start as *mut libc::c_void); STACK_DEL!((*document).nodes);
let fresh183 = addr_of_mut!((*document).nodes.end);
*fresh183 = ptr::null_mut::<yaml_node_t>();
let fresh184 = addr_of_mut!((*document).nodes.top);
*fresh184 = *fresh183;
let fresh185 = addr_of_mut!((*document).nodes.start);
*fresh185 = *fresh184;
yaml_free((*document).version_directive as *mut libc::c_void); yaml_free((*document).version_directive as *mut libc::c_void);
tag_directive = (*document).tag_directives.start; tag_directive = (*document).tag_directives.start;
while tag_directive != (*document).tag_directives.end { while tag_directive != (*document).tag_directives.end {
@ -1764,10 +1647,7 @@ pub unsafe fn yaml_document_add_sequence(
} }
} }
} }
yaml_free(items.start as *mut libc::c_void); STACK_DEL!(items);
items.end = ptr::null_mut::<yaml_node_item_t>();
items.top = items.end;
items.start = items.top;
yaml_free(tag_copy as *mut libc::c_void); yaml_free(tag_copy as *mut libc::c_void);
0_i32 0_i32
} }
@ -1832,10 +1712,7 @@ pub unsafe fn yaml_document_add_mapping(
} }
} }
} }
yaml_free(pairs.start as *mut libc::c_void); STACK_DEL!(pairs);
pairs.end = ptr::null_mut::<yaml_node_pair_t>();
pairs.top = pairs.end;
pairs.start = pairs.top;
yaml_free(tag_copy as *mut libc::c_void); yaml_free(tag_copy as *mut libc::c_void);
0_i32 0_i32
} }

View file

@ -197,26 +197,14 @@ unsafe fn yaml_emitter_delete_document_and_anchors(mut emitter: *mut yaml_emitte
} }
} }
if node.type_ as libc::c_uint == YAML_SEQUENCE_NODE as libc::c_int as libc::c_uint { if node.type_ as libc::c_uint == YAML_SEQUENCE_NODE as libc::c_int as libc::c_uint {
yaml_free(node.data.sequence.items.start as *mut libc::c_void); STACK_DEL!(node.data.sequence.items);
node.data.sequence.items.end = ptr::null_mut::<yaml_node_item_t>();
node.data.sequence.items.top = node.data.sequence.items.end;
node.data.sequence.items.start = node.data.sequence.items.top;
} }
if node.type_ as libc::c_uint == YAML_MAPPING_NODE as libc::c_int as libc::c_uint { if node.type_ as libc::c_uint == YAML_MAPPING_NODE as libc::c_int as libc::c_uint {
yaml_free(node.data.mapping.pairs.start as *mut libc::c_void); STACK_DEL!(node.data.mapping.pairs);
node.data.mapping.pairs.end = ptr::null_mut::<yaml_node_pair_t>();
node.data.mapping.pairs.top = node.data.mapping.pairs.end;
node.data.mapping.pairs.start = node.data.mapping.pairs.top;
} }
index += 1; index += 1;
} }
yaml_free((*(*emitter).document).nodes.start as *mut libc::c_void); STACK_DEL!((*(*emitter).document).nodes);
let fresh3 = addr_of_mut!((*(*emitter).document).nodes.end);
*fresh3 = ptr::null_mut::<yaml_node_t>();
let fresh4 = addr_of_mut!((*(*emitter).document).nodes.top);
*fresh4 = *fresh3;
let fresh5 = addr_of_mut!((*(*emitter).document).nodes.start);
*fresh5 = *fresh4;
yaml_free((*emitter).anchors as *mut libc::c_void); yaml_free((*emitter).anchors as *mut libc::c_void);
let fresh6 = addr_of_mut!((*emitter).anchors); let fresh6 = addr_of_mut!((*emitter).anchors);
*fresh6 = ptr::null_mut::<yaml_anchors_t>(); *fresh6 = ptr::null_mut::<yaml_anchors_t>();

View file

@ -131,13 +131,7 @@ unsafe fn yaml_parser_delete_aliases(parser: *mut yaml_parser_t) {
*fresh12 = (*fresh12).wrapping_offset(-1); *fresh12 = (*fresh12).wrapping_offset(-1);
yaml_free((**fresh12).anchor as *mut libc::c_void); yaml_free((**fresh12).anchor as *mut libc::c_void);
} }
yaml_free((*parser).aliases.start as *mut libc::c_void); STACK_DEL!((*parser).aliases);
let fresh13 = addr_of_mut!((*parser).aliases.end);
*fresh13 = ptr::null_mut::<yaml_alias_data_t>();
let fresh14 = addr_of_mut!((*parser).aliases.top);
*fresh14 = *fresh13;
let fresh15 = addr_of_mut!((*parser).aliases.start);
*fresh15 = *fresh14;
} }
unsafe fn yaml_parser_load_document( unsafe fn yaml_parser_load_document(
@ -164,16 +158,10 @@ unsafe fn yaml_parser_load_document(
return 0_i32; return 0_i32;
} }
if yaml_parser_load_nodes(parser, addr_of_mut!(ctx)) == 0 { if yaml_parser_load_nodes(parser, addr_of_mut!(ctx)) == 0 {
yaml_free(ctx.start as *mut libc::c_void); STACK_DEL!(ctx);
ctx.end = ptr::null_mut::<libc::c_int>();
ctx.top = ctx.end;
ctx.start = ctx.top;
return 0_i32; return 0_i32;
} }
yaml_free(ctx.start as *mut libc::c_void); STACK_DEL!(ctx);
ctx.end = ptr::null_mut::<libc::c_int>();
ctx.top = ctx.end;
ctx.start = ctx.top;
1_i32 1_i32
} }

View file

@ -409,7 +409,12 @@ macro_rules! STACK_INIT {
} }
macro_rules! STACK_DEL { macro_rules! STACK_DEL {
() => {}; // TODO ($stack:expr) => {
yaml_free($stack.start as *mut libc::c_void);
$stack.end = ptr::null_mut();
$stack.top = ptr::null_mut();
$stack.start = ptr::null_mut();
};
} }
macro_rules! STACK_EMPTY { macro_rules! STACK_EMPTY {

View file

@ -1482,19 +1482,13 @@ unsafe fn yaml_parser_process_directives(
*tag_directives_end_ref = *tag_directives_end_ref =
ptr::null_mut::<yaml_tag_directive_t>(); ptr::null_mut::<yaml_tag_directive_t>();
*tag_directives_start_ref = *tag_directives_end_ref; *tag_directives_start_ref = *tag_directives_end_ref;
yaml_free(tag_directives.start as *mut libc::c_void); STACK_DEL!(tag_directives);
tag_directives.end = ptr::null_mut::<yaml_tag_directive_t>();
tag_directives.top = tag_directives.end;
tag_directives.start = tag_directives.top;
} else { } else {
*tag_directives_start_ref = tag_directives.start; *tag_directives_start_ref = tag_directives.start;
*tag_directives_end_ref = tag_directives.top; *tag_directives_end_ref = tag_directives.top;
} }
} else { } else {
yaml_free(tag_directives.start as *mut libc::c_void); STACK_DEL!(tag_directives);
tag_directives.end = ptr::null_mut::<yaml_tag_directive_t>();
tag_directives.top = tag_directives.end;
tag_directives.start = tag_directives.top;
} }
if version_directive_ref.is_null() { if version_directive_ref.is_null() {
yaml_free(version_directive as *mut libc::c_void); yaml_free(version_directive as *mut libc::c_void);
@ -1513,10 +1507,7 @@ unsafe fn yaml_parser_process_directives(
yaml_free(tag_directive.handle as *mut libc::c_void); yaml_free(tag_directive.handle as *mut libc::c_void);
yaml_free(tag_directive.prefix as *mut libc::c_void); yaml_free(tag_directive.prefix as *mut libc::c_void);
} }
yaml_free(tag_directives.start as *mut libc::c_void); STACK_DEL!(tag_directives);
tag_directives.end = ptr::null_mut::<yaml_tag_directive_t>();
tag_directives.top = tag_directives.end;
tag_directives.start = tag_directives.top;
0_i32 0_i32
} }