mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
0a31183e60
commit
1714195da4
@ -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;
|
||||
|
@ -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) { \
|
||||
|
@ -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()));
|
||||
|
@ -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]来比较两个浮点数是否相等
|
||||
|
Loading…
x
Reference in New Issue
Block a user