Commit 01ade7ac authored by Kirill Smelkov's avatar Kirill Smelkov

*: NULL -> nil (Pyx and only where we can)

Convert Pyx part of the project to use nil instead of NULL.

Not every usage of NULL was converted and some places were left to use
NULL where changing it to nil currently hits Cython compilation error:

https://github.com/cython/cython/issues/3314
parent fc1c3e24
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# cython: language_level=2 # cython: language_level=2
# Copyright (C) 2019 Nexedi SA and Contributors. # Copyright (C) 2019-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your # it under the terms of the GNU General Public License version 3, or (at your
...@@ -58,7 +58,7 @@ cdef class PyContext: ...@@ -58,7 +58,7 @@ cdef class PyContext:
raise AssertionError("Context must not be instantiated by user") raise AssertionError("Context must not be instantiated by user")
def __dealloc__(PyContext pyctx): def __dealloc__(PyContext pyctx):
ctx = NULL ctx = nil
# deadline() returns context deadline or None, if there is no deadline. # deadline() returns context deadline or None, if there is no deadline.
def deadline(PyContext pyctx): # -> time | None def deadline(PyContext pyctx): # -> time | None
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# distutils: language = c++ # distutils: language = c++
# distutils: depends = libgolang.h # distutils: depends = libgolang.h
# #
# Copyright (C) 2018-2019 Nexedi SA and Contributors. # Copyright (C) 2018-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -66,7 +66,7 @@ cdef void topyexc() except *: ...@@ -66,7 +66,7 @@ cdef void topyexc() except *:
# recover_ is declared `except +` - if it was another - not panic - # recover_ is declared `except +` - if it was another - not panic -
# exception, it will be converted to py exc by cython automatically. # exception, it will be converted to py exc by cython automatically.
arg = recover_() arg = recover_()
if arg != NULL: if arg != nil:
pyarg = <bytes>arg pyarg = <bytes>arg
if PY_MAJOR_VERSION >= 3: if PY_MAJOR_VERSION >= 3:
pyarg = pyarg.decode("utf-8") pyarg = pyarg.decode("utf-8")
...@@ -188,7 +188,7 @@ cdef class pychan: ...@@ -188,7 +188,7 @@ cdef class pychan:
return pynil(parse_dtype(dtype)) return pynil(parse_dtype(dtype))
def __dealloc__(pychan pych): def __dealloc__(pychan pych):
if pych._ch == NULL: if pych._ch == nil:
return return
# pychan[X!=object]: just decref the raw chan and we are done. # pychan[X!=object]: just decref the raw chan and we are done.
...@@ -264,7 +264,7 @@ cdef class pychan: ...@@ -264,7 +264,7 @@ cdef class pychan:
cdef PyObject *_rxpy cdef PyObject *_rxpy
if pych.dtype == DTYPE_PYOBJECT: if pych.dtype == DTYPE_PYOBJECT:
_rxpy = (<PyObject **>&_rx)[0] _rxpy = (<PyObject **>&_rx)[0]
if _rxpy != NULL: if _rxpy != nil:
# we received the object and the channel dropped pointer to it. # we received the object and the channel dropped pointer to it.
rx = <object>_rxpy rx = <object>_rxpy
Py_DECREF(rx) Py_DECREF(rx)
...@@ -287,7 +287,7 @@ cdef class pychan: ...@@ -287,7 +287,7 @@ cdef class pychan:
return _chanlen_pyexc(pych._ch) return _chanlen_pyexc(pych._ch)
def __repr__(pychan pych): def __repr__(pychan pych):
if pych._ch == NULL: if pych._ch == nil:
if pych.dtype == DTYPE_PYOBJECT: if pych.dtype == DTYPE_PYOBJECT:
return "nilchan" return "nilchan"
else: else:
...@@ -309,7 +309,7 @@ cdef class pychan: ...@@ -309,7 +309,7 @@ cdef class pychan:
# if one of the sides is nil[*] (untyped nil). # if one of the sides is nil[*] (untyped nil).
if a.dtype == b.dtype: if a.dtype == b.dtype:
return True return True
if a._ch != NULL: if a._ch != nil:
return False return False
if a.dtype == DTYPE_PYOBJECT or b.dtype == DTYPE_PYOBJECT: if a.dtype == DTYPE_PYOBJECT or b.dtype == DTYPE_PYOBJECT:
return True return True
...@@ -425,7 +425,7 @@ def pyselect(*pycasev): ...@@ -425,7 +425,7 @@ def pyselect(*pycasev):
pypanic("pyselect: send expected: %r" % (pysend,)) pypanic("pyselect: send expected: %r" % (pysend,))
tx = <object>(_tcase.ob_item[1]) tx = <object>(_tcase.ob_item[1])
casev[i] = _selsend(pych._ch, NULL) casev[i] = _selsend(pych._ch, nil)
casev[i].flags = _INPLACE_DATA casev[i].flags = _INPLACE_DATA
casev[i].user = pych.dtype casev[i].user = pych.dtype
...@@ -481,17 +481,17 @@ def pyselect(*pycasev): ...@@ -481,17 +481,17 @@ def pyselect(*pycasev):
cdef PyObject *_rxpy cdef PyObject *_rxpy
cdef DType rxtype = <DType>casev[selected].user cdef DType rxtype = <DType>casev[selected].user
if rxtype == DTYPE_PYOBJECT: if rxtype == DTYPE_PYOBJECT:
# we received NULL or the object; if it is object, corresponding channel # we received nil or the object; if it is object, corresponding channel
# dropped pointer to it (see pychan.recv_ for details). # dropped pointer to it (see pychan.recv_ for details).
_rxpy = (<PyObject **>&_rx)[0] _rxpy = (<PyObject **>&_rx)[0]
if _rxpy != NULL: if _rxpy != nil:
rx = <object>_rxpy rx = <object>_rxpy
Py_DECREF(rx) Py_DECREF(rx)
else: else:
rx = c_to_py(rxtype, &_rx) rx = c_to_py(rxtype, &_rx)
if casev[selected].rxok != NULL: if casev[selected].rxok != nil:
return selected, (rx, rxok) return selected, (rx, rxok)
else: else:
return selected, rx return selected, rx
...@@ -522,8 +522,8 @@ cdef void _init_libgolang() except*: ...@@ -522,8 +522,8 @@ cdef void _init_libgolang() except*:
runtimecaps = (runtimemod + ".libgolang_runtime_ops").encode("utf-8") # py3 runtimecaps = (runtimemod + ".libgolang_runtime_ops").encode("utf-8") # py3
cdef const _libgolang_runtime_ops *runtime_ops = \ cdef const _libgolang_runtime_ops *runtime_ops = \
<const _libgolang_runtime_ops*>PyCapsule_Import(runtimecaps, 0) <const _libgolang_runtime_ops*>PyCapsule_Import(runtimecaps, 0)
if runtime_ops == NULL: if runtime_ops == nil:
pypanic("init: %s: libgolang_runtime_ops=NULL" % runtimemod) pypanic("init: %s: libgolang_runtime_ops=nil" % runtimemod)
_libgolang_init(runtime_ops) _libgolang_init(runtime_ops)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# cython: language_level=2 # cython: language_level=2
# distutils: language=c++ # distutils: language=c++
# #
# Copyright (C) 2018-2019 Nexedi SA and Contributors. # Copyright (C) 2018-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -38,11 +38,11 @@ cdef extern from "golang/libgolang.h" namespace "golang" nogil: ...@@ -38,11 +38,11 @@ cdef extern from "golang/libgolang.h" namespace "golang" nogil:
# pylen_{recv,send}q returns len(_chan._{recv,send}q) # pylen_{recv,send}q returns len(_chan._{recv,send}q)
def pylen_recvq(pychan pych not None): # -> int def pylen_recvq(pychan pych not None): # -> int
if pych._ch == NULL: if pych._ch == nil:
raise AssertionError('len(.recvq) on nil channel') raise AssertionError('len(.recvq) on nil channel')
return _tchanrecvqlen(pych._ch) return _tchanrecvqlen(pych._ch)
def pylen_sendq(pychan pych not None): # -> int def pylen_sendq(pychan pych not None): # -> int
if pych._ch == NULL: if pych._ch == nil:
raise AssertionError('len(.sendq) on nil channel') raise AssertionError('len(.sendq) on nil channel')
return _tchansendqlen(pych._ch) return _tchansendqlen(pych._ch)
...@@ -82,7 +82,7 @@ cdef class pypanicWhenBlocked: ...@@ -82,7 +82,7 @@ cdef class pypanicWhenBlocked:
return t return t
def __exit__(pypanicWhenBlocked t, typ, val, tb): def __exit__(pypanicWhenBlocked t, typ, val, tb):
_tblockforever = NULL _tblockforever = nil
cdef void _panicblocked() nogil: cdef void _panicblocked() nogil:
panic("t: blocks forever") panic("t: blocks forever")
...@@ -158,12 +158,12 @@ def test_go_nogil(): ...@@ -158,12 +158,12 @@ def test_go_nogil():
# interfere with current py state ) # interfere with current py state )
def test_runtime_vs_pyexc(): def test_runtime_vs_pyexc():
cdef PyObject *pyexc cdef PyObject *pyexc
assert PyErr_Occurred() == NULL # no exception initially assert PyErr_Occurred() == nil # no exception initially
# set "current" exception # set "current" exception
PyErr_SetString(RuntimeError, "abc") PyErr_SetString(RuntimeError, "abc")
pyexc = PyErr_Occurred() pyexc = PyErr_Occurred()
assert pyexc != NULL assert pyexc != nil
assert pyexc == PyErr_Occurred() assert pyexc == PyErr_Occurred()
# makechan (also tests sema alloc) # makechan (also tests sema alloc)
...@@ -193,7 +193,7 @@ def test_runtime_vs_pyexc(): ...@@ -193,7 +193,7 @@ def test_runtime_vs_pyexc():
# clear current exception, or else test driver will see calling us as failure # clear current exception, or else test driver will see calling us as failure
PyErr_Clear() PyErr_Clear()
assert PyErr_Occurred() == NULL assert PyErr_Occurred() == nil
cdef void _noop() nogil: cdef void _noop() nogil:
pass pass
......
# cython: language_level=2 # cython: language_level=2
# Copyright (C) 2019 Nexedi SA and Contributors. # Copyright (C) 2019-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your # it under the terms of the GNU General Public License version 3, or (at your
...@@ -169,7 +169,7 @@ cdef class PyWorkGroup: ...@@ -169,7 +169,7 @@ cdef class PyWorkGroup:
pywg._pyctx = context.PyContext.from_ctx(_WorkGroup_ctx(pywg.wg._ptr())) pywg._pyctx = context.PyContext.from_ctx(_WorkGroup_ctx(pywg.wg._ptr()))
def __dealloc__(PyWorkGroup pywg): def __dealloc__(PyWorkGroup pywg):
pywg.wg = NULL pywg.wg = nil
def go(PyWorkGroup pywg, f, *argv, **kw): def go(PyWorkGroup pywg, f, *argv, **kw):
# run f(._pyctx, ...) via _PyCtxFunc whose operator()(ctx) # run f(._pyctx, ...) via _PyCtxFunc whose operator()(ctx)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# cython: language_level=2 # cython: language_level=2
# distutils: language=c++ # distutils: language=c++
# #
# Copyright (C) 2018-2019 Nexedi SA and Contributors. # Copyright (C) 2018-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -75,13 +75,13 @@ cdef nogil: ...@@ -75,13 +75,13 @@ cdef nogil:
cdef double Wstart, now cdef double Wstart, now
while 1: while 1:
i += 1 i += 1
# wait till .sema != NULL and pop it # wait till .sema != nil and pop it
Wstart = time.now() Wstart = time.now()
j = 0 j = 0
while 1: while 1:
state.mu.lock() state.mu.lock()
sema = state.sema sema = state.sema
if sema != NULL: if sema != nil:
state.sema = NULL state.sema = NULL
stop = state.stop stop = state.stop
state.mu.unlock() state.mu.unlock()
...@@ -89,7 +89,7 @@ cdef nogil: ...@@ -89,7 +89,7 @@ cdef nogil:
if stop: if stop:
state.done.close() state.done.close()
return return
if sema != NULL: if sema != nil:
break break
now = time.now() now = time.now()
...@@ -109,8 +109,8 @@ cdef nogil: ...@@ -109,8 +109,8 @@ cdef nogil:
void _test_sema_wakeup() except +topyexc: void _test_sema_wakeup() except +topyexc:
cdef WorkState *state = <WorkState *>calloc(1, sizeof(WorkState)) cdef WorkState *state = <WorkState *>calloc(1, sizeof(WorkState))
if state == NULL: if state == nil:
panic("malloc -> NULL") panic("malloc -> nil")
state.sema = NULL state.sema = NULL
_mutex_init(&state.mu) _mutex_init(&state.mu)
state.stop = False state.stop = False
......
# cython: language_level=2 # cython: language_level=2
# Copyright (C) 2019 Nexedi SA and Contributors. # Copyright (C) 2019-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your # it under the terms of the GNU General Public License version 3, or (at your
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
from golang cimport pychan, topyexc from golang cimport nil, pychan, topyexc
from golang cimport sync from golang cimport sync
from golang.pyx cimport runtime from golang.pyx cimport runtime
from cpython cimport PyObject from cpython cimport PyObject
...@@ -74,7 +74,7 @@ cdef class PyTicker: ...@@ -74,7 +74,7 @@ cdef class PyTicker:
pytx.c = pychan.from_chan_double( pytx.tx.c ) pytx.c = pychan.from_chan_double( pytx.tx.c )
def __dealloc__(PyTicker pytx): def __dealloc__(PyTicker pytx):
pytx.tx = NULL pytx.tx = nil
# stop cancels the ticker. # stop cancels the ticker.
# #
...@@ -104,7 +104,7 @@ cdef class PyTimer: ...@@ -104,7 +104,7 @@ cdef class PyTimer:
pyt.c = pychan.from_chan_double( pyt.t.c ) pyt.c = pychan.from_chan_double( pyt.t.c )
def __dealloc__(PyTimer pyt): def __dealloc__(PyTimer pyt):
pyt.t = NULL pyt.t = nil
# stop cancels the timer. # stop cancels the timer.
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment