File tree 3 files changed +10
-7
lines changed
3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -500,7 +500,7 @@ func (m Module) Dump() {
500
500
501
501
func (m Module ) String () string {
502
502
cir := C .LLVMPrintModuleToString (m .C )
503
- defer C .free ( unsafe . Pointer ( cir ) )
503
+ defer C .LLVMDisposeMessage ( cir )
504
504
ir := C .GoString (cir )
505
505
return ir
506
506
}
Original file line number Diff line number Diff line change 13
13
package llvm
14
14
15
15
/*
16
+ #include "llvm-c/Core.h"
16
17
#include "llvm-c/IRReader.h"
17
18
#include <stdlib.h>
18
19
*/
19
20
import "C"
20
21
21
22
import (
22
23
"errors"
23
- "unsafe"
24
24
)
25
25
26
26
// ParseIR parses the textual IR given in the memory buffer and returns a new
@@ -30,7 +30,7 @@ func (c *Context) ParseIR(buf MemoryBuffer) (Module, error) {
30
30
var errmsg * C.char
31
31
if C .LLVMParseIRInContext (c .C , buf .C , & m .C , & errmsg ) != 0 {
32
32
err := errors .New (C .GoString (errmsg ))
33
- C .free ( unsafe . Pointer ( errmsg ) )
33
+ C .LLVMDisposeMessage ( errmsg )
34
34
return Module {}, err
35
35
}
36
36
return m , nil
Original file line number Diff line number Diff line change @@ -19,8 +19,10 @@ package llvm
19
19
#include <stdlib.h>
20
20
*/
21
21
import "C"
22
- import "unsafe"
23
- import "errors"
22
+ import (
23
+ "errors"
24
+ "unsafe"
25
+ )
24
26
25
27
type (
26
28
TargetData struct {
@@ -220,7 +222,7 @@ func GetTargetFromTriple(triple string) (t Target, err error) {
220
222
fail := C .LLVMGetTargetFromTriple (ctriple , & t .C , & errstr )
221
223
if fail != 0 {
222
224
err = errors .New (C .GoString (errstr ))
223
- C .free ( unsafe . Pointer ( errstr ) )
225
+ C .LLVMDisposeMessage ( errstr )
224
226
}
225
227
return
226
228
}
@@ -264,6 +266,7 @@ func (tm TargetMachine) CreateTargetData() TargetData {
264
266
// Triple returns the triple describing the machine (arch-vendor-os).
265
267
func (tm TargetMachine ) Triple () string {
266
268
cstr := C .LLVMGetTargetMachineTriple (tm .C )
269
+ defer C .LLVMDisposeMessage (cstr )
267
270
return C .GoString (cstr )
268
271
}
269
272
@@ -290,7 +293,7 @@ func (tm TargetMachine) Dispose() {
290
293
291
294
func DefaultTargetTriple () (triple string ) {
292
295
cTriple := C .LLVMGetDefaultTargetTriple ()
293
- defer C .free ( unsafe . Pointer ( cTriple ) )
296
+ defer C .LLVMDisposeMessage ( cTriple )
294
297
triple = C .GoString (cTriple )
295
298
return
296
299
}
You can’t perform that action at this time.
0 commit comments