Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps towards Python 3.11 support #3231

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions src/core/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cstring> // std::strerror, std::memcpy
#include <mutex> // std::mutex, std::lock_guard
#include "buffer.h"
#include "lib/pythoncapi_compat.h" // Py_SET_REFCNT()
#include "mmm.h" // MemoryMapWorker, MemoryMapManager
#include "python/pybuffer.h" // py::buffer
#include "utils/alloc.h" // dt::malloc, dt::realloc
Expand Down Expand Up @@ -235,7 +236,7 @@ class BufferImpl
PyObject** elements = static_cast<PyObject**>(data_);
for (size_t i = 0; i < n; ++i) {
XAssert(elements[i] != nullptr);
XAssert(elements[i]->ob_refcnt > 0);
XAssert(Py_REFCNT(elements[i]) > 0);
}
}
}
Expand Down Expand Up @@ -929,7 +930,7 @@ class Mmap_BufferImpl : public BufferImpl, MemoryMapWorker {
for (size_t i = 0; i < n; ++i) {
data[i] = Py_None;
}
Py_None->ob_refcnt += n;
Py_SET_REFCNT(Py_None, Py_REFCNT(Py_None) + n);
}
impl_->contains_pyobjects_ = true;
return *this;
Expand All @@ -954,7 +955,7 @@ class Mmap_BufferImpl : public BufferImpl, MemoryMapWorker {
if (n_new > n_old) {
PyObject** data = static_cast<PyObject**>(xptr());
for (size_t i = n_old; i < n_new; ++i) data[i] = Py_None;
Py_None->ob_refcnt += n_new - n_old;
Py_SET_REFCNT(Py_None, Py_REFCNT(Py_None) + n_new - n_old);
}
} else {
impl_->resize(newsize);
Expand Down Expand Up @@ -1018,7 +1019,7 @@ class Mmap_BufferImpl : public BufferImpl, MemoryMapWorker {
size_t i = 0;
for (; i < n_copy; ++i) Py_INCREF(newdata[i]);
for (; i < n_new; ++i) newdata[i] = Py_None;
Py_None->ob_refcnt += n_new - n_copy;
Py_SET_REFCNT(Py_None, Py_REFCNT(Py_None) + n_new - n_copy);
}
impl_->release(); // noexcept
}
Expand Down
5 changes: 3 additions & 2 deletions src/core/column/const_na.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//------------------------------------------------------------------------------
#include "lib/pythoncapi_compat.h" // Py_SET_REFCNT()
#include "column/const.h"
#include "column/sentinel_fw.h"
#include "column/sentinel_str.h"
Expand Down Expand Up @@ -84,7 +85,7 @@ static Column _fw_col(size_t nrows, SType stype) {
});

if (std::is_same<T, PyObject*>::value) {
Py_None->ob_refcnt += nrows;
Py_SET_REFCNT(Py_None, Py_REFCNT(Py_None) + nrows);
buf.set_pyobjects(/* clear_data= */ false);
}
return Column(new ColClass(nrows, stype, std::move(buf)));
Expand All @@ -101,7 +102,7 @@ static Column _special_col(size_t nrows) {
});

if (std::is_same<T, PyObject*>::value) {
Py_None->ob_refcnt += nrows;
Py_SET_REFCNT(Py_None, Py_REFCNT(Py_None) + nrows);
buf.set_pyobjects(/* clear_data= */ false);
}
return Column(new ColClass(nrows, std::move(buf)));
Expand Down
Loading