This commit is contained in:
blueloveTH 2024-02-01 12:48:46 +08:00
parent b1ee038583
commit 120d1dfb27
8 changed files with 9 additions and 30 deletions

View File

@ -18,7 +18,7 @@
#include <random>
#include <deque>
#define PK_VERSION "1.4.0"
#define PK_VERSION "1.4.1"
#include "config.h"
#include "export.h"
@ -115,13 +115,6 @@ union BitsCvtImpl<4>{
BitsCvtImpl(NumberTraits<4>::float_t val): _float(val) {}
BitsCvtImpl(NumberTraits<4>::int_t val): _int(val) {}
// void print(){
// std::string s = std::bitset<32>(_int).to_string();
// std::cout << s.substr(0, 1) << '|';
// std::cout << s.substr(1, 8) << '|';
// std::cout << s.substr(9) << std::endl;
// }
};
template<>
@ -146,13 +139,6 @@ union BitsCvtImpl<8>{
BitsCvtImpl(NumberTraits<8>::float_t val): _float(val) {}
BitsCvtImpl(NumberTraits<8>::int_t val): _int(val) {}
// void print(){
// std::string s = std::bitset<64>(_int).to_string();
// std::cout << s.substr(0, 1) << '|';
// std::cout << s.substr(1, 11) << '|';
// std::cout << s.substr(12) << std::endl;
// }
};
using BitsCvt = BitsCvtImpl<sizeof(void*)>;

View File

@ -29,7 +29,7 @@ struct SourceData {
Str filename;
CompileMode mode;
std::string source; // assume '\0' terminated
Str source;
std::vector<const char*> line_starts;
SourceData(const Str& source, const Str& filename, CompileMode mode);

View File

@ -87,7 +87,7 @@ PK_EXPORT bool pkpy_vectorcall(pkpy_vm*, int argc);
/* Special APIs */
PK_EXPORT void pkpy_free(void* p);
PK_EXPORT pkpy_CString pkpy_string(const char* s);
#define pkpy_string(__s) (__s)
PK_EXPORT pkpy_CName pkpy_name(const char* s);
PK_EXPORT pkpy_CString pkpy_name_to_string(pkpy_CName name);
PK_EXPORT void pkpy_set_output_handler(pkpy_vm*, pkpy_COutputHandler handler);

View File

@ -582,7 +582,7 @@ inline const char* _py_cast<const char*>(VM* vm, PyObject* obj){
}
inline PyObject* py_var(VM* vm, std::string val){
return VAR(Str(std::move(val)));
return VAR(Str(val));
}
inline PyObject* py_var(VM* vm, std::string_view val){

View File

@ -12,8 +12,7 @@ namespace pkpy{
if(source[index] != '\r') ss << source[index];
index++;
}
this->source = ss.str().str();
this->source = ss.str();
line_starts.push_back(this->source.c_str());
}

View File

@ -546,10 +546,6 @@ void pkpy_free(void* p){
free(p);
}
pkpy_CString pkpy_string(const char* value){
return value;
}
pkpy_CName pkpy_name(const char* name){
return StrName(name).index;
}

View File

@ -60,6 +60,7 @@ int utf8len(unsigned char c, bool suppress){
for(int i=0; i<size; i++){
if(!isascii(data[i])){ is_ascii = false; break; }
}
data[size] = '\0';
}
Str::Str(const Str& other): size(other.size), is_ascii(other.is_ascii) {
@ -101,6 +102,7 @@ int utf8len(unsigned char c, bool suppress){
is_ascii = other.is_ascii;
PK_STR_ALLOCATE()
memcpy(data, other.data, size);
data[size] = '\0';
return *this;
}
@ -108,6 +110,7 @@ int utf8len(unsigned char c, bool suppress){
Str ret(size + other.size, is_ascii && other.is_ascii);
memcpy(ret.data, data, size);
memcpy(ret.data + size, other.data, other.size);
ret.data[ret.size] = '\0';
return ret;
}
@ -171,6 +174,7 @@ int utf8len(unsigned char c, bool suppress){
Str Str::substr(int start, int len) const {
Str ret(len, is_ascii);
memcpy(ret.data, data + start, len);
ret.data[len] = '\0';
return ret;
}
@ -432,7 +436,6 @@ int utf8len(unsigned char c, bool suppress){
}
Str SStream::str(){
buffer.push_back('\0');
// after this call, the buffer is no longer valid
return Str(buffer.detach());
}

View File

@ -223,11 +223,6 @@ void pkpy_free(void* p) {
}
pkpy_CString pkpy_string(const char* s) {
pkpy_CString returnValue;
return returnValue;
}
pkpy_CName pkpy_name(const char* s) {
pkpy_CName returnValue;
return returnValue;