Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use XINCREF in copy constructor and subview constructor, since arr ma…
…y be NULL
  • Loading branch information
mdboom committed Nov 17, 2014
commit f94ffd798c3a9da3a1ec38b9f1cc1dab66e71da1
4 changes: 2 additions & 2 deletions src/numpy_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
array_view(const array_view &other, bool contiguous = false) : m_arr(NULL), m_data(NULL)
{
m_arr = other.m_arr;
Py_INCREF(m_arr);
Py_XINCREF(m_arr);
m_data = other.m_data;
m_shape = other.m_shape;
m_strides = other.m_strides;
Expand All @@ -379,7 +379,7 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
array_view(PyArrayObject *arr, char *data, npy_intp *shape, npy_intp *strides)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this ctor also need to specify the member variables?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been awhile since I did heavy C++, but couldn't the copy ctor call the other ctor below for good code reuse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling ctor's from other ctor's isn't supported since a ctor is special (sets up vtables & stuff). it's perhaps a good idea to call a helper, but that's arguably no better since it would still reference all the actual names of members.

whatever the case about this, travis isn't happy (in ways that really confuse me).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I could have sworn I was able to do something like this using gcc, but maybe I am thinking of subclassing?

In any case, it appears that C++11 added "delegating constructors": http://www-01.ibm.com/support/knowledgecenter/SSGH3R_11.1.0/com.ibm.xlcpp111.aix.doc/language_ref/delegating_ctors.html

Don't know what the compiler support is, but it is nice to know it has a name.

{
m_arr = arr;
Py_INCREF(arr);
Py_XINCREF(arr);
m_data = data;
m_shape = shape;
m_strides = strides;
Expand Down