From 68f34e929a5df39a59fe1a2df08f26512edf93d9 Mon Sep 17 00:00:00 2001 From: Ben Haller Date: Fri, 17 Jan 2025 08:49:55 -0600 Subject: [PATCH] fix minor bugs in treeSeqMetadata() --- VERSIONS | 1 + core/slim_functions.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/VERSIONS b/VERSIONS index aabc3212..45cf465d 100644 --- a/VERSIONS +++ b/VERSIONS @@ -100,6 +100,7 @@ development head (in the master branch): add recipe 15.22, "Complex multi-chromosome inheritance with addMultiRecombinant()", to illustrate addMultiRecombinant() modified recipes 15.14 and 15.21 to illustrate that NULL can now be passed to addRecombinant() for breaks to get automatic breakpoint generation cleaned up the confusion around Dictionary vs. DictionaryBase; methods/functions can now use Dictionary in their signature without problems + fix a bug in treeSeqMetadata(); if no metadata was found, it would return object(0), not an empty Dictionary object (and it leaked) version 4.3 (Eidos version 3.3): diff --git a/core/slim_functions.cpp b/core/slim_functions.cpp index 2b048e91..1e5f4b30 100644 --- a/core/slim_functions.cpp +++ b/core/slim_functions.cpp @@ -1963,8 +1963,12 @@ EidosValue_SP SLiM_ExecuteFunction_treeSeqMetadata(const std::vectorAllocateChunk()) EidosValue_Object(gEidosDictionaryRetained_Class)); + // With no metadata, return an empty dictionary. BCH 1/17/2025: prior to SLiM 5, this erroneously returned object(0) + EidosDictionaryRetained *objectElement = new EidosDictionaryRetained(); + EidosValue_SP result_SP = EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Object(objectElement, gEidosDictionaryRetained_Class)); + + objectElement->Release(); // retained by result_SP + return result_SP; } std::string metadata_schema_string(temp_tables.metadata_schema, temp_tables.metadata_schema_length); @@ -2015,6 +2019,7 @@ EidosValue_SP SLiM_ExecuteFunction_treeSeqMetadata(const std::vectorAllocateChunk()) EidosValue_Object(objectElement, gEidosDictionaryRetained_Class)); + objectElement->Release(); // retained by result_SP objectElement->AddJSONFrom(metadata); objectElement->ContentsChanged("treeSeqMetadata()"); return result_SP;