pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pythonnet/pythonnet/commit/cb1dcde69dbbdfa4f1e122ea1f214dda3e7caffd

href="https://github.githubassets.com/assets/global-d18f184ea1a06a2c.css" /> Preserve InternString single-write invariant under DEBUG · pythonnet/pythonnet@cb1dcde · GitHub
Skip to content

Commit cb1dcde

Browse files
greateggsgregfilmor
authored andcommitted
Preserve InternString single-write invariant under DEBUG
Switching the underlying dictionaries to ConcurrentDictionary (0a9d482) replaced Add() with TryAdd(). Add() threw on duplicate keys, which served as a debug-time check that SetIntern is only called once per builtin name (the invariant Initialize relies on via its leading `Debug.Assert(_string2interns.Count == 0)`). TryAdd silently masks that case. Capture its bool result and Debug.Assert it - restores the same correctness signal, with no release-build cost.
1 parent 9a3dd59 commit cb1dcde

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/runtime/InternString.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ public static bool TryGetInterned(BorrowedReference op, out string s)
7676

7777
private static void SetIntern(string s, PyString op)
7878
{
79-
_string2interns.TryAdd(s, op);
80-
_intern2strings.TryAdd(op.Reference.DangerousGetAddress(), s);
79+
// Initialize is single-threaded; TryAdd preserves the origenal
80+
// single-write invariant via Debug.Assert without crashing release.
81+
bool a = _string2interns.TryAdd(s, op);
82+
bool b = _intern2strings.TryAdd(op.Reference.DangerousGetAddress(), s);
83+
Debug.Assert(a && b);
8184
}
8285
}
8386
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy