re-enable full demo code
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 5m16s

This commit is contained in:
Emil Lerch 2023-08-27 17:36:26 -07:00
parent 978bb783e3
commit 06429e0853
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 41 additions and 47 deletions

View File

@ -858,15 +858,7 @@ fn FullResponse(comptime action: anytype) type {
const Response = @TypeOf(self.response); const Response = @TypeOf(self.response);
if (@hasDecl(Response, "http_header")) { if (@hasDecl(Response, "http_header")) {
inline for (std.meta.fields(@TypeOf(Response.http_header))) |f| { inline for (std.meta.fields(@TypeOf(Response.http_header))) |f| {
const field_type = @TypeOf(@field(self.response, f.name)); safeFree(self.allocator, @field(self.response, f.name));
// TODO: Fix this. We need to make this much more robust
// The deal is we have to do the dupe though
// Also, this is a memory leak atm
if (@typeInfo(field_type) == .Optional) {
if (@field(self.response, f.name) != null) {
self.allocator.free(@field(self.response, f.name).?);
}
}
} }
} }
if (@hasDecl(Response, "http_payload")) { if (@hasDecl(Response, "http_payload")) {
@ -883,6 +875,13 @@ fn FullResponse(comptime action: anytype) type {
} }
}; };
} }
fn safeFree(allocator: std.mem.Allocator, obj: anytype) void {
switch (@typeInfo(@TypeOf(obj))) {
.Pointer => allocator.free(obj),
.Optional => if (obj) |o| safeFree(allocator, o),
else => {},
}
}
fn queryFieldTransformer(allocator: std.mem.Allocator, field_name: []const u8, options: url.EncodingOptions) anyerror![]const u8 { fn queryFieldTransformer(allocator: std.mem.Allocator, field_name: []const u8, options: url.EncodingOptions) anyerror![]const u8 {
_ = options; _ = options;
return try case.snakeToPascal(allocator, field_name); return try case.snakeToPascal(allocator, field_name);

View File

@ -238,7 +238,6 @@ pub fn main() anyerror!void {
// that frees both a bool and an i64 // that frees both a bool and an i64
std.log.err("This demo (rest_xml_work_with_s3) is not yet fully functional in 0.11", .{}); std.log.err("This demo (rest_xml_work_with_s3) is not yet fully functional in 0.11", .{});
const key = "i/am/a/teapot/foo"; const key = "i/am/a/teapot/foo";
_ = key;
// // const key = "foo"; // // const key = "foo";
// //
const bucket = blk: { const bucket = blk: {
@ -266,43 +265,39 @@ pub fn main() anyerror!void {
.region = location, .region = location,
.client = client, .client = client,
}; };
// TODO: This block triggers the free(bool) problem. Note that the rest of this will have runtime issues {
// without the block const result = try aws.Request(services.s3.put_object).call(.{
// { .bucket = bucket,
// const result = try aws.Request(services.s3.put_object).call(.{ .key = key,
// .bucket = bucket, .content_type = "text/plain",
// .key = key, .body = "bar",
// .content_type = "text/plain", .storage_class = "STANDARD",
// .body = "bar", }, s3opts);
// .storage_class = "STANDARD", std.log.info("PutObject Request id: {any}", .{result.response_metadata.request_id});
// }, s3opts); std.log.info("PutObject etag: {any}", .{result.response.e_tag.?});
// std.log.info("PutObject Request id: {any}", .{result.response_metadata.request_id}); defer result.deinit();
// std.log.info("PutObject etag: {any}", .{result.response.e_tag.?}); }
// defer result.deinit(); {
// } // Note that boto appears to redirect by default, but java
// TODO: This block triggers both compile errors // does not. We will not
// { const result = try aws.Request(services.s3.get_object).call(.{
// // Note that boto appears to redirect by default, but java .bucket = bucket,
// // does not. We will not .key = key,
// const result = try aws.Request(services.s3.get_object).call(.{ }, s3opts);
// .bucket = bucket, std.log.info("GetObject Request id: {any}", .{result.response_metadata.request_id});
// .key = key, std.log.info("GetObject Body: {any}", .{result.response.body});
// }, s3opts); std.log.info("GetObject etag: {any}", .{result.response.e_tag.?});
// std.log.info("GetObject Request id: {any}", .{result.response_metadata.request_id}); std.log.info("GetObject last modified (seconds since epoch): {d}", .{result.response.last_modified.?});
// std.log.info("GetObject Body: {any}", .{result.response.body}); defer result.deinit();
// std.log.info("GetObject etag: {any}", .{result.response.e_tag.?}); }
// std.log.info("GetObject last modified (seconds since epoch): {d}", .{result.response.last_modified.?}); {
// defer result.deinit(); const result = try aws.Request(services.s3.delete_object).call(.{
// } .bucket = bucket,
// TODO: This block triggers the free(bool) problem. Note that the rest of this will have runtime issues .key = key,
// { }, s3opts);
// const result = try aws.Request(services.s3.delete_object).call(.{ std.log.info("DeleteObject Request id: {any}", .{result.response_metadata.request_id});
// .bucket = bucket, defer result.deinit();
// .key = key, }
// }, s3opts);
// std.log.info("DeleteObject Request id: {any}", .{result.response_metadata.request_id});
// defer result.deinit();
// }
{ {
const result = try aws.Request(services.s3.list_objects).call(.{ const result = try aws.Request(services.s3.list_objects).call(.{
.bucket = bucket, .bucket = bucket,