I’m stuck on this problem, I’m not sure how to proceed. I’ve tried debugging using print and gdb, but I’m unable to figure out my mistake. Any help is appreciated.
In my main.zig
, res
is empty and in gdb when I try to print res
it says there is no reference to res.
There are two files main.zig
and browser.zig
.
// zig: 0.13.0
// main.zig
// allocator: generalPurposeAllocator
var t = browser.Tab.init(buffer[0..bufferReadLen], allocator) catch |err| {
print("There was a problem with the URL: {}\n", .{err});
return;
};
defer t.deinit();
const rawRes = t.request("/index.html") catch |err| {
print("There was an error making that request: {}\n", .{err});
return;
};
const res = browser.Response.parseResponse(rawRes, allocator) catch |err| {
print("There was an error parsing that response: {}\n", .{err});
return;
};
defer res.free(allocator);
print("Body: {s}\n", .{res.body}); // prints the []const u8 as expected
const html = browser.renderHTML(res.body); // res.body is empty here
print("Parsed Body: {s}\n", .{html});
print("Body: {s}\n", .{res.body}); // is empty
// browser.zig
const struct = Response {
body: []const u8,
pub fn parseResponse(...) {
...
const res = try allocator.create(Response);
res.* = Response{ ..., .body = iter.rest() };
return res;
}
}