<p><spanstyle="border-bottom: solid 1px grey;">Generated by Cython 0.29b1</span></p>
<p>
<spanstyle="background-color: #FFFF00">Yellow lines</span> hint at Python interaction.<br/>
Click on a line that starts with a "<code>+</code>" to see the C code that Cython generated for it.
</p>
<p>Raw output: <ahref="test.c">test.c</a></p>
<divclass="cython"><preclass="cython line score-0"> <spanclass="">001</span>: #cython: language_level = 3</pre>
<preclass="cython line score-0"> <spanclass="">002</span>: from cython.parallel import parallel</pre>
<preclass="cython line score-0"> <spanclass="">003</span>: from libc.stdio cimport printf</pre>
<preclass="cython line score-0"> <spanclass="">004</span>: """</pre>
<preclass="cython line score-0"> <spanclass="">005</span>: GOAL: implement nogil option in cdef class (extension types)</pre>
<preclass="cython line score-0"> <spanclass="">006</span>: and native memory manager (refcount based) that does not</pre>
<preclass="cython line score-0"> <spanclass="">007</span>: depend on cpython's memory manager and that does not require GIL.</pre>
<preclass="cython line score-0"> <spanclass="">008</span>: </pre>
<preclass="cython line score-0"> <spanclass="">009</span>: HINT: look at C++ standard library (that works very nicely with Cython)</pre>
<preclass="cython line score-0"> <spanclass="">010</span>: </pre>
<preclass="cython line score-0"> <spanclass="">011</span>: Cython documentation if here: http://docs.cython.org/en/latest/</pre>
<preclass="cython line score-0"> <spanclass="">012</span>: </pre>
<preclass="cython line score-0"> <spanclass="">013</span>: Basic usage: http://docs.cython.org/en/latest/src/quickstart/build.html</pre>
<preclass="cython line score-0"> <spanclass="">014</span>: </pre>
<preclass="cython line score-0"> <spanclass="">015</span>: Tutorial: http://docs.cython.org/en/latest/src/tutorial/cython_tutorial.html</pre>
<preclass="cython line score-0"> <spanclass="">016</span>: </pre>
<preclass="cython line score-0"> <spanclass="">017</span>: Language: http://docs.cython.org/en/latest/src/userguide/language_basics.html</pre>
<preclass="cython line score-0"> <spanclass="">018</span>: </pre>
<preclass="cython line score-0"> <spanclass="">019</span>: Extension types: http://docs.cython.org/en/latest/src/userguide/extension_types.html</pre>
<preclass="cython line score-0"> <spanclass="">020</span>: </pre>
<preclass="cython line score-0"> <spanclass="">021</span>: Extension Types are the "pure cython" classes that I want to be able to</pre>
<preclass="cython line score-0"> <spanclass="">022</span>: use without depending on cpython GIL (and in essence runtime, memory manager, etc.)</pre>
<preclass="cython line score-0"> <spanclass="">023</span>: </pre>
<preclass="cython line score-0"> <spanclass="">024</span>: Cython memory allocation: http://docs.cython.org/en/latest/src/tutorial/memory_allocation.html</pre>
<preclass="cython line score-0"> <spanclass="">025</span>: </pre>
<preclass="cython line score-0"> <spanclass="">026</span>: Parallelism: http://docs.cython.org/en/latest/src/userguide/parallelism.html</pre>
<preclass="cython line score-0"> <spanclass="">027</span>: </pre>
<preclass="cython line score-0"> <spanclass="">028</span>: Explains how nogil is posisble in cython for anything that</pre>
<preclass="cython line score-0"> <spanclass="">029</span>: only relies on C libraries that are multi-threaded</pre>
<preclass="cython line score-0"> <spanclass="">030</span>: """</pre>
<preclass="cython line score-0"> <spanclass="">031</span>: </pre>
<preclass="cython line score-0"> <spanclass="">032</span>: </pre>
<preclass="cython line score-0"> <spanclass="">033</span>: </pre>
<preclass="cython line score-0"> <spanclass="">034</span>: # cdef class SomeMemory:</pre>
<preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">035</span>: cdef class SomeMemory nogil:</pre>
</pre><preclass="cython line score-0"> <spanclass="">053</span>: """</pre>
<preclass="cython line score-0"> <spanclass="">054</span>: It is possible to define native C/Cython methods</pre>
<preclass="cython line score-0"> <spanclass="">055</span>: that release the GIL (cool...)</pre>
<preclass="cython line score-0"> <spanclass="">056</span>: """</pre>
<preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">057</span>: while 1:</pre>
<preclass='cython code score-0 '> while (1) {
</pre><preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">058</span>: self.a += 1</pre>
</pre><preclass="cython line score-0"> <spanclass="">059</span>: </pre>
<preclass="cython line score-0"> <spanclass="">060</span>: # Not allowed to define pure Python function in the extension type with nogil option now</pre>
<preclass="cython line score-0"> <spanclass="">061</span>: # since we want this extension type is CPython free</pre>
<preclass="cython line score-0"> <spanclass="">062</span>: # def baz(self):</pre>
<preclass="cython line score-0"> <spanclass="">063</span>: # """</pre>
<preclass="cython line score-0"> <spanclass="">064</span>: # It is also possible to define standard python</pre>
<preclass="cython line score-0"> <spanclass="">065</span>: # methods</pre>
<preclass="cython line score-0"> <spanclass="">066</span>: # """</pre>
<preclass="cython line score-0"> <spanclass="">067</span>: # pass</pre>
<preclass="cython line score-0"> <spanclass="">068</span>: </pre>
<preclass="cython line score-0"> <spanclass="">069</span>: </pre>
<preclass="cython line score-0"> <spanclass="">070</span>: # cdef bar(): # it is currently impossible to release GIL</pre>
<preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">071</span>: cdef double bar() nogil: # yet this is what we would like to</pre>
</pre><preclass="cython line score-0"> <spanclass="">072</span>: """</pre>
<preclass="cython line score-0"> <spanclass="">073</span>: This is a pure "cython method" which we would like to</pre>
<preclass="cython line score-0"> <spanclass="">074</span>: be able to declare with nogil option but this requires</pre>
<preclass="cython line score-0"> <spanclass="">075</span>: to first introduce the concept of nogil in cdef class</pre>
<preclass="cython line score-0"> <spanclass="">076</span>: """</pre>
<preclass="cython line score-0"> <spanclass="">077</span>: # cdef SomeMemory o = SomeMemory(42.0, 3.14) # for this we need class allocation to handle memory without libpython</pre>
<preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">078</span>: cdef SomeMemory o1 = SomeMemory(1, 1.0)</pre>
</pre><preclass="cython line score-4"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">080</span>: with nogil, parallel():</pre>
</pre><preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">081</span>: o1.foo()</pre>
</pre><preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">082</span>: o2.foo()</pre>
</pre><preclass="cython line score-0"> <spanclass="">083</span>: # o.foo() # and we need method selection to be independent of libpython</pre>
<preclass="cython line score-0"> <spanclass="">084</span>: # o.foo1(2)</pre>
<preclass="cython line score-0"> <spanclass="">085</span>: # o.a = 2.732</pre>
<preclass="cython line score-0"> <spanclass="">086</span>: # o.fact(100)</pre>
<preclass="cython line score-0"> <spanclass="">087</span>: </pre>
<preclass="cython line score-0"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">088</span>: return o1.a</pre>
</pre><preclass="cython line score-0"> <spanclass="">089</span>: </pre>
<preclass="cython line score-7"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">090</span>: cpdef baz():</pre>
static char __pyx_doc_4test_baz[] = "\n This method is both callable from python and pure \"cython\".\n It can call both cdef methods and usual python functions\n ";
</pre><preclass="cython line score-0"> <spanclass="">091</span>: """</pre>
<preclass="cython line score-0"> <spanclass="">092</span>: This method is both callable from python and pure "cython".</pre>
<preclass="cython line score-0"> <spanclass="">093</span>: It can call both cdef methods and usual python functions</pre>
<preclass="cython line score-0"> <spanclass="">094</span>: """</pre>
<preclass="cython line score-6"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">095</span>: return bar()</pre>
</pre><preclass="cython line score-0"> <spanclass="">096</span>: </pre>
<preclass="cython line score-12"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">097</span>: def bag():</pre>
</pre><preclass="cython line score-4"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">098</span>: return str(baz())</pre>
</pre><preclass="cython line score-0"> <spanclass="">099</span>: </pre>
<preclass="cython line score-0"> <spanclass="">100</span>: # We call here a cpdef function, which calls a def function</pre>
<preclass="cython line score-0"> <spanclass="">101</span>: # which then allocates cdef class SomeMemory</pre>
<preclass="cython line score-9"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">102</span>: print(bag())</pre>
<preclass='cython code score-9 '><spanclass='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_t_1, __pyx_n_s_bag);<spanclass='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error)</span>
</pre><preclass="cython line score-3"onclick="(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)">+<spanclass="">103</span>: print("done")</pre>