Skip to content

Commit 4995d27

Browse files
committed
Remove patches, no longer can make owned relocations
1 parent 5176586 commit 4995d27

File tree

5 files changed

+9
-1592
lines changed

5 files changed

+9
-1592
lines changed

build.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub fn build(b: *std.Build) !void {
5757
});
5858
lib.linkLibC();
5959
lib.addIncludePath(b.path("src/config"));
60-
lib.addIncludePath(b.path("src/patch"));
6160
lib.addIncludePath(tcc_dep.path("."));
6261
lib.addIncludePath(tcc_dep.path("include"));
6362

@@ -152,7 +151,6 @@ pub fn build(b: *std.Build) !void {
152151
.files = C_SOURCES.items,
153152
.flags = FLAGS.items,
154153
});
155-
lib.addCSourceFile(.{ .file = b.path("src/patch/tccrun.c"), .flags = FLAGS.items });
156154

157155
const module = b.addModule("tinycc", .{
158156
.root_source_file = b.path("src/lib.zig"),
@@ -181,6 +179,7 @@ pub fn build(b: *std.Build) !void {
181179
const SOURCES = [_][]const u8{
182180
"libtcc.c",
183181
"tccpp.c",
182+
"tccrun.c",
184183
"tccgen.c",
185184
"tccdbg.c",
186185
"tccelf.c",

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.version = "0.0.1",
44
.dependencies = .{
55
.tinycc = .{
6-
.url = "https://codeload.github.com/TinyCC/tinycc/tar.gz/c6afdff7ab4dfd338a30f6aab3288e3a2d6274de",
6+
.url = "https://codeload.github.com/TinyCC/tinycc/tar.gz/6ca228339cbae14203b255e3e27f56586d2b10dc",
77
.hash = "N-V-__8AAPoeQACt9PObjqzWO2RLVHoL6LMnzJrdYoi-T52O",
88
},
99
},

src/lib.zig

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub extern fn tcc_add_symbol(s: *TCCState, name: [*:0]const u8, val: *const anyo
2323
pub extern fn tcc_output_file(s: *TCCState, filename: [*:0]const u8) c_int;
2424
pub extern fn tcc_run(s: *TCCState, argc: c_int, argv: [*c][*c]u8) c_int;
2525
pub extern fn tcc_relocate(s1: *TCCState) c_int;
26-
pub extern fn tcc_relocate2(s1: *TCCState, ptr: ?*anyopaque, mode: c_int) c_int;
2726
pub extern fn tcc_get_symbol(s: *TCCState, name: [*:0]const u8) ?*anyopaque;
2827
pub extern fn tcc_list_symbols(s: *TCCState, ctx: ?*anyopaque, symbol_cb: TCCSymbolCallbackFunc) void;
2928

@@ -151,23 +150,12 @@ pub const TCCState = opaque {
151150
}
152151

153152
/// do all relocations (needed before using get_symbol())
154-
pub fn relocate(self: *TCCState, position: TCCRelocation) !void {
155-
const ret = switch (position) {
156-
.auto => tcc_relocate(self),
157-
.addr => |ptr| tcc_relocate2(self, ptr, 1),
158-
};
153+
pub fn relocate(self: *TCCState) !void {
154+
const ret = tcc_relocate(self);
159155
if (ret == -1)
160156
return error.RelocateError;
161157
}
162158

163-
/// return required memory size for relocation
164-
pub fn relocationSize(self: *TCCState) !c_int {
165-
const size = tcc_relocate2(self, null, 2);
166-
if (size == -1)
167-
return error.RelocateSizeError;
168-
return size;
169-
}
170-
171159
/// return symbol value or NULL if not found
172160
pub fn get_symbol(self: *TCCState, name: [:0]const u8) ?*anyopaque {
173161
return tcc_get_symbol(self, name.ptr);
@@ -178,19 +166,11 @@ pub const TCCState = opaque {
178166
tcc_list_symbols(self, ctx, symbol_cb);
179167
}
180168

181-
pub fn relocateAlloc(self: *TCCState, allocator: std.mem.Allocator) !DynMem {
182-
const bytes = try self.relocationSize();
183-
const mem = try DynMem.alloc(allocator, @intCast(bytes));
184-
errdefer mem.free();
185-
try self.relocate(.{ .addr = @ptrCast(@alignCast(mem.mem.ptr)) });
186-
return mem;
187-
}
188-
189-
pub fn compileStringOnceAlloc(self: *TCCState, allocator: std.mem.Allocator, buf: []const u8) !DynMem {
169+
pub fn compileStringOnce(self: *TCCState, allocator: std.mem.Allocator, buf: []const u8) !void {
190170
const zbytes = try allocator.dupeZ(u8, buf);
191171
defer allocator.free(zbytes);
192172
try self.compile_string(zbytes);
193-
return try self.relocateAlloc(allocator);
173+
return try self.relocate();
194174
}
195175

196176
/// free a TCC compilation context
@@ -234,7 +214,7 @@ test "tcc - compile" {
234214
\\}
235215
);
236216

237-
try tcc.relocate(.auto);
217+
try tcc.relocate();
238218

239219
const Fn = *const fn () callconv(.c) c_int;
240220

@@ -245,7 +225,7 @@ test "tcc - compile" {
245225
try std.testing.expectEqual(res, 123);
246226
}
247227

248-
test "tcc - compileStringOnceAlloc" {
228+
test "tcc - compileStringOnce" {
249229
const allocator = std.testing.allocator;
250230

251231
const tcc = try new();
@@ -254,12 +234,11 @@ test "tcc - compileStringOnceAlloc" {
254234
tcc.set_options("-std=c11 -nostdlib -Wl,--export-all-symbols");
255235
tcc.set_output_type(TCC_OUTPUT_MEMORY);
256236

257-
const mem = try tcc.compileStringOnceAlloc(allocator,
237+
try tcc.compileStringOnce(allocator,
258238
\\int blank() {
259239
\\ return 234;
260240
\\}
261241
);
262-
defer mem.free();
263242

264243
const Fn = *const fn () callconv(.c) c_int;
265244

src/patch/relocate.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)