4
4
mirror of https://github.com/H-uru/korman.git synced 2025-07-14 02:27:36 -04:00

C Korlib code de-duplication

Moves all PyHSPlasma struct definitions into a private header file.
Also adds move constructor and assignment support to PyObjectRef.
This commit is contained in:
2019-01-14 20:50:24 -05:00
parent a3ed2f0178
commit ce6cd0811e
10 changed files with 63 additions and 47 deletions

View File

@ -21,6 +21,7 @@
#include <cstdint>
#include <Python.h>
#include <utility>
#define _pycs(x) const_cast<char*>(x)
#define arrsize(a) (sizeof(a) / sizeof((a)[0]))
@ -31,14 +32,29 @@ class PyObjectRef {
public:
PyObjectRef() : m_object() { }
PyObjectRef(PyObject* o) : m_object(o) { }
PyObjectRef(const PyObjectRef& copy) = delete;
PyObjectRef(PyObjectRef&& move) {
m_object = move.m_object;
move.m_object = NULL;
}
~PyObjectRef() { Py_XDECREF(m_object); }
operator PyObject*() const { return m_object; }
PyObjectRef& operator =(PyObject* rhs) {
Py_XDECREF(m_object);
m_object = rhs;
return *this;
}
PyObjectRef& operator =(PyObjectRef&& move) {
m_object = move.m_object;
move.m_object = NULL;
return *this;
}
PyObjectRef& operator =(const PyObjectRef& copy) = delete;
};
#endif // _KORLIB_H