mirror of
https://github.com/pocketpy/pocketpy
synced 2026-08-12 17:17:11 +08:00
Compare commits
1 Commits
9c65c7f1b3
...
14d1572328
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14d1572328 |
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@ -56,11 +56,11 @@ jobs:
|
||||
- name: Setup Clang
|
||||
uses: egor-tensin/setup-clang@v1
|
||||
with:
|
||||
version: 19
|
||||
version: 17
|
||||
platform: x64
|
||||
- name: Run Sanitizers
|
||||
run: |
|
||||
sudo apt-get install -y libclang-rt-19-dev
|
||||
sudo apt-get install -y libclang-rt-17-dev
|
||||
bash build_g.sh
|
||||
bash run_tests.sh
|
||||
rm -rf ./main
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
typedef struct PyObject PyObject;
|
||||
typedef struct VM VM;
|
||||
extern PK_THREAD_LOCAL VM* pk_current_vm;
|
||||
extern _Thread_local VM* pk_current_vm;
|
||||
|
||||
typedef struct py_TValue {
|
||||
py_Type type;
|
||||
|
||||
@ -17,7 +17,7 @@ rm -rf .coverage
|
||||
mkdir .coverage
|
||||
|
||||
UNITS=$(find ./ -name "*.gcno")
|
||||
llvm-cov-19 gcov ${UNITS} -r -s include/ -r -s src/ >> .coverage/coverage.txt
|
||||
llvm-cov-17 gcov ${UNITS} -r -s include/ -r -s src/ >> .coverage/coverage.txt
|
||||
|
||||
mv *.gcov .coverage
|
||||
rm *.gcda
|
||||
|
||||
@ -189,8 +189,8 @@ static Error* LexerError(Lexer* self, const char* fmt, ...) {
|
||||
err->src = self->src;
|
||||
PK_INCREF(self->src);
|
||||
err->lineno = self->current_line;
|
||||
const char* p_end = self->src->source->data + self->src->source->size;
|
||||
if(self->curr_char <= p_end && *self->curr_char == '\n') { err->lineno--; }
|
||||
const char* end = self->src->source->data + self->src->source->size;
|
||||
if(self->curr_char <= end && *self->curr_char == '\n') { err->lineno--; }
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(err->msg, sizeof(err->msg), fmt, args);
|
||||
@ -282,16 +282,9 @@ static Error* _eat_string(Lexer* self, c11_sbuf* buff, char quote, enum StringTy
|
||||
case 'b': c11_sbuf__write_char(buff, '\b'); break;
|
||||
case 'f': c11_sbuf__write_char(buff, '\f'); break;
|
||||
case 'v': c11_sbuf__write_char(buff, '\v'); break;
|
||||
// Special case for the often used \0 while we don't have full support for octal
|
||||
// literals.
|
||||
// Special case for the often used \0 while we don't have full support for octal literals.
|
||||
case '0': c11_sbuf__write_char(buff, '\0'); break;
|
||||
case 'x': {
|
||||
// check there are at least 2 chars can read
|
||||
const char* p_end = self->src->source->data + self->src->source->size;
|
||||
if(p_end - self->curr_char < 2) {
|
||||
return LexerError(self, "invalid hex escape");
|
||||
}
|
||||
|
||||
char hex[3] = {eatchar(self), eatchar(self), '\0'};
|
||||
int code;
|
||||
if(sscanf(hex, "%x", &code) != 1 || code > 0xFF) {
|
||||
|
||||
@ -580,9 +580,8 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall
|
||||
}
|
||||
|
||||
if(p0->type == tp_type) {
|
||||
py_Type p0_type = py_totype(p0);
|
||||
// [cls, NULL, args..., kwargs...]
|
||||
py_Ref new_f = py_tpfindmagic(p0_type, __new__);
|
||||
py_Ref new_f = py_tpfindmagic(py_totype(p0), __new__);
|
||||
assert(new_f && py_isnil(p0 + 1));
|
||||
bool is_default_new = new_f->type == tp_nativefunc && new_f->_cfunc == pk__object_new;
|
||||
|
||||
@ -600,16 +599,14 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall
|
||||
// NOTE: previously we use `get_unbound_method` but here we just use `tpfindmagic`
|
||||
// >> [cls, NULL, args..., kwargs...]
|
||||
// >> py_retval() is the new instance
|
||||
py_Ref init_f = py_tpfindmagic(p0_type, __init__);
|
||||
py_Ref init_f = py_tpfindmagic(py_totype(p0), __init__);
|
||||
if(init_f) {
|
||||
if(py_isinstance(py_retval(), p0_type)) {
|
||||
// do an inplace patch
|
||||
*p0 = *init_f; // __init__
|
||||
p0[1] = self->last_retval; // self
|
||||
// [__init__, self, args..., kwargs...]
|
||||
if(VM__vectorcall(self, argc, kwargc, false) == RES_ERROR) return RES_ERROR;
|
||||
*py_retval() = p0[1]; // restore the new instance
|
||||
}
|
||||
} else {
|
||||
if(is_default_new) {
|
||||
if(argc != 0 || kwargc != 0) {
|
||||
@ -717,16 +714,8 @@ void ManagedHeap__mark(ManagedHeap* self) {
|
||||
}
|
||||
}
|
||||
|
||||
if(obj->type > tp_object) {
|
||||
// NOTE: `defaultdict` -> `dict` -> `object`
|
||||
// NOTE: native types must extend from `object`.
|
||||
py_TypeInfo* ti = pk_typeinfo(obj->type);
|
||||
while(ti->base != tp_object) {
|
||||
ti = ti->base_ti;
|
||||
}
|
||||
|
||||
void* ud = PyObject__userdata(obj);
|
||||
switch(ti->index) {
|
||||
switch(obj->type) {
|
||||
case tp_list: {
|
||||
List* self = ud;
|
||||
for(int i = 0; i < self->length; i++) {
|
||||
@ -776,4 +765,3 @@ void ManagedHeap__mark(ManagedHeap* self) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include "pocketpy/common/name.h"
|
||||
#include "pocketpy/interpreter/vm.h"
|
||||
|
||||
PK_THREAD_LOCAL VM* pk_current_vm;
|
||||
_Thread_local VM* pk_current_vm;
|
||||
|
||||
static bool pk_initialized;
|
||||
static bool pk_finalized;
|
||||
|
||||
@ -168,13 +168,3 @@ class DerivedClass(BaseClass):
|
||||
|
||||
|
||||
assert DerivedClass.f() == 'BaseClass'
|
||||
|
||||
# bad __init__
|
||||
class A:
|
||||
def __new__(cls, *args, **kwargs):
|
||||
return 1
|
||||
|
||||
def __init__(self):
|
||||
assert False
|
||||
|
||||
A()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user