v.depgraph: ensure `v -d debug_realloc -o v cmd/v` works
parent
db152868c0
commit
b6d089b605
|
@ -87,8 +87,8 @@ jobs:
|
||||||
- name: Build v
|
- name: Build v
|
||||||
run: |
|
run: |
|
||||||
echo $VFLAGS
|
echo $VFLAGS
|
||||||
sudo ln -s $PWD/thirdparty/tcc/tcc.exe /usr/local/bin/tcc ## TODO: remove
|
make
|
||||||
make -j4
|
./v -d debug_realloc -o v cmd/v
|
||||||
./v -cg -cflags -Werror -o v cmd/v
|
./v -cg -cflags -Werror -o v cmd/v
|
||||||
- name: Test v->c
|
- name: Test v->c
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -230,7 +230,8 @@ pub fn realloc_data(old_data byteptr, old_size int, new_size int) byteptr {
|
||||||
$if prealloc {
|
$if prealloc {
|
||||||
unsafe {
|
unsafe {
|
||||||
new_ptr := malloc(new_size)
|
new_ptr := malloc(new_size)
|
||||||
C.memcpy(new_ptr, old_data, old_size)
|
min_size := if old_size < new_size { old_size } else { new_size }
|
||||||
|
C.memcpy(new_ptr, old_data, min_size)
|
||||||
return new_ptr
|
return new_ptr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,7 +246,8 @@ pub fn realloc_data(old_data byteptr, old_size int, new_size int) byteptr {
|
||||||
// it will point to memory that is now filled with 0x57.
|
// it will point to memory that is now filled with 0x57.
|
||||||
unsafe {
|
unsafe {
|
||||||
new_ptr := malloc(new_size)
|
new_ptr := malloc(new_size)
|
||||||
C.memcpy(new_ptr, old_data, old_size)
|
min_size := if old_size < new_size { old_size } else { new_size }
|
||||||
|
C.memcpy(new_ptr, old_data, min_size)
|
||||||
C.memset(old_data, 0x57, old_size)
|
C.memset(old_data, 0x57, old_size)
|
||||||
C.free(old_data)
|
C.free(old_data)
|
||||||
return new_ptr
|
return new_ptr
|
||||||
|
@ -253,7 +255,7 @@ pub fn realloc_data(old_data byteptr, old_size int, new_size int) byteptr {
|
||||||
}
|
}
|
||||||
nptr := unsafe { C.realloc(old_data, new_size) }
|
nptr := unsafe { C.realloc(old_data, new_size) }
|
||||||
if nptr == 0 {
|
if nptr == 0 {
|
||||||
panic('realloc_data($new_size) failed')
|
panic('realloc_data($old_data, $old_size, $new_size) failed')
|
||||||
}
|
}
|
||||||
return nptr
|
return nptr
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub fn (mut o OrderedDepMap) set(name string, deps []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut o OrderedDepMap) add(name string, deps []string) {
|
pub fn (mut o OrderedDepMap) add(name string, deps []string) {
|
||||||
mut d := o.data[name]
|
mut d := o.get(name)
|
||||||
for dep in deps {
|
for dep in deps {
|
||||||
if dep !in d {
|
if dep !in d {
|
||||||
d << dep
|
d << dep
|
||||||
|
@ -42,7 +42,8 @@ pub fn (mut o OrderedDepMap) add(name string, deps []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (o &OrderedDepMap) get(name string) []string {
|
pub fn (o &OrderedDepMap) get(name string) []string {
|
||||||
return o.data[name]
|
res := o.data[name] or { []string{} }
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut o OrderedDepMap) delete(name string) {
|
pub fn (mut o OrderedDepMap) delete(name string) {
|
||||||
|
@ -60,7 +61,8 @@ pub fn (mut o OrderedDepMap) delete(name string) {
|
||||||
|
|
||||||
pub fn (mut o OrderedDepMap) apply_diff(name string, deps []string) {
|
pub fn (mut o OrderedDepMap) apply_diff(name string, deps []string) {
|
||||||
mut diff := []string{}
|
mut diff := []string{}
|
||||||
for dep in o.data[name] {
|
deps_of_name := o.get(name)
|
||||||
|
for dep in deps_of_name {
|
||||||
if dep !in deps {
|
if dep !in deps {
|
||||||
diff << dep
|
diff << dep
|
||||||
}
|
}
|
||||||
|
@ -75,14 +77,16 @@ pub fn (o &OrderedDepMap) size() int {
|
||||||
pub fn new_dep_graph() &DepGraph {
|
pub fn new_dep_graph() &DepGraph {
|
||||||
return &DepGraph{
|
return &DepGraph{
|
||||||
acyclic: true
|
acyclic: true
|
||||||
|
nodes: []DepGraphNode{cap: 1024}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut graph DepGraph) add(mod string, deps []string) {
|
pub fn (mut graph DepGraph) add(mod string, deps []string) {
|
||||||
graph.nodes << DepGraphNode{
|
new_node := DepGraphNode{
|
||||||
name: mod
|
name: mod
|
||||||
deps: deps.clone()
|
deps: deps.clone()
|
||||||
}
|
}
|
||||||
|
graph.nodes << new_node
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (graph &DepGraph) resolve() &DepGraph {
|
pub fn (graph &DepGraph) resolve() &DepGraph {
|
||||||
|
@ -96,7 +100,7 @@ pub fn (graph &DepGraph) resolve() &DepGraph {
|
||||||
for node_deps.size() != 0 {
|
for node_deps.size() != 0 {
|
||||||
mut ready_set := []string{}
|
mut ready_set := []string{}
|
||||||
for name in node_deps.keys {
|
for name in node_deps.keys {
|
||||||
deps := node_deps.data[name]
|
deps := node_deps.get(name)
|
||||||
if deps.len == 0 {
|
if deps.len == 0 {
|
||||||
ready_set << name
|
ready_set << name
|
||||||
}
|
}
|
||||||
|
@ -105,13 +109,14 @@ pub fn (graph &DepGraph) resolve() &DepGraph {
|
||||||
mut g := new_dep_graph()
|
mut g := new_dep_graph()
|
||||||
g.acyclic = false
|
g.acyclic = false
|
||||||
for name in node_deps.keys {
|
for name in node_deps.keys {
|
||||||
g.add(name, node_names.data[name])
|
g.add(name, node_names.get(name))
|
||||||
}
|
}
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
for name in ready_set {
|
for name in ready_set {
|
||||||
node_deps.delete(name)
|
node_deps.delete(name)
|
||||||
resolved.add(name, node_names.data[name])
|
resolved_deps := node_names.get(name)
|
||||||
|
resolved.add(name, resolved_deps)
|
||||||
}
|
}
|
||||||
for name in node_deps.keys {
|
for name in node_deps.keys {
|
||||||
node_deps.apply_diff(name, ready_set)
|
node_deps.apply_diff(name, ready_set)
|
||||||
|
|
Loading…
Reference in New Issue