sapling/cfastmanifest/tests.c
Kostia Balytskyi 918e1011b3 portability: use COMPOUND_LITERAL macro in place of actual compound literals
Summary:
This is a s//g replacement of all the `return (type_name) {` with
`return COMPOUND_LITERAL(type_name) {`.
This is the command which produced the diff:
`egrep 'return \(\w*\) \{' -Ir . --exclude='*.py*' --exclude-dir=.hg -l | xargs sed 's/return (\(\w*\)) {/return COMPOUND_LITERAL(\1) {/g' -i `

After I've done this, I checked:
`egrep '\(\w+\) \{' -Ir . --exclude='*.py*' --exclude-dir=.hg | egrep -v '(switch|while)' | grep -v 'if (' | grep -v 'COMPOUND_LITERAL' | less`
and it looks like the only things of `(something) {` syntax are function definitions, adding space before `(` in search pattern yields no results.

This is needed to make this compile on Windows under MSVC2015.

Depends on: D4843230

Test Plan:
- run `python setup.py build -f`, see it compile
- run all the tests, see them pass

Reviewers: #sourcecontrol, rmcelroy

Reviewed By: rmcelroy

Subscribers: rmcelroy, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4843240

Signature: t1:4843240:1491495690:a097bfab403805052d5ac25d1db7bb32af3bca28
2017-04-06 09:34:40 -07:00

79 lines
2.2 KiB
C

// Copyright 2016-present Facebook. All Rights Reserved.
//
// tests.c: convenience functions for unit tests.
//
// no-check-code
#include "node.h"
#include "tree.h"
#include "tree_path.h"
#include "tests.h"
typedef struct _get_path_unfiltered_metadata_t {
node_t *node;
} get_path_unfiltered_metadata_t;
static find_path_callback_result_t get_path_unfiltered_callback(
tree_t *tree,
node_t *const root_parent,
node_t *root,
const char *name, const size_t name_sz,
tree_state_changes_t *changes,
void *context) {
get_path_unfiltered_metadata_t *metadata =
(get_path_unfiltered_metadata_t *) context;
// does the path already exist?
node_t *child = get_child_by_name(root, name, name_sz);
if (child == NULL) {
return COMPOUND_LITERAL(find_path_callback_result_t) {
FIND_PATH_NOT_FOUND, root};
}
metadata->node = child;
return COMPOUND_LITERAL(find_path_callback_result_t) {FIND_PATH_OK, root};
}
get_path_unfiltered_result_t get_path_unfiltered(
tree_t *tree,
const char *path,
const size_t path_sz) {
tree_state_changes_t changes = {0};
get_path_unfiltered_metadata_t metadata;
node_t *shadow_root = tree->shadow_root;
node_t *real_root = get_child_by_index(shadow_root, 0);
if (real_root == NULL) {
return COMPOUND_LITERAL(get_path_unfiltered_result_t) {GET_PATH_WTF, NULL};
}
find_path_result_t result =
find_path(
tree,
shadow_root,
real_root,
path, path_sz,
BASIC_WALK_ALLOW_IMPLICIT_NODES,
&changes,
get_path_unfiltered_callback,
&metadata);
assert(changes.size_change == 0);
assert(changes.num_leaf_node_change == 0);
assert(changes.non_arena_allocations == false);
switch (result) {
case FIND_PATH_OK:
return COMPOUND_LITERAL(get_path_unfiltered_result_t) {GET_PATH_OK, metadata.node};
case FIND_PATH_NOT_FOUND:
case FIND_PATH_CONFLICT:
// `FIND_PATH_CONFLICT` is returned if there is a leaf node where we
// expect a directory node. this is treated the same as a NOT_FOUND.
return COMPOUND_LITERAL(get_path_unfiltered_result_t) {GET_PATH_NOT_FOUND, NULL};
default:
return COMPOUND_LITERAL(get_path_unfiltered_result_t) {GET_PATH_WTF, NULL};
}
}