@@ -140,7 +140,7 @@ unsafe extern "C" fn c_database_change_listener(
140140 c_doc_ids : * mut FLString ,
141141) {
142142 let callback = context as * const DatabaseChangeListener ;
143- let database = Database :: retain ( db as * mut CBLDatabase ) ;
143+ let database = Database :: reference ( db as * mut CBLDatabase ) ;
144144
145145 let doc_ids = std:: slice:: from_raw_parts ( c_doc_ids, num_docs as usize )
146146 . iter ( )
@@ -159,7 +159,7 @@ unsafe extern "C" fn c_database_buffer_notifications(
159159) {
160160 let callback: BufferNotifications = std:: mem:: transmute ( context) ;
161161
162- let database = Database :: retain ( db. cast :: < CBLDatabase > ( ) ) ;
162+ let database = Database :: reference ( db. cast :: < CBLDatabase > ( ) ) ;
163163
164164 callback ( & database) ;
165165}
@@ -180,15 +180,15 @@ impl CblRef for Database {
180180impl Database {
181181 //////// CONSTRUCTORS:
182182
183- /// Takes ownership of the object and increase it's reference counter .
184- pub ( crate ) fn retain ( cbl_ref : * mut CBLDatabase ) -> Self {
183+ /// Increase the reference counter of the CBL ref, so dropping the instance will NOT free the ref .
184+ pub ( crate ) fn reference ( cbl_ref : * mut CBLDatabase ) -> Self {
185185 Self {
186186 cbl_ref : unsafe { retain ( cbl_ref) } ,
187187 }
188188 }
189189
190- /// References the object without taking ownership and increasing it's reference counter
191- pub ( crate ) const fn wrap ( cbl_ref : * mut CBLDatabase ) -> Self {
190+ /// Takes ownership of the CBL ref, the reference counter is not increased so dropping the instance will free the ref.
191+ pub ( crate ) const fn take_ownership ( cbl_ref : * mut CBLDatabase ) -> Self {
192192 Self { cbl_ref }
193193 }
194194
@@ -217,7 +217,7 @@ impl Database {
217217 if db_ref. is_null ( ) {
218218 return failure ( err) ;
219219 }
220- Ok ( Self :: wrap ( db_ref) )
220+ Ok ( Self :: take_ownership ( db_ref) )
221221 }
222222
223223 //////// OTHER STATIC METHODS:
@@ -418,7 +418,7 @@ impl Database {
418418 if scope. is_null ( ) {
419419 None
420420 } else {
421- Some ( Scope :: wrap ( scope) )
421+ Some ( Scope :: take_ownership ( scope) )
422422 }
423423 } )
424424 }
@@ -445,7 +445,7 @@ impl Database {
445445 if collection. is_null ( ) {
446446 None
447447 } else {
448- Some ( Collection :: wrap ( collection) )
448+ Some ( Collection :: take_ownership ( collection) )
449449 }
450450 } )
451451 }
@@ -474,7 +474,7 @@ impl Database {
474474 )
475475 } ;
476476
477- check_error ( & error) . map ( |( ) | Collection :: wrap ( collection) )
477+ check_error ( & error) . map ( |( ) | Collection :: take_ownership ( collection) )
478478 }
479479
480480 /// Delete an existing collection.
@@ -499,7 +499,7 @@ impl Database {
499499 let mut error = CBLError :: default ( ) ;
500500 let scope = unsafe { CBLDatabase_DefaultScope ( self . get_ref ( ) , & mut error) } ;
501501
502- check_error ( & error) . map ( |( ) | Scope :: wrap ( scope) )
502+ check_error ( & error) . map ( |( ) | Scope :: take_ownership ( scope) )
503503 }
504504
505505 /// Returns the default collection.
@@ -511,7 +511,7 @@ impl Database {
511511 if collection. is_null ( ) {
512512 None
513513 } else {
514- Some ( Collection :: wrap ( collection) )
514+ Some ( Collection :: take_ownership ( collection) )
515515 }
516516 } )
517517 }
@@ -526,7 +526,7 @@ impl Database {
526526 if collection. is_null ( ) {
527527 Err ( Error :: cbl_error ( CouchbaseLiteError :: NotFound ) )
528528 } else {
529- Ok ( Collection :: wrap ( collection) )
529+ Ok ( Collection :: take_ownership ( collection) )
530530 }
531531 }
532532
@@ -596,6 +596,6 @@ impl Drop for Database {
596596
597597impl Clone for Database {
598598 fn clone ( & self ) -> Self {
599- Self :: retain ( self . get_ref ( ) )
599+ Self :: reference ( self . get_ref ( ) )
600600 }
601601}
0 commit comments