pygolang:647656885aabaecba8249b968e16dc07c9926fcb commitshttps://lab.nexedi.com/kirr/pygolang/-/commits/647656885aabaecba8249b968e16dc07c9926fcb2019-12-06T10:27:23+03:00https://lab.nexedi.com/kirr/pygolang/-/commit/647656885aabaecba8249b968e16dc07c9926fcbpyx.build: Provide DSO that should be used to build DSOs that use/link-to lib...2019-12-06T10:27:23+03:00Kirill Smelkovkirr@nexedi.com
Providing pygolang-specific DSO is needed because using just
setuptools_dso.DSO in external project will result in that e.g.
"<golang/libgolang.h>" won't be found.https://lab.nexedi.com/kirr/pygolang/-/commit/c5c3071b89b9e4e045b78671c86030b5a0607a0apygolang v0.0.52019-11-27T19:19:46+03:00Kirill Smelkovkirr@nexedi.com
This release is driven by wendelin.core v2 needs with one of the changes
being that now most of the library was moved into nogil code and can be
used fully from inside nogil world(*). Python modules are now just wrappers
of their nogil counterparts. The way for Python and nogil worlds to
communicate is also provided.
The move to nogil required many other enhancements along the way. Please
see CHANGELOG for overview.
The move to nogil brought some speedup automatically.
Below are benchmark results of this release compared to pygolang v0.0.4
(<a href="/kirr/pygolang/-/commit/1573d1015e3897a188a9ace1c980d316b5954359" data-original="1573d101" data-link="false" data-link-reference="false" data-project="1158" data-commit="1573d1015e3897a188a9ace1c980d316b5954359" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="pygolang v0.0.4" class="gfm gfm-commit has-tooltip">1573d101</a>) for python-level benchmarks (we have only those at present):
(on i7@2.6GHz)
thread runtime:
name old time/op new time/op delta
go 18.3µs ± 0% 18.3µs ± 1% ~ (p=1.000 n=10+10)
chan 2.91µs ± 3% 2.99µs ± 5% +2.73% (p=0.022 n=10+10)
select 3.57µs ± 3% 3.57µs ± 4% ~ (p=0.720 n=9+10)
def 55.0ns ± 0% 54.0ns ± 0% -1.82% (p=0.002 n=8+10)
func_def 43.8µs ± 2% 44.1µs ± 1% +0.64% (p=0.035 n=10+9)
call 64.0ns ± 0% 66.3ns ± 1% +3.59% (p=0.000 n=10+10)
func_call 1.05µs ± 1% 1.24µs ± 0% +17.80% (p=0.000 n=10+7)
try_finally 138ns ± 0% 137ns ± 1% -0.51% (p=0.003 n=10+10)
defer 2.32µs ± 1% 2.63µs ± 1% +13.52% (p=0.000 n=10+10)
workgroup_empty 38.0µs ± 1% 24.1µs ± 1% -36.43% (p=0.000 n=10+10)
workgroup_raise 47.7µs ± 1% 28.2µs ± 0% -40.76% (p=0.000 n=10+10)
gevent runtime:
name old time/op new time/op delta
go 16.9µs ± 1% 17.2µs ± 2% +1.94% (p=0.000 n=10+10)
chan 7.43µs ± 0% 7.82µs ± 0% +5.34% (p=0.000 n=10+7)
select 10.5µs ± 0% 11.2µs ± 0% +6.74% (p=0.000 n=10+10)
def 63.0ns ± 0% 57.6ns ± 1% -8.57% (p=0.000 n=9+10)
func_def 44.0µs ± 1% 44.2µs ± 1% ~ (p=0.063 n=10+10)
call 67.0ns ± 0% 64.0ns ± 0% -4.48% (p=0.002 n=8+10)
func_call 1.06µs ± 1% 1.23µs ± 1% +16.50% (p=0.000 n=10+10)
try_finally 144ns ± 0% 136ns ± 0% -5.90% (p=0.000 n=10+10)
defer 2.37µs ± 1% 2.61µs ± 1% +10.07% (p=0.000 n=10+10)
workgroup_empty 57.0µs ± 0% 55.0µs ± 2% -3.53% (p=0.000 n=10+9)
workgroup_raise 72.4µs ± 0% 69.6µs ± 6% -3.95% (p=0.035 n=9+10)
workgroup_* changes for thread runtime is the speedup I am talking about.
defer/func_call slowdown is due to added exception chaining. We did not
optimize Python-level defer yet, and if/when that would be needed, it should
be possible to optimize by moving pydefer implementation into Cython.
(*) go and channels were moved into nogil world in Pygolang v0.0.3 +
v0.0.4 . Now it is the rest of the library that was moved with packages
like context, time, sync etc.
wendelin.core v2 needs nogil to run pinner thread on client side to
support isolation property in cooperation with wcfs: since there is a
`client -> wcfs -> pinner` loop:
- - - - - -
| |
pinner <------.
| | wcfs
client -------^
| |
- - - - - -
client process
the pinner thread would deadlock if it tries to take the GIL because
client thread can be holding GIL already while accessing wcfs-mmaped
memory (think doing e.g. `x = A[i]` in Python).https://lab.nexedi.com/kirr/pygolang/-/commit/37ae291fed9e89df4f2346708abd74fb1be86634readme: Turn package references into links2019-11-27T18:07:28+03:00Kirill Smelkovkirr@nexedi.com
For base functionality we have overview in the readme itself, but for
packages we have only their listing with brief overview and no
documentation for in-package functionality.
Let's have at least links to .h/.pxd/.py where package functionality is
documented.https://lab.nexedi.com/kirr/pygolang/-/commit/45c8cddddb709ee0480b7c4f4e91f888732ca5felibgolang: Provide top-level overview for interfaces2019-11-27T17:48:13+03:00Kirill Smelkovkirr@nexedi.com
See commit <a href="/nexedi/pygolang/-/commit/5a99b7693b90e000a3e2cf6b84350c8ac3ca8901" data-original="5a99b769" data-link="false" data-link-reference="false" data-project="1156" data-commit="5a99b7693b90e000a3e2cf6b84350c8ac3ca8901" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Start providing interfaces" class="gfm gfm-commit has-tooltip">5a99b769</a> (libgolang: Start providing interfaces) for context.https://lab.nexedi.com/kirr/pygolang/-/commit/7f0672aa2adb9d65afb163c8f8ae5ed429a56889libgolang: Provide top-level overview for automatic memory management2019-11-27T17:43:19+03:00Kirill Smelkovkirr@nexedi.com
Provide top-level documentation for memory management facilities that
was marked as TODO in refptr & co matches. See e.g. the following
commits for context:
- <a href="/nexedi/pygolang/-/commit/e82b4fabe2d153b235b4eb89bce4ba47cbe0b2b7" data-original="e82b4fab" data-link="false" data-link-reference="false" data-project="1156" data-commit="e82b4fabe2d153b235b4eb89bce4ba47cbe0b2b7" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Objects refcounting (initial draft)" class="gfm gfm-commit has-tooltip">e82b4fab</a> (libgolang: Objects refcounting (initial draft))
- <a href="/nexedi/pygolang/-/commit/b2253abfbbf2eb9974772487614e573ceffa44fc" data-original="b2253abf" data-link="false" data-link-reference="false" data-project="1156" data-commit="b2253abfbbf2eb9974772487614e573ceffa44fc" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Rename refobj -> object" class="gfm gfm-commit has-tooltip">b2253abf</a> (libgolang: Rename refobj -> object)
- <a href="/nexedi/pygolang/-/commit/fd2a6fab3fd4fb0b5df36442d44ee8a1353e447f" data-original="fd2a6fab" data-link="false" data-link-reference="false" data-project="1156" data-commit="fd2a6fab3fd4fb0b5df36442d44ee8a1353e447f" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Fix globals atexit race condition of ~refptr vs access from another thread" class="gfm gfm-commit has-tooltip">fd2a6fab</a> (libgolang: Fix globals atexit race condition of ~refptr vs
access from another thread)https://lab.nexedi.com/kirr/pygolang/-/commit/39f401598792dc712c21944ee18140eee4ef5223libgolang: Provide top-level overview for defer2019-11-27T17:40:53+03:00Kirill Smelkovkirr@nexedi.com
defer is now part of libgolang API (see <a href="/nexedi/pygolang/-/commit/1d153a4584bb2e41a6c7b9f2997380dccfa05071" data-original="1d153a45" data-link="false" data-link-reference="false" data-project="1156" data-commit="1d153a4584bb2e41a6c7b9f2997380dccfa05071" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Expose defer as public C++ API" class="gfm gfm-commit has-tooltip">1d153a45</a> "libgolang: Expose
defer as public C++ API"). It should be explained in top-level overview.https://lab.nexedi.com/kirr/pygolang/-/commit/c7a1bce725729b4b0ae464a8059b642cc1ab14eafixup! time: Move/Port timers to C++/Pyx nogil2019-11-27T16:19:23+03:00Kirill Smelkovkirr@nexedi.com
This amends commit <a href="/nexedi/pygolang/-/commit/b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-original="b073f6df" data-link="false" data-link-reference="false" data-project="1156" data-commit="b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="time: Move/Port timers to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">b073f6df</a>: clang was complaining that _Ticker/_Timer
were forward-declared as class, but later declared as struct:
./golang/time.h:107:1: warning: '_Ticker' defined as a struct here but previously declared as a class [-Wmismatched-tags]
struct _Ticker : object {
^
./golang/time.h:77:1: note: did you mean struct here?
class _Ticker;
^~~~~
struct
./golang/time.h:140:1: warning: '_Timer' defined as a struct here but previously declared as a class [-Wmismatched-tags]
struct _Timer : object {
^
./golang/time.h:78:1: note: did you mean struct here?
class _Timer;
^~~~~
struct
-> Fix it by using struct. Also used inline style inside refptr.https://lab.nexedi.com/kirr/pygolang/-/commit/d51bcd7e40411ddbf3d2b1564a7f4056471c332flibgolang/thread: Upstream PyThread_release_lock bug should have been fixed2019-11-27T16:12:24+03:00Kirill Smelkovkirr@nexedi.com
Race condition inside PyThread_release_lock should have been fixed on
both CPython/darwin and PyPy/darwin:
<a href="https://github.com/python/cpython/commit/c5abd63e94fc" rel="nofollow noreferrer noopener" target="_blank">https://github.com/python/cpython/commit/c5abd63e94fc</a>
<a href="https://bitbucket.org/pypy/pypy/commits/6cd7a0d1a940" rel="nofollow noreferrer noopener" target="_blank">https://bitbucket.org/pypy/pypy/commits/6cd7a0d1a940</a>
<a href="https://bitbucket.org/pypy/pypy/commits/a9d36d6af872" rel="nofollow noreferrer noopener" target="_blank">https://bitbucket.org/pypy/pypy/commits/a9d36d6af872</a>
The bug is explained here:
<a href="https://bugs.python.org/issue38106" rel="nofollow noreferrer noopener" target="_blank">https://bugs.python.org/issue38106</a>
<a href="https://bitbucket.org/pypy/pypy/issues/3072" rel="nofollow noreferrer noopener" target="_blank">https://bitbucket.org/pypy/pypy/issues/3072</a>
The following commits added tests for the bug on Pygolang side:
<a href="/nexedi/pygolang/-/commit/34b7a1f490223736778fb7fbea5678c92e6d742f" data-original="34b7a1f4" data-link="false" data-link-reference="false" data-project="1156" data-commit="34b7a1f490223736778fb7fbea5678c92e6d742f" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="golang: Expose Sema and Mutex as public Python and Cython/nogil API" class="gfm gfm-commit has-tooltip">34b7a1f4</a> (golang: Expose Sema and Mutex as public Python and Cython/nogil API)
<a href="/nexedi/pygolang/-/commit/5142460dffa2b41e09d01bfcecc43790a059f266" data-original="5142460d" data-link="false" data-link-reference="false" data-project="1156" data-commit="5142460dffa2b41e09d01bfcecc43790a059f266" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang/thread: Add links to upstream PyThread_release_lock bug" class="gfm gfm-commit has-tooltip">5142460d</a> (libgolang/thread: Add links to upstream PyThread_release_lock bug)https://lab.nexedi.com/kirr/pygolang/-/commit/0efd4a9ac46a22c5a8bd29a2be592028371b802fstrings: New package2019-11-27T16:12:24+03:00Kirill Smelkovkirr@nexedi.com
Provide string utilities to verify whether string has suffix/prefix,
trim it, and split string by a delimiter. The code originated in wcfs
codebase in wendelin.core .
Pyx/nogil only.https://lab.nexedi.com/kirr/pygolang/-/commit/309963f86745c4bc4dc6d522515f9345d67e1100fmt: New package2019-11-27T16:12:22+03:00Kirill Smelkovkirr@nexedi.com
With fmt.sprintf() and fmt.errorf() to format strings and errors. The
code was extracted from wcfs in wendelin.core .
Pyx/nogil only.https://lab.nexedi.com/kirr/pygolang/-/commit/9ea53ec63a9ddafcd90f5f8f622ee9cbc0280f84libgolang: Provide string as alias for std::string2019-11-27T00:04:56+03:00Kirill Smelkovkirr@nexedi.com
std::string is frequently too cumbersome. Providing string in golang::
namespace allows to have a more closer feel of a Go environment after
`using namespace golang`.https://lab.nexedi.com/kirr/pygolang/-/commit/cf96559c4decc176c8c4569dd002ce5232623872fixup! sync: Move/Port sync.WorkGroup to C++/Pyx nogil2019-11-25T19:47:14+03:00Kirill Smelkovkirr@nexedi.com
This ammends <a href="/nexedi/pygolang/-/commit/33cf3113f14131c7a374ca7f68e0c8dbf8242711" data-original="33cf3113" data-link="false" data-link-reference="false" data-project="1156" data-commit="33cf3113f14131c7a374ca7f68e0c8dbf8242711" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="sync: Move/Port sync.WorkGroup to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">33cf3113</a>: Kill now unused imports.https://lab.nexedi.com/kirr/pygolang/-/commit/6d94fccf368d36cf2e4d00b40c8f85ff810b1c84libpyxruntime: It should link to libgolang2019-11-25T19:47:14+03:00Kirill Smelkovkirr@nexedi.com
It was all working on Debian 10, but running tests on Ubuntu 16.04
turned out to fail:
$ python -m pytest
================================== test session starts ===================================
platform linux2 -- Python 2.7.12, pytest-4.6.6, py-1.8.0, pluggy-0.13.0
rootdir: /home/kirr/src/pygolang
collected 0 items / 10 errors
========================================= ERRORS =========================================
________________________ ERROR collecting golang/_gopath_test.py _________________________
ImportError while importing test module '/home/kirr/src/pygolang/golang/_gopath_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
golang/__init__.py:42: in <module>
from golang._golang import _pysys_exc_clear as _sys_exc_clear
golang/_golang.pyx:35: in init golang._golang
_init_libpyxruntime()
golang/_golang.pyx:532: in golang._golang._init_libpyxruntime
import golang.pyx.runtime
E ImportError: /home/kirr/src/pygolang/golang/pyx/../runtime/liblibpyxruntime.so.0.1: undefined symbol: _ZN6golang4sync9WaitGroup3addEi
$ c++filt _ZN6golang4sync9WaitGroup3addEi
golang::sync::WaitGroup::add(int)
So since libpyxruntime is using sync.WaitGroup (and sync.Mutex etc) it should
be linking to libgolang where those symbols are provided. Fix it.
Fixes: <a href="/kirr/pygolang/-/commit/4fc6e49c900b996ab6ee066c6512e986802aeb79" data-original="4fc6e49c" data-link="false" data-link-reference="false" data-project="1158" data-commit="4fc6e49c900b996ab6ee066c6512e986802aeb79" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="time: Factor-out PyFunc into shared library libpyxruntime.so" class="gfm gfm-commit has-tooltip">4fc6e49c</a> (time: Factor-out PyFunc into shared library libpyxruntime.so)https://lab.nexedi.com/kirr/pygolang/-/commit/1477dd02f9083f97ee1c1f91c629cb194acbcac3golang: Fix defer exception chaining in the presence of subchains2019-11-22T19:33:34+03:00Kirill Smelkovkirr@nexedi.com
A deferred function can raise exception and this exception itself can
have .__context__ - consider for example if B1 is raised and its chain
is B1->B2->B3. Before calling that deferred function, we save
then-current exception A1 into GoFrame.exc_ctx and link-to .exc_ctx after
the call. We were previously trying to link-to .exc_ctx from raised
exception itself - i.e. B1 in the above example which is not correct:
B1 was raised while B2 was being raised ... etc and it was B3 who was
raised after A1. The consequence was that A1 was list, since B1 already
had non-empty .__context__
-> Fix it by linking-to A1 from B3, not from B1. In other words by
linking-to .exc_ctx chain from tail of exception chain of raised
exception.
We can be sure that updated test is correct because it passes under
Python3 where exception chaining is implemented natively.
Fixes: <a href="/kirr/pygolang/-/commit/bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-original="bb9a94c3" data-link="false" data-link-reference="false" data-project="1158" data-commit="bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="golang: Teach defer to chain exceptions (PEP 3134) even on Python2" class="gfm gfm-commit has-tooltip">bb9a94c3</a> (golang: Teach defer to chain exceptions (PEP 3134) even on Python2)https://lab.nexedi.com/kirr/pygolang/-/commit/06cac90b7b1874e3452f0466b66f5f0aca0df6d0golang: Fix defer exception chaining for regular exceptions raised from under...2019-11-22T15:43:29+03:00Kirill Smelkovkirr@nexedi.com
Defer support for exception chaining on Python2 (see <a href="/nexedi/pygolang/-/commit/bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-original="bb9a94c3" data-link="false" data-link-reference="false" data-project="1156" data-commit="bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="golang: Teach defer to chain exceptions (PEP 3134) even on Python2" class="gfm gfm-commit has-tooltip">bb9a94c3</a> "golang:
Teach defer to chain exceptions (PEP 3134) even on Python2") simulates
PEP 3134 by manually setting and chaining exc .__context__, .__cause__
and .__traceback__: if exceptions are thrown by several deferred
functions they are linked into exception chain via .__context__
attribute. Defer support in @func also makes sure that any exception
that comes out of a function has all those PEP 3134 attributes and
presets them to their default values if exception object did not have
them initially. In particular .__context__ is preset to None for first
raised exception.
There was a logic error in chaining handling: .__context__ was glued to
previously raised exception only if current exception object did not
have .__context__ attribute at all. And this was failing to chain them
if current exception was raised from under another function wrapped in
@func, because GoFrame wrapping that function makes sure to set
curexc.__context__=None and oops - it was not changed later.
-> Fix chaining implementation by gluing .__context__ either if there is
no such attribute in current exception, or if .__context__ is None.
This is correct to do since .__context__, by its definition, represents
implicitly / automatically chained exceptions - contrary to .__cause__
which is explicitly set and would be incorrect to automatically change
from None to something. We also know that the end result is the same as
Python3 behaviour since updated tests (see bellow) pass OK also when run
under Python3 where exceptions chaining is implemented by Python runtime
natively.
Update test_defer_excchain() in golang_test.py, which verifies how
raised exceptions are chained.
No need to update testprog/golang_test_defer_excchain.{py,txt} since the
test there verifies that our traceback dumper is correctly hooked into
Python interpreter - where we know that exceptions are already chained
correctly and we verify only that automatic traceback dump takes this
chaining into account.
Fixes: <a href="/nexedi/pygolang/-/commit/bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-original="bb9a94c3" data-link="false" data-link-reference="false" data-project="1156" data-commit="bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="golang: Teach defer to chain exceptions (PEP 3134) even on Python2" class="gfm gfm-commit has-tooltip">bb9a94c3</a> (golang: Teach defer to chain exceptions (PEP 3134) even on Python2)https://lab.nexedi.com/kirr/pygolang/-/commit/7faaecbc5ff621c6ecd297873373a6243a7ad806golang: Fix defer traceback tests when run somewhere under symlink2019-11-22T15:43:23+03:00Kirill Smelkovkirr@nexedi.com
Since realpath was used to find out pygolang dir, it will give different
prefix compared to what actual prefix of __file__ is if __file__ was
imported through some symlinked directory. And it is the actual
__file__ that is included into traceback - not its realpath'ed version.
This was breaking for example like this on py27-gevent tox tests:
__file__: '.../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py'
dirname(__file__): '.../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang'
PYGOLANG: '.../pygolang/.tox/py27-gevent/lib/python2.7/site-packages'
E Failed: not equal:
E Differences (unified diff with -expected +actual):
E @@ -1,8 +1,8 @@
E Traceback (most recent call last):
E - File "PYGOLANG/golang/golang_test.py", line ..., in test_defer_excchain_traceback
E + File ".../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py", line 1360, in test_defer_excchain_traceback
E alpha()
E - File "PYGOLANG/golang/golang_test.py", line ..., in alpha
E + File ".../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py", line 1357, in alpha
E beta()
E - File "PYGOLANG/golang/golang_test.py", line ..., in beta
E + File ".../pygolang/.tox/py27-gevent/local/lib/python2.7/site-packages/golang/golang_test.py", line 1356, in beta
E raise RuntimeError("gamma")
E RuntimeError: gamma
-> Fix it by not doing realpath'ification when detecting PYGOLANG
prefix.
Fixes: <a href="/kirr/pygolang/-/commit/bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-original="bb9a94c3" data-link="false" data-link-reference="false" data-project="1158" data-commit="bb9a94c36a9ffd7dd02adab805d26f4113ef299e" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="golang: Teach defer to chain exceptions (PEP 3134) even on Python2" class="gfm gfm-commit has-tooltip">bb9a94c3</a> (golang: Teach defer to chain exceptions (PEP 3134) even on Python2)https://lab.nexedi.com/kirr/pygolang/-/commit/fd2a6fab3fd4fb0b5df36442d44ee8a1353e447flibgolang: Fix globals atexit race condition of ~refptr vs access from anothe...2019-11-22T11:58:18+03:00Kirill Smelkovkirr@nexedi.com
Until now we were defining errors like this:
const error ErrSomething = errors::New("abc");
However there is a problem here: the runtime will call ErrSomething
destructor on program exit, and for refptr<T> the destructor does 2
things: a) decrefs the object, and b) switches embedded pointer to NULL;
If another thread is still running both "a" and "b" can become race
conditions if that T2 uses ErrSomething via e.g. just
...
if (err == ErrSomething)
...
Here is, for example TSAN report about ErrPyStopped usage when accessed by timer thread:
WARNING: ThreadSanitizer: data race (pid=4224)
Read of size 8 at 0x7f0d6840e150 by thread T92:
#0 golang::refptr<golang::_error>::refptr(golang::refptr<golang::_error> const&) golang/libgolang.h:525 (liblibpyxruntime.so.0.1+0x4edc)
#1 golang::pyx::runtime::PyFunc::operator()() const golang/runtime/libpyxruntime.cpp:222 (liblibpyxruntime.so.0.1+0x423d)
#2 std::_Function_handler<void (), golang::pyx::runtime::PyFunc>::_M_invoke(std::_Any_data const&) /usr/include/c++/8/bits/std_function.h:297 (_time.so+0x1382b)
#3 std::function<void ()>::operator()() const /usr/include/c++/8/bits/std_function.h:687 (liblibgolang.so.0.1+0x2ede6)
#4 golang::time::_Timer::_fire(double, int) golang/time.cpp:197 (liblibgolang.so.0.1+0x48cbe)
#5 operator() golang/time.cpp:171 (liblibgolang.so.0.1+0x4894c)
#6 __invoke_impl<void, golang::time::_Timer::reset(double)::<lambda(int)>&, int&> /usr/include/c++/8/bits/invoke.h:60 (liblibgolang.so.0.1+0x4a142)
#7 __invoke<golang::time::_Timer::reset(double)::<lambda(int)>&, int&> /usr/include/c++/8/bits/invoke.h:95 (liblibgolang.so.0.1+0x4a080)
#8 __call<void, 0> /usr/include/c++/8/functional:400 (liblibgolang.so.0.1+0x49fcc)
#9 operator()<> /usr/include/c++/8/functional:484 (liblibgolang.so.0.1+0x49cee)
#10 _M_invoke /usr/include/c++/8/bits/std_function.h:297 (liblibgolang.so.0.1+0x49858)
#11 std::function<void ()>::operator()() const /usr/include/c++/8/bits/std_function.h:687 (liblibgolang.so.0.1+0x2ede6)
#12 operator() golang/libgolang.h:326 (liblibgolang.so.0.1+0x48fa1)
#13 _FUN golang/libgolang.h:324 (liblibgolang.so.0.1+0x49004)
#14 <null> <null> (python2+0x194d13)
Previous write of size 8 at 0x7f0d6840e150 by main thread:
#0 golang::refptr<golang::_error>::~refptr() golang/libgolang.h:510 (liblibpyxruntime.so.0.1+0x4d39)
#1 at_exit_wrapper ../../../../src/libsanitizer/tsan/tsan_interceptors.cc:389 (libtsan.so.0+0x28693)
As if synchronized via sleep:
#0 nanosleep ../../../../src/libsanitizer/tsan/tsan_interceptors.cc:366 (libtsan.so.0+0x49960)
#1 __pyx_f_6golang_7runtime_15_runtime_thread_nanosleep golang/runtime/_runtime_thread.c:1702 (_runtime_thread.so+0x48f2)
#2 _tasknanosleep golang/runtime/libgolang.cpp:1237 (liblibgolang.so.0.1+0x2cca7)
#3 golang::time::sleep(double) golang/runtime/libgolang.cpp:1251 (liblibgolang.so.0.1+0x2ce0b)
#4 golang::time::_Timer::_fire(double, int) golang/time.cpp:179 (liblibgolang.so.0.1+0x48bd6)
#5 operator() golang/time.cpp:171 (liblibgolang.so.0.1+0x4894c)
#6 __invoke_impl<void, golang::time::_Timer::reset(double)::<lambda(int)>&, int&> /usr/include/c++/8/bits/invoke.h:60 (liblibgolang.so.0.1+0x4a142)
#7 __invoke<golang::time::_Timer::reset(double)::<lambda(int)>&, int&> /usr/include/c++/8/bits/invoke.h:95 (liblibgolang.so.0.1+0x4a080)
#8 __call<void, 0> /usr/include/c++/8/functional:400 (liblibgolang.so.0.1+0x49fcc)
#9 operator()<> /usr/include/c++/8/functional:484 (liblibgolang.so.0.1+0x49cee)
#10 _M_invoke /usr/include/c++/8/bits/std_function.h:297 (liblibgolang.so.0.1+0x49858)
#11 std::function<void ()>::operator()() const /usr/include/c++/8/bits/std_function.h:687 (liblibgolang.so.0.1+0x2ede6)
#12 operator() golang/libgolang.h:326 (liblibgolang.so.0.1+0x48fa1)
#13 _FUN golang/libgolang.h:324 (liblibgolang.so.0.1+0x49004)
#14 <null> <null> (python2+0x194d13)
Location is global 'golang::pyx::runtime::ErrPyStopped' of size 8 at 0x7f0d6840e150 (liblibpyxruntime.so.0.1+0x000000009150)
Thread T92 (tid=7834, running) created by thread T15 at:
#0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors.cc:915 (libtsan.so.0+0x2be1b)
#1 PyThread_start_new_thread <null> (python2+0x194ccf)
#2 _taskgo golang/runtime/libgolang.cpp:124 (liblibgolang.so.0.1+0x288e7)
#3 go<golang::time::_Timer::reset(double)::<lambda(int)>, int> golang/libgolang.h:324 (liblibgolang.so.0.1+0x490b7)
#4 golang::time::_Timer::reset(double) golang/time.cpp:170 (liblibgolang.so.0.1+0x48b36)
#5 __pyx_f_6golang_5_time_timer_reset_pyexc golang/_time.cpp:3271 (_time.so+0xa506)
#6 __pyx_pf_6golang_5_time_7PyTimer_6reset golang/_time.cpp:2824 (_time.so+0x97d8)
#7 __pyx_pw_6golang_5_time_7PyTimer_7reset golang/_time.cpp:2789 (_time.so+0x9751)
#8 PyEval_EvalFrameEx <null> (python2+0xf27f7)
#9 std::_Function_handler<void (), golang::pyx::runtime::PyFunc>::_M_invoke(std::_Any_data const&) /usr/include/c++/8/bits/std_function.h:297 (_time.so+0x1382b)
#10 std::function<void ()>::operator()() const /usr/include/c++/8/bits/std_function.h:687 (liblibgolang.so.0.1+0x2ede6)
#11 golang::time::_Timer::_fire(double, int) golang/time.cpp:197 (liblibgolang.so.0.1+0x48cbe)
#12 operator() golang/time.cpp:171 (liblibgolang.so.0.1+0x4894c)
#13 __invoke_impl<void, golang::time::_Timer::reset(double)::<lambda(int)>&, int&> /usr/include/c++/8/bits/invoke.h:60 (liblibgolang.so.0.1+0x4a142)
#14 __invoke<golang::time::_Timer::reset(double)::<lambda(int)>&, int&> /usr/include/c++/8/bits/invoke.h:95 (liblibgolang.so.0.1+0x4a080)
#15 __call<void, 0> /usr/include/c++/8/functional:400 (liblibgolang.so.0.1+0x49fcc)
#16 operator()<> /usr/include/c++/8/functional:484 (liblibgolang.so.0.1+0x49cee)
#17 _M_invoke /usr/include/c++/8/bits/std_function.h:297 (liblibgolang.so.0.1+0x49858)
#18 std::function<void ()>::operator()() const /usr/include/c++/8/bits/std_function.h:687 (liblibgolang.so.0.1+0x2ede6)
#19 operator() golang/libgolang.h:326 (liblibgolang.so.0.1+0x48fa1)
#20 _FUN golang/libgolang.h:324 (liblibgolang.so.0.1+0x49004)
#21 <null> <null> (python2+0x194d13)
SUMMARY: ThreadSanitizer: data race golang/libgolang.h:525 in golang::refptr<golang::_error>::refptr(golang::refptr<golang::_error> const&)
-> Fix it by not deallocating the object, nor clearing the pointer on smart pointer destruction.
To do so in ergonomic way introduce another template type global<X>,
which can be used instead of X and change types of all global error
variables from `const error` to `const global<error>`. Don't change pxd
to offload pyx users from thinking about global/not-global aspect.
Top-level documentation is TODO.https://lab.nexedi.com/kirr/pygolang/-/commit/33cf3113f14131c7a374ca7f68e0c8dbf8242711sync: Move/Port sync.WorkGroup to C++/Pyx nogil2019-11-22T11:58:06+03:00Kirill Smelkovkirr@nexedi.com
Provide sync.WorkGroup that can be used directly from C++ and Pyx/nogil codes.
Python-level sync.WorkGroup becomes a wrapper around pyx/nogil one.
Like with context (<a href="/kirr/pygolang/-/commit/2a359791b31edaac43763570f879503ea4cb9b77" data-original="2a359791" data-link="false" data-link-reference="false" data-project="1158" data-commit="2a359791b31edaac43763570f879503ea4cb9b77" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="context: Move/Port context package to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">2a359791</a> "context: Move/Port context package to
C++/Pyx nogil"), timers (<a href="/kirr/pygolang/-/commit/b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-original="b073f6df" data-link="false" data-link-reference="false" data-project="1158" data-commit="b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="time: Move/Port timers to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">b073f6df</a> "time: Move/Port timers to C++/Pyx
nogil") and interfaces (<a href="/kirr/pygolang/-/commit/5a99b7693b90e000a3e2cf6b84350c8ac3ca8901" data-original="5a99b769" data-link="false" data-link-reference="false" data-project="1158" data-commit="5a99b7693b90e000a3e2cf6b84350c8ac3ca8901" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Start providing interfaces" class="gfm gfm-commit has-tooltip">5a99b769</a> "libgolang: Start providing
interfaces") memory for on-heap allocated WorkGroup is managed
automatically.
Python-level tests should be enough to cover C++/Pyx functionality at
zero-level approximation.https://lab.nexedi.com/kirr/pygolang/-/commit/e678817067d213352981d4b8faae9cc726a85b8dfixup! golang: Expose Sema and Mutex as public Python and Cython/nogil API2019-11-20T12:16:44+03:00Kirill Smelkovkirr@nexedi.com
This amends commit <a href="/kirr/pygolang/-/commit/34b7a1f490223736778fb7fbea5678c92e6d742f" data-original="34b7a1f4" data-link="false" data-link-reference="false" data-project="1158" data-commit="34b7a1f490223736778fb7fbea5678c92e6d742f" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="golang: Expose Sema and Mutex as public Python and Cython/nogil API" class="gfm gfm-commit has-tooltip">34b7a1f4</a>: Fix copy-paste typo in _sync_test.pyx
description.https://lab.nexedi.com/kirr/pygolang/-/commit/1de59346dc308f52ffdb2b4f654613e6dd34b330fixup! sync: Provide package documentation2019-11-20T12:12:31+03:00Kirill Smelkovkirr@nexedi.com
This amends commit <a href="/kirr/pygolang/-/commit/40f3b90c109e91259f6bac9a8cd87953226fadce" data-original="40f3b90c" data-link="false" data-link-reference="false" data-project="1158" data-commit="40f3b90c109e91259f6bac9a8cd87953226fadce" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="sync: Provide package documentation" class="gfm gfm-commit has-tooltip">40f3b90c</a>: sync.Sema is not provided in Go version.https://lab.nexedi.com/kirr/pygolang/-/commit/c5c576d273fa0f7f1ba102c5acadd2d25517716esync: Rename WaitGroup-related pyexc functions wg_*_pyexc -> waitgroup_*_pyexc2019-11-20T12:07:58+03:00Kirill Smelkovkirr@nexedi.com
We will soon land WorkGroup into sync.pyx; Before that let's renamge
WaitGroup helpers to avoid ambiguity of what "wg" means - WaitGroup or
WorkGroup?
This amends <a href="/kirr/pygolang/-/commit/b316e5047f2edc0ed0291c78c1b329bb1b7574ab" data-original="b316e504" data-link="false" data-link-reference="false" data-project="1158" data-commit="b316e5047f2edc0ed0291c78c1b329bb1b7574ab" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="sync: Move/Port WaitGroup to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">b316e504</a> (sync: Move/Port WaitGroup to C++/Pyx nogil).https://lab.nexedi.com/kirr/pygolang/-/commit/4fb9b51c6a344a5398a670624ad9bb0d4bf3b4bccontext: Provide way to create PyContext from raw Context2019-11-19T21:38:54+03:00Kirill Smelkovkirr@nexedi.com
sync.PyWorkGroup will need to wrap raw Context into PyContext for
spawned workers.https://lab.nexedi.com/kirr/pygolang/-/commit/a36efe6d4bb604397bc9a2b7ae3573ec3ba9cbdclibpyxruntime: Teach PyFunc to report Python exception after the call2019-11-19T21:38:21+03:00Kirill Smelkovkirr@nexedi.com
- Add PyError class that wraps Python exception;
- change PyFunc::operator() return from void -> to error, which might be
either PyError or special error indicating that Python interpreter is
stopped.
- Provide way to reraise that Python exception.
We will need to see which exception, if any, PyFunc call raised in
sync.PyWorkGroup, where this python-level exception will need to be
propagated to PyWorkGroup.wait() and reraised from there.https://lab.nexedi.com/kirr/pygolang/-/commit/73182038abce2b443984622324c2122bf33811celibpyxruntime: Fix deadlock in pygil_ensure()2019-11-19T20:54:40+03:00Kirill Smelkovkirr@nexedi.com
pygil_ensure() was taking pyexitedMu and then GIL, which can deadlock
via AB BA scenario if pygil_ensure() is also called in another thread
with GIL already held.
-> Fix it by always taking GIL with pyexitedMu released.
Without the fix the test added always hangs with thread backend, e.g.
like this:
golang/pyx/runtime_test.py::test_pyx_pyfunc_vs_gil_deadlock
STUCK
terminate called after throwing an instance of 'golang::PanicError'
what(): STUCK
Fatal Python error: Aborted
The bug was introduced in <a href="/kirr/pygolang/-/commit/b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-original="b073f6df" data-link="false" data-link-reference="false" data-project="1158" data-commit="b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="time: Move/Port timers to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">b073f6df</a> (time: Move/Port timers to C++/Pyx nogil).https://lab.nexedi.com/kirr/pygolang/-/commit/4fc6e49c900b996ab6ee066c6512e986802aeb79time: Factor-out PyFunc into shared library libpyxruntime.so2019-11-19T20:16:01+03:00Kirill Smelkovkirr@nexedi.com
Commit <a href="/kirr/pygolang/-/commit/b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-original="b073f6df" data-link="false" data-link-reference="false" data-project="1158" data-commit="b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="time: Move/Port timers to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">b073f6df</a> (time: Move/Port timers to C++/Pyx nogil) added C++
level PyFunc as a way to call Python function from under nogil code.
We will soon need this functionality for sync.WorkGroup too, so move it
into shared place.
We move into regular library - not a pyx module (e.g. golang.pyx) -
because for pyx modules linking is done at import time by specially
generated code, while we need the linker support to automatically
resolve e.g. calls to PyFunc::operator() from inside std::function.https://lab.nexedi.com/kirr/pygolang/-/commit/5146a416c5e17f93c99cfdc9d238792eb3c5c15elibgolang: Provide DSO_EXPORT/DSO_IMPORT macros for other libraries2019-11-19T19:22:45+03:00Kirill Smelkovkirr@nexedi.com
In the next patch we are going to move PyFunc from time.pyx into shared
library. Before doing that let's provide DSO visibility macros from
libgolang.h to offload other libraries from duplicating dance on how to
mark symbols visibility properly depending on compiler/OS.https://lab.nexedi.com/kirr/pygolang/-/commit/47fac0a9a4a9b57ef04ea9662a449c428e1537aclibgolang/{gevent,thread}: Preserve Python-level exception in runtime calls2019-11-18T22:00:00+03:00Kirill Smelkovkirr@nexedi.com
Gevent runtime uses python-level calls internally which might interfere
with current python state. For example if current python exception is
set, and e.g. go or makesema runtime call is made, the following
happens:
golang/golang_test.py::test_pyx_runtime_vs_pyexc RuntimeError: abc
The above exception was the direct cause of the following exception:
SystemError: <class 'gevent.__semaphore.Semaphore'> returned a result with an error set
Exception ignored in: 'golang.runtime._runtime_gevent._sema_alloc'
SystemError: <class 'gevent.__semaphore.Semaphore'> returned a result with an error set
terminate called after throwing an instance of 'golang::PanicError'
what(): makesema: alloc failed
Fatal Python error: Aborted
-> Fix all functions in the runtimes that work at Python level to
save/restore Python-level exception on entry/exit.
This is mostly gevent runtime, but also a couple of non-posix fallbacks in
thread runtime.
The bug was there from day 1 of runtimes - from <a href="/nexedi/pygolang/-/commit/ce8152a23262af76877a3f3e1ce3b9c6fa6d9d34" data-original="ce8152a2" data-link="false" data-link-reference="false" data-project="1156" data-commit="ce8152a23262af76877a3f3e1ce3b9c6fa6d9d34" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="pyx api: Provide sleep" class="gfm gfm-commit has-tooltip">ce8152a2</a> (pyx api:
Provide sleep), <a href="/nexedi/pygolang/-/commit/f971a2a8e7cc22bb0572104920cb06b5e11ceef5" data-original="f971a2a8" data-link="false" data-link-reference="false" data-project="1156" data-commit="f971a2a8e7cc22bb0572104920cb06b5e11ceef5" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="pyx api: Provide go" class="gfm gfm-commit has-tooltip">f971a2a8</a> (pyx api: Provide go) and <a href="/nexedi/pygolang/-/commit/69db91bf7e2fcb300acf2bf7544c49ccda463054" data-original="69db91bf" data-link="false" data-link-reference="false" data-project="1156" data-commit="69db91bf7e2fcb300acf2bf7544c49ccda463054" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Add internal semaphores" class="gfm gfm-commit has-tooltip">69db91bf</a> (libgolang:
Add internal semaphores).https://lab.nexedi.com/kirr/pygolang/-/commit/689dc862974d0ed3a667d62f9924d3e458ade894libgolang/{gevent,thread}: Restructure to keep functions that access Python l...2019-11-18T21:42:41+03:00Kirill Smelkovkirr@nexedi.com
In the next patch we will fix runtime functions that work at Python
level to preserve user Python exception state. Before that, as a
preparatory step, restructure runtimes code, so that all such
Python-accessing functions are grouped together.https://lab.nexedi.com/kirr/pygolang/-/commit/b4feee6f8e805bd9be5481b1b82790a0baa46d24pyx.build: Allow to use custom build_ext2019-11-15T15:07:25+03:00Kirill Smelkovkirr@nexedi.com
setuptools_dso hardcodes to use its own build_ext in its setup.
We amend that build_ext and inject our own version carefully while
setup() is run - see <a href="/kirr/pygolang/-/commit/7ae8c4f3c127325490534fec97985cbb8e70e3a5" data-original="7ae8c4f3" data-link="false" data-link-reference="false" data-project="1158" data-commit="7ae8c4f3c127325490534fec97985cbb8e70e3a5" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="pyx.build: Allow to combine C and C++ sources in one extension" class="gfm gfm-commit has-tooltip">7ae8c4f3</a> (pyx.build: Allow to combine C and C++
sources in one extension). However, currently, if user uses cmdclass =
{'build_ext': ...} in his own setup, this will be ignored and
overwritten by golang.pyx.build.build_ext . One example where this
breaks things is wendelin.core which hooks into build_ext to first
configure/build CCAN before any extension:
<a href="https://lab.nexedi.com/nexedi/wendelin.core/blob/b26ba558/setup.py#L147-153">https://lab.nexedi.com/nexedi/wendelin.core/blob/b26ba558/setup.py#L147-153</a>
-> Fix it by taking into account what user could put into cmdclass.https://lab.nexedi.com/kirr/pygolang/-/commit/14a249cbd2a3d723dce7bdc2b44202a7f1424b2clibgolang: Fix double C++ defer2019-11-14T18:23:07+03:00Kirill Smelkovkirr@nexedi.com
If defer was used multiple times in one function it was failing to
compile. For example added test is failing like this:
In file included from golang/runtime/libgolang_test.cpp:22:
golang/runtime/libgolang_test.cpp: In function ‘void __test_defer(int*)’:
./golang/libgolang.h:457:59: error: redeclaration of ‘golang::_deferred _defer___COUNTER__’
#define defer(f) golang::_deferred _defer_ ## __COUNTER__ (f)
^
golang/runtime/libgolang_test.cpp:473:5: note: in expansion of macro ‘defer’
defer([&]() {
^~~~~
./golang/libgolang.h:457:36: note: ‘golang::_deferred _defer___COUNTER__’ previously declared here
#define defer(f) golang::_deferred _defer_ ## __COUNTER__ (f)
^~~~~~~
golang/runtime/libgolang_test.cpp:470:5: note: in expansion of macro ‘defer’
defer([&]() {
^~~~~
It turns out the __COUNTER__ was not expanded and they say you have to
use 3 level of macro calls. Oh well...
<a href="https://stackoverflow.com/a/27611869/9456786" rel="nofollow noreferrer noopener" target="_blank">https://stackoverflow.com/a/27611869/9456786</a>https://lab.nexedi.com/kirr/pygolang/-/commit/de269272271001b54464e38109c487cafa020e6alibgolang: Provide func as alias for std::function2019-11-14T17:55:32+03:00Kirill Smelkovkirr@nexedi.com
std::function is frequently too long to type while func is more native to Go.https://lab.nexedi.com/kirr/pygolang/-/commit/a6c1c984bb5a0e1ed6a6428aa95f4b04b4986443context: Export PyContext for cimport2019-11-14T13:18:10+03:00Kirill Smelkovkirr@nexedi.com
For example wendelin.core wants to accept Python-level context,
transform it into C-level context and pass to pyx/nogil code.https://lab.nexedi.com/kirr/pygolang/-/commit/2a359791b31edaac43763570f879503ea4cb9b77context: Move/Port context package to C++/Pyx nogil2019-11-14T12:27:42+03:00Kirill Smelkovkirr@nexedi.com
Provide context-related functionality that can be used directly from C++
and Pyx/nogil codes. Python-level classes and functions become small
wrappers around pyx/nogil ones.
Like with timers (<a href="/nexedi/pygolang/-/commit/b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-original="b073f6df" data-link="false" data-link-reference="false" data-project="1156" data-commit="b073f6df1caee2a2ce7974e777da7d4c8f6c4360" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="time: Move/Port timers to C++/Pyx nogil" class="gfm gfm-commit has-tooltip">b073f6df</a> "time: Move/Port timers to C++/Pyx nogil")
and interfaces (<a href="/nexedi/pygolang/-/commit/5a99b7693b90e000a3e2cf6b84350c8ac3ca8901" data-original="5a99b769" data-link="false" data-link-reference="false" data-project="1156" data-commit="5a99b7693b90e000a3e2cf6b84350c8ac3ca8901" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Start providing interfaces" class="gfm gfm-commit has-tooltip">5a99b769</a> "libgolang: Start providing interfaces")
memory for objects dynamically allocated on heap is managed
automatically.https://lab.nexedi.com/kirr/pygolang/-/commit/9785f2d324ab91375c3f369bf0a24bcb64aaf97acxx: New package2019-11-14T10:43:57+03:00Kirill Smelkovkirr@nexedi.com
Start new package that provides C++ amendments to be used by libgolang
and its users. Current functionality: dict and set that wrap
std::unordered_map and std::unordered_set into ergonomic interface.
The code originates from wendelin.core:
<a href="https://lab.nexedi.com/kirr/wendelin.core/blob/5a045ed1/wcfs/internal/wcfs_misc.h#L214-257">https://lab.nexedi.com/kirr/wendelin.core/blob/5a045ed1/wcfs/internal/wcfs_misc.h#L214-257</a>
Pyx/nogil only.https://lab.nexedi.com/kirr/pygolang/-/commit/a245ab56e1c8b555ed01e091b55b9f80d88e3deeerrors: New package2019-11-14T10:43:46+03:00Kirill Smelkovkirr@nexedi.com
With just one function - errors.New() - to create new error with given
text.
This will be soon used in Pyx/nogil context package to create context.canceled
and context.deadlineExceeded errors.
Pyx/nogil only for now.https://lab.nexedi.com/kirr/pygolang/-/commit/5a99b7693b90e000a3e2cf6b84350c8ac3ca8901libgolang: Start providing interfaces2019-11-14T10:41:52+03:00Kirill Smelkovkirr@nexedi.com
- interface is analog of interface{} in Go.
- error is analog of error in Go.
For now the interfaces are implemented via classic C++ scheme via
inheritance and additional vtable field in pointed object.
In the future we might want to consider reworking that to Go-style
interfaces without predeclaring which interfaces a class implements.
Top-level documentation is TODO.
Interfaces will be soon needed to describe Context interface in C
context package.https://lab.nexedi.com/kirr/pygolang/-/commit/274afa3f075f0736afe35a0a71f9fefdd6062d3bgolang.pxd: Expose missing memory-management bits2019-11-14T10:39:05+03:00Kirill Smelkovkirr@nexedi.com
- refptr==refptr (e.g. to compare whether returned error object is
something particular)
- adoptref() and newref()
- object (exposed as gobject not to be confused with builtin pyx
"object" referring to python object)
All this will be soon used in C version of context package.https://lab.nexedi.com/kirr/pygolang/-/commit/9216e2dbef7e81b876989255446054a6e0cb2f59context: Provide package documentation2019-11-14T10:36:44+03:00Kirill Smelkovkirr@nexedi.com
Briefly describe provided functionality instead of only referring to
<a href="https://golang.org/pkg/context" rel="nofollow noreferrer noopener" target="_blank">https://golang.org/pkg/context</a> and <a href="https://blog.golang.org/context" rel="nofollow noreferrer noopener" target="_blank">https://blog.golang.org/context</a>.https://lab.nexedi.com/kirr/pygolang/-/commit/b2253abfbbf2eb9974772487614e573ceffa44fclibgolang: Rename refobj -> object2019-11-14T10:36:27+03:00Kirill Smelkovkirr@nexedi.com
Thinking a bit more after <a href="/nexedi/pygolang/-/commit/e82b4fabe2d153b235b4eb89bce4ba47cbe0b2b7" data-original="e82b4fab" data-link="false" data-link-reference="false" data-project="1156" data-commit="e82b4fabe2d153b235b4eb89bce4ba47cbe0b2b7" data-reference-type="commit" data-container="body" data-placement="top" data-html="true" title="libgolang: Objects refcounting (initial draft)" class="gfm gfm-commit has-tooltip">e82b4fab</a> (libgolang: Objects refcounting
(initial draft)) and working on interfaces as part of context pyx -> C
move, I've came to conclusion that the better name for on-heap objects
managed by libgolang is just "object" without "ref" prefix.
-> Rename refobj -> object and amend its documentation correspondingly.https://lab.nexedi.com/kirr/pygolang/-/commit/af4a8d806c182b38a04f7dc1916fa093453d85ealibgolang: Provide std::hash<refptr>2019-11-14T10:28:39+03:00Kirill Smelkovkirr@nexedi.com
So that refptr<T> could be used as keys in e.g. dict (unordered_map) or
set (unordered_set). set<refptr> will soon be used by C version of
context package.