|
15 | 15 | #include "upb/hash/str_table.h" |
16 | 16 | #include "upb/mem/arena.h" |
17 | 17 | #include "upb/mini_table/extension.h" |
| 18 | +#include "upb/mini_table/generated_registry.h" |
| 19 | +#include "upb/mini_table/internal/generated_registry.h" |
18 | 20 | #include "upb/mini_table/message.h" |
19 | 21 |
|
20 | 22 | // Must be last. |
@@ -89,25 +91,46 @@ upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray( |
89 | 91 | return status; |
90 | 92 | } |
91 | 93 |
|
92 | | -#ifdef UPB_LINKARR_DECLARE |
93 | | - |
94 | | -UPB_LINKARR_DECLARE(upb_AllExts, const upb_MiniTableExtension); |
| 94 | +const UPB_PRIVATE(upb_GeneratedExtensionListEntry) * |
| 95 | + UPB_PRIVATE(upb_generated_extension_list) = NULL; |
95 | 96 |
|
96 | 97 | bool upb_ExtensionRegistry_AddAllLinkedExtensions(upb_ExtensionRegistry* r) { |
97 | | - const upb_MiniTableExtension* start = UPB_LINKARR_START(upb_AllExts); |
98 | | - const upb_MiniTableExtension* stop = UPB_LINKARR_STOP(upb_AllExts); |
99 | | - for (const upb_MiniTableExtension* p = start; p < stop; p++) { |
100 | | - // Windows can introduce zero padding, so we have to skip zeroes. |
101 | | - if (upb_MiniTableExtension_Number(p) != 0) { |
102 | | - if (upb_ExtensionRegistry_Add(r, p) != kUpb_ExtensionRegistryStatus_Ok) { |
| 98 | + const UPB_PRIVATE(upb_GeneratedExtensionListEntry)* entry = |
| 99 | + UPB_PRIVATE(upb_generated_extension_list); |
| 100 | + while (entry != NULL) { |
| 101 | + // Comparing pointers to different objects is undefined behavior, so we |
| 102 | + // convert them to uintptr_t and compare their values. |
| 103 | + uintptr_t begin = (uintptr_t)entry->start; |
| 104 | + uintptr_t end = (uintptr_t)entry->stop; |
| 105 | + uintptr_t current = begin; |
| 106 | + while (current < end) { |
| 107 | + const upb_MiniTableExtension* ext = |
| 108 | + (const upb_MiniTableExtension*)current; |
| 109 | + // Sentinels and padding introduced by the linker can result in zeroed |
| 110 | + // entries, so simply skip them. |
| 111 | + if (upb_MiniTableExtension_Number(ext) == 0) { |
| 112 | + // MSVC introduces padding that might not be sized exactly the same as |
| 113 | + // upb_MiniTableExtension, so we can't iterate by sizeof. This is a |
| 114 | + // valid thing for any linker to do, so it's safer to just always do it. |
| 115 | + current += UPB_ALIGN_OF(upb_MiniTableExtension); |
| 116 | + continue; |
| 117 | + } |
| 118 | + |
| 119 | + if (upb_ExtensionRegistry_Add(r, ext) != |
| 120 | + kUpb_ExtensionRegistryStatus_Ok) { |
103 | 121 | return false; |
104 | 122 | } |
| 123 | + current += sizeof(upb_MiniTableExtension); |
105 | 124 | } |
| 125 | + entry = entry->next; |
106 | 126 | } |
107 | 127 | return true; |
108 | 128 | } |
109 | 129 |
|
110 | | -#endif // UPB_LINKARR_DECLARE |
| 130 | +const upb_ExtensionRegistry* upb_ExtensionRegistry_GetGenerated( |
| 131 | + const upb_GeneratedRegistryRef* genreg) { |
| 132 | + return genreg != NULL ? genreg->registry : NULL; |
| 133 | +} |
111 | 134 |
|
112 | 135 | const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( |
113 | 136 | const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { |
|
0 commit comments