sapling/edenscm/hgext/extlib/cfastmanifest/tree_arena.h
Jun Wu c12e300bb8 codemod: move Python packages to edenscm
Summary:
Move top-level Python packages `mercurial`, `hgext` and `hgdemandimport` to
a new top-level package `edenscm`. This allows the Python packages provided by
the upstream Mercurial to be installed side-by-side.

To maintain compatibility, `edenscm/` gets added to `sys.path` in
`mercurial/__init__.py`.

Reviewed By: phillco, ikostia

Differential Revision: D13853115

fbshipit-source-id: b296b0673dc54c61ef6a591ebc687057ff53b22e
2019-01-28 18:35:41 -08:00

81 lines
2.2 KiB
C

// Copyright 2016-present Facebook. All Rights Reserved.
//
// tree_arena.h: declarations for methods to create a tree with a fixed
// memory arena and to allocate nodes from the fixed memory
// arena. for internal use only.
//
// no-check-code
#ifndef __FASTMANIFEST_TREE_ARENA_H__
#define __FASTMANIFEST_TREE_ARENA_H__
#include "edenscm/hgext/extlib/cfastmanifest/tree.h"
#include "node.h"
typedef enum {
ARENA_POLICY_FAIL, // fail immediately when there is
// insufficient space
ARENA_POLICY_REALLOC, // attempt to realloc until realloc
// fails.
} arena_policy_t;
typedef enum {
ARENA_ALLOC_OK,
ARENA_ALLOC_OOM,
ARENA_ALLOC_EXCEEDED_LIMITS,
} arena_alloc_node_code_t;
typedef struct _arena_alloc_node_result_t {
arena_alloc_node_code_t code;
node_t* node;
} arena_alloc_node_result_t;
static inline bool in_arena(const tree_t* tree, void* _ptr) {
intptr_t arena_start = (intptr_t)tree->arena;
intptr_t arena_end = arena_start + tree->arena_sz - 1;
intptr_t ptr = (intptr_t)_ptr;
if (ptr >= arena_start && ptr < arena_end) {
return true;
}
return false;
}
/**
* Allocate space for a node within a heap-allocated arena. If the arena does
* not have enough space for the node, consult the policy to determine what to
* do next.
*/
extern arena_alloc_node_result_t arena_alloc_node_helper(
arena_policy_t policy,
tree_t* tree,
const char* name,
size_t name_sz,
size_t max_children);
static inline arena_alloc_node_result_t arena_alloc_node(
tree_t* tree,
const char* name,
size_t name_sz,
size_t max_children) {
return arena_alloc_node_helper(
ARENA_POLICY_REALLOC, tree, name, name_sz, max_children);
}
static inline arena_alloc_node_result_t arena_alloc_node_strict(
tree_t* tree,
const char* name,
size_t name_sz,
size_t max_children) {
return arena_alloc_node_helper(
ARENA_POLICY_FAIL, tree, name, name_sz, max_children);
}
/**
* Creates a tree and sets up the shadow root node. This does *not* initialize
* the real root node. It is the responsibility of the caller to do so.
*/
extern tree_t* alloc_tree_with_arena(size_t arena_sz);
#endif /* #ifndef __FASTMANIFEST_TREE_ARENA_H__ */