Comments (4)
I had a feeling there would be a lingering case of this somewhere...
As with other places where this was all cleaned up some time ago, the solution is to retrieve the expected offset into the stack, and then reference the actual stack pointer for each of the subsequent accesses.
diff --git a/src/vm.c b/src/vm.c
index 22385c8..9141338 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -428,11 +428,11 @@ int krk_processComplexArguments(int argCount, KrkValueArray * positionals, KrkTa
krk_writeValueArray(positionals, krk_currentThread.stackTop[-argCount + i - TOP_ARGS]);
}
- KrkValue * startOfExtras = &krk_currentThread.stackTop[-kwargsCount * 2 - TOP_ARGS];
+ size_t startOfExtras = &krk_currentThread.stackTop[-kwargsCount * 2 - TOP_ARGS] - krk_currentThread.stack;
/* Now unpack everything else. */
for (size_t i = 0; i < kwargsCount; ++i) {
- KrkValue key = startOfExtras[i*2];
- KrkValue value = startOfExtras[i*2 + 1];
+ KrkValue key = krk_currentThread.stack[startOfExtras + i*2];
+ KrkValue value = krk_currentThread.stack[startOfExtras + i*2 + 1];
if (IS_KWARGS(key)) {
if (AS_INTEGER(key) == KWARGS_LIST) { /* unpack list */
if (krk_unpackIterable(value,positionals,_unpack_args)) return 0;
from kuroko.
I should try running some complex workloads with the stack set up to always reallocate on push and see if that weeds out any other cases...
from kuroko.
You might be interested to see that Valgrind caught this rather well:
==1354975== Memcheck, a memory error detector
==1354975== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1354975== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==1354975== Command: kuroko test.krk
==1354975==
==1354975== Invalid read of size 8
==1354975== at 0x158A7B: krk_processComplexArguments (in /usr/bin/kuroko)
==1354975== by 0x159E27: krk_callValue (in /usr/bin/kuroko)
==1354975== by 0x15F859: ??? (in /usr/bin/kuroko)
==1354975== by 0x162AD9: krk_callStack (in /usr/bin/kuroko)
==1354975== by 0x15AD60: krk_runfile (in /usr/bin/kuroko)
==1354975== by 0x111525: main (in /usr/bin/kuroko)
==1354975== Address 0x4afa520 is 96 bytes inside a block of size 256 free'd
==1354975== at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1354975== by 0x157C97: krk_growStack (in /usr/bin/kuroko)
==1354975== by 0x157D59: krk_push (in /usr/bin/kuroko)
==1354975== by 0x112195: krk_valuesSameOrEqual (in /usr/bin/kuroko)
==1354975== by 0x1565B6: krk_findEntry (in /usr/bin/kuroko)
==1354975== by 0x156A3F: krk_tableSet (in /usr/bin/kuroko)
==1354975== by 0x158B13: krk_processComplexArguments (in /usr/bin/kuroko)
==1354975== by 0x159E27: krk_callValue (in /usr/bin/kuroko)
==1354975== by 0x15F859: ??? (in /usr/bin/kuroko)
==1354975== by 0x162AD9: krk_callStack (in /usr/bin/kuroko)
==1354975== by 0x15AD60: krk_runfile (in /usr/bin/kuroko)
==1354975== by 0x111525: main (in /usr/bin/kuroko)
==1354975== Block was alloc'd at
==1354975== at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1354975== by 0x157C97: krk_growStack (in /usr/bin/kuroko)
==1354975== by 0x1617A1: ??? (in /usr/bin/kuroko)
==1354975== by 0x162AD9: krk_callStack (in /usr/bin/kuroko)
==1354975== by 0x15AD60: krk_runfile (in /usr/bin/kuroko)
==1354975== by 0x111525: main (in /usr/bin/kuroko)
==1354975==
==1354975== Invalid read of size 8
==1354975== at 0x158A7F: krk_processComplexArguments (in /usr/bin/kuroko)
==1354975== by 0x159E27: krk_callValue (in /usr/bin/kuroko)
==1354975== by 0x15F859: ??? (in /usr/bin/kuroko)
==1354975== by 0x162AD9: krk_callStack (in /usr/bin/kuroko)
==1354975== by 0x15AD60: krk_runfile (in /usr/bin/kuroko)
==1354975== by 0x111525: main (in /usr/bin/kuroko)
==1354975== Address 0x4afa528 is 104 bytes inside a block of size 256 free'd
==1354975== at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1354975== by 0x157C97: krk_growStack (in /usr/bin/kuroko)
==1354975== by 0x157D59: krk_push (in /usr/bin/kuroko)
==1354975== by 0x112195: krk_valuesSameOrEqual (in /usr/bin/kuroko)
==1354975== by 0x1565B6: krk_findEntry (in /usr/bin/kuroko)
==1354975== by 0x156A3F: krk_tableSet (in /usr/bin/kuroko)
==1354975== by 0x158B13: krk_processComplexArguments (in /usr/bin/kuroko)
==1354975== by 0x159E27: krk_callValue (in /usr/bin/kuroko)
==1354975== by 0x15F859: ??? (in /usr/bin/kuroko)
==1354975== by 0x162AD9: krk_callStack (in /usr/bin/kuroko)
==1354975== by 0x15AD60: krk_runfile (in /usr/bin/kuroko)
==1354975== by 0x111525: main (in /usr/bin/kuroko)
==1354975== Block was alloc'd at
==1354975== at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1354975== by 0x157C97: krk_growStack (in /usr/bin/kuroko)
==1354975== by 0x1617A1: ??? (in /usr/bin/kuroko)
==1354975== by 0x162AD9: krk_callStack (in /usr/bin/kuroko)
==1354975== by 0x15AD60: krk_runfile (in /usr/bin/kuroko)
==1354975== by 0x111525: main (in /usr/bin/kuroko)
==1354975==
{'moment': 7, 'all': 1, 'zero': 0, 'scalar': 2, 'antiscalar': 3, 'point': 4, 'translation': 11, 'flector': 12, 'line': 5, 'motor': 9, 'plane': 6, 'rotation': 10, 'direction': 8}
==1354975==
==1354975== HEAP SUMMARY:
==1354975== in use at exit: 0 bytes in 0 blocks
==1354975== total heap usage: 2,427 allocs, 2,427 frees, 232,168 bytes allocated
==1354975==
==1354975== All heap blocks were freed -- no leaks are possible
==1354975==
==1354975== For lists of detected and suppressed errors, rerun with: -s
==1354975== ERROR SUMMARY: 16 errors from 2 contexts (suppressed: 0 from 0)
from kuroko.
ah, so you were able to reproduce it! I was definitely led astray by my intuition, and should've checked with valgrind first…
from kuroko.
Related Issues (20)
- `dict` argument compatibility with Python HOT 2
- keyword arguments can't default to themselves HOT 4
- Compile to native code? HOT 2
- Globals should be bound to `function`s, not `codeobject`s HOT 1
- Kuroko 1.3
- missing gamma function when built against musl HOT 4
- [Question] Class field declaration? HOT 2
- [Termux] TypeError: __init__() expects list, not 'list' HOT 14
- [scope] `for` iteration scope HOT 3
- [KEP] Allow using `let` to define local variable in "legacy `for` loop" like Javascript HOT 2
- Externalize core modules HOT 1
- Kuroko 1.6 Roadmap
- Evalaute Profile-Guided Optimization (PGO)
- Local time? HOT 3
- “Missing” output HOT 13
- Remove/Rename un-namespaced macros
- Could time.*time() silently truncate floats into ints? HOT 1
- Float parsing uses `strtod`, but rline calls `setlocale` HOT 26
- Does Kuroko have an equivalent to Python's `round()` method? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kuroko.