Browse Source

[i18n] Fix segfault on destroy on Linux

Forgot to intern the section string in QT TS loader.
Jeroen van Rijn 3 years ago
parent
commit
ff0f0c447f
3 changed files with 27 additions and 20 deletions
  1. 14 10
      core/text/i18n/i18n.odin
  2. 4 1
      core/text/i18n/qt_linguist.odin
  3. 9 9
      tests/core/assets/I18N/duplicate-key.ts

+ 14 - 10
core/text/i18n/i18n.odin

@@ -163,16 +163,20 @@ get_by_slot :: proc{get_by_slot_single_section, get_by_slot_by_section}
 	- destroy(), to clean up the currently active catalog catalog i18n.ACTIVE
 	- destroy(catalog), to clean up a specific catalog.
 */
-destroy :: proc(catalog: ^Translation = ACTIVE) {
-	if catalog != nil {
-		strings.intern_destroy(&catalog.intern)
-		for section in &catalog.k_v {
-			for key in &catalog.k_v[section] {
-				delete(catalog.k_v[section][key])
-			}
-			delete(catalog.k_v[section])
+destroy :: proc(catalog: ^Translation = ACTIVE, allocator := context.allocator) {
+	context.allocator = allocator
+
+	if catalog == nil {
+		return
+	}
+
+	for section in &catalog.k_v {
+		for key in &catalog.k_v[section] {
+			delete(catalog.k_v[section][key])
 		}
-		delete(catalog.k_v)
-		free(catalog)
+		delete(catalog.k_v[section])
 	}
+	delete(catalog.k_v)
+	strings.intern_destroy(&catalog.intern)
+	free(catalog)
 }

+ 4 - 1
core/text/i18n/qt_linguist.odin

@@ -59,7 +59,10 @@ parse_qt_linguist_from_slice :: proc(data: []u8, options := DEFAULT_PARSE_OPTION
 			return translation, .TS_File_Expected_Context_Name,
 		}
 
-		section_name := "" if options.merge_sections else ts.elements[section_name_id].value
+		section_name := strings.intern_get(&translation.intern, "")
+		if !options.merge_sections {
+			section_name = strings.intern_get(&translation.intern, ts.elements[section_name_id].value)
+		}
 
 		if section_name not_in translation.k_v {
 			translation.k_v[section_name] = {}

+ 9 - 9
tests/core/assets/I18N/duplicate-key.ts

@@ -10,13 +10,13 @@
 	</message>
 </context>
 <context>
-		<name>apple_count</name>
-		<message numerus="yes">
-			<source>%d apple(s)</source>
-			<translation>
-				<numerusform>%d appel</numerusform>
-				<numerusform>%d appels</numerusform>
-			</translation>
-		</message>
-	</context>
+	<name>apple_count</name>
+	<message numerus="yes">
+		<source>%d apple(s)</source>
+		<translation>
+		<numerusform>%d appel</numerusform>
+			<numerusform>%d appels</numerusform>
+		</translation>
+	</message>
+</context>
 </TS>