Re: [RFC PATCH 2/6] repository: add initialize_repo wrapper without pointer
- From
Mike Hommey <mh@glandium.org>
- Date
- Aug 7, 2024, 22:52 UTC
- Message-ID
- <20240807225246.7jhqioyqh4e2ibza@glandium.org>
- In-Reply-To
- <5f2e816cf6359725f2a86ce1d08e5e272fba4dac.1723054623.git.steadmon@google.com>
On Wed, Aug 07, 2024 at 11:21:27AM -0700, Josh Steadmon wrote:
Show 7 quoted lines
> Non-C external consumers of libgit.a have to redefine the `repository` > object in their own language if they want to call > initialize_repository() to ensure memory for the object is allocated > correctly. This is not ideal for external consumers that have no need > for the entire `the_repository` object but need to call other functions > from an initialized repository. Therefore, add a friendly > initialize_repository() wrapper without a `the_repository` pointer.
Technically speaking, you don't really need this.
You can define `repository` as an opaque type in Rust: ``` #[allow(non_camel_case_types)] #[repr(C)] pub struct repository([u8; 0]); ```
And define `the_repository` as an extern symbol:
```
extern "C" {
pub static mut the_repository: *mut repository;
}
```Mike