@@ -518,14 +518,14 @@ import kotlin.concurrent.write
518518 * Race-free wrapper around a raw `Box<T>` pointer obtained from native
519519 * code via `Box::into_raw(Box::new(v))`. Pairs the pointer with a
520520 * `ReentrantReadWriteLock` so that borrow-style JNI calls run in
521- * parallel under the read lock and consume/close serialise against
521+ * parallel under the read lock and consume/free serialise against
522522 * them under the write lock.
523523 *
524524 * This is the Java-side half of the type-conversion rule for opaque
525525 * handles: `&T` parameters route through [withPtr] (borrow); by-value
526526 * `T` parameters route through [consume] (write lock, slot stays
527527 * valid during the action, then null-ed in `finally`); destructor
528- * entry points without a matching `#[prebindgen]` fn use [close ]. The
528+ * entry points without a matching `#[prebindgen]` fn use [free ]. The
529529 * auto-generated wrappers in `JNIWrappers.kt` are the only callers
530530 * that need to know which mode applies.
531531 *
@@ -536,13 +536,13 @@ public open class NativeHandle(initial: Long) {
536536 private val lock = ReentrantReadWriteLock()
537537
538538 /** Volatile so [peek] is atomic on 32-bit JVMs and observes the
539- * write done by [close ] / [consume] without holding the lock. */
539+ * write done by [free ] / [consume] without holding the lock. */
540540 @Volatile private var ptr: Long = initial
541541
542542 /**
543543 * Run [block] with the live pointer under the read lock. Throws
544- * [ZError] if [close ] has already released the handle. Multiple
545- * concurrent invocations run in parallel; only [close ]/[consume]
544+ * [ZError] if [free ] has already released the handle. Multiple
545+ * concurrent invocations run in parallel; only [free ]/[consume]
546546 * are serialised against them.
547547 */
548548 @Throws(ZError::class)
@@ -554,10 +554,10 @@ public open class NativeHandle(initial: Long) {
554554
555555 /**
556556 * Take the pointer under the write lock and pass it to [freeFn]
557- * exactly once. Subsequent [close ] calls are no-ops. Blocks until
557+ * exactly once. Subsequent [free ] calls are no-ops. Blocks until
558558 * all in-flight [withPtr] calls finish.
559559 */
560- public fun close (freeFn: (Long) -> Unit) {
560+ public fun free (freeFn: (Long) -> Unit) {
561561 lock.write {
562562 val p = ptr
563563 if (p == 0L) return@write
@@ -577,9 +577,9 @@ public open class NativeHandle(initial: Long) {
577577 * typed handle to JNI and have JNI extract the pointer via [peek]
578578 * — symmetric with [withPtr] for the Borrow path. Unique-ownership
579579 * is still guaranteed: the write lock excludes every other
580- * [withPtr] / [consume] / [close ], and the `finally` clause
580+ * [withPtr] / [consume] / [free ], and the `finally` clause
581581 * unconditionally nulls the slot before the lock is released, so
582- * the next [withPtr] / [consume] / [close ] sees `ptr == 0` and
582+ * the next [withPtr] / [consume] / [free ] sees `ptr == 0` and
583583 * cannot reach the freed allocation.
584584 *
585585 * Throws if the handle has already been closed/consumed.
@@ -595,7 +595,7 @@ public open class NativeHandle(initial: Long) {
595595 }
596596 }
597597
598- /** True iff [close ] has run. */
598+ /** True iff [free ] has run. */
599599 public fun isClosed(): Boolean = lock.read { ptr == 0L }
600600
601601 /**
@@ -612,7 +612,7 @@ public open class NativeHandle(initial: Long) {
612612///
613613/// ```kotlin
614614/// public class JNIFoo(initialPtr: Long) : NativeHandle(initialPtr) {
615- /// public fun close () = close { freePtrViaJNI(it) }
615+ /// public fun free () = free { freePtrViaJNI(it) }
616616/// private external fun freePtrViaJNI(ptr: Long)
617617/// }
618618/// ```
@@ -709,7 +709,7 @@ fn render_typed_handle_source(
709709 "public class {}(initialPtr: Long) : NativeHandle(initialPtr) {{\n " ,
710710 class_name
711711 ) ) ;
712- s. push_str ( " public fun close () = close { freePtrViaJNI(it) }\n " ) ;
712+ s. push_str ( " public fun free () = free { freePtrViaJNI(it) }\n " ) ;
713713 s. push_str ( " private external fun freePtrViaJNI(ptr: Long)\n " ) ;
714714 if !methods_body. is_empty ( ) {
715715 s. push ( '\n' ) ;
0 commit comments