Skip to content

Commit 2aa7579

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Fix / workaround a couple of more 2 return value issues
Summary: There's a couple of more spots where 2 return values are biting is: 1) JITRT_CallWithIncorrectArgcount - for now this is just working around things by making this return PyObject* on Windows. That means it won't work properly w/ static Python but gets everything else working. 2) LoadTypeMethodCache::lookupHelper needs the appendCall2RetValues treatment. Reviewed By: alexmalyshev Differential Revision: D103952453 fbshipit-source-id: 854f2d03d7a40c9eca909e2489712b6ca49e5d52
1 parent 5e91a09 commit 2aa7579

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

cinderx/Jit/jit_rt.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,12 @@ JITRT_StaticCallFPReturn JITRT_CallWithIncorrectArgcountFPReturn(
366366
(PyObject*)defaulted_args);
367367
}
368368

369-
JITRT_StaticCallReturn JITRT_CallWithIncorrectArgcount(
369+
#ifdef _WIN32
370+
PyObject*
371+
#else
372+
JITRT_StaticCallReturn
373+
#endif
374+
JITRT_CallWithIncorrectArgcount(
370375
PyFunctionObject* func,
371376
PyObject** args,
372377
size_t nargsf,
@@ -377,7 +382,11 @@ JITRT_StaticCallReturn JITRT_CallWithIncorrectArgcount(
377382
// Fallback to the default _PyFunction_Vectorcall implementation
378383
// to produce an appropriate exception.
379384
auto interpVectorcall = getInterpretedVectorcall(func);
385+
#ifdef _WIN32
386+
return interpVectorcall((PyObject*)func, args, nargsf, nullptr);
387+
#else
380388
return {interpVectorcall((PyObject*)func, args, nargsf, nullptr), nullptr};
389+
#endif
381390
}
382391
Py_ssize_t defcount = PyTuple_GET_SIZE(defaults);
383392
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
@@ -387,7 +396,11 @@ JITRT_StaticCallReturn JITRT_CallWithIncorrectArgcount(
387396
if (nargs + defcount < argcount || nargs > argcount) {
388397
// Not enough args with defaults, or too many args without defaults.
389398
auto interpVectorcall = getInterpretedVectorcall(func);
399+
#ifdef _WIN32
400+
return interpVectorcall((PyObject*)func, args, nargsf, nullptr);
401+
#else
390402
return {interpVectorcall((PyObject*)func, args, nargsf, nullptr), nullptr};
403+
#endif
391404
}
392405

393406
Py_ssize_t i;
@@ -403,6 +416,10 @@ JITRT_StaticCallReturn JITRT_CallWithIncorrectArgcount(
403416

404417
size_t new_nargsf = argcount;
405418

419+
#ifdef _WIN32
420+
return JITRT_GET_REENTRY(func->vectorcall)(
421+
(PyObject*)func, arg_space.get(), new_nargsf, (PyObject*)defaulted_args);
422+
#else
406423
return reinterpret_cast<staticvectorcallfunc>(
407424
JITRT_GET_REENTRY(func->vectorcall))(
408425
(PyObject*)func,
@@ -411,6 +428,7 @@ JITRT_StaticCallReturn JITRT_CallWithIncorrectArgcount(
411428
// We lie to C++ here, and smuggle in the number of defaulted args filled
412429
// in.
413430
(PyObject*)defaulted_args);
431+
#endif
414432
}
415433

416434
bool JITRT_PackStaticArgs(

cinderx/Jit/jit_rt.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ PyObject* JITRT_CallWithKeywordArgsSimple(
9696
size_t nargsf,
9797
PyObject* kwnames);
9898

99-
JITRT_StaticCallReturn JITRT_CallWithIncorrectArgcount(
99+
// On Windows x64, returning JITRT_StaticCallReturn (16 bytes) would use a
100+
// hidden first parameter for the return pointer, shifting all visible
101+
// arguments. Return PyObject* instead to keep register assignments correct.
102+
#ifdef _WIN32
103+
PyObject*
104+
#else
105+
JITRT_StaticCallReturn
106+
#endif
107+
JITRT_CallWithIncorrectArgcount(
100108
PyFunctionObject* func,
101109
PyObject** args,
102110
size_t nargsf,

cinderx/Jit/lir/generator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ void GeneratePrimitiveArgsPrologueBlock(
767767
auto helper = returns_primitive_double
768768
? reinterpret_cast<uint64_t>(JITRT_CallStaticallyWithPrimitiveSignatureFP)
769769
: reinterpret_cast<uint64_t>(JITRT_CallStaticallyWithPrimitiveSignature);
770+
770771
block->allocateInstr(Instruction::kCall, nullptr, Imm{helper});
771772

772773
// The helper either handled the call (result in return register) and we
@@ -2503,7 +2504,8 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
25032504
PyUnicode_AsUTF8(code->co_filename),
25042505
PyUnicode_AsUTF8(code->co_name));
25052506
}
2506-
bbb.appendCallInstruction(
2507+
appendCall2RetValues(
2508+
bbb,
25072509
instr->output(),
25082510
LoadTypeMethodCache::lookupHelper,
25092511
cache_entry,

0 commit comments

Comments
 (0)