From 55f92468c89c311a2240efbaa3324da593049a78 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 5 Dec 2022 02:49:54 +0800 Subject: [PATCH] remove std::shared_ptr --- src/main.cpp | 4 ++-- src/obj.h | 2 +- src/pocketpy.h | 16 ++++++++-------- src/vm.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9a9eb107..2d44d5e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,8 +2,8 @@ #include "pocketpy.h" -#define PK_DEBUG_TIME -//#define PK_DEBUG_THREADED +//#define PK_DEBUG_TIME +#define PK_DEBUG_THREADED struct Timer{ const char* title; diff --git a/src/obj.h b/src/obj.h index f0ba7fcf..5bbdaf18 100644 --- a/src/obj.h +++ b/src/obj.h @@ -65,7 +65,7 @@ public: }; typedef pkpy::shared_ptr _Func; -typedef std::variant,_BoundedMethod,_Range,_Slice,_Pointer> _Value; +typedef std::variant,_BoundedMethod,_Range,_Slice,_Pointer> _Value; const int _SIZEOF_VALUE = sizeof(_Value); diff --git a/src/pocketpy.h b/src/pocketpy.h index 61431bbd..6a59541b 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -148,8 +148,8 @@ void __initializeBuiltinFunctions(VM* _vm) { _vm->bindMethod("range", "__iter__", [](VM* vm, const pkpy::ArgList& args) { vm->__checkType(args[0], vm->_tp_range); - auto iter = std::make_shared(vm, args[0]); - return vm->PyIter(iter); + _Iterator* iter = new RangeIterator(vm, args[0]); + return vm->PyIter(pkpy::shared_ptr<_Iterator>(iter)); }); _vm->bindMethod("NoneType", "__repr__", [](VM* vm, const pkpy::ArgList& args) { @@ -313,8 +313,8 @@ void __initializeBuiltinFunctions(VM* _vm) { }); _vm->bindMethod("str", "__iter__", [](VM* vm, const pkpy::ArgList& args) { - auto it = std::make_shared(vm, args[0]); - return vm->PyIter(it); + _Iterator* iter = new StringIterator(vm, args[0]); + return vm->PyIter(pkpy::shared_ptr<_Iterator>(iter)); }); _vm->bindMethod("str", "__repr__", [](VM* vm, const pkpy::ArgList& args) { @@ -426,8 +426,8 @@ void __initializeBuiltinFunctions(VM* _vm) { /************ PyList ************/ _vm->bindMethod("list", "__iter__", [](VM* vm, const pkpy::ArgList& args) { vm->__checkType(args[0], vm->_tp_list); - auto iter = std::make_shared(vm, args[0]); - return vm->PyIter(iter); + _Iterator* iter = new VectorIterator(vm, args[0]); + return vm->PyIter(pkpy::shared_ptr<_Iterator>(iter)); }); _vm->bindMethod("list", "append", [](VM* vm, const pkpy::ArgList& args) { @@ -523,8 +523,8 @@ void __initializeBuiltinFunctions(VM* _vm) { _vm->bindMethod("tuple", "__iter__", [](VM* vm, const pkpy::ArgList& args) { vm->__checkType(args[0], vm->_tp_tuple); - auto iter = std::make_shared(vm, args[0]); - return vm->PyIter(iter); + _Iterator* iter = new VectorIterator(vm, args[0]); + return vm->PyIter(pkpy::shared_ptr<_Iterator>(iter)); }); _vm->bindMethod("tuple", "__len__", [](VM* vm, const pkpy::ArgList& args) { diff --git a/src/vm.h b/src/vm.h index a4dc3a57..114fdc88 100644 --- a/src/vm.h +++ b/src/vm.h @@ -786,7 +786,7 @@ public: DEF_NATIVE(Tuple, PyVarList, _tp_tuple) DEF_NATIVE(Function, _Func, _tp_function) DEF_NATIVE(NativeFunction, _CppFunc, _tp_native_function) - DEF_NATIVE(Iter, std::shared_ptr<_Iterator>, _tp_native_iterator) + DEF_NATIVE(Iter, pkpy::shared_ptr<_Iterator>, _tp_native_iterator) DEF_NATIVE(BoundedMethod, _BoundedMethod, _tp_bounded_method) DEF_NATIVE(Range, _Range, _tp_range) DEF_NATIVE(Slice, _Slice, _tp_slice)