<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">I am replying to my own thread.<br>Doing a PyStackless_GetRunCount() shows that 0 tasklets are running and that explains why the st.current is in that state.However, I'm not sure crashing the whole application is the best way for PyStackless_GetCurrent() to behave.<br>Also, what contributed to my confusion was that from the PyRun_Simplestring("<span class="yiv2035395251st0">print stackless.getcurrent()</span>") the return value was 1.I guess I will look further today to see why exactly that is so.<br><br><br>--- On <b>Mon, 17/1/11, Andrew Macentire <i><amacentire@ymail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Andrew Macentire <amacentire@ymail.com><br>Subject: [Stackless] Basic stackless embedding<br>To: stackless@stackless.com<br>Date: Monday, 17 January,
 2011, 6:18 PM<br><br><div id="yiv2035395251"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top">Hello! I'm new to the field and I was trying a simple stackless embedding test and experienced problems.Here is the short source code to my test:<br><br><pre class="yiv2035395251source"><pre class="yiv2035395251de1"><span class="yiv2035395251co2">#include <stackless_api.h></span><br><span class="yiv2035395251co2">#include <windows.h></span><br> <br><span class="yiv2035395251kw4">int</span> main<span class="yiv2035395251br0">(</span><span class="yiv2035395251kw4">void</span><span class="yiv2035395251br0">)</span><br> <br><span class="yiv2035395251br0">{</span><br>PyInterpreterState<span class="yiv2035395251sy0">*</span> pys<span class="yiv2035395251sy0">;</span><br>Py_Initialize<span class="yiv2035395251br0">(</span><span class="yiv2035395251br0">)</span><span
 class="yiv2035395251sy0">;</span><br>PyRun_SimpleString<span class="yiv2035395251br0">(</span><span class="yiv2035395251st0">"import stackless"</span><span class="yiv2035395251br0">)</span><span class="yiv2035395251sy0">;</span><br>PyRun_SimpleString<span class="yiv2035395251br0">(</span><span class="yiv2035395251st0">"print<br> stackless.runcount"</span><span class="yiv2035395251br0">)</span><span class="yiv2035395251sy0">;</span><br>PyRun_SimpleString<span class="yiv2035395251br0">(</span><span class="yiv2035395251st0">"print stackless.getcurrent()"</span><span class="yiv2035395251br0">)</span><span class="yiv2035395251sy0">;</span><br>PyObject <span class="yiv2035395251sy0">*</span>task<span class="yiv2035395251sy0">;</span><br>task<span class="yiv2035395251sy0">=</span>PyStackless_GetCurrent<span class="yiv2035395251br0">(</span><span class="yiv2035395251br0">)</span><span class="yiv2035395251sy0">;</span>    <span
 class="yiv2035395251co1">//  <==== CRASH HERE</span><br>Py_DECREF<span class="yiv2035395251br0">(</span>task<span class="yiv2035395251br0">)</span><span class="yiv2035395251sy0">;</span><br> <br><span class="yiv2035395251kw1">return</span> <span class="yiv2035395251nu0">1</span><span class="yiv2035395251sy0">;</span><br><span class="yiv2035395251br0">}<br><br>I am using MSVC 8 and an unmodified distribution of Python 2.7.1 Stackless 3.1b3 060516,<br>built with the same compiler.<br>The crash happens inside </span>PyStackless_GetCurrent, which looks like this:<br><br>PyObject<br> *<br>PyStackless_GetCurrent(void)<br>{<br>    PyThreadState *ts = PyThreadState_GET();<br>    PyObject *t = (PyObject*)ts->st.current;<br><br>    Py_INCREF(t);<br>    return t;<br>}<br><br>The crash happens on Py_INCREF(t), because the thread state object returned by PyThreadState_GET<br>doesn't seem to be properly initialized.<br>I'm probably missing something
 very basic, but any help is appreciated.<br><br>Cheers!<br></pre></pre><br></td></tr></tbody></table><br>

      </div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>Stackless mailing list<br><a ymailto="mailto:Stackless@stackless.com" href="/mc/compose?to=Stackless@stackless.com">Stackless@stackless.com</a><br><a href="http://www.stackless.com/mailman/listinfo/stackless" target="_blank">http://www.stackless.com/mailman/listinfo/stackless</a></div></blockquote></td></tr></table><br>