Skip to content

Commit 364e9ce

Browse files
committed
make cue_compile_{string,bytes} return an error
Signed-off-by: Aram Hăvărneanu <[email protected]>
1 parent 3a7f0cc commit 364e9ce

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

cue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ extern "C" {
9999
cue_ctx cue_newctx(void);
100100
char* cue_error_string(cue_error);
101101

102-
cue_value cue_compile_string(cue_ctx, char*, cue_bopt*);
103-
cue_value cue_compile_bytes(cue_ctx, void*, size_t, cue_bopt*);
102+
cue_error cue_compile_string(cue_ctx, char*, cue_bopt*, cue_value*);
103+
cue_error cue_compile_bytes(cue_ctx, void*, size_t, cue_bopt*, cue_value*);
104104
cue_value cue_top(cue_ctx);
105105
cue_value cue_bottom(cue_ctx);
106106
cue_value cue_unify(cue_value, cue_value);

value.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
#include "option.h"
1818
#include "_cgo_export.h"
1919

20-
cue_value
21-
cue_compile_string(cue_ctx ctx, char *s, cue_bopt *opts) {
22-
return cue_compile_string_raw(ctx, s, opts, cue_bopt_len(opts));
20+
cue_error
21+
cue_compile_string(cue_ctx ctx, char *s, cue_bopt *opts, cue_value *v) {
22+
return cue_compile_string_raw(ctx, s, opts, cue_bopt_len(opts), v);
2323
}
2424

25-
cue_value
26-
cue_compile_bytes(cue_ctx ctx, void *b, size_t len, cue_bopt *opts) {
27-
return cue_compile_bytes_raw(ctx, b, len, opts, cue_bopt_len(opts));
25+
cue_error
26+
cue_compile_bytes(cue_ctx ctx, void *b, size_t len, cue_bopt *opts, cue_value *v) {
27+
return cue_compile_bytes_raw(ctx, b, len, opts, cue_bopt_len(opts), v);
2828
}
2929

3030
cue_error

value.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,27 @@ import (
2828
)
2929

3030
//export cue_compile_string_raw
31-
func cue_compile_string_raw(ctx C.cue_ctx, str *C.char, opts *C.struct_cue_bopt, len C.size_t) C.cue_value {
31+
func cue_compile_string_raw(ctx C.cue_ctx, str *C.char, opts *C.struct_cue_bopt, len C.size_t, v *C.cue_value) C.cue_error {
3232
bopts := buildOptions(opts, len)
3333
val := cueContext(ctx).CompileString(C.GoString(str), bopts...)
34-
return cueValueHandle(val)
34+
35+
if err := val.Err(); err != nil {
36+
return cueErrorHandle(err)
37+
}
38+
*v = cueValueHandle(val)
39+
return 0
3540
}
3641

3742
//export cue_compile_bytes_raw
38-
func cue_compile_bytes_raw(ctx C.cue_ctx, buf unsafe.Pointer, bufLen C.size_t, opts *C.struct_cue_bopt, optLen C.size_t) C.cue_value {
43+
func cue_compile_bytes_raw(ctx C.cue_ctx, buf unsafe.Pointer, bufLen C.size_t, opts *C.struct_cue_bopt, optLen C.size_t, v *C.cue_value) C.cue_error {
3944
bopts := buildOptions(opts, optLen)
4045
val := cueContext(ctx).CompileBytes(C.GoBytes(buf, C.int(bufLen)), bopts...)
41-
return cueValueHandle(val)
46+
47+
if err := val.Err(); err != nil {
48+
return cueErrorHandle(err)
49+
}
50+
*v = cueValueHandle(val)
51+
return 0
4252
}
4353

4454
//export cue_top

0 commit comments

Comments
 (0)