Skip to content

Commit

Permalink
Update style to be consistent (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRobinsonMSFT authored Aug 15, 2023
1 parent 283750a commit dcfa890
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 115 deletions.
34 changes: 17 additions & 17 deletions src/dnmd/deltas.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
static bool append_heaps_from_delta(mdcxt_t* cxt, mdcxt_t* delta)
{
assert(delta != NULL);

if (!append_heap(cxt, delta, mdtc_hstring))
return false;

Expand Down Expand Up @@ -36,13 +36,13 @@ typedef enum
// We'll strip this high bit if it is set since we don't need it.
#define RemoveRecordBit(x) (x & 0x7fffffff)

typedef struct _map_table_group_t
typedef struct map_table_group__
{
mdcursor_t start;
uint32_t count;
} map_table_group_t;

typedef struct _enc_token_map_t
typedef struct enc_token_map__
{
map_table_group_t map_cur_by_table[MDTABLE_MAX_COUNT];
} enc_token_map_t;
Expand Down Expand Up @@ -71,7 +71,7 @@ static bool initialize_token_map(mdtable_t* map, enc_token_map_t* token_map)
mdToken tk;
if (1 != md_get_column_value_as_constant(map_cur, mdtENCMap_Token, 1, &tk))
return false;

mdtable_id_t table_id = ExtractTokenType(RemoveRecordBit(tk));

if (table_id < mdtid_First || table_id >= mdtid_End)
Expand Down Expand Up @@ -124,14 +124,14 @@ static bool resolve_token(enc_token_map_t* token_map, mdToken referenced_token,
mdToken mappedToken;
if (1 != md_get_column_value_as_constant(map_record, mdtENCMap_Token, 1, &mappedToken))
return false;

assert((mdtable_id_t)ExtractTokenType(RemoveRecordBit(mappedToken)) == type);
if (RidFromToken(mappedToken) == rid)
{
return md_token_to_cursor(delta_image, TokenFromRid(i + 1, CreateTokenType(type)), row_in_delta);
}
}

// If we have a set of remapped tokens for a table,
// we will remap all tokens in the EncLog.
return false;
Expand Down Expand Up @@ -256,19 +256,19 @@ static bool process_log(mdcxt_t* cxt, mdcxt_t* delta)

if (rid == 0)
return false;

// Resolve the token in the delta image that has the data that we need to copy to the base image.
mdcursor_t delta_record;
if (!resolve_token(&token_map, tk, delta, &delta_record))
return false;

// Try resolving the original token to determine what row we're editing.
// We'll try to look up the row in the base image.
// If we fail to resolve the original token, then we aren't editing an existing row,
// but instead creating a new row.
mdcursor_t record_to_edit;
bool edit_record = md_token_to_cursor(cxt, tk, &record_to_edit);

// We can only add rows directly to the end of the table.
// TODO: In the future, we could be smarter
// and try to insert a row in the middle of a table to preserve sorting.
Expand All @@ -285,14 +285,14 @@ static bool process_log(mdcxt_t* cxt, mdcxt_t* delta)
// The ENC Log is invalid.
if (table->row_count != (rid - 1))
return false;

if (!md_append_row(cxt, table_id, &record_to_edit))
return false;
}

if (!copy_cursor(record_to_edit, delta_record))
return false;

if (!edit_record)
md_commit_row_add(record_to_edit);

Expand Down Expand Up @@ -339,25 +339,25 @@ bool merge_in_delta(mdcxt_t* cxt, mdcxt_t* delta)
mdcursor_t base_module = create_cursor(&cxt->tables[mdtid_Module], 1);
mdcursor_t delta_module = create_cursor(&delta->tables[mdtid_Module], 1);

md_guid_t base_mvid;
mdguid_t base_mvid;
if (1 != md_get_column_value_as_guid(base_module, mdtModule_Mvid, 1, &base_mvid))
return false;

md_guid_t delta_mvid;
mdguid_t delta_mvid;
if (1 != md_get_column_value_as_guid(delta_module, mdtModule_Mvid, 1, &delta_mvid))
return false;

// MVIDs must match between base and delta images.
if (memcmp(&base_mvid, &delta_mvid, sizeof(md_guid_t)) != 0)
if (memcmp(&base_mvid, &delta_mvid, sizeof(mdguid_t)) != 0)
return false;

// The EncBaseId of the delta must equal the EncId of the base image.
// This ensures that we are applying deltas in order.
md_guid_t enc_id;
md_guid_t delta_enc_base_id;
mdguid_t enc_id;
mdguid_t delta_enc_base_id;
if (1 != md_get_column_value_as_guid(base_module, mdtModule_EncId, 1, &enc_id)
|| 1 != md_get_column_value_as_guid(delta_module, mdtModule_EncBaseId, 1, &delta_enc_base_id)
|| memcmp(&enc_id, &delta_enc_base_id, sizeof(md_guid_t)) != 0)
|| memcmp(&enc_id, &delta_enc_base_id, sizeof(mdguid_t)) != 0)
{
return false;
}
Expand Down
46 changes: 23 additions & 23 deletions src/dnmd/editor.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "dnmd.h"
#include "internal.h"

typedef struct _mdtable_editor_t
typedef struct mdtable_editor__
{
mddata_t data; // If non-null, points to allocated data for the table.
mdtable_t* table; // The read-only table that corresponds to this editor.
} mdtable_editor_t;

typedef struct _md_heap_editor_t
typedef struct md_heap_editor__
{
mddata_t heap; // If non-null, points to allocated data for the heap.
mdstream_t* stream; // The read-only stream that corresponds to this editor.
} md_heap_editor_t;

typedef struct _mdeditor_t
typedef struct mdeditor__
{
mdcxt_t* cxt; // Non-null is indication of complete initialization

Expand All @@ -31,7 +31,7 @@ static mdeditor_t* get_editor(mdcxt_t* cxt)
{
if (cxt->editor != NULL)
return cxt->editor;

assert(cxt->editor == NULL);
// If we haven't edited yet, initialize the table editor.
size_t editor_mem = align_to(sizeof(mdeditor_t), sizeof(void*));
Expand Down Expand Up @@ -180,7 +180,7 @@ static bool copy_row(uint8_t** dest, size_t* dest_len, mdtcol_t const* dest_cols
return false;
}
}

return true;
}

Expand All @@ -198,7 +198,7 @@ static bool set_column_size_for_max_row_count(mdeditor_t* editor, mdtable_t* tab
else if (updated_heap == mdtc_hguid)
{
mdstream_t* stream = get_heap_by_id(table->cxt, updated_heap);
initial_row_count = (uint32_t)(stream->size / sizeof(md_guid_t));
initial_row_count = (uint32_t)(stream->size / sizeof(mdguid_t));
}
else
{
Expand Down Expand Up @@ -408,7 +408,7 @@ bool allocate_new_table(mdcxt_t* cxt, mdtable_id_t table_id)
bool insert_row_into_table(mdcxt_t* cxt, mdtable_id_t table_id, uint32_t row_index, mdcursor_t* new_row)
{
assert(row_index != 0); // Row indexes are 1-based.
mdeditor_t* editor = get_editor(cxt);
mdeditor_t* editor = get_editor(cxt);
if (editor == NULL)
return false;

Expand All @@ -422,7 +422,7 @@ bool insert_row_into_table(mdcxt_t* cxt, mdtable_id_t table_id, uint32_t row_ind
// We can either insert a row in the middle of a table or directly after the end of the table.
if (target_table_editor->table->row_count < (row_index - 1))
return false;

// If we are out of space in our table, then we need to allocate a new table buffer.
if (target_table_editor->data.ptr == NULL || target_table_editor->data.size < target_table_editor->table->row_size_bytes * (size_t)(target_table_editor->table->row_count + 1))
{
Expand Down Expand Up @@ -486,7 +486,7 @@ static bool reserve_heap_space(mdeditor_t* editor, uint32_t space_size, mdtcol_t
{
// Set the default heap size based on likely reasonable sizes for the heaps.
// In most images, there won't be more than three guids, so we can start with a small heap in that case.
const size_t initial_heap_size = heap_id == mdtc_hguid ? sizeof(md_guid_t) * 3 : 0x100;
const size_t initial_heap_size = heap_id == mdtc_hguid ? sizeof(mdguid_t) * 3 : 0x100;
void* mem = alloc_mdmem(editor->cxt, initial_heap_size);
if (mem == NULL)
return false;
Expand All @@ -497,7 +497,7 @@ static bool reserve_heap_space(mdeditor_t* editor, uint32_t space_size, mdtcol_t

// The first character in the strings heap must be the '\0' - II.24.2.3
// The first character in the user_string and blob heaps must be the 0 - II.24.2.4
// The guid heap doesn't start with a 0 byte, but it must be emitted in sizeof(md_guid_t)-based chuncks.
// The guid heap doesn't start with a 0 byte, but it must be emitted in sizeof(mdguid_t)-based chuncks.
// If we are preserving offsets, then we don't initialize the heap, as we will be copying an existing heap that has already been validated and
// we must have the exact same offsets as the existing heap to avoid breaking heap references.
if (heap_id != mdtc_hguid && !preserve_offsets)
Expand All @@ -508,7 +508,7 @@ static bool reserve_heap_space(mdeditor_t* editor, uint32_t space_size, mdtcol_t
}

*heap_offset = (uint32_t)heap_editor->stream->size;

if (*heap_offset > UINT32_MAX - space_size)
{
// The max heap size is 2^32-1, so we don't have space left to allocate.
Expand All @@ -524,7 +524,7 @@ static bool reserve_heap_space(mdeditor_t* editor, uint32_t space_size, mdtcol_t
}

// Update heap references in case the additional used space crosses the boundary for index sizes.
uint32_t index_scale = (heap_id == mdtc_hguid ? sizeof(md_guid_t) : 1);
uint32_t index_scale = (heap_id == mdtc_hguid ? sizeof(mdguid_t) : 1);
assert(heap_editor->stream->size % index_scale == 0);
for (mdtable_id_t i = mdtid_First; i < mdtid_End; i++)
{
Expand All @@ -549,7 +549,7 @@ uint32_t add_to_string_heap(mdcxt_t* cxt, char const* str)
mdeditor_t* editor = get_editor(cxt);
if (editor == NULL)
return 0;

// TODO: Deduplicate heap
uint32_t str_len = (uint32_t)strlen(str);
uint32_t heap_offset;
Expand All @@ -572,7 +572,7 @@ uint32_t add_to_blob_heap(mdcxt_t* cxt, uint8_t const* data, uint32_t length)
size_t compressed_length_size = 0;
if (!compress_u32(length, compressed_length, &compressed_length_size))
return 0;

uint32_t heap_slot_size = length + (uint32_t)compressed_length_size;

uint32_t heap_offset;
Expand Down Expand Up @@ -604,7 +604,7 @@ uint32_t add_to_user_string_heap(mdcxt_t* cxt, char16_t const* str)
// This final byte holds the value 1 if and only if any UTF16 character
// within the string has any bit set in its top byte,
// or its low byte is any of the following: 0x01-0x08, 0x0E–0x1F, 0x27, 0x2D, 0x7F.
// Otherwise, it holds 0.
// Otherwise, it holds 0.
if ((c & 0x80) != 0)
{
has_special_char = 1;
Expand All @@ -630,12 +630,12 @@ uint32_t add_to_user_string_heap(mdcxt_t* cxt, char16_t const* str)
has_special_char = 1;
}
}

uint8_t compressed_length[sizeof(str_len)];
size_t compressed_length_size = 0;
if (!compress_u32(str_len, compressed_length, &compressed_length_size))
return 0;

uint32_t heap_slot_size = str_len + (uint32_t)compressed_length_size + 1;
uint32_t heap_offset;
if (!reserve_heap_space(editor, heap_slot_size, mdtc_hus, false, &heap_offset))
Expand All @@ -650,21 +650,21 @@ uint32_t add_to_user_string_heap(mdcxt_t* cxt, char16_t const* str)
return heap_offset;
}

uint32_t add_to_guid_heap(mdcxt_t* cxt, md_guid_t guid)
uint32_t add_to_guid_heap(mdcxt_t* cxt, mdguid_t guid)
{
mdeditor_t* editor = get_editor(cxt);
if (editor == NULL)
return 0;
// TODO: Deduplicate heap

uint32_t heap_offset;
if (!reserve_heap_space(editor, sizeof(md_guid_t), mdtc_hguid, false, &heap_offset))
if (!reserve_heap_space(editor, sizeof(mdguid_t), mdtc_hguid, false, &heap_offset))
{
return 0;
}

memcpy(editor->guid_heap.heap.ptr + heap_offset, &guid, sizeof(md_guid_t));
return heap_offset / sizeof(md_guid_t);
memcpy(editor->guid_heap.heap.ptr + heap_offset, &guid, sizeof(mdguid_t));
return heap_offset / sizeof(mdguid_t);
}

bool append_heap(mdcxt_t* cxt, mdcxt_t* delta, mdtcol_t heap_id)
Expand All @@ -678,7 +678,7 @@ bool append_heap(mdcxt_t* cxt, mdcxt_t* delta, mdtcol_t heap_id)
mdstream_t* delta_heap = get_heap_by_id(delta, heap_id);
if (delta_heap->size == 0)
return true;

size_t copy_offset;
size_t delta_size;
if (is_minimal_delta && heap_id != mdtc_hguid)
Expand Down Expand Up @@ -715,6 +715,6 @@ mduserstringcursor_t md_add_userstring_to_heap(mdhandle_t handle, char16_t const
mdcxt_t* cxt = extract_mdcxt(handle);
if (cxt == NULL)
return 0;

return add_to_user_string_heap(cxt, userstring);
}
6 changes: 3 additions & 3 deletions src/dnmd/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ bool md_apply_delta(mdhandle_t handle, void const* data, size_t data_len)
return result;
}

typedef struct _mdmem_t
typedef struct mdmem__
{
mdmem_t* next;
struct mdmem__* next;
size_t size;
uint8_t data[];
} mdmem_t;
Expand Down Expand Up @@ -322,7 +322,7 @@ static bool dump_table_rows(mdtable_t* table)
}

char const* str;
md_guid_t guid;
mdguid_t guid;
uint8_t const* blob;
uint32_t blob_len;
uint32_t constant;
Expand Down
Loading

0 comments on commit dcfa890

Please sign in to comment.