@@ -14,17 +14,19 @@ initialization macros. Direct access to the libgit2 C library is also provided
1414by the package. See [ Usage] ( #Usage ) for an example of how to import and use
1515either library.
1616
17+ The bindings use memory-safe Swift types wherever possible, while preserving
18+ libgit2's behavior and semantics. For example, some bindings use native Swift
19+ types like ` String ` instead of ` UnsafePointer<CChar> ` , and accept ` inout `
20+ parameters to memory-safe Swift structs instead of unsafe pointers to C structs.
21+ In these cases, swift-libgit2 safely converts types between Swift and C,
22+ managing and freeing memory as needed. See
23+ [ Memory Management] ( #Memory-Management ) for more information.
24+
1725The bindings use the same signatures and names as their C equivalents, but are
1826written using [ camel case] ( https://en.wikipedia.org/wiki/Camel_case ) instead of
19- [ snake case] ( https://en.wikipedia.org/wiki/Snake_case ) .
20-
21- Similar to libgit2, the bindings do not use
22- [ namespaces] ( https://en.wikipedia.org/wiki/Namespace ) . All bindings are
23- available globally.
24-
25- The bindings use native Swift types wherever possible, while preserving
26- libgit2's behavior and semantics. For example, some bindings use Swift types
27- like ` String ` instead of ` UnsafePointer<CChar> ` .
27+ [ snake case] ( https://en.wikipedia.org/wiki/Snake_case ) . Similar to libgit2, the
28+ bindings do not use [ namespaces] ( https://en.wikipedia.org/wiki/Namespace ) . All
29+ bindings are available globally.
2830
2931
3032
@@ -103,13 +105,17 @@ converted from Swift to C, or in other cases specific to individual functions.
103105
104106### Memory Management
105107
106- swift-libgit2 directly invokes libgit2 C code. The caller is responsible for
107- freeing memory allocated by libgit2, unless otherwise specified.
108+ swift-libgit2 handles memory management for most bindings. For example, ` inout `
109+ Swift types are safely converted between Swift and C, with any allocated
110+ memory being freed as needed.
111+
112+ However, some bindings require manual memory management, particularly when
113+ working with opaque or unsafe pointers. The caller is responsible for freeing
114+ the memory using the appropriate swift-libgit2 or libgit2 function.
108115
109116Consider using
110117[ ` defer ` ] ( https://docs.swift.org/swift-book/documentation/the-swift-programming-language/statements/#Defer-Statement )
111- statements with memory-freeing function bindings to consistently and safely
112- free memory.
118+ statements with memory-freeing functions to consistently and safely free memory.
113119
114120### Thread Safety
115121
0 commit comments