@@ -23,7 +23,6 @@ pub extern fn tcc_add_symbol(s: *TCCState, name: [*:0]const u8, val: *const anyo
23
23
pub extern fn tcc_output_file (s : * TCCState , filename : [* :0 ]const u8 ) c_int ;
24
24
pub extern fn tcc_run (s : * TCCState , argc : c_int , argv : [* c ][* c ]u8 ) c_int ;
25
25
pub extern fn tcc_relocate (s1 : * TCCState ) c_int ;
26
- pub extern fn tcc_relocate2 (s1 : * TCCState , ptr : ? * anyopaque , mode : c_int ) c_int ;
27
26
pub extern fn tcc_get_symbol (s : * TCCState , name : [* :0 ]const u8 ) ? * anyopaque ;
28
27
pub extern fn tcc_list_symbols (s : * TCCState , ctx : ? * anyopaque , symbol_cb : TCCSymbolCallbackFunc ) void ;
29
28
@@ -151,23 +150,12 @@ pub const TCCState = opaque {
151
150
}
152
151
153
152
/// 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 );
159
155
if (ret == -1 )
160
156
return error .RelocateError ;
161
157
}
162
158
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
-
171
159
/// return symbol value or NULL if not found
172
160
pub fn get_symbol (self : * TCCState , name : [:0 ]const u8 ) ? * anyopaque {
173
161
return tcc_get_symbol (self , name .ptr );
@@ -178,19 +166,11 @@ pub const TCCState = opaque {
178
166
tcc_list_symbols (self , ctx , symbol_cb );
179
167
}
180
168
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 {
190
170
const zbytes = try allocator .dupeZ (u8 , buf );
191
171
defer allocator .free (zbytes );
192
172
try self .compile_string (zbytes );
193
- return try self .relocateAlloc ( allocator );
173
+ return try self .relocate ( );
194
174
}
195
175
196
176
/// free a TCC compilation context
@@ -234,7 +214,7 @@ test "tcc - compile" {
234
214
\\}
235
215
);
236
216
237
- try tcc .relocate (.auto );
217
+ try tcc .relocate ();
238
218
239
219
const Fn = * const fn () callconv (.c ) c_int ;
240
220
@@ -245,7 +225,7 @@ test "tcc - compile" {
245
225
try std .testing .expectEqual (res , 123 );
246
226
}
247
227
248
- test "tcc - compileStringOnceAlloc " {
228
+ test "tcc - compileStringOnce " {
249
229
const allocator = std .testing .allocator ;
250
230
251
231
const tcc = try new ();
@@ -254,12 +234,11 @@ test "tcc - compileStringOnceAlloc" {
254
234
tcc .set_options ("-std=c11 -nostdlib -Wl,--export-all-symbols" );
255
235
tcc .set_output_type (TCC_OUTPUT_MEMORY );
256
236
257
- const mem = try tcc .compileStringOnceAlloc (allocator ,
237
+ try tcc .compileStringOnce (allocator ,
258
238
\\int blank() {
259
239
\\ return 234;
260
240
\\}
261
241
);
262
- defer mem .free ();
263
242
264
243
const Fn = * const fn () callconv (.c ) c_int ;
265
244
0 commit comments