blueloveTH 1 год назад
Родитель
Сommit
1714195da4
4 измененных файлов с 8 добавлено и 4 удалено
  1. 2 2
      include/pocketpy/gc.h
  2. 1 1
      include/pocketpy/obj.h
  3. 1 1
      include/pocketpy/vm.h
  4. 4 0
      tests/80_linalg.py

+ 2 - 2
include/pocketpy/gc.h

@@ -41,7 +41,7 @@ struct ManagedHeap{
     template<typename T, typename... Args>
     PyVar gcnew(Type type, Args&&... args){
         using __T = Py_<std::decay_t<T>>;
-        static_assert(!is_sso_v<__T>, "gcnew cannot be used with SSO types");
+        static_assert(!is_sso_v<std::decay_t<T>>, "gcnew cannot be used with SSO types");
         // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476
         PyObject* p = new(pool128_alloc<__T>()) Py_<std::decay_t<T>>(std::forward<Args>(args)...);
         PyVar obj(type, p);
@@ -53,7 +53,7 @@ struct ManagedHeap{
     template<typename T, typename... Args>
     PyVar _new(Type type, Args&&... args){
         using __T = Py_<std::decay_t<T>>;
-        static_assert(!is_sso_v<__T>);
+        static_assert(!is_sso_v<std::decay_t<T>>);
         PyObject* p = new(pool128_alloc<__T>()) Py_<std::decay_t<T>>(std::forward<Args>(args)...);
         PyVar obj(type, p);
         obj->gc_enabled = false;

+ 1 - 1
include/pocketpy/obj.h

@@ -166,7 +166,7 @@ template<typename T> T to_void_p(VM*, PyVar);
 PyVar from_void_p(VM*, void*);
 
 
-#define PK_OBJ_GET(T, obj) (obj.is_sso ? obj.as<T>() : (((Py_<T>*)(obj.get()))->_value))
+#define PK_OBJ_GET(T, obj) (is_sso_v<T> ? obj.as<T>() : (((Py_<T>*)(obj.get()))->_value))
 
 #define PK_OBJ_MARK(obj) \
     if(!is_tagged(obj) && !(obj)->gc_marked) {                          \

+ 1 - 1
include/pocketpy/vm.h

@@ -582,7 +582,7 @@ PyVar VM::register_user_class(PyVar mod, StrName name, RegisterFunc _register, T
         if constexpr(std::is_default_constructible_v<T>) {
             bind_func(type, __new__, -1, [](VM* vm, ArgsView args){
                 Type cls_t = PK_OBJ_GET(Type, args[0]);
-                return vm->heap.gcnew<T>(cls_t);
+                return vm->new_object<T>(cls_t);
             });
         }else{
             bind_func(type, __new__, -1, PK_ACTION(vm->NotImplementedError()));

+ 4 - 0
tests/80_linalg.py

@@ -3,6 +3,10 @@ import random
 import sys
 import math
 
+a = vec2(1, 2)
+assert a.x == 1
+assert a.y == 2
+
 assert repr(math) == "<module 'math'>"
 
 # 出于对精度转换的考虑,在本测试中具体将采用str(floating_num)[:6]来比较两个浮点数是否相等