From 743d41edd841fdd00df0c26be816cddeb8ef641f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Thu, 27 Feb 2020 00:00:00 +0000 Subject: [PATCH] pure_cpp: prepare for object move --- userland/libs/python_embed/Makefile | 2 +- userland/libs/python_embed/pure_cpp.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/userland/libs/python_embed/Makefile b/userland/libs/python_embed/Makefile index b89fd7d..2750dea 100644 --- a/userland/libs/python_embed/Makefile +++ b/userland/libs/python_embed/Makefile @@ -3,7 +3,7 @@ CC = gcc CXX = g++ CFLGS = -std=c99 -CCFLGS = -ggdb3 -O0 -pedantic-errors -Wall -Wextra +CCFLGS = -ggdb3 -O0 -pedantic-errors -Wall -Wextra -Wno-missing-field-initializers CXXFLGS = -std=c++11 IN_EXT = .c IN_CXX_EXT = .cpp diff --git a/userland/libs/python_embed/pure_cpp.cpp b/userland/libs/python_embed/pure_cpp.cpp index c2b65ce..676fdae 100644 --- a/userland/libs/python_embed/pure_cpp.cpp +++ b/userland/libs/python_embed/pure_cpp.cpp @@ -77,6 +77,7 @@ struct MyDerivedNativeClass : public MyNativeClass { typedef struct { PyObject_HEAD + MyNativeClass *cpp_object; PyObject *first; PyObject *last; int number; @@ -106,12 +107,9 @@ my_native_module_MyNativeClass_clear(my_native_module_MyNativeClass *self) } static PyObject * -my_native_module_MyNativeClass_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ +my_native_module_MyNativeClass_new_noalloc (my_native_module_MyNativeClass *self, PyObject *args, PyObject *kwds) { (void)args; (void)kwds; - my_native_module_MyNativeClass *self; - self = (my_native_module_MyNativeClass *) type->tp_alloc(type, 0); if (self != NULL) { self->first = PyUnicode_FromString(""); if (self->first == NULL) { @@ -128,6 +126,14 @@ my_native_module_MyNativeClass_new(PyTypeObject *type, PyObject *args, PyObject return (PyObject *) self; } +static PyObject * +my_native_module_MyNativeClass_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + my_native_module_MyNativeClass *self; + self = (my_native_module_MyNativeClass *) type->tp_alloc(type, 0); + return (PyObject *) my_native_module_MyNativeClass_new_noalloc(self, args, kwds); +} + static int my_native_module_MyNativeClass_init(my_native_module_MyNativeClass *self, PyObject *args, PyObject *kwds) { @@ -289,6 +295,7 @@ my_native_module_MyDerivedNativeClass_new(PyTypeObject *type, PyObject *args, Py (void)kwds; my_native_module_MyDerivedNativeClass *self; self = (my_native_module_MyDerivedNativeClass *) type->tp_alloc(type, 0); + my_native_module_MyNativeClass_new_noalloc((my_native_module_MyNativeClass *) self, args, kwds); if (self != NULL) { self->first2 = PyUnicode_FromString(""); if (self->first2 == NULL) {