Re: [PATCH 4/7] xdiff: make fields of xrecord_t Rust friendly
- From
Ezekiel Newren <ezekielnewren@gmail.com>
- Date
- Jul 28, 2025, 19:34 UTC
- Message-ID
- <CAH=ZcbCnEpBokM9rxmmkeM9GT948n7+RipXODHLfPssuwJuVCw@mail.gmail.com>
- In-Reply-To
- <91f6352f-abc4-4e99-938b-6a56aba2faed@gmail.com>
On Fri, Jul 18, 2025 at 7:35 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 14 quoted lines
> > Hi Ezekiel > > On 17/07/2025 21:32, Ezekiel Newren via GitGitGadget wrote: > > From: Ezekiel Newren <ezekielnewren@gmail.com> > > > > A few commits ago, we added definitions for Rust primitive types, > > to facilitate interoperability between C and Rust. Switch a > > few variables to use these types. Which, for now, will > > require adding some casts. > > How necessary is it to change char' to 'u8' so long as the rust and C > sides both use a type that is the same size? Also what's the advantage > of using these typedefs rather than the normal C types like unit8_t ?
Rust defines char as 32 bits. C treats char as signed 8 bits. What git really means by char* is treat everything like a byte string, and u8 is how raw bytes are handled in Rust.
Show 13 quoted lines
> > diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
> > index 5a96e36dfbea..3b364c61f671 100644
> > --- a/xdiff/xdiffi.c
> > +++ b/xdiff/xdiffi.c
> > @@ -418,7 +418,7 @@ static int get_indent(xrecord_t *rec)
> > long i;
> > int ret = 0;
> >
> > - for (i = 0; i < rec->size; i++) {
> > + for (i = 0; i < (long) rec->size; i++) {
>
> i is a loop counter and array index so we can lose this cast by
> changeing i to size_tOk, but I'm going to change the type of i to usize and stuff it inside the loop i.e. for (usize i = 0; ...
> Thanks > > Phillip