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