Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions from_cpython/Include/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ typedef struct _ts {
int trash_delete_nesting;
PyObject *trash_delete_later;

PyObject *async_exc; /* Asynchronous exception to raise */
long thread_id; /* Thread id where this tstate was created */

// Pyston change:
// Pyston note: additions in here need to be mirrored in PyThreadState_Clear
#if 0
Expand All @@ -109,9 +112,6 @@ typedef struct _ts {
*/
int tick_counter;

PyObject *async_exc; /* Asynchronous exception to raise */
long thread_id; /* Thread id where this tstate was created */

/* XXX signal handlers should also be here */
#endif
} PyThreadState;
Expand Down
4 changes: 3 additions & 1 deletion from_cpython/Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ int _PyArg_ParseSingle_SizeT(PyObject* obj, int arg_idx, const char* fname, cons
return r;
}

extern PyTypeObject* attrwrapper_cls;

/* Convert a non-tuple argument. Return NULL if conversion went OK,
or a string with a message describing the failure. The message is
formatted as "must be <desired type>, not <actual type>".
Expand Down Expand Up @@ -1279,7 +1281,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
type = va_arg(*p_va, PyTypeObject*);
p = va_arg(*p_va, PyObject **);
format++;
if (PyType_IsSubtype(arg->ob_type, type))
if (PyType_IsSubtype(arg->ob_type, type) || /* Pyston hack */ (arg->ob_type == attrwrapper_cls && type == &PyDict_Type))
*p = arg;
else
return converterr(type->tp_name, arg, msgbuf, bufsize);
Expand Down
22 changes: 17 additions & 5 deletions from_cpython/Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -2949,21 +2949,34 @@ PyImport_Import(PyObject *module_name)
importing modules.
*/

// Pyston change: we don't support get_magic
#if 0
// Pyston change: there is a surprising number of custom pyc-reading and -writing
// code out there that wants to use imp.get_magic. If we simply remove imp.get_magic,
// that code will tend to fail in unrecoverable ways. While hacky, the best-working option
// found so far seems to be to have imp.get_magic exist but to return a changing value so
// that the check will never succeed.
static PyObject *
imp_get_magic(PyObject *self, PyObject *noargs)
{
static int counter;
if (counter == 0) {
// something randomish
counter = 0x12345678 + (getpid() << 16);
}
// and that changes each time you call it
counter++;

char buf[4];
memcpy(buf, &counter, 4);

#if 0
buf[0] = (char) ((pyc_magic >> 0) & 0xff);
buf[1] = (char) ((pyc_magic >> 8) & 0xff);
buf[2] = (char) ((pyc_magic >> 16) & 0xff);
buf[3] = (char) ((pyc_magic >> 24) & 0xff);
#endif

return PyString_FromStringAndSize(buf, 4);
}
#endif

static PyObject *
imp_get_suffixes(PyObject *self, PyObject *noargs)
Expand Down Expand Up @@ -3329,8 +3342,7 @@ On platforms without threads, this function does nothing.");
static PyMethodDef imp_methods[] = {
{"reload", imp_reload, METH_O, doc_reload},
{"find_module", imp_find_module, METH_VARARGS, doc_find_module},
// Pyston change: we don't support this function
// {"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic},
{"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic},
{"get_suffixes", imp_get_suffixes, METH_NOARGS, doc_get_suffixes},
{"load_module", imp_load_module, METH_VARARGS, doc_load_module},
{"new_module", imp_new_module, METH_VARARGS, doc_new_module},
Expand Down
8 changes: 7 additions & 1 deletion src/capi/modsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,13 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
}
}

BoxedModule* module = createModule(autoDecref(boxString(name)), NULL, doc);
BoxedModule* module;
try {
module = createModule(autoDecref(boxString(name)), NULL, doc);
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
}

// Pass self as is, even if NULL we are not allowed to change it to None
Box* passthrough = static_cast<Box*>(self);
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/ast_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ Box* ASTInterpreterJitInterface::landingpadHelper(void* _interpreter) {

void ASTInterpreterJitInterface::pendingCallsCheckHelper() {
#if ENABLE_SIGNAL_CHECKING
if (unlikely(_pendingcalls_to_do))
if (unlikely(_stop_thread))
makePendingCalls();
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/irgen/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ CompiledFunction* compileFunction(BoxedCode* code, FunctionSpecialization* spec,

if (spec) {
ss << "\033[" << colors[(int)effort] << ";1mJIT'ing " << code->filename->s() << ":" << name->s()
<< " with signature (";
<< " (starting at line " << code->firstlineno << ") with signature (";
for (int i = 0; i < spec->arg_types.size(); i++) {
if (i > 0)
ss << ", ";
Expand Down
12 changes: 6 additions & 6 deletions src/codegen/irgen/irgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,19 @@ class IREmitterImpl : public IREmitter {
#if ENABLE_SIGNAL_CHECKING
auto&& builder = *getBuilder();

llvm::GlobalVariable* pendingcalls_to_do_gv = g.cur_module->getGlobalVariable("_pendingcalls_to_do");
llvm::GlobalVariable* pendingcalls_to_do_gv = g.cur_module->getGlobalVariable("_stop_thread");
if (!pendingcalls_to_do_gv) {
static_assert(sizeof(_pendingcalls_to_do) == 4, "");
pendingcalls_to_do_gv = new llvm::GlobalVariable(
*g.cur_module, g.i32, false, llvm::GlobalValue::ExternalLinkage, 0, "_pendingcalls_to_do");
static_assert(sizeof(_stop_thread) == 4, "");
pendingcalls_to_do_gv = new llvm::GlobalVariable(*g.cur_module, g.i32, false,
llvm::GlobalValue::ExternalLinkage, 0, "_stop_thread");
pendingcalls_to_do_gv->setAlignment(4);
}

llvm::BasicBlock* cur_block = builder.GetInsertBlock();

llvm::BasicBlock* pendingcalls_set = createBasicBlock("_pendingcalls_set");
llvm::BasicBlock* pendingcalls_set = createBasicBlock("_stop_thread_set");
pendingcalls_set->moveAfter(cur_block);
llvm::BasicBlock* join_block = createBasicBlock("continue_after_pendingcalls_check");
llvm::BasicBlock* join_block = createBasicBlock("continue_after_stopthread_check");
join_block->moveAfter(pendingcalls_set);

llvm::Value* pendingcalls_to_do_val = builder.CreateLoad(pendingcalls_to_do_gv, true /* volatile */);
Expand Down
40 changes: 20 additions & 20 deletions src/core/bst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,83 +1542,83 @@ class FlattenVisitor : public BSTVisitor {
return false;
}

virtual bool visit_landingpad(BST_Landingpad* node) override {
virtual bool visit_landingpad(BST_Landingpad* node) {
output->push_back(node);
return false;
}
virtual bool visit_locals(BST_Locals* node) override {
virtual bool visit_locals(BST_Locals* node) {
output->push_back(node);
return false;
}
virtual bool visit_getiter(BST_GetIter* node) override {
virtual bool visit_getiter(BST_GetIter* node) {
output->push_back(node);
return false;
}
virtual bool visit_importfrom(BST_ImportFrom* node) override {
virtual bool visit_importfrom(BST_ImportFrom* node) {
output->push_back(node);
return false;
}
virtual bool visit_importname(BST_ImportName* node) override {
virtual bool visit_importname(BST_ImportName* node) {
output->push_back(node);
return false;
}
virtual bool visit_importstar(BST_ImportStar* node) override {
virtual bool visit_importstar(BST_ImportStar* node) {
output->push_back(node);
return false;
}
virtual bool visit_nonzero(BST_Nonzero* node) override {
virtual bool visit_nonzero(BST_Nonzero* node) {
output->push_back(node);
return false;
}
virtual bool visit_checkexcmatch(BST_CheckExcMatch* node) override {
virtual bool visit_checkexcmatch(BST_CheckExcMatch* node) {
output->push_back(node);
return false;
}
virtual bool visit_setexcinfo(BST_SetExcInfo* node) override {
virtual bool visit_setexcinfo(BST_SetExcInfo* node) {
output->push_back(node);
return false;
}
virtual bool visit_uncacheexcinfo(BST_UncacheExcInfo* node) override {
virtual bool visit_uncacheexcinfo(BST_UncacheExcInfo* node) {
output->push_back(node);
return false;
}
virtual bool visit_hasnext(BST_HasNext* node) override {
virtual bool visit_hasnext(BST_HasNext* node) {
output->push_back(node);
return false;
}
virtual bool visit_printexpr(BST_PrintExpr* node) override {
virtual bool visit_printexpr(BST_PrintExpr* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadname(BST_LoadName* node) override {
virtual bool visit_loadname(BST_LoadName* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadattr(BST_LoadAttr* node) override {
virtual bool visit_loadattr(BST_LoadAttr* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadsub(BST_LoadSub* node) override {
virtual bool visit_loadsub(BST_LoadSub* node) {
output->push_back(node);
return false;
}
virtual bool visit_loadsubslice(BST_LoadSubSlice* node) override {
virtual bool visit_loadsubslice(BST_LoadSubSlice* node) {
output->push_back(node);
return false;
}
virtual bool visit_storename(BST_StoreName* node) override {
virtual bool visit_storename(BST_StoreName* node) {
output->push_back(node);
return false;
}
virtual bool visit_storesub(BST_StoreSub* node) override {
virtual bool visit_storesub(BST_StoreSub* node) {
output->push_back(node);
return false;
}
virtual bool visit_storesubslice(BST_StoreSubSlice* node) override {
virtual bool visit_storesubslice(BST_StoreSubSlice* node) {
output->push_back(node);
return false;
}
virtual bool visit_storeattr(BST_StoreAttr* node) override {
virtual bool visit_storeattr(BST_StoreAttr* node) {
output->push_back(node);
return false;
}
Expand Down
13 changes: 11 additions & 2 deletions src/core/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,7 @@ class CFGVisitor : public ASTVisitor {
curblock->connectTo(test_false);

CFGBlock* loop_block = cfg->addBlock();
CFGBlock* break_block = cfg->addDeferredBlock();
CFGBlock* end_block = cfg->addDeferredBlock();
CFGBlock* else_block = cfg->addDeferredBlock();

Expand All @@ -2429,8 +2430,7 @@ class CFGVisitor : public ASTVisitor {
curblock = test_false;
pushJump(else_block);

// TODO: need to del the iter_name when break'ing out of the loop
pushLoopContinuation(test_block, end_block);
pushLoopContinuation(test_block, break_block);

curblock = loop_block;
TmpValue next_name = makeCallAttr(_dup(itername), internString("next"), true);
Expand Down Expand Up @@ -2478,6 +2478,15 @@ class CFGVisitor : public ASTVisitor {
if (curblock)
pushJump(end_block);

if (break_block->predecessors.size() == 0) {
delete break_block;
} else {
cfg->placeBlock(break_block);
curblock = break_block;
push_back(makeKill(itername.is));
pushJump(end_block);
}

if (end_block->predecessors.size() == 0) {
delete end_block;
curblock = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/core/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern bool ENABLE_ICS, ENABLE_ICGENERICS, ENABLE_ICGETITEMS, ENABLE_ICSETITEMS,
#define BOOLS_AS_I64 1

#define ENABLE_SAMPLING_PROFILER 0
#define ENABLE_SIGNAL_CHECKING 1
#define ENABLE_SIGNAL_CHECKING 1 // This also controls async exceptions
}
}

Expand Down
Loading