mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix a bug
This commit is contained in:
parent
97c923e514
commit
bbe3773154
@ -18,6 +18,7 @@
|
||||
#include <type_traits>
|
||||
#include <random>
|
||||
#include <deque>
|
||||
#include <initializer_list>
|
||||
|
||||
#define PK_VERSION "1.4.1"
|
||||
|
||||
|
@ -19,6 +19,12 @@ struct pod_vector{
|
||||
_data = (T*)pool64_alloc(_capacity * sizeof(T));
|
||||
}
|
||||
|
||||
// support initializer list
|
||||
pod_vector(std::initializer_list<T> il): _size(il.size()), _capacity(std::max(N, _size)) {
|
||||
_data = (T*)pool64_alloc(_capacity * sizeof(T));
|
||||
for(int i=0; i<_size; i++) _data[i] = *(il.begin() + i);
|
||||
}
|
||||
|
||||
pod_vector(int size): _size(size), _capacity(std::max(N, size)) {
|
||||
_data = (T*)pool64_alloc(_capacity * sizeof(T));
|
||||
}
|
||||
|
@ -1048,14 +1048,13 @@ void init_builtins(VM* _vm) {
|
||||
// tp_bytes
|
||||
_vm->bind_constructor<2>(_vm->_t(VM::tp_bytes), [](VM* vm, ArgsView args){
|
||||
List& list = CAST(List&, args[1]);
|
||||
pod_vector<unsigned char> buffer(list.size());
|
||||
unsigned char* buffer = new unsigned char[list.size()];
|
||||
for(int i=0; i<list.size(); i++){
|
||||
i64 b = CAST(i64, list[i]);
|
||||
if(b<0 || b>255) vm->ValueError("byte must be in range[0, 256)");
|
||||
buffer[i] = (char)b;
|
||||
}
|
||||
auto detached = buffer.detach();
|
||||
return VAR(Bytes(detached.first, detached.second));
|
||||
return VAR(Bytes(buffer, list.size()));
|
||||
});
|
||||
|
||||
_vm->bind__getitem__(VM::tp_bytes, [](VM* vm, PyObject* obj, PyObject* index) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user