From 055e8410afeb5bbe59b1a93445bb76493d596e69 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 5 Jun 2026 11:00:53 +0400 Subject: [PATCH] Clean up destroyMapping doc and redundant guard --- api.md | 8 ++++---- libplum/plum.nim | 9 ++++----- tests/test_plum.nim | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/api.md b/api.md index 1fc7e59..e9b25d1 100644 --- a/api.md +++ b/api.md @@ -108,10 +108,10 @@ Returns an error if no NAT device is found, the mapping fails, or the timeout ex proc destroyMapping*(id: cint) ``` -Removes a mapping. Must be called exactly once after a successful `createMapping`, -otherwise the mapping's internal handle is leaked for the lifetime of the process. -Calling it again, or with an unknown `id`, is a safe no-op. `cleanup` also releases -any mappings still active. +Removes a mapping. Call it after a successful `createMapping`, otherwise the +mapping's internal handle is leaked for the lifetime of the process. Calling it +again, or with an unknown `id`, is a safe no-op. `cleanup` also releases any +mappings still active. ### hasMapping diff --git a/libplum/plum.nim b/libplum/plum.nim index 2549561..6711a93 100644 --- a/libplum/plum.nim +++ b/libplum/plum.nim @@ -274,11 +274,10 @@ proc createMapping*( return err("plum: mapping " & $id & " failed") proc destroyMapping*(id: cint) = - ## Must be called exactly once after a successful createMapping. - ## Safe to call again or on an unknown id - withSafeLock: - if id notin activeMappings: - return + ## Releases a mapping created by createMapping. Safe to call again or + ## with an unknown id. + # libplum locks internally and ignores unknown ids: no wrapper-side + # bookkeeping needed. discard plum_destroy_mapping(id) proc hasMapping*(id: cint): bool = diff --git a/tests/test_plum.nim b/tests/test_plum.nim index 430ee89..fc8efd3 100644 --- a/tests/test_plum.nim +++ b/tests/test_plum.nim @@ -14,7 +14,6 @@ import unittest2 import std/atomics import chronos import libplum/plum -import libplum/libplum const miniupnp_protocol {.strdefine.} = ""