Giter VIP home page Giter VIP logo

Comments (8)

Dr-Syn avatar Dr-Syn commented on July 22, 2024

I see you're using Ubuntu; which version do you have, so I can replicate?

from micropython.

Chananyah avatar Chananyah commented on July 22, 2024

OS is
ubuntu 13.04 (GNU/Linux 3.8.0-34-generic x86_64)

gcc --version gives
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3

from micropython.

hagenkaye avatar hagenkaye commented on July 22, 2024

just as a side note. It seems the stack trace made github markdown go crazy and link this post with others. I tried to edit by putting a code fence block around the stack trace, but the links are still there.

from micropython.

dpgeorge avatar dpgeorge commented on July 22, 2024

Yes, this is a bug. It doesn't crash for me, but prints the wrong number (10 times).

If you want to try and fix it, enable debug output in runtime.c, at line 20. Then run the example again.

from micropython.

Dr-Syn avatar Dr-Syn commented on July 22, 2024

I can confirm that the above program listing will segfault on ubuntu 12.04 using GCC.

Using that setup, with the runtime.c debug output, I get:

store name test <- 0x94da7e0
assign byte code: id=1 code=0x94daca8 len=36 n_args=0
 00 90 02 25 27 13 0a 00 80 92 01 52 92 01 35 2c
 25 2c 52 53 0c 00 35 2d 25 26 25 2d 92 01 42 45
 f1 7f 11 80
(NUM_LOCAL 0)
00 MAKE_FUNCTION 2
02 LOAD_NAME range
04 LOAD_CONST_SMALL_INT 10
08 CALL_FUNCTION n=1 nkw=0
10 GET_ITER
11 CALL_FUNCTION n=1 nkw=0
13 STORE_NAME gen
15 LOAD_NAME gen
17 GET_ITER
18 FOR_ITER 33
21 STORE_NAME i
23 LOAD_NAME print
25 LOAD_NAME i
27 CALL_FUNCTION n=1 nkw=0
29 POP_TOP
30 JUMP 18
33 LOAD_CONST_NONE
34 RETURN_VALUE
assign byte code: id=2 code=0x94dac68 len=14 n_args=1
 00 20 53 07 00 31 21 82 42 45 f6 7f 11 80
(NUM_LOCAL 0)
00 LOAD_FAST_0
01 FOR_ITER 11
04 STORE_FAST_1
05 LOAD_FAST_1
06 YIELD_VALUE
07 POP_TOP
08 JUMP 1
11 LOAD_CONST_NONE
12 RETURN_VALUE
make_function_from_id 1
calling function 0x94dbfc8(n_args=0, args=(nil))
make_function_from_id 2
load name range
calling function 0x94daa68(n_args=1, args=0xbf819d3c)
calling function 0x94dac18(n_args=1, args=0xbf819d40)
store name gen <- 0x94dc038
load name gen
store name i <- (nil)
load name print
load name i
calling function 0x94daa50(n_args=1, args=0xbf819d3c)
Segmentation fault

from micropython.

Dr-Syn avatar Dr-Syn commented on July 22, 2024

And interestingly enough, changing the generator function in the original code to

gen = (1*i for i in range(10))

results in a successful test, returning 0 through 9 as expected.

from micropython.

Dr-Syn avatar Dr-Syn commented on July 22, 2024

Also, using the list comprehension, as:

gen = [i for i in range(10)]

will work just fine and dandy. For some reason, it just doesn't like the naked variable sitting there without something happening to it.

Update: go figure while I'm digging around that you fix it. :-)

from micropython.

dpgeorge avatar dpgeorge commented on July 22, 2024

It was a pretty nasty bug: I allocated enough memory for the state of the generator (to hold local variables and the stack), but I initialised the stack pointer to the last element, when it should be initialised to the position just after the last element of the state. This is because the stack is pre-decrement

Sorry if I spoiled your fun!

from micropython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.