Commit fc1c3e24 authored by Kirill Smelkov's avatar Kirill Smelkov

*: NULL/nullptr -> nil (C++ only)

Convert C++ part of the project to use nil instead of NULL/nullptr.

We do not convert pyx part yet, because Cython currently does not
understand that nullptr_t has properties of NULL and with e.g. the
following change

    --- a/golang/_context.pyx
    +++ b/golang/_context.pyx
    @@ -116,7 +116,7 @@ cdef cppclass _PyValue (_interface, gobject) nogil:
         __dealloc__():
             with gil:
                 obj = <object>this.pyobj
    -            this.pyobj = NULL
    +            this.pyobj = nil
                 Py_DECREF(obj)

errors as

    Error compiling Cython file:
    ------------------------------------------------------------
    ...
            if __decref():
                del self
        __dealloc__():
            with gil:
                obj = <object>this.pyobj
                this.pyobj = nil
                            ^
    ------------------------------------------------------------

    golang/_context.pyx:119:25: Cannot assign type 'nullptr_t' to 'PyObject *'

https://github.com/cython/cython/issues/3314
parent 60f6db6f
// 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
...@@ -53,9 +53,9 @@ struct _Background final : _Context, object { ...@@ -53,9 +53,9 @@ struct _Background final : _Context, object {
} }
double deadline() { return INFINITY; } double deadline() { return INFINITY; }
chan<structZ> done() { return NULL; } chan<structZ> done() { return nil; }
error err() { return NULL; } error err() { return nil; }
interface value(const void *key) { return NULL; } interface value(const void *key) { return nil; }
}; };
static Context _background = adoptref(static_cast<_Context *>(new _Background())); static Context _background = adoptref(static_cast<_Context *>(new _Background()));
...@@ -98,7 +98,7 @@ struct _BaseCtx : _Context, object { ...@@ -98,7 +98,7 @@ struct _BaseCtx : _Context, object {
// chan: if context can be canceled on its own // chan: if context can be canceled on its own
// nil: if context can not be canceled on its own // nil: if context can not be canceled on its own
ctx._done = done; ctx._done = done;
if (done == NULL) { if (done == nil) {
if (parentv.size() != 1) if (parentv.size() != 1)
panic("BUG: _BaseCtx: done==nil, but len(parentv) != 1"); panic("BUG: _BaseCtx: done==nil, but len(parentv) != 1");
} }
...@@ -109,7 +109,7 @@ struct _BaseCtx : _Context, object { ...@@ -109,7 +109,7 @@ struct _BaseCtx : _Context, object {
chan<structZ> done() { chan<structZ> done() {
_BaseCtx& ctx = *this; _BaseCtx& ctx = *this;
if (ctx._done != NULL) if (ctx._done != nil)
return ctx._done; return ctx._done;
return ctx._parentv[0]->done(); return ctx._parentv[0]->done();
} }
...@@ -130,10 +130,10 @@ struct _BaseCtx : _Context, object { ...@@ -130,10 +130,10 @@ struct _BaseCtx : _Context, object {
for (auto parent : ctx._parentv) { for (auto parent : ctx._parentv) {
interface v = parent->value(key); interface v = parent->value(key);
if (v != NULL) if (v != nil)
return v; return v;
} }
return NULL; return nil;
} }
double deadline() { double deadline() {
...@@ -152,7 +152,7 @@ struct _BaseCtx : _Context, object { ...@@ -152,7 +152,7 @@ struct _BaseCtx : _Context, object {
// _cancel cancels ctx and its children. // _cancel cancels ctx and its children.
void _cancel(error err) { void _cancel(error err) {
_BaseCtx& ctx = *this; _BaseCtx& ctx = *this;
return ctx._cancelFrom(NULL, err); return ctx._cancelFrom(nil, err);
} }
// _cancelFrom cancels ctx and its children. // _cancelFrom cancels ctx and its children.
...@@ -162,7 +162,7 @@ struct _BaseCtx : _Context, object { ...@@ -162,7 +162,7 @@ struct _BaseCtx : _Context, object {
set<refptr<_BaseCtx>> children; set<refptr<_BaseCtx>> children;
ctx._mu.lock(); ctx._mu.lock();
if (ctx._err != NULL) { if (ctx._err != nil) {
ctx._mu.unlock(); ctx._mu.unlock();
return; // already canceled return; // already canceled
} }
...@@ -171,7 +171,7 @@ struct _BaseCtx : _Context, object { ...@@ -171,7 +171,7 @@ struct _BaseCtx : _Context, object {
ctx._children.swap(children); ctx._children.swap(children);
ctx._mu.unlock(); ctx._mu.unlock();
if (ctx._done != NULL) if (ctx._done != nil)
ctx._done.close(); ctx._done.close();
// no longer need to propagate cancel from parent after we are canceled // no longer need to propagate cancel from parent after we are canceled
...@@ -180,7 +180,7 @@ struct _BaseCtx : _Context, object { ...@@ -180,7 +180,7 @@ struct _BaseCtx : _Context, object {
if (parent == cancelFrom) if (parent == cancelFrom)
continue; continue;
_BaseCtx *_parent = dynamic_cast<_BaseCtx *>(parent._ptr()); _BaseCtx *_parent = dynamic_cast<_BaseCtx *>(parent._ptr());
if (_parent != NULL) { if (_parent != nil) {
_parent->_mu.lock(); _parent->_mu.lock();
_parent->_children.erase(bctx); _parent->_children.erase(bctx);
_parent->_mu.unlock(); _parent->_mu.unlock();
...@@ -204,14 +204,14 @@ struct _BaseCtx : _Context, object { ...@@ -204,14 +204,14 @@ struct _BaseCtx : _Context, object {
// if parent can never be canceled (e.g. it is background) - we // if parent can never be canceled (e.g. it is background) - we
// don't need to propagate cancel from it. // don't need to propagate cancel from it.
chan<structZ> pdone = parent->done(); chan<structZ> pdone = parent->done();
if (pdone == NULL) if (pdone == nil)
continue; continue;
// parent is cancellable - glue to propagate cancel from it to us // parent is cancellable - glue to propagate cancel from it to us
_BaseCtx *_parent = dynamic_cast<_BaseCtx *>(parent._ptr()); _BaseCtx *_parent = dynamic_cast<_BaseCtx *>(parent._ptr());
if (_parent != NULL) { if (_parent != nil) {
_parent->_mu.lock(); _parent->_mu.lock();
if (_parent->_err != NULL) if (_parent->_err != nil)
ctx._cancel(_parent->_err); ctx._cancel(_parent->_err);
else else
_parent->_children.insert(bctx); _parent->_children.insert(bctx);
...@@ -259,7 +259,7 @@ struct _ValueCtx : _BaseCtx { ...@@ -259,7 +259,7 @@ struct _ValueCtx : _BaseCtx {
interface _value; interface _value;
_ValueCtx(const void *key, interface value, Context parent) _ValueCtx(const void *key, interface value, Context parent)
: _BaseCtx(NULL, {parent}) { : _BaseCtx(nil, {parent}) {
_ValueCtx& ctx = *this; _ValueCtx& ctx = *this;
ctx._key = key; ctx._key = key;
...@@ -363,7 +363,7 @@ static bool _ready(chan<structZ> ch) { ...@@ -363,7 +363,7 @@ static bool _ready(chan<structZ> ch) {
// _tctxchildren returns context's children, assuming context is instance of _BaseCtx. // _tctxchildren returns context's children, assuming context is instance of _BaseCtx.
set<Context> _tctxchildren(Context ctx) { set<Context> _tctxchildren(Context ctx) {
_BaseCtx *_bctx = dynamic_cast<_BaseCtx*>(ctx._ptr()); _BaseCtx *_bctx = dynamic_cast<_BaseCtx*>(ctx._ptr());
if (_bctx == NULL) if (_bctx == nil)
panic("context is not instance of golang.context._BaseCtx"); panic("context is not instance of golang.context._BaseCtx");
set<Context> children; set<Context> children;
......
// 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
...@@ -38,7 +38,7 @@ string _vsprintf(const char *format, va_list argp) { ...@@ -38,7 +38,7 @@ string _vsprintf(const char *format, va_list argp) {
// based on https://stackoverflow.com/a/26221725/9456786 // based on https://stackoverflow.com/a/26221725/9456786
va_list argp2; va_list argp2;
va_copy(argp2, argp); va_copy(argp2, argp);
size_t nchar = ::vsnprintf(NULL, 0, format, argp2); size_t nchar = ::vsnprintf(nil, 0, format, argp2);
va_end(argp2); va_end(argp2);
std::unique_ptr<char[]> buf( new char[nchar /*for \0*/+1] ); std::unique_ptr<char[]> buf( new char[nchar /*for \0*/+1] );
......
...@@ -412,14 +412,14 @@ class chan { ...@@ -412,14 +412,14 @@ class chan {
_chan *_ch; _chan *_ch;
public: public:
inline chan() { _ch = NULL; } // nil channel if not explicitly initialized inline chan() { _ch = nil; } // nil channel if not explicitly initialized
friend chan<T> makechan<T>(unsigned size); friend chan<T> makechan<T>(unsigned size);
friend chan<T> _wrapchan<T>(_chan *_ch); friend chan<T> _wrapchan<T>(_chan *_ch);
inline ~chan() { _chanxdecref(_ch); _ch = NULL; } inline ~chan() { _chanxdecref(_ch); _ch = nil; }
// = nil // = nil
inline chan(nullptr_t) { _ch = NULL; } inline chan(nullptr_t) { _ch = nil; }
inline chan& operator=(nullptr_t) { _chanxdecref(_ch); _ch = NULL; return *this; } inline chan& operator=(nullptr_t) { _chanxdecref(_ch); _ch = nil; return *this; }
// copy // copy
inline chan(const chan& from) { _ch = from._ch; _chanxincref(_ch); } inline chan(const chan& from) { _ch = from._ch; _chanxincref(_ch); }
inline chan& operator=(const chan& from) { inline chan& operator=(const chan& from) {
...@@ -429,10 +429,10 @@ public: ...@@ -429,10 +429,10 @@ public:
return *this; return *this;
} }
// move // move
inline chan(chan&& from) { _ch = from._ch; from._ch = NULL; } inline chan(chan&& from) { _ch = from._ch; from._ch = nil; }
inline chan& operator=(chan&& from) { inline chan& operator=(chan&& from) {
if (this != &from) { if (this != &from) {
_chanxdecref(_ch); _ch = from._ch; from._ch = NULL; _chanxdecref(_ch); _ch = from._ch; from._ch = nil;
} }
return *this; return *this;
} }
...@@ -457,7 +457,7 @@ public: ...@@ -457,7 +457,7 @@ public:
// //
// if pok is provided the case is extended to `[*prx, *pok] = ch.recv_()` // if pok is provided the case is extended to `[*prx, *pok] = ch.recv_()`
// if both prx and pok are omitted the case is reduced to `ch.recv()`. // if both prx and pok are omitted the case is reduced to `ch.recv()`.
[[nodiscard]] inline _selcase recvs(T *prx=NULL, bool *pok=NULL) const { [[nodiscard]] inline _selcase recvs(T *prx=nil, bool *pok=nil) const {
return _selrecv_(_ch, prx, pok); return _selrecv_(_ch, prx, pok);
} }
...@@ -466,8 +466,8 @@ public: ...@@ -466,8 +466,8 @@ public:
inline unsigned cap() const { return _chancap(_ch); } inline unsigned cap() const { return _chancap(_ch); }
// compare wrt nil // compare wrt nil
inline bool operator==(nullptr_t) const { return (_ch == NULL); } inline bool operator==(nullptr_t) const { return (_ch == nil); }
inline bool operator!=(nullptr_t) const { return (_ch != NULL); } inline bool operator!=(nullptr_t) const { return (_ch != nil); }
// compare wrt chan // compare wrt chan
inline bool operator==(const chan<T>& ch2) const { return (_ch == ch2._ch); } inline bool operator==(const chan<T>& ch2) const { return (_ch == ch2._ch); }
...@@ -494,7 +494,7 @@ chan<T> makechan(unsigned size) { ...@@ -494,7 +494,7 @@ chan<T> makechan(unsigned size) {
} }
// _wrapchan<T> wraps raw channel with chan<T>. // _wrapchan<T> wraps raw channel with chan<T>.
// raw channel must be either NULL or its element size must correspond to T. // raw channel must be either nil or its element size must correspond to T.
LIBGOLANG_API void __wrapchan(_chan *_ch, unsigned elemsize); LIBGOLANG_API void __wrapchan(_chan *_ch, unsigned elemsize);
template<typename T> static inline template<typename T> static inline
chan<T> _wrapchan(_chan *_ch) { chan<T> _wrapchan(_chan *_ch) {
...@@ -577,36 +577,36 @@ class refptr { ...@@ -577,36 +577,36 @@ class refptr {
public: public:
// nil if not explicitly initialized // nil if not explicitly initialized
inline refptr() { _obj = NULL; } inline refptr() { _obj = nil; }
inline ~refptr() { inline ~refptr() {
if (_obj != NULL) { if (_obj != nil) {
_obj->decref(); _obj->decref();
_obj = NULL; _obj = nil;
} }
} }
// = nil // = nil
inline refptr(nullptr_t) { _obj = NULL; } inline refptr(nullptr_t) { _obj = nil; }
inline refptr& operator=(nullptr_t) { inline refptr& operator=(nullptr_t) {
if (_obj != NULL) if (_obj != nil)
_obj->decref(); _obj->decref();
_obj = NULL; _obj = nil;
return *this; return *this;
} }
// copy // copy
inline refptr(const refptr& from) { inline refptr(const refptr& from) {
_obj = from._obj; _obj = from._obj;
if(_obj != NULL) if (_obj != nil)
_obj->incref(); _obj->incref();
} }
inline refptr& operator=(const refptr& from) { inline refptr& operator=(const refptr& from) {
if (this != &from) { if (this != &from) {
if (_obj != NULL) if (_obj != nil)
_obj->decref(); _obj->decref();
_obj = from._obj; _obj = from._obj;
if (_obj != NULL) if (_obj != nil)
_obj->incref(); _obj->incref();
} }
return *this; return *this;
...@@ -615,14 +615,14 @@ public: ...@@ -615,14 +615,14 @@ public:
// move // move
inline refptr(refptr&& from) { inline refptr(refptr&& from) {
_obj = from._obj; _obj = from._obj;
from._obj = NULL; from._obj = nil;
} }
inline refptr& operator=(refptr&& from) { inline refptr& operator=(refptr&& from) {
if (this != &from) { if (this != &from) {
if (_obj != NULL) if (_obj != nil)
_obj->decref(); _obj->decref();
_obj = from._obj; _obj = from._obj;
from._obj = NULL; from._obj = nil;
} }
return *this; return *this;
} }
...@@ -632,8 +632,8 @@ public: ...@@ -632,8 +632,8 @@ public:
friend refptr<T> newref<T> (T *_obj); friend refptr<T> newref<T> (T *_obj);
// compare wrt nil // compare wrt nil
inline bool operator==(nullptr_t) const { return (_obj == NULL); } inline bool operator==(nullptr_t) const { return (_obj == nil); }
inline bool operator!=(nullptr_t) const { return (_obj != NULL); } inline bool operator!=(nullptr_t) const { return (_obj != nil); }
// compare wrt refptr // compare wrt refptr
inline bool operator==(const refptr& p2) const { return (_obj == p2._obj); } inline bool operator==(const refptr& p2) const { return (_obj == p2._obj); }
...@@ -681,21 +681,21 @@ public: ...@@ -681,21 +681,21 @@ public:
} }
// nil if not explicitly initialized // nil if not explicitly initialized
inline global() { _obj = NULL; } inline global() { _obj = nil; }
// init from refptr<T> // init from refptr<T>
inline global(const refptr<T>& from) { inline global(const refptr<T>& from) {
_obj = from._obj; _obj = from._obj;
if (_obj != NULL) if (_obj != nil)
_obj->incref(); _obj->incref();
} }
// = nil // = nil
inline global(nullptr_t) { _obj = NULL; } inline global(nullptr_t) { _obj = nil; }
inline global& operator=(nullptr_t) { inline global& operator=(nullptr_t) {
if (_obj != NULL) if (_obj != nil)
_obj->decref(); _obj->decref();
_obj = NULL; _obj = nil;
return *this; return *this;
} }
...@@ -703,8 +703,8 @@ public: ...@@ -703,8 +703,8 @@ public:
// move - no need due to refptr<T> cast // move - no need due to refptr<T> cast
// compare wrt nil // compare wrt nil
inline bool operator==(nullptr_t) const { return (_obj == NULL); } inline bool operator==(nullptr_t) const { return (_obj == nil); }
inline bool operator!=(nullptr_t) const { return (_obj != NULL); } inline bool operator!=(nullptr_t) const { return (_obj != nil); }
// compare wrt refptr // compare wrt refptr
inline bool operator==(const refptr<T>& p2) const { return (_obj == p2._obj); } inline bool operator==(const refptr<T>& p2) const { return (_obj == p2._obj); }
...@@ -747,7 +747,7 @@ template<typename T> ...@@ -747,7 +747,7 @@ template<typename T>
inline refptr<T> newref(T *_obj) { inline refptr<T> newref(T *_obj) {
refptr<T> p; refptr<T> p;
p._obj = _obj; p._obj = _obj;
if (_obj != NULL) if (_obj != nil)
_obj->incref(); _obj->incref();
return p; return p;
} }
......
This diff is collapsed.
// 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
...@@ -46,14 +46,14 @@ using std::vector; ...@@ -46,14 +46,14 @@ using std::vector;
// verify chan<T> automatic reference counting. // verify chan<T> automatic reference counting.
void _test_chan_cpp_refcount() { void _test_chan_cpp_refcount() {
chan<int> ch; chan<int> ch;
ASSERT(ch == NULL); ASSERT(ch == nil);
ASSERT(!(ch != NULL)); ASSERT(!(ch != nil));
ASSERT(ch._rawchan() == NULL); ASSERT(ch._rawchan() == nil);
ch = makechan<int>(); ch = makechan<int>();
ASSERT(!(ch == NULL)); ASSERT(!(ch == nil));
ASSERT(ch != NULL); ASSERT(ch != nil);
ASSERT(ch._rawchan() != NULL); ASSERT(ch._rawchan() != nil);
_chan *_ch = ch._rawchan(); _chan *_ch = ch._rawchan();
ASSERT(_chanrefcnt(_ch) == 1); ASSERT(_chanrefcnt(_ch) == 1);
...@@ -71,8 +71,8 @@ void _test_chan_cpp_refcount() { ...@@ -71,8 +71,8 @@ void _test_chan_cpp_refcount() {
// copy = // copy =
{ {
chan<int> ch2; chan<int> ch2;
ASSERT(ch2 == NULL); ASSERT(ch2 == nil);
ASSERT(ch2._rawchan() == NULL); ASSERT(ch2._rawchan() == nil);
ch2 = ch; ch2 = ch;
ASSERT(ch2._rawchan() == _ch); ASSERT(ch2._rawchan() == _ch);
...@@ -80,9 +80,9 @@ void _test_chan_cpp_refcount() { ...@@ -80,9 +80,9 @@ void _test_chan_cpp_refcount() {
ASSERT(ch2 == ch); ASSERT(ch2 == ch);
ASSERT(!(ch2 != ch)); ASSERT(!(ch2 != ch));
ch2 = NULL; ch2 = nil;
ASSERT(ch2 == NULL); ASSERT(ch2 == nil);
ASSERT(ch2._rawchan() == NULL); ASSERT(ch2._rawchan() == nil);
ASSERT(_chanrefcnt(_ch) == 1); ASSERT(_chanrefcnt(_ch) == 1);
ASSERT(!(ch2 == ch)); ASSERT(!(ch2 == ch));
ASSERT(ch2 != ch); ASSERT(ch2 != ch);
...@@ -91,18 +91,18 @@ void _test_chan_cpp_refcount() { ...@@ -91,18 +91,18 @@ void _test_chan_cpp_refcount() {
// move ctor // move ctor
chan<int> ch2(move(ch)); chan<int> ch2(move(ch));
ASSERT(ch == NULL); ASSERT(ch == nil);
ASSERT(ch._rawchan() == NULL); ASSERT(ch._rawchan() == nil);
ASSERT(ch2 != NULL); ASSERT(ch2 != nil);
ASSERT(ch2._rawchan() == _ch); ASSERT(ch2._rawchan() == _ch);
ASSERT(_chanrefcnt(_ch) == 1); ASSERT(_chanrefcnt(_ch) == 1);
// move = // move =
ch = move(ch2); ch = move(ch2);
ASSERT(ch != NULL); ASSERT(ch != nil);
ASSERT(ch._rawchan() == _ch); ASSERT(ch._rawchan() == _ch);
ASSERT(ch2 == NULL); ASSERT(ch2 == nil);
ASSERT(ch2._rawchan() == NULL); ASSERT(ch2._rawchan() == nil);
ASSERT(_chanrefcnt(_ch) == 1); ASSERT(_chanrefcnt(_ch) == 1);
// ch goes out of scope and destroys raw channel // ch goes out of scope and destroys raw channel
...@@ -117,7 +117,7 @@ struct Point { ...@@ -117,7 +117,7 @@ struct Point {
void _test_chan_cpp() { void _test_chan_cpp() {
chan<structZ> done = makechan<structZ>(); chan<structZ> done = makechan<structZ>();
chan<int> chi = makechan<int>(1); chan<int> chi = makechan<int>(1);
chan<Point> chp = makechan<Point>(); chp = NULL; chan<Point> chp = makechan<Point>(); chp = nil;
int i, j, _; int i, j, _;
Point p; Point p;
...@@ -155,7 +155,7 @@ void _test_chan_cpp() { ...@@ -155,7 +155,7 @@ void _test_chan_cpp() {
// waitBlocked waits until at least nrx recv and ntx send operations block // waitBlocked waits until at least nrx recv and ntx send operations block
// waiting on the channel. // waiting on the channel.
void waitBlocked(_chan *ch, int nrx, int ntx) { void waitBlocked(_chan *ch, int nrx, int ntx) {
if (ch == NULL) if (ch == nil)
panic("wait blocked: called on nil channel"); panic("wait blocked: called on nil channel");
double t0 = time::now(); double t0 = time::now();
...@@ -308,12 +308,12 @@ void __test_close_wakeup_all(bool vs_select) { ...@@ -308,12 +308,12 @@ void __test_close_wakeup_all(bool vs_select) {
// as other workers vvv don't use ch after wakeup from ch.recv(). // as other workers vvv don't use ch after wakeup from ch.recv().
if (!vs_select) if (!vs_select)
ASSERT(_chanrefcnt(ch._rawchan()) == 1); ASSERT(_chanrefcnt(ch._rawchan()) == 1);
ch = NULL; ch = nil;
done.send(structZ{}); done.send(structZ{});
}); });
waitBlocked(_ch, /*nrx=*/1, /*ntx=*/0); waitBlocked(_ch, /*nrx=*/1, /*ntx=*/0);
ASSERT(_chanrefcnt(_ch) == 2); ASSERT(_chanrefcnt(_ch) == 2);
ch = NULL; ch = nil;
ASSERT(_chanrefcnt(_ch) == 1); ASSERT(_chanrefcnt(_ch) == 1);
// many other ch.recv or select({ch.recv}) subscribers queued to ch.recvq // many other ch.recv or select({ch.recv}) subscribers queued to ch.recvq
...@@ -321,7 +321,7 @@ void __test_close_wakeup_all(bool vs_select) { ...@@ -321,7 +321,7 @@ void __test_close_wakeup_all(bool vs_select) {
for (i=0; i < N; i++) { for (i=0; i < N; i++) {
go([_ch, done, vs_select]() { go([_ch, done, vs_select]() {
if (!vs_select) { if (!vs_select) {
_chanrecv(_ch, NULL); _chanrecv(_ch, nil);
} else { } else {
int rx; int rx;
select({ select({
...@@ -363,7 +363,7 @@ void __test_select_win_while_queue() { ...@@ -363,7 +363,7 @@ void __test_select_win_while_queue() {
Data *data_send = (Data *)calloc(1, sizeof(Data)); Data *data_send = (Data *)calloc(1, sizeof(Data));
Data *data_recv = (Data *)calloc(1, sizeof(Data)); Data *data_recv = (Data *)calloc(1, sizeof(Data));
if (data_send == NULL || data_recv == NULL) if (data_send == nil || data_recv == nil)
throw std::bad_alloc(); throw std::bad_alloc();
for (i=0; i<Ndata; i++) for (i=0; i<Ndata; i++)
data_send->_[i] = i % 0xff; data_send->_[i] = i % 0xff;
...@@ -407,7 +407,7 @@ void _test_select_inplace() { ...@@ -407,7 +407,7 @@ void _test_select_inplace() {
// inplace tx // inplace tx
go([ch]() { go([ch]() {
_selcase sel[1]; _selcase sel[1];
sel[0] = ch.sends(NULL); sel[0] = ch.sends(nil);
*(int *)&sel[0].itxrx = 12345; *(int *)&sel[0].itxrx = 12345;
sel[0].flags = _INPLACE_DATA; sel[0].flags = _INPLACE_DATA;
int _ = select(sel); int _ = select(sel);
...@@ -421,34 +421,34 @@ void _test_select_inplace() { ...@@ -421,34 +421,34 @@ void _test_select_inplace() {
_selcase sel[1]; _selcase sel[1];
sel[0] = ch.recvs(); sel[0] = ch.recvs();
sel[0].flags = _INPLACE_DATA; sel[0].flags = _INPLACE_DATA;
const char *err = NULL; const char *err = nil;
try { try {
select(sel); select(sel);
} catch (...) { } catch (...) {
err = recover(); err = recover();
} }
ASSERT(err != NULL); ASSERT(err != nil);
ASSERT(!strcmp(err, "select: recv into inplace data")); ASSERT(!strcmp(err, "select: recv into inplace data"));
// _selcase ptx/prx // _selcase ptx/prx
_selcase cas = _default; _selcase cas = _default;
err = NULL; err = nil;
try { try {
cas.ptx(); cas.ptx();
} catch (...) { } catch (...) {
err = recover(); err = recover();
} }
ASSERT(err != NULL); ASSERT(err != nil);
ASSERT(!strcmp(err, "_selcase: ptx: op != send")); ASSERT(!strcmp(err, "_selcase: ptx: op != send"));
err = NULL; err = nil;
try { try {
cas.prx(); cas.prx();
} catch (...) { } catch (...) {
err = recover(); err = recover();
} }
ASSERT(err != NULL); ASSERT(err != nil);
ASSERT(!strcmp(err, "_selcase: prx: op != recv")); ASSERT(!strcmp(err, "_selcase: prx: op != recv"));
cas = ch.sends(&i); cas = ch.sends(&i);
...@@ -459,13 +459,13 @@ void _test_select_inplace() { ...@@ -459,13 +459,13 @@ void _test_select_inplace() {
cas = ch.recvs(&i); cas = ch.recvs(&i);
ASSERT(cas.prx() == &i); ASSERT(cas.prx() == &i);
cas.flags = _INPLACE_DATA; cas.flags = _INPLACE_DATA;
err = NULL; err = nil;
try { try {
cas.prx(); cas.prx();
} catch (...) { } catch (...) {
err = recover(); err = recover();
} }
ASSERT(err != NULL); ASSERT(err != nil);
ASSERT(!strcmp(err, "_selcase: prx: recv with inplace data")); ASSERT(!strcmp(err, "_selcase: prx: recv with inplace data"));
} }
...@@ -501,9 +501,9 @@ public: ...@@ -501,9 +501,9 @@ public:
void _test_refptr() { void _test_refptr() {
refptr<MyObj> p; refptr<MyObj> p;
ASSERT(p == NULL); ASSERT(p == nil);
ASSERT(!(p != NULL)); ASSERT(!(p != nil));
ASSERT(p._ptr() == NULL); ASSERT(p._ptr() == nil);
MyObj *obj = new MyObj(); MyObj *obj = new MyObj();
ASSERT(obj->refcnt() == 1); ASSERT(obj->refcnt() == 1);
...@@ -551,8 +551,8 @@ void _test_refptr() { ...@@ -551,8 +551,8 @@ void _test_refptr() {
{ {
refptr<MyObj> q; refptr<MyObj> q;
ASSERT(obj->refcnt() == 1); ASSERT(obj->refcnt() == 1);
ASSERT(q == NULL); ASSERT(q == nil);
ASSERT(q._ptr() == NULL); ASSERT(q._ptr() == nil);
ASSERT(!(p == q)); ASSERT(!(p == q));
ASSERT(p != q); ASSERT(p != q);
...@@ -563,10 +563,10 @@ void _test_refptr() { ...@@ -563,10 +563,10 @@ void _test_refptr() {
ASSERT(p == q); ASSERT(p == q);
ASSERT(!(p != q)); ASSERT(!(p != q));
q = NULL; q = nil;
ASSERT(obj->refcnt() == 1); ASSERT(obj->refcnt() == 1);
ASSERT(p._ptr() == obj); ASSERT(p._ptr() == obj);
ASSERT(q._ptr() == NULL); ASSERT(q._ptr() == nil);
ASSERT(!(p == q)); ASSERT(!(p == q));
ASSERT(p != q); ASSERT(p != q);
} }
...@@ -575,34 +575,34 @@ void _test_refptr() { ...@@ -575,34 +575,34 @@ void _test_refptr() {
// move ctor // move ctor
refptr<MyObj> q(move(p)); refptr<MyObj> q(move(p));
ASSERT(obj->refcnt() == 1); ASSERT(obj->refcnt() == 1);
ASSERT(p == NULL); ASSERT(p == nil);
ASSERT(p._ptr() == NULL); ASSERT(p._ptr() == nil);
ASSERT(q != NULL); ASSERT(q != nil);
ASSERT(q._ptr() == obj); ASSERT(q._ptr() == obj);
// move = // move =
p = move(q); p = move(q);
ASSERT(obj->refcnt() == 1); ASSERT(obj->refcnt() == 1);
ASSERT(p != NULL); ASSERT(p != nil);
ASSERT(p._ptr() == obj); ASSERT(p._ptr() == obj);
ASSERT(q == NULL); ASSERT(q == nil);
ASSERT(q._ptr() == NULL); ASSERT(q._ptr() == nil);
// p goes out of scope and destroys obj // p goes out of scope and destroys obj
} }
void _test_global() { void _test_global() {
global<refptr<MyObj>> g; global<refptr<MyObj>> g;
ASSERT(g == NULL); ASSERT(g == nil);
ASSERT(!(g != NULL)); ASSERT(!(g != nil));
ASSERT(g._ptr() == NULL); ASSERT(g._ptr() == nil);
MyObj *obj = new MyObj(); MyObj *obj = new MyObj();
refptr<MyObj> p = adoptref(obj); refptr<MyObj> p = adoptref(obj);
ASSERT(obj->refcnt() == 1); ASSERT(obj->refcnt() == 1);
obj->i = 3; obj->i = 3;
ASSERT(g._ptr() == NULL); ASSERT(g._ptr() == nil);
ASSERT(p._ptr() == obj); ASSERT(p._ptr() == obj);
ASSERT(!(g == p)); ASSERT(!(g == p));
ASSERT(!(p == g)); ASSERT(!(p == g));
...@@ -614,8 +614,8 @@ void _test_global() { ...@@ -614,8 +614,8 @@ void _test_global() {
ASSERT(obj->refcnt() == 2); ASSERT(obj->refcnt() == 2);
ASSERT(g._ptr() == obj); ASSERT(g._ptr() == obj);
ASSERT(p._ptr() == obj); ASSERT(p._ptr() == obj);
ASSERT(!(g == NULL)); ASSERT(!(g == nil));
ASSERT(g != NULL); ASSERT(g != nil);
ASSERT(g == p); ASSERT(g == p);
ASSERT(p == g); ASSERT(p == g);
ASSERT(!(g != p)); ASSERT(!(g != p));
...@@ -630,15 +630,15 @@ void _test_global() { ...@@ -630,15 +630,15 @@ void _test_global() {
// global = nil - obj reference is released // global = nil - obj reference is released
ASSERT(obj->refcnt() == 2); ASSERT(obj->refcnt() == 2);
g = NULL; g = nil;
ASSERT(obj->refcnt() == 1); ASSERT(obj->refcnt() == 1);
ASSERT(g._ptr() == NULL); ASSERT(g._ptr() == nil);
// copy ctor global <- refptr // copy ctor global <- refptr
{ {
global<refptr<MyObj>> h(p); global<refptr<MyObj>> h(p);
ASSERT(obj->refcnt() == 2); ASSERT(obj->refcnt() == 2);
ASSERT(g._ptr() == NULL); ASSERT(g._ptr() == nil);
ASSERT(h._ptr() == obj); ASSERT(h._ptr() == obj);
ASSERT(p._ptr() == obj); ASSERT(p._ptr() == obj);
ASSERT(!(h == g)); ASSERT(!(h == g));
......
// 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
...@@ -39,8 +39,8 @@ namespace runtime { ...@@ -39,8 +39,8 @@ namespace runtime {
// pyexited indicates whether Python interpreter exited. // pyexited indicates whether Python interpreter exited.
static sync::Mutex *pyexitedMu = NULL; // allocated in _init and never freed not to race static sync::Mutex *pyexitedMu = nil; // allocated in _init and never freed not to race
static sync::WaitGroup *pygilTaking = NULL; // at exit on dtor vs use. static sync::WaitGroup *pygilTaking = nil; // at exit on dtor vs use.
static bool pyexited = false; static bool pyexited = false;
void _init() { void _init() {
...@@ -102,8 +102,8 @@ error PyErr_Fetch() { ...@@ -102,8 +102,8 @@ error PyErr_Fetch() {
PyGILState_Release(gstate); PyGILState_Release(gstate);
// no error // no error
if (pyexc_type == NULL && pyexc_value == NULL && pyexc_tb == NULL) if (pyexc_type == nil && pyexc_value == nil && pyexc_tb == nil)
return NULL; return nil;
// -> _PyError // -> _PyError
_PyError* _e = new _PyError(); _PyError* _e = new _PyError();
...@@ -141,9 +141,9 @@ _PyError::~_PyError() { ...@@ -141,9 +141,9 @@ _PyError::~_PyError() {
PyObject *pyexc_type = this->pyexc_type; PyObject *pyexc_type = this->pyexc_type;
PyObject *pyexc_value = this->pyexc_value; PyObject *pyexc_value = this->pyexc_value;
PyObject *pyexc_tb = this->pyexc_tb; PyObject *pyexc_tb = this->pyexc_tb;
this->pyexc_type = NULL; this->pyexc_type = nil;
this->pyexc_value = NULL; this->pyexc_value = nil;
this->pyexc_tb = NULL; this->pyexc_tb = nil;
if (!ok) { if (!ok) {
return; return;
} }
...@@ -182,7 +182,7 @@ PyFunc::PyFunc(const PyFunc& from) { ...@@ -182,7 +182,7 @@ PyFunc::PyFunc(const PyFunc& from) {
tie(gstate, ok) = pygil_ensure(); tie(gstate, ok) = pygil_ensure();
if (!ok) { if (!ok) {
pyf = NULL; // won't be used pyf = nil; // won't be used
return; return;
} }
...@@ -197,7 +197,7 @@ PyFunc::~PyFunc() { ...@@ -197,7 +197,7 @@ PyFunc::~PyFunc() {
tie(gstate, ok) = pygil_ensure(); tie(gstate, ok) = pygil_ensure();
PyObject *pyf = this->pyf; PyObject *pyf = this->pyf;
this->pyf = NULL; this->pyf = nil;
if (!ok) { if (!ok) {
return; return;
} }
...@@ -222,8 +222,8 @@ error PyFunc::operator() () const { ...@@ -222,8 +222,8 @@ error PyFunc::operator() () const {
} }
error err; error err;
PyObject *ret = PyObject_CallFunction(pyf, NULL); PyObject *ret = PyObject_CallFunction(pyf, nil);
if (ret == NULL) { if (ret == nil) {
err = PyErr_Fetch(); err = PyErr_Fetch();
} }
Py_XDECREF(ret); Py_XDECREF(ret);
......
// 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
...@@ -84,13 +84,13 @@ void WaitGroup::add(int delta) { ...@@ -84,13 +84,13 @@ void WaitGroup::add(int delta) {
void WaitGroup::wait() { void WaitGroup::wait() {
WaitGroup& wg = *this; WaitGroup& wg = *this;
chan<structZ> done = NULL; chan<structZ> done = nil;
wg._mu.lock(); wg._mu.lock();
if (wg._count != 0) if (wg._count != 0)
done = wg._done; done = wg._done;
wg._mu.unlock(); wg._mu.unlock();
if (done == NULL) // wg._count was =0 if (done == nil) // wg._count was =0
return; return;
done.recv(); done.recv();
...@@ -123,7 +123,7 @@ void _WorkGroup::go(func<error(context::Context)> f) { ...@@ -123,7 +123,7 @@ void _WorkGroup::go(func<error(context::Context)> f) {
}); });
error err = f(g->_ctx); // TODO consider also propagating panic error err = f(g->_ctx); // TODO consider also propagating panic
if (err == NULL) if (err == nil)
return; return;
g->_mu.lock(); g->_mu.lock();
...@@ -131,7 +131,7 @@ void _WorkGroup::go(func<error(context::Context)> f) { ...@@ -131,7 +131,7 @@ void _WorkGroup::go(func<error(context::Context)> f) {
g->_mu.unlock(); g->_mu.unlock();
}); });
if (g->_err == NULL) { if (g->_err == nil) {
// this goroutine is the first failed task // this goroutine is the first failed task
g->_err = err; g->_err = err;
g->_cancel(); g->_cancel();
......
// 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
...@@ -39,7 +39,7 @@ Timer _new_timer(double dt, func<void()>); ...@@ -39,7 +39,7 @@ Timer _new_timer(double dt, func<void()>);
chan<double> tick(double dt) { chan<double> tick(double dt) {
if (dt <= 0) if (dt <= 0)
return NULL; return nil;
return new_ticker(dt)->c; return new_ticker(dt)->c;
} }
...@@ -120,7 +120,7 @@ void _Timer::decref() { ...@@ -120,7 +120,7 @@ void _Timer::decref() {
Timer _new_timer(double dt, func<void()> f) { Timer _new_timer(double dt, func<void()> f) {
Timer t = adoptref(new _Timer()); Timer t = adoptref(new _Timer());
t->c = (f == NULL ? makechan<double>(1) : NULL); t->c = (f == nil ? makechan<double>(1) : nil);
t->_f = f; t->_f = f;
t->_dt = INFINITY; t->_dt = INFINITY;
t->_ver = 0; t->_ver = 0;
...@@ -129,7 +129,7 @@ Timer _new_timer(double dt, func<void()> f) { ...@@ -129,7 +129,7 @@ Timer _new_timer(double dt, func<void()> f) {
} }
Timer new_timer(double dt) { Timer new_timer(double dt) {
return _new_timer(dt, NULL); return _new_timer(dt, nil);
} }
bool _Timer::stop() { bool _Timer::stop() {
...@@ -186,7 +186,7 @@ void _Timer::_fire(double dt, int ver) { ...@@ -186,7 +186,7 @@ void _Timer::_fire(double dt, int ver) {
// send under ._mu so that .stop can be sure that if it sees // send under ._mu so that .stop can be sure that if it sees
// ._dt = INFINITY, there is no ongoing .c send. // ._dt = INFINITY, there is no ongoing .c send.
if (t._f == NULL) { if (t._f == nil) {
t.c.send(now()); t.c.send(now());
t._mu.unlock(); t._mu.unlock();
return; return;
......
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