srctree

Gregory Mullen parent d994e2d4 e733e54f
put exported vars into environ

src/builtins/export.zig added: 22, removed: 11, total 11
@@ -84,9 +84,12 @@ pub fn exports(h: *HSH, pitr: *ParsedIterator) Err!u8 {
var keyitr = std.mem.split(u8, name.?.cannon(), "=");
const key = keyitr.first();
const value = keyitr.rest();
// TODO push into variables
Variables.put(key, value) catch {
log.err("Unable to save variable", .{});
return 1;
};
add(key, value) catch {
log.err("", .{});
log.err("unable to save export", .{});
return 1;
};
return 0;
@@ -103,7 +106,7 @@ pub fn exports(h: *HSH, pitr: *ParsedIterator) Err!u8 {
};
return 0;
}
unreachable; // there's a logic error here so crash if we hit it.
comptime unreachable;
}
 
/// TODO method to remove an export
 
src/variables.zig added: 22, removed: 11, total 11
@@ -81,7 +81,15 @@ pub fn get(k: []const u8) ?[]const u8 {
}
 
pub fn put(k: []const u8, v: []const u8) !void {
return variables.put(k, v);
environ_dirty = true;
const key = try environ_alloc.dupe(u8, k);
const value = try environ_alloc.dupe(u8, v);
const kv = try variables.getOrPut(key);
if (kv.found_existing) {
environ_alloc.free(key);
environ_alloc.free(kv.value_ptr.*);
}
kv.value_ptr.* = value;
}
 
// del(k, v) where v can be an optional, delete only of v matches current value
@@ -94,11 +102,11 @@ pub fn del(k: []const u8) !void {
//}
 
pub fn raze() void {
//var itr = variables.iterator();
//while (itr.next()) |*ent| {
// a.free(ent.key_ptr.*);
// a.free(ent.value_ptr.value);
//}
var itr = variables.iterator();
while (itr.next()) |*ent| {
environ_alloc.free(ent.key_ptr.*);
environ_alloc.free(ent.value_ptr.*);
}
variables.clearAndFree();
environ_alloc.free(environ);
}