wlav / cppyy

Other
391 stars 40 forks source link

typed nullptr != nullptr #102

Closed N-Coder closed 1 year ago

N-Coder commented 1 year ago

The typed nullptr created by bind_object does not compare equal to the generic nullptr, i.e.

cppyy.bind_object(cppyy.nullptr, 'std::vector<int>') != cppyy.nullptr

This makes checks whether a returned (typed) pointer is null harder as they should be. While both types of nullptr are false-y, this check can't always be used, e.g. it couldn't differentiate between a nullptr and an empty vector in the example above. My generic way of testing for nullptr now is the following, but having to remember to use the function instead of != nullptr is still somewhat annoying and an easy source for errors.

def is_nullptr(o):
    return cppyy.ll.addressof(o) == 0
wlav commented 1 year ago

That's indeed an omission, which probably never showed up b/c the double meaning (nullptr v.s. empty) is not common. Is fixed in repo.

wlav commented 1 year ago

Released with cppyy 2.4.2 and its dependencies.