Skip to content

Commit 1961ce6

Browse files
authored
Merge pull request #1379 from kmod/metaserver_merge
A number of small fixes from the dropbox testsuite
2 parents 9cd8e75 + c026399 commit 1961ce6

27 files changed

+456
-179
lines changed

from_cpython/Include/pystate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ typedef struct _ts {
8383
int trash_delete_nesting;
8484
PyObject *trash_delete_later;
8585

86+
PyObject *async_exc; /* Asynchronous exception to raise */
87+
long thread_id; /* Thread id where this tstate was created */
88+
8689
// Pyston change:
8790
// Pyston note: additions in here need to be mirrored in PyThreadState_Clear
8891
#if 0
@@ -109,9 +112,6 @@ typedef struct _ts {
109112
*/
110113
int tick_counter;
111114

112-
PyObject *async_exc; /* Asynchronous exception to raise */
113-
long thread_id; /* Thread id where this tstate was created */
114-
115115
/* XXX signal handlers should also be here */
116116
#endif
117117
} PyThreadState;

from_cpython/Python/getargs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ int _PyArg_ParseSingle_SizeT(PyObject* obj, int arg_idx, const char* fname, cons
619619
return r;
620620
}
621621

622+
extern PyTypeObject* attrwrapper_cls;
623+
622624
/* Convert a non-tuple argument. Return NULL if conversion went OK,
623625
or a string with a message describing the failure. The message is
624626
formatted as "must be <desired type>, not <actual type>".
@@ -1279,7 +1281,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
12791281
type = va_arg(*p_va, PyTypeObject*);
12801282
p = va_arg(*p_va, PyObject **);
12811283
format++;
1282-
if (PyType_IsSubtype(arg->ob_type, type))
1284+
if (PyType_IsSubtype(arg->ob_type, type) || /* Pyston hack */ (arg->ob_type == attrwrapper_cls && type == &PyDict_Type))
12831285
*p = arg;
12841286
else
12851287
return converterr(type->tp_name, arg, msgbuf, bufsize);

from_cpython/Python/import.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,21 +2949,34 @@ PyImport_Import(PyObject *module_name)
29492949
importing modules.
29502950
*/
29512951

2952-
// Pyston change: we don't support get_magic
2953-
#if 0
2952+
// Pyston change: there is a surprising number of custom pyc-reading and -writing
2953+
// code out there that wants to use imp.get_magic. If we simply remove imp.get_magic,
2954+
// that code will tend to fail in unrecoverable ways. While hacky, the best-working option
2955+
// found so far seems to be to have imp.get_magic exist but to return a changing value so
2956+
// that the check will never succeed.
29542957
static PyObject *
29552958
imp_get_magic(PyObject *self, PyObject *noargs)
29562959
{
2960+
static int counter;
2961+
if (counter == 0) {
2962+
// something randomish
2963+
counter = 0x12345678 + (getpid() << 16);
2964+
}
2965+
// and that changes each time you call it
2966+
counter++;
2967+
29572968
char buf[4];
2969+
memcpy(buf, &counter, 4);
29582970

2971+
#if 0
29592972
buf[0] = (char) ((pyc_magic >> 0) & 0xff);
29602973
buf[1] = (char) ((pyc_magic >> 8) & 0xff);
29612974
buf[2] = (char) ((pyc_magic >> 16) & 0xff);
29622975
buf[3] = (char) ((pyc_magic >> 24) & 0xff);
2976+
#endif
29632977

29642978
return PyString_FromStringAndSize(buf, 4);
29652979
}
2966-
#endif
29672980

29682981
static PyObject *
29692982
imp_get_suffixes(PyObject *self, PyObject *noargs)
@@ -3329,8 +3342,7 @@ On platforms without threads, this function does nothing.");
33293342
static PyMethodDef imp_methods[] = {
33303343
{"reload", imp_reload, METH_O, doc_reload},
33313344
{"find_module", imp_find_module, METH_VARARGS, doc_find_module},
3332-
// Pyston change: we don't support this function
3333-
// {"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic},
3345+
{"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic},
33343346
{"get_suffixes", imp_get_suffixes, METH_NOARGS, doc_get_suffixes},
33353347
{"load_module", imp_load_module, METH_VARARGS, doc_load_module},
33363348
{"new_module", imp_new_module, METH_VARARGS, doc_new_module},

src/capi/modsupport.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,13 @@ extern "C" PyObject* Py_InitModule4(const char* name, PyMethodDef* methods, cons
434434
}
435435
}
436436

437-
BoxedModule* module = createModule(autoDecref(boxString(name)), NULL, doc);
437+
BoxedModule* module;
438+
try {
439+
module = createModule(autoDecref(boxString(name)), NULL, doc);
440+
} catch (ExcInfo e) {
441+
setCAPIException(e);
442+
return NULL;
443+
}
438444

439445
// Pass self as is, even if NULL we are not allowed to change it to None
440446
Box* passthrough = static_cast<Box*>(self);

src/codegen/ast_interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ Box* ASTInterpreterJitInterface::landingpadHelper(void* _interpreter) {
18801880

18811881
void ASTInterpreterJitInterface::pendingCallsCheckHelper() {
18821882
#if ENABLE_SIGNAL_CHECKING
1883-
if (unlikely(_pendingcalls_to_do))
1883+
if (unlikely(_stop_thread))
18841884
makePendingCalls();
18851885
#endif
18861886
}

src/codegen/irgen/hooks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ CompiledFunction* compileFunction(BoxedCode* code, FunctionSpecialization* spec,
150150

151151
if (spec) {
152152
ss << "\033[" << colors[(int)effort] << ";1mJIT'ing " << code->filename->s() << ":" << name->s()
153-
<< " with signature (";
153+
<< " (starting at line " << code->firstlineno << ") with signature (";
154154
for (int i = 0; i < spec->arg_types.size(); i++) {
155155
if (i > 0)
156156
ss << ", ";

src/codegen/irgen/irgenerator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,19 @@ class IREmitterImpl : public IREmitter {
406406
#if ENABLE_SIGNAL_CHECKING
407407
auto&& builder = *getBuilder();
408408

409-
llvm::GlobalVariable* pendingcalls_to_do_gv = g.cur_module->getGlobalVariable("_pendingcalls_to_do");
409+
llvm::GlobalVariable* pendingcalls_to_do_gv = g.cur_module->getGlobalVariable("_stop_thread");
410410
if (!pendingcalls_to_do_gv) {
411-
static_assert(sizeof(_pendingcalls_to_do) == 4, "");
412-
pendingcalls_to_do_gv = new llvm::GlobalVariable(
413-
*g.cur_module, g.i32, false, llvm::GlobalValue::ExternalLinkage, 0, "_pendingcalls_to_do");
411+
static_assert(sizeof(_stop_thread) == 4, "");
412+
pendingcalls_to_do_gv = new llvm::GlobalVariable(*g.cur_module, g.i32, false,
413+
llvm::GlobalValue::ExternalLinkage, 0, "_stop_thread");
414414
pendingcalls_to_do_gv->setAlignment(4);
415415
}
416416

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

419-
llvm::BasicBlock* pendingcalls_set = createBasicBlock("_pendingcalls_set");
419+
llvm::BasicBlock* pendingcalls_set = createBasicBlock("_stop_thread_set");
420420
pendingcalls_set->moveAfter(cur_block);
421-
llvm::BasicBlock* join_block = createBasicBlock("continue_after_pendingcalls_check");
421+
llvm::BasicBlock* join_block = createBasicBlock("continue_after_stopthread_check");
422422
join_block->moveAfter(pendingcalls_set);
423423

424424
llvm::Value* pendingcalls_to_do_val = builder.CreateLoad(pendingcalls_to_do_gv, true /* volatile */);

src/core/bst.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,83 +1542,83 @@ class FlattenVisitor : public BSTVisitor {
15421542
return false;
15431543
}
15441544

1545-
virtual bool visit_landingpad(BST_Landingpad* node) override {
1545+
virtual bool visit_landingpad(BST_Landingpad* node) {
15461546
output->push_back(node);
15471547
return false;
15481548
}
1549-
virtual bool visit_locals(BST_Locals* node) override {
1549+
virtual bool visit_locals(BST_Locals* node) {
15501550
output->push_back(node);
15511551
return false;
15521552
}
1553-
virtual bool visit_getiter(BST_GetIter* node) override {
1553+
virtual bool visit_getiter(BST_GetIter* node) {
15541554
output->push_back(node);
15551555
return false;
15561556
}
1557-
virtual bool visit_importfrom(BST_ImportFrom* node) override {
1557+
virtual bool visit_importfrom(BST_ImportFrom* node) {
15581558
output->push_back(node);
15591559
return false;
15601560
}
1561-
virtual bool visit_importname(BST_ImportName* node) override {
1561+
virtual bool visit_importname(BST_ImportName* node) {
15621562
output->push_back(node);
15631563
return false;
15641564
}
1565-
virtual bool visit_importstar(BST_ImportStar* node) override {
1565+
virtual bool visit_importstar(BST_ImportStar* node) {
15661566
output->push_back(node);
15671567
return false;
15681568
}
1569-
virtual bool visit_nonzero(BST_Nonzero* node) override {
1569+
virtual bool visit_nonzero(BST_Nonzero* node) {
15701570
output->push_back(node);
15711571
return false;
15721572
}
1573-
virtual bool visit_checkexcmatch(BST_CheckExcMatch* node) override {
1573+
virtual bool visit_checkexcmatch(BST_CheckExcMatch* node) {
15741574
output->push_back(node);
15751575
return false;
15761576
}
1577-
virtual bool visit_setexcinfo(BST_SetExcInfo* node) override {
1577+
virtual bool visit_setexcinfo(BST_SetExcInfo* node) {
15781578
output->push_back(node);
15791579
return false;
15801580
}
1581-
virtual bool visit_uncacheexcinfo(BST_UncacheExcInfo* node) override {
1581+
virtual bool visit_uncacheexcinfo(BST_UncacheExcInfo* node) {
15821582
output->push_back(node);
15831583
return false;
15841584
}
1585-
virtual bool visit_hasnext(BST_HasNext* node) override {
1585+
virtual bool visit_hasnext(BST_HasNext* node) {
15861586
output->push_back(node);
15871587
return false;
15881588
}
1589-
virtual bool visit_printexpr(BST_PrintExpr* node) override {
1589+
virtual bool visit_printexpr(BST_PrintExpr* node) {
15901590
output->push_back(node);
15911591
return false;
15921592
}
1593-
virtual bool visit_loadname(BST_LoadName* node) override {
1593+
virtual bool visit_loadname(BST_LoadName* node) {
15941594
output->push_back(node);
15951595
return false;
15961596
}
1597-
virtual bool visit_loadattr(BST_LoadAttr* node) override {
1597+
virtual bool visit_loadattr(BST_LoadAttr* node) {
15981598
output->push_back(node);
15991599
return false;
16001600
}
1601-
virtual bool visit_loadsub(BST_LoadSub* node) override {
1601+
virtual bool visit_loadsub(BST_LoadSub* node) {
16021602
output->push_back(node);
16031603
return false;
16041604
}
1605-
virtual bool visit_loadsubslice(BST_LoadSubSlice* node) override {
1605+
virtual bool visit_loadsubslice(BST_LoadSubSlice* node) {
16061606
output->push_back(node);
16071607
return false;
16081608
}
1609-
virtual bool visit_storename(BST_StoreName* node) override {
1609+
virtual bool visit_storename(BST_StoreName* node) {
16101610
output->push_back(node);
16111611
return false;
16121612
}
1613-
virtual bool visit_storesub(BST_StoreSub* node) override {
1613+
virtual bool visit_storesub(BST_StoreSub* node) {
16141614
output->push_back(node);
16151615
return false;
16161616
}
1617-
virtual bool visit_storesubslice(BST_StoreSubSlice* node) override {
1617+
virtual bool visit_storesubslice(BST_StoreSubSlice* node) {
16181618
output->push_back(node);
16191619
return false;
16201620
}
1621-
virtual bool visit_storeattr(BST_StoreAttr* node) override {
1621+
virtual bool visit_storeattr(BST_StoreAttr* node) {
16221622
output->push_back(node);
16231623
return false;
16241624
}

src/core/cfg.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@ class CFGVisitor : public ASTVisitor {
24192419
curblock->connectTo(test_false);
24202420

24212421
CFGBlock* loop_block = cfg->addBlock();
2422+
CFGBlock* break_block = cfg->addDeferredBlock();
24222423
CFGBlock* end_block = cfg->addDeferredBlock();
24232424
CFGBlock* else_block = cfg->addDeferredBlock();
24242425

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

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

24352435
curblock = loop_block;
24362436
TmpValue next_name = makeCallAttr(_dup(itername), internString("next"), true);
@@ -2478,6 +2478,15 @@ class CFGVisitor : public ASTVisitor {
24782478
if (curblock)
24792479
pushJump(end_block);
24802480

2481+
if (break_block->predecessors.size() == 0) {
2482+
delete break_block;
2483+
} else {
2484+
cfg->placeBlock(break_block);
2485+
curblock = break_block;
2486+
push_back(makeKill(itername.is));
2487+
pushJump(end_block);
2488+
}
2489+
24812490
if (end_block->predecessors.size() == 0) {
24822491
delete end_block;
24832492
curblock = NULL;

src/core/options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern bool ENABLE_ICS, ENABLE_ICGENERICS, ENABLE_ICGETITEMS, ENABLE_ICSETITEMS,
5050
#define BOOLS_AS_I64 1
5151

5252
#define ENABLE_SAMPLING_PROFILER 0
53-
#define ENABLE_SIGNAL_CHECKING 1
53+
#define ENABLE_SIGNAL_CHECKING 1 // This also controls async exceptions
5454
}
5555
}
5656

0 commit comments

Comments
 (0)