Skip to content

Commit 4cd8f74

Browse files
david-vandersonikskuh
authored andcommitted
always use a pointer to first arg for struct member functions
This fixes some rendering problems I encountered using zig stage2. See ziglang/zig#13244 which was me trying to figure out the bug. Also ziglang/zig#13249 which has more explanation.
1 parent cb5e859 commit 4cd8f74

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/lib/parsing.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ pub fn Parser(comptime Reader: type) type {
457457
};
458458
}
459459

460-
fn readNode(self: Self) !Path.Node {
460+
fn readNode(self: *Self) !Path.Node {
461461
const Tag = packed struct {
462462
type: Path.Type,
463463
padding0: u1 = 0,
@@ -534,15 +534,15 @@ pub fn Parser(comptime Reader: type) type {
534534
};
535535
}
536536

537-
fn readStyle(self: Self, kind: StyleType) !Style {
537+
fn readStyle(self: *Self, kind: StyleType) !Style {
538538
return switch (kind) {
539539
.flat => Style{ .flat = try self.readUInt() },
540540
.linear => Style{ .linear = try self.readGradient() },
541541
.radial => Style{ .radial = try self.readGradient() },
542542
};
543543
}
544544

545-
fn readGradient(self: Self) !Gradient {
545+
fn readGradient(self: *Self) !Gradient {
546546
var grad: Gradient = undefined;
547547
grad.point_0 = Point{
548548
.x = try self.readUnit(),
@@ -563,7 +563,7 @@ pub fn Parser(comptime Reader: type) type {
563563
return grad;
564564
}
565565

566-
fn readUInt(self: Self) error{InvalidData}!u32 {
566+
fn readUInt(self: *Self) error{InvalidData}!u32 {
567567
var byte_count: u8 = 0;
568568
var result: u32 = 0;
569569
while (true) {
@@ -581,19 +581,19 @@ pub fn Parser(comptime Reader: type) type {
581581
return result;
582582
}
583583

584-
fn readUnit(self: Self) !f32 {
584+
fn readUnit(self: *const Self) !f32 {
585585
switch (self.header.coordinate_range) {
586586
.reduced => return @intToEnum(tvg.Unit, try self.reader.readIntLittle(i8)).toFloat(self.header.scale),
587587
.default => return @intToEnum(tvg.Unit, try self.reader.readIntLittle(i16)).toFloat(self.header.scale),
588588
.enhanced => return @intToEnum(tvg.Unit, try self.reader.readIntLittle(i32)).toFloat(self.header.scale),
589589
}
590590
}
591591

592-
fn readByte(self: Self) !u8 {
592+
fn readByte(self: *Self) !u8 {
593593
return try self.reader.readByte();
594594
}
595595

596-
fn readU16(self: Self) !u16 {
596+
fn readU16(self: *Self) !u16 {
597597
return try self.reader.readIntLittle(u16);
598598
}
599599
};
@@ -604,11 +604,11 @@ const CountAndStyleTag = packed struct {
604604
raw_count: u6,
605605
style_kind: u2,
606606

607-
pub fn getCount(self: Self) usize {
607+
pub fn getCount(self: *const Self) usize {
608608
return @as(usize, self.raw_count) + 1;
609609
}
610610

611-
pub fn getStyleType(self: Self) !StyleType {
611+
pub fn getStyleType(self: *const Self) !StyleType {
612612
return convertStyleType(self.style_kind);
613613
}
614614
};

src/lib/rendering.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const Framebuffer = struct {
176176
width: usize,
177177
height: usize,
178178

179-
pub fn setPixel(self: Self, x: isize, y: isize, src_color: tvg.Color) void {
179+
pub fn setPixel(self: *const Self, x: isize, y: isize, src_color: tvg.Color) void {
180180
if (x < 0 or y < 0)
181181
return;
182182
if (x >= self.width or y >= self.height)
@@ -1196,14 +1196,14 @@ pub fn FixedBufferList(comptime T: type, comptime N: usize) type {
11961196
return self.buffer[0..self.count];
11971197
}
11981198

1199-
pub fn items(self: Self) []const T {
1199+
pub fn items(self: *const Self) []const T {
12001200
if (self.large) |*large| {
12011201
return large.items;
12021202
}
12031203
return self.buffer[0..self.count];
12041204
}
12051205

1206-
pub fn front(self: Self) ?T {
1206+
pub fn front(self: *const Self) ?T {
12071207
if (self.large) |*large| {
12081208
if (large.items.len > 0) {
12091209
return large.items[0];
@@ -1216,7 +1216,7 @@ pub fn FixedBufferList(comptime T: type, comptime N: usize) type {
12161216
return self.buffer[0];
12171217
}
12181218

1219-
pub fn back(self: Self) ?T {
1219+
pub fn back(self: *const Self) ?T {
12201220
if (self.large) |*large| {
12211221
if (large.items.len > 0) {
12221222
return large.items[large.items.len - 1];

src/lib/tinyvg.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ pub const Scale = enum(u4) {
145145
@"1/16384" = 14,
146146
@"1/32768" = 15,
147147

148-
pub fn map(self: Self, value: f32) Unit {
149-
return Unit.init(self, value);
148+
pub fn map(self: *const Self, value: f32) Unit {
149+
return Unit.init(self.*, value);
150150
}
151151

152-
pub fn getShiftBits(self: Self) u4 {
153-
return @enumToInt(self);
152+
pub fn getShiftBits(self: *const Self) u4 {
153+
return @enumToInt(self.*);
154154
}
155155

156-
pub fn getScaleFactor(self: Self) u15 {
156+
pub fn getScaleFactor(self: *const Self) u15 {
157157
return @as(u15, 1) << self.getShiftBits();
158158
}
159159
};
@@ -168,20 +168,20 @@ pub const Unit = enum(i32) {
168168
return @intToEnum(Self, @floatToInt(i32, value * @intToFloat(f32, scale.getScaleFactor()) + 0.5));
169169
}
170170

171-
pub fn raw(self: Self) i32 {
172-
return @enumToInt(self);
171+
pub fn raw(self: *const Self) i32 {
172+
return @enumToInt(self.*);
173173
}
174174

175-
pub fn toFloat(self: Self, scale: Scale) f32 {
176-
return @intToFloat(f32, @enumToInt(self)) / @intToFloat(f32, scale.getScaleFactor());
175+
pub fn toFloat(self: *const Self, scale: Scale) f32 {
176+
return @intToFloat(f32, @enumToInt(self.*)) / @intToFloat(f32, scale.getScaleFactor());
177177
}
178178

179-
pub fn toInt(self: Self, scale: Scale) i32 {
179+
pub fn toInt(self: *const Self, scale: Scale) i32 {
180180
const factor = scale.getScaleFactor();
181-
return @divFloor(@enumToInt(self) + (@divExact(factor, 2)), factor);
181+
return @divFloor(@enumToInt(self.*) + (@divExact(factor, 2)), factor);
182182
}
183183

184-
pub fn toUnsignedInt(self: Self, scale: Scale) !u31 {
184+
pub fn toUnsignedInt(self: *const Self, scale: Scale) !u31 {
185185
const i = toInt(self, scale);
186186
if (i < 0)
187187
return error.InvalidData;
@@ -197,7 +197,7 @@ pub const Color = extern struct {
197197
b: f32,
198198
a: f32,
199199

200-
pub fn toRgba8(self: Self) [4]u8 {
200+
pub fn toRgba8(self: *const Self) [4]u8 {
201201
return [4]u8{
202202
@floatToInt(u8, std.math.clamp(255.0 * self.r, 0.0, 255.0)),
203203
@floatToInt(u8, std.math.clamp(255.0 * self.g, 0.0, 255.0)),

0 commit comments

Comments
 (0)