authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-06 11:42:22-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-09-21 21:08:52+02:00
log670c4fae617af3a7cfbdfcd850b65d61b94d1cf8
tree3aad1537a4a2016c57e15257b65fd55df5db354f
parent4d102751b6346cf614699f0a830fb5a2c1ee9f66
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

frontend: additionally handle C pointers in ptrOptPayload


1 files changed, 9 insertions(+), 3 deletions(-)

src/Value.zig+9-3
......@@ -2149,15 +2149,18 @@ pub fn makeBool(x: bool) Value {
21492149 return if (x) .true else .false;
21502150}
21512151
2152/// `parent_ptr` must be a single-pointer to some optional.
2152/// `parent_ptr` must be a single-pointer or C pointer to some optional.
2153///
21532154/// Returns a pointer to the payload of the optional.
2155///
21542156/// May perform type resolution.
21552157pub fn ptrOptPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
21562158 const zcu = pt.zcu;
21572159 const parent_ptr_ty = parent_ptr.typeOf(zcu);
21582160 const opt_ty = parent_ptr_ty.childType(zcu);
2161 const ptr_size = parent_ptr_ty.ptrSize(zcu);
21592162
2160 assert(parent_ptr_ty.ptrSize(zcu) == .one);
2163 assert(ptr_size == .one or ptr_size == .c);
21612164 assert(opt_ty.zigTypeTag(zcu) == .optional);
21622165
21632166 const result_ty = try pt.ptrTypeSema(info: {
......@@ -2212,9 +2215,12 @@ pub fn ptrEuPayload(parent_ptr: Value, pt: Zcu.PerThread) !Value {
22122215 } }));
22132216}
22142217
2215/// `parent_ptr` must be a single-pointer to a struct, union, or slice.
2218/// `parent_ptr` must be a single-pointer or c pointer to a struct, union, or slice.
2219///
22162220/// Returns a pointer to the aggregate field at the specified index.
2221///
22172222/// For slices, uses `slice_ptr_index` and `slice_len_index`.
2223///
22182224/// May perform type resolution.
22192225pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
22202226 const zcu = pt.zcu;