fix SEGV issue & merge xmake
This commit is contained in:
parent
22a2e87003
commit
c582108917
2 changed files with 71 additions and 12 deletions
|
|
@ -73,6 +73,7 @@ struct string_list {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
struct capn capn;
|
||||||
struct str HDR;
|
struct str HDR;
|
||||||
struct str SRC;
|
struct str SRC;
|
||||||
struct capn_segment g_valseg;
|
struct capn_segment g_valseg;
|
||||||
|
|
@ -1118,7 +1119,7 @@ static void encode_member(capnp_ctx_t *ctx, struct str *func, struct field *f,
|
||||||
static void decode_member(capnp_ctx_t *ctx, struct str *func, struct field *f,
|
static void decode_member(capnp_ctx_t *ctx, struct str *func, struct field *f,
|
||||||
const char *tab, const char *var, const char *var2) {
|
const char *tab, const char *var, const char *var2) {
|
||||||
struct Type list_type;
|
struct Type list_type;
|
||||||
struct node * n = NULL;
|
struct node *n = NULL;
|
||||||
|
|
||||||
if (f->v.t.which == Type__void) {
|
if (f->v.t.which == Type__void) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -2110,18 +2111,17 @@ static void declare_codec(capnp_ctx_t *ctx, struct node *file_node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int ctx_init(capnp_ctx_t *ctx, FILE *fp) {
|
int ctx_init(capnp_ctx_t *ctx, FILE *fp) {
|
||||||
struct capn capn;
|
|
||||||
struct capn_segment *current_seg = NULL;
|
struct capn_segment *current_seg = NULL;
|
||||||
int total_len = 0;
|
int total_len = 0;
|
||||||
int i;
|
int i;
|
||||||
struct node *n;
|
struct node *n;
|
||||||
|
|
||||||
memset(ctx, 0x0, sizeof(*ctx));
|
memset(ctx, 0x0, sizeof(*ctx));
|
||||||
if (capn_init_fp(&capn, fp, 0) < 0) {
|
if (capn_init_fp(&(ctx->capn), fp, 0) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_seg = capn.seglist;
|
current_seg = ctx->capn.seglist;
|
||||||
while (current_seg != NULL) {
|
while (current_seg != NULL) {
|
||||||
total_len += current_seg->len;
|
total_len += current_seg->len;
|
||||||
current_seg = current_seg->next;
|
current_seg = current_seg->next;
|
||||||
|
|
@ -2130,7 +2130,7 @@ int ctx_init(capnp_ctx_t *ctx, FILE *fp) {
|
||||||
ctx->g_valseg.data = calloc(1, total_len);
|
ctx->g_valseg.data = calloc(1, total_len);
|
||||||
ctx->g_valseg.cap = total_len;
|
ctx->g_valseg.cap = total_len;
|
||||||
|
|
||||||
ctx->root.p = capn_getp(capn_root(&capn), 0, 1);
|
ctx->root.p = capn_getp(capn_root(&(ctx->capn)), 0, 1);
|
||||||
read_CodeGeneratorRequest(&(ctx->req), ctx->root);
|
read_CodeGeneratorRequest(&(ctx->req), ctx->root);
|
||||||
|
|
||||||
for (i = 0; i < capn_len(ctx->req.nodes); i++) {
|
for (i = 0; i < capn_len(ctx->req.nodes); i++) {
|
||||||
|
|
@ -2518,13 +2518,14 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fp = stdin;
|
fp = stdin;
|
||||||
#if defined(_WIN32)
|
|
||||||
if (_setmode(_fileno(fp), _O_BINARY) == -1) {
|
|
||||||
fail(-1, "fail to set stdin to binary mode\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
if (_setmode(_fileno(fp), _O_BINARY) == -1) {
|
||||||
|
fail(-1, "fail to set stdin to binary mode\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ctx_init(&ctx, fp);
|
ctx_init(&ctx, fp);
|
||||||
|
|
||||||
ctx_resolve_names(&ctx);
|
ctx_resolve_names(&ctx);
|
||||||
|
|
|
||||||
58
xmake.lua
Normal file
58
xmake.lua
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
includes("@builtin/xpack")
|
||||||
|
|
||||||
|
add_requires("gtest")
|
||||||
|
|
||||||
|
option("trace")
|
||||||
|
set_default(false)
|
||||||
|
set_showmenu(true)
|
||||||
|
add_defines("DEBUG")
|
||||||
|
|
||||||
|
target("CapnC_Runtime")
|
||||||
|
set_kind("static")
|
||||||
|
add_rules("utils.install.pkgconfig_importfiles")
|
||||||
|
add_files("lib/*.c")
|
||||||
|
add_headerfiles("lib/capnp_c.h")
|
||||||
|
add_options("trace")
|
||||||
|
|
||||||
|
target("capnpc-c")
|
||||||
|
set_kind("binary")
|
||||||
|
add_files("compiler/*.c")
|
||||||
|
add_includedirs("lib", "compiler")
|
||||||
|
add_installfiles("compiler/c.capnp", "compiler/c++.capnp","compiler/schema.capnp",{ prefixdir = "share/schema"})
|
||||||
|
add_deps("CapnC_Runtime")
|
||||||
|
add_options("trace")
|
||||||
|
|
||||||
|
rule("capnproto.c")
|
||||||
|
set_extensions(".capnp")
|
||||||
|
on_build_file(function (target, sourcefile,opt)
|
||||||
|
os.setenv("PATH", string.format("%s:%s", target:targetdir(), os.getenv("PATH")))
|
||||||
|
os.runv("capnp", {"compile", "-oc", "-Icompiler", sourcefile})
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
target("test")
|
||||||
|
set_kind("binary")
|
||||||
|
add_packages("gtest")
|
||||||
|
add_files("tests/*.c", "tests/*.cpp")
|
||||||
|
add_deps("CapnC_Runtime", "capnpc-c")
|
||||||
|
add_includedirs("compiler", "lib")
|
||||||
|
add_options("trace")
|
||||||
|
|
||||||
|
target("book")
|
||||||
|
set_kind("binary")
|
||||||
|
set_policy("build.across_targets_in_parallel", false)
|
||||||
|
add_packages("capnpc-c")
|
||||||
|
add_rules("capnproto.c")
|
||||||
|
add_files("examples/book/book.capnp")
|
||||||
|
add_files("examples/book/*.c")
|
||||||
|
add_includedirs("compiler","lib","examples/book")
|
||||||
|
add_deps("CapnC_Runtime", "capnpc-c")
|
||||||
|
|
||||||
|
xpack("capnpc-c")
|
||||||
|
set_formats("targz")
|
||||||
|
set_title("c-capnproto")
|
||||||
|
set_licensefile("COPYING")
|
||||||
|
add_targets("capnpc-c", "CapnC_Runtime")
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue