From: Vibhav Pant <vibhavp(a)gmail.com> --- dlls/rometadata/assembly.c | 50 -------------------- dlls/rometadata/mdtables.c | 74 ++++++++++++++++++++++++++---- dlls/rometadata/rometadatapriv.h | 50 ++++++++++++++++++++ dlls/rometadata/tests/rometadata.c | 30 ++++++------ 4 files changed, 131 insertions(+), 73 deletions(-) diff --git a/dlls/rometadata/assembly.c b/dlls/rometadata/assembly.c index a76cf6099ec..83b8e7338bb 100644 --- a/dlls/rometadata/assembly.c +++ b/dlls/rometadata/assembly.c @@ -70,56 +70,6 @@ struct metadata_stream const BYTE *start; }; -enum table -{ - TABLE_MODULE = 0x00, - TABLE_TYPEREF = 0x01, - TABLE_TYPEDEF = 0x02, - TABLE_FIELDPTR = 0x03, - TABLE_FIELD = 0x04, - TABLE_METHODPTR = 0x05, - TABLE_METHODDEF = 0x06, - TABLE_PARAMPTR = 0x07, - TABLE_PARAM = 0x08, - TABLE_INTERFACEIMPL = 0x09, - TABLE_MEMBERREF = 0x0a, - TABLE_CONSTANT = 0x0b, - TABLE_CUSTOMATTRIBUTE = 0x0c, - TABLE_FIELDMARSHAL = 0x0d, - TABLE_DECLSECURITY = 0x0e, - TABLE_CLASSLAYOUT = 0x0f, - TABLE_FIELDLAYOUT = 0x10, - TABLE_STANDALONESIG = 0x11, - TABLE_EVENTMAP = 0x12, - TABLE_EVENTPTR = 0x13, - TABLE_EVENT = 0x14, - TABLE_PROPERTYMAP = 0x15, - TABLE_PROPERTYPTR = 0x16, - TABLE_PROPERTY = 0x17, - TABLE_METHODSEMANTICS = 0x18, - TABLE_METHODIMPL = 0x19, - TABLE_MODULEREF = 0x1a, - TABLE_TYPESPEC = 0x1b, - TABLE_IMPLMAP = 0x1c, - TABLE_FIELDRVA = 0x1d, - TABLE_ENCLOG = 0x1e, - TABLE_ENCMAP = 0x1f, - TABLE_ASSEMBLY = 0x20, - TABLE_ASSEMBLYPROCESSOR = 0x21, - TABLE_ASSEMBLYOS = 0x22, - TABLE_ASSEMBLYREF = 0x23, - TABLE_ASSEMBLYREFPROCESSOR = 0x24, - TABLE_ASSEMBLYREFOS = 0x25, - TABLE_FILE = 0x26, - TABLE_EXPORTEDTYPE = 0x27, - TABLE_MANIFESTRESOURCE = 0x28, - TABLE_NESTEDCLASS = 0x29, - TABLE_GENERICPARAM = 0x2a, - TABLE_METHODSPEC = 0x2b, - TABLE_GENERICPARAMCONSTRAINT = 0x2c, - TABLE_MAX = 0x2d -}; - enum coded_idx_type { CT_TypeDefOrRef = 64, diff --git a/dlls/rometadata/mdtables.c b/dlls/rometadata/mdtables.c index 8c9f4825584..8c073a3f165 100644 --- a/dlls/rometadata/mdtables.c +++ b/dlls/rometadata/mdtables.c @@ -317,27 +317,85 @@ static ULONG WINAPI import_Release(IMetaDataImport *iface) return IMetaDataTables_Release(&impl->IMetaDataTables_iface); } +struct token_enum +{ + ULONG count; + ULONG row_start; + ULONG row_cur; + ULONG row_end; +}; + +HRESULT token_enum_create(HCORENUM *out) +{ + struct token_enum *md_enum; + + if (!(md_enum = calloc(1, sizeof(*md_enum)))) return E_OUTOFMEMORY; + *out = md_enum; + return S_OK; +} + static void WINAPI import_CloseEnum(IMetaDataImport *iface, HCORENUM henum) { - FIXME("(%p, %p): stub!\n", iface, henum); + TRACE("(%p, %p)\n", iface, henum); + free(henum); } static HRESULT WINAPI import_CountEnum(IMetaDataImport *iface, HCORENUM henum, ULONG *count) { - FIXME("(%p, %p, %p): stub!\n", iface, henum, count); - return E_NOTIMPL; + const struct token_enum *md_enum = henum; + + TRACE("(%p, %p, %p)\n", iface, henum, count); + + *count = henum ? md_enum->count : 0; + return S_OK; } static HRESULT WINAPI import_ResetEnum(IMetaDataImport *iface, HCORENUM henum, ULONG idx) { - FIXME("(%p, %p, %lu): stub\n", iface, henum, idx); - return E_NOTIMPL; + struct token_enum *md_enum = henum; + + TRACE("(%p, %p, %lu)\n", iface, henum, idx); + + if (henum) + md_enum->row_cur = md_enum->row_start + idx; + return S_OK; } -static HRESULT WINAPI import_EnumTypeDefs(IMetaDataImport *iface, HCORENUM *henum, mdTypeDef *typedefs, ULONG len, ULONG *count) +static HRESULT WINAPI import_EnumTypeDefs(IMetaDataImport *iface, HCORENUM *ret_henum, mdTypeDef *typedefs, ULONG len, ULONG *count) { - FIXME("(%p, %p, %p, %lu, %p): stub!\n", iface, henum, typedefs, len, count); - return E_NOTIMPL; + struct metadata_tables *impl = impl_from_IMetaDataImport(iface); + ULONG row_size, rows, cols, key_idx, i = 0; + struct token_enum *henum = *ret_henum; + const char *name; + HRESULT hr; + + TRACE("(%p, %p, %p, %lu, %p)\n", iface, ret_henum, typedefs, len, count); + + if (count) + *count = 0; + + if (!henum) + { + hr = IMetaDataTables_GetTableInfo(&impl->IMetaDataTables_iface, TABLE_TYPEDEF, &row_size, &rows, &cols, + &key_idx, &name); + if (FAILED(hr)) return hr; + /* Skip the <Module> row. */ + if (rows < 2) return S_FALSE; + if (FAILED((hr = token_enum_create((HCORENUM *)&henum)))) return hr; + + henum->count = rows - 1; + henum->row_start = henum->row_cur = 2; + henum->row_end = rows; + *ret_henum = henum; + } + + while (henum->row_cur <= henum->row_end && i < len) + typedefs[i++] = TokenFromRid(henum->row_cur++, mdtTypeDef); + + if (count) + *count = i; + + return i ? S_OK : S_FALSE; } static HRESULT WINAPI import_EnumInterfaceImpls(IMetaDataImport *iface, HCORENUM *henum, mdTypeDef type_def, diff --git a/dlls/rometadata/rometadatapriv.h b/dlls/rometadata/rometadatapriv.h index 3e5ddaf8649..e91a50a133f 100644 --- a/dlls/rometadata/rometadatapriv.h +++ b/dlls/rometadata/rometadatapriv.h @@ -54,6 +54,56 @@ enum heap_type HEAP_USER_STRING = 3 }; +enum table +{ + TABLE_MODULE = 0x00, + TABLE_TYPEREF = 0x01, + TABLE_TYPEDEF = 0x02, + TABLE_FIELDPTR = 0x03, + TABLE_FIELD = 0x04, + TABLE_METHODPTR = 0x05, + TABLE_METHODDEF = 0x06, + TABLE_PARAMPTR = 0x07, + TABLE_PARAM = 0x08, + TABLE_INTERFACEIMPL = 0x09, + TABLE_MEMBERREF = 0x0a, + TABLE_CONSTANT = 0x0b, + TABLE_CUSTOMATTRIBUTE = 0x0c, + TABLE_FIELDMARSHAL = 0x0d, + TABLE_DECLSECURITY = 0x0e, + TABLE_CLASSLAYOUT = 0x0f, + TABLE_FIELDLAYOUT = 0x10, + TABLE_STANDALONESIG = 0x11, + TABLE_EVENTMAP = 0x12, + TABLE_EVENTPTR = 0x13, + TABLE_EVENT = 0x14, + TABLE_PROPERTYMAP = 0x15, + TABLE_PROPERTYPTR = 0x16, + TABLE_PROPERTY = 0x17, + TABLE_METHODSEMANTICS = 0x18, + TABLE_METHODIMPL = 0x19, + TABLE_MODULEREF = 0x1a, + TABLE_TYPESPEC = 0x1b, + TABLE_IMPLMAP = 0x1c, + TABLE_FIELDRVA = 0x1d, + TABLE_ENCLOG = 0x1e, + TABLE_ENCMAP = 0x1f, + TABLE_ASSEMBLY = 0x20, + TABLE_ASSEMBLYPROCESSOR = 0x21, + TABLE_ASSEMBLYOS = 0x22, + TABLE_ASSEMBLYREF = 0x23, + TABLE_ASSEMBLYREFPROCESSOR = 0x24, + TABLE_ASSEMBLYREFOS = 0x25, + TABLE_FILE = 0x26, + TABLE_EXPORTEDTYPE = 0x27, + TABLE_MANIFESTRESOURCE = 0x28, + TABLE_NESTEDCLASS = 0x29, + TABLE_GENERICPARAM = 0x2a, + TABLE_METHODSPEC = 0x2b, + TABLE_GENERICPARAMCONSTRAINT = 0x2c, + TABLE_MAX = 0x2d +}; + extern HRESULT assembly_open_from_file(const WCHAR *path, assembly_t **out); extern void assembly_free(assembly_t *assembly); extern HRESULT assembly_get_table(const assembly_t *assembly, ULONG table_idx, struct metadata_table_info *info); diff --git a/dlls/rometadata/tests/rometadata.c b/dlls/rometadata/tests/rometadata.c index a4fa39c6f5a..c8e33d86a81 100644 --- a/dlls/rometadata/tests/rometadata.c +++ b/dlls/rometadata/tests/rometadata.c @@ -1005,21 +1005,21 @@ static void test_IMetaDataImport(void) buf_count = 0xdeadbeef; henum = NULL; hr = IMetaDataImport_EnumTypeDefs(md_import, &henum, NULL, 0, &buf_count); - todo_wine ok(hr == S_FALSE, "got hr %#lx\n", hr); - todo_wine ok(buf_count == 0, "got buf_reqd %lu\n", buf_count); - todo_wine ok(!!henum, "got henum %p\n", henum); + ok(hr == S_FALSE, "got hr %#lx\n", hr); + ok(buf_count == 0, "got buf_reqd %lu\n", buf_count); + ok(!!henum, "got henum %p\n", henum); buf_len = 0; hr = IMetaDataImport_CountEnum(md_import, henum, &buf_len); - todo_wine ok(hr == S_OK, "got hr %#lx\n", hr); + ok(hr == S_OK, "got hr %#lx\n", hr); /* The <Module> typedef is ommitted. */ - todo_wine ok(buf_len == ARRAY_SIZE(type_defs), "got len %lu\n", buf_len); + ok(buf_len == ARRAY_SIZE(type_defs), "got len %lu\n", buf_len); typedef_tokens = calloc(buf_len, sizeof(*typedef_tokens)); ok(!!typedef_tokens, "got typedef_tokens %p\n", typedef_tokens); hr = IMetaDataImport_EnumTypeDefs(md_import, &henum, typedef_tokens, buf_len, &buf_count); - todo_wine ok(hr == S_OK, "got hr %#lx\n", hr); - todo_wine ok(buf_len == buf_count, "got len %lu != %lu\n", buf_len, buf_count); + ok(hr == S_OK, "got hr %#lx\n", hr); + ok(buf_len == buf_count, "got len %lu != %lu\n", buf_len, buf_count); for (i = 0; i < buf_len; i++) { const struct type_info *info = &type_defs[i]; @@ -1077,16 +1077,16 @@ static void test_IMetaDataImport(void) winetest_pop_context(); } hr = IMetaDataImport_EnumTypeDefs(md_import, &henum, typedef_tokens, buf_len, &buf_count); - todo_wine ok(hr == S_FALSE, "got hr %#lx\n", hr); + ok(hr == S_FALSE, "got hr %#lx\n", hr); hr = IMetaDataImport_ResetEnum(md_import, henum, 0); - todo_wine ok(hr == S_OK, "got hr %#lx\n", hr); + ok(hr == S_OK, "got hr %#lx\n", hr); buf_count = 0xdeadbeef; hr = IMetaDataImport_EnumTypeDefs(md_import, &henum, typedef_tokens, buf_len, &buf_count); - todo_wine ok(hr == S_OK, "got hr %#lx\n", hr); - todo_wine ok(buf_len == buf_count, "got len %lu != %lu\n", buf_len, buf_count); + ok(hr == S_OK, "got hr %#lx\n", hr); + ok(buf_len == buf_count, "got len %lu != %lu\n", buf_len, buf_count); hr = IMetaDataImport_EnumTypeDefs(md_import, &henum, typedef_tokens, buf_len, &buf_count); - todo_wine ok(hr == S_FALSE, "got hr %#lx\n", hr); + ok(hr == S_FALSE, "got hr %#lx\n", hr); IMetaDataImport_CloseEnum(md_import, henum); free(typedef_tokens); @@ -1109,7 +1109,7 @@ static void test_IMetaDataImport(void) todo_wine ok(buf_count == 0, "got buf_reqd %lu\n", buf_count); buf_len = 0; hr = IMetaDataImport_CountEnum(md_import, henum, &buf_len); - todo_wine ok(hr == S_OK, "got hr %#lx\n", hr); + ok(hr == S_OK, "got hr %#lx\n", hr); todo_wine ok(buf_len == ARRAY_SIZE(test2_methods), "got buf_len %#lx\n" , buf_len); methoddef_tokens = calloc(buf_len, sizeof(*methoddef_tokens)); ok(!!methoddef_tokens, "got methoddef_tokens %p\n", methoddef_tokens); @@ -1174,7 +1174,7 @@ static void test_IMetaDataImport(void) todo_wine ok(buf_count == 0, "got buf_count %lu\n", buf_count); buf_len = 0; hr = IMetaDataImport_CountEnum(md_import, henum, &buf_len); - todo_wine ok(hr == S_OK, "got hr %#lx\n", hr); + ok(hr == S_OK, "got hr %#lx\n", hr); todo_wine ok(buf_len == fields_len, "got buf_len %lu\n", buf_len); fielddef_tokens = calloc(buf_len, sizeof(*fielddef_tokens)); ok(!!fielddef_tokens, "got fielddef_tokens %p\n", fielddef_tokens); @@ -1241,7 +1241,7 @@ static void test_IMetaDataImport(void) hr = IMetaDataImport_EnumProperties(md_import, &henum, typedef1, NULL, 0, NULL); todo_wine ok(hr == S_FALSE, "got hr %#lx\n", hr); hr = IMetaDataImport_CountEnum(md_import, henum, &buf_len); - todo_wine ok(hr == S_OK, "got hr %#lx\n", hr); + ok(hr == S_OK, "got hr %#lx\n", hr); todo_wine ok(buf_len == ARRAY_SIZE(test3_props), "got buf_len %lu\n", buf_len); property_tokens = calloc(buf_len, sizeof(*property_tokens)); ok(!!property_tokens, "got property_tokens %p\n", property_tokens); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9525