From: Justin Tobler Date: Tue, 03 Feb 2026 16:46:22 GMT Subject: Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic Message-ID: In-Reply-To: <87o6m5rff8.fsf@iotcl.com> On 26/02/03 04:54PM, Toon Claes wrote: > Justin Tobler writes: > > -static void prepare_loose_object_transaction(struct odb_transaction *transaction) > > +static void prepare_loose_object_transaction(struct odb_transaction *base) > > { > > + struct odb_transaction_files *transaction = (struct odb_transaction_files *)base; > > So you're assuming `struct odb_transaction` is the first field in > `struct odb_transaction_files`? Yes, `struct odb_transaction_files` contains a reference to `struct odb_transaction` as its first member which is the "base" transaction type. This way we can easily cast to the containing "concrete" type. > I think it would be safer to do this instead: > > + struct odb_transaction_files *transaction = > + container_of(base, struct odb_transaction_files, base); > > (this also can be applied in a few other places in this patch) So long as `struct odb_transaction` remains the first member of `struct odb_transaction_files`, using `container_of()` is functionally the same thing as casting. This is also how we do things for `odb_read_stream` and `odb_loose_read_stream` so I don't think it is too big of a deal either way. I've made the change locally, but will hold off from sending another version unless folks feel strongly about this change or there is other feedback. Thanks, -Justin