Skip to content

Commit 4feb6ad

Browse files
committed
feat: add quickjs_backtrace package
1 parent d9cf56e commit 4feb6ad

File tree

12 files changed

+337
-19
lines changed

12 files changed

+337
-19
lines changed

src/core/gc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ void __JS_FreeValue(JSContext* ctx, JSValue v) {
529529
void add_gc_object(JSRuntime* rt, JSGCObjectHeader* h, JSGCObjectTypeEnum type) {
530530
h->mark = 0;
531531
h->gc_obj_type = type;
532+
533+
// TODO: monitor new created object
534+
// print_gc_object(&rt->gc_obj_list);
535+
// printf("stack: %s", get_backtrace());
536+
532537
list_add_tail(&h->link, &rt->gc_obj_list);
533538
}
534539

src/core/runtime.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,9 @@ void JS_FreeRuntime(JSRuntime* rt) {
26702670
printf("Secondary object leaks: %d\n", count);
26712671
}
26722672
#endif
2673-
print_gc_objects(&rt->gc_obj_list);
2673+
// Fixme: find the reason why there still some objects not freed
2674+
// print_gc_objects(&rt->gc_obj_list);
2675+
26742676
assert(list_empty(&rt->gc_obj_list));
26752677

26762678
/* free the classes */

src/core/shape.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ JSValue JS_NewObjectFromShape(JSContext* ctx, JSShape* sh, JSClassID class_id) {
559559
break;
560560
}
561561
p->header.ref_count = 1;
562-
add_gc_object(ctx->rt, &p->header, JS_GC_OBJ_TYPE_JS_OBJECT);
562+
add_gc_object(ctx->rt, &p->header, JS_GC_OBJ_TYPE_JS_OBJECT);
563563
return JS_MKPTR(JS_TAG_OBJECT, p);
564564
}
565565

src/crates/Cargo.lock

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/crates/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
resolver = "2"
33
members = [
44
"quickjs",
5-
"quickjs_gc"
5+
"quickjs_gc",
6+
"quickjs_backtrace"
67
]

src/crates/cbindgen.toml

Lines changed: 150 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,152 @@
1-
# Whether cbindgen's default C/C++ standard imports should be suppressed. These
2-
# imports are included by default because our generated headers tend to require
3-
# them (e.g. for uint32_t). Currently, the generated imports are:
1+
# This is a template cbindgen.toml file with all of the default values.
2+
# Some values are commented out because their absence is the real default.
43
#
5-
# * for C: <stdarg.h>, <stdbool.h>, <stdint.h>, <stdlib.h>, <uchar.h>
6-
#
7-
# * for C++: <cstdarg>, <cstdint>, <cstdlib>, <new>, <cassert> (depending on config)
8-
#
9-
# default: false
4+
# See https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml
5+
# for detailed documentation of every option here.
6+
7+
8+
9+
language = "c"
10+
11+
12+
13+
############## Options for Wrapping the Contents of the Header #################
14+
15+
# header = "/* Text to put at the beginning of the generated file. Probably a license. */"
16+
# trailer = "/* Text to put at the end of the generated file */"
17+
# include_guard = "my_bindings_h"
18+
# pragma_once = true
19+
# autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
20+
include_version = false
21+
# namespace = "my_namespace"
22+
namespaces = []
23+
using_namespaces = []
24+
sys_includes = []
25+
includes = []
1026
no_includes = true
27+
after_includes = ""
28+
29+
30+
31+
32+
############################ Code Style Options ################################
33+
34+
braces = "SameLine"
35+
line_length = 100
36+
tab_width = 2
37+
documentation = true
38+
documentation_style = "auto"
39+
documentation_length = "full"
40+
line_endings = "LF" # also "CR", "CRLF", "Native"
41+
42+
43+
44+
45+
############################# Codegen Options ##################################
46+
47+
style = "both"
48+
sort_by = "Name" # default for `fn.sort_by` and `const.sort_by`
49+
usize_is_size_t = true
50+
51+
52+
53+
[defines]
54+
# "target_os = freebsd" = "DEFINE_FREEBSD"
55+
# "feature = serde" = "DEFINE_SERDE"
56+
57+
58+
59+
[export]
60+
include = []
61+
exclude = ["JSGCObjectHeader"]
62+
# prefix = "CAPI_"
63+
item_types = []
64+
renaming_overrides_prefixing = false
65+
66+
67+
68+
[export.rename]
69+
70+
71+
72+
[export.body]
73+
74+
75+
[export.mangle]
76+
77+
78+
[fn]
79+
rename_args = "None"
80+
# must_use = "MUST_USE_FUNC"
81+
# no_return = "NO_RETURN"
82+
# prefix = "START_FUNC"
83+
# postfix = "END_FUNC"
84+
args = "auto"
85+
sort_by = "Name"
86+
87+
88+
89+
90+
[struct]
91+
rename_fields = "None"
92+
# must_use = "MUST_USE_STRUCT"
93+
derive_constructor = false
94+
derive_eq = false
95+
derive_neq = false
96+
derive_lt = false
97+
derive_lte = false
98+
derive_gt = false
99+
derive_gte = false
100+
101+
102+
103+
104+
[enum]
105+
rename_variants = "None"
106+
# must_use = "MUST_USE_ENUM"
107+
add_sentinel = false
108+
prefix_with_name = false
109+
derive_helper_methods = false
110+
derive_const_casts = false
111+
derive_mut_casts = false
112+
# cast_assert_name = "ASSERT"
113+
derive_tagged_enum_destructor = false
114+
derive_tagged_enum_copy_constructor = false
115+
enum_class = true
116+
private_default_tagged_enum_constructor = false
117+
118+
119+
120+
121+
[const]
122+
allow_static_const = true
123+
allow_constexpr = false
124+
sort_by = "Name"
125+
126+
127+
128+
129+
[macro_expansion]
130+
bitflags = false
131+
132+
133+
134+
135+
136+
137+
############## Options for How Your Rust library Should Be Parsed ##############
138+
139+
[parse]
140+
parse_deps = true
141+
# include = [""]
142+
exclude = ["memchr"]
143+
clean = false
144+
extra_bindings = ["quickjs_gc", "quickjs_backtrace"]
145+
146+
147+
148+
[parse.expand]
149+
crates = []
150+
all_features = false
151+
default_features = true
152+
features = []

src/crates/quickjs/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ crate-type = ["staticlib"]
1010

1111
[dependencies]
1212

13-
quickjs_gc = { path = "../quickjs_gc" }
13+
quickjs_gc = { path = "../quickjs_gc" }
14+
quickjs_backtrace = { path = "../quickjs_backtrace" }

src/crates/quickjs/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ fn main() {
1515
.arg("--config")
1616
.arg("cbindgen.toml")
1717
.arg("--crate")
18-
.arg("quickjs_gc") // quickjs_gc
18+
.arg("quickjs")
1919
.arg("--lang")
2020
.arg("c")
2121
.arg("--output")
2222
.arg("include/quickjs-rs.h")
2323
.output()
24-
.expect("FAiled");
24+
.expect("Failed to execute command.");
2525

2626
println!("{}", String::from_utf8_lossy(&output.stdout));
2727
eprintln!("{}", String::from_utf8_lossy(&output.stderr));

src/crates/quickjs/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pub use quickjs_gc::print_gc_objects;
1+
pub use quickjs_gc::{print_gc_objects, print_gc_object};
2+
pub use quickjs_backtrace::{get_backtrace, free_backtrace_string};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "quickjs_backtrace"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
backtrace = "0.3.67"
8+
libc = "0.2.146"

0 commit comments

Comments
 (0)