TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Implementing Regular Expressions in Hare

5 pointsby vladharbuzalmost 3 years ago

1 comment

prirunalmost 3 years ago
I&#x27;m curious, when there is code like:<p><pre><code> case let matches: [][]regex::capture =&gt; defer regex::free_matches(matches); </code></pre> is there a gap between those two statements where memory for matches has been allocated in regex but won&#x27;t be freed because the defer hasn&#x27;t happened?<p>For example, in Python I&#x27;d write:<p><pre><code> fd = None try: fd = os.open(...) (do stuff with fd) except Exception, err: (report err) finally: if fd is not None: os.close(fd) </code></pre> so that there is no gap. It might be tempting to write:<p><pre><code> try: fd = os.open(...) (do stuff with fd) except Exception, err: (report err) finally: os.close(fd) </code></pre> That works if (do stuff with fd) fails but blows up with fd uninitialized in os.close if os.open fails.