Commit a0affc4e authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1270 from Daetalus/scipy_fixing4_nexedi

fix some scipy segfaults
parents 20c9a7dc 7f56274b
......@@ -448,8 +448,10 @@ void Rewriter::_getAttr(RewriterVar* result, RewriterVar* ptr, int offset, Locat
ptr->bumpUseEarlyIfPossible();
assembler::Register newvar_reg = result->initializeInReg(dest);
assembler->mov_generic(assembler::Indirect(ptr_reg, offset), newvar_reg, type);
if (!failed) {
assembler::Register newvar_reg = result->initializeInReg(dest);
assembler->mov_generic(assembler::Indirect(ptr_reg, offset), newvar_reg, type);
}
result->releaseIfNoUses();
......@@ -2172,7 +2174,7 @@ assembler::Register RewriterVar::initializeInReg(Location l) {
// Add this to vars_by_locations
RewriterVar*& var = rewriter->vars_by_location[l];
assert(!var);
assert(!var || rewriter->failed);
var = this;
// Add the location to this
......
......@@ -580,6 +580,9 @@ protected:
void _callOptimalEncoding(assembler::Register tmp_reg, void* func_addr);
void assertConsistent() {
if (failed)
return;
#ifndef NDEBUG
for (RewriterVar& var : vars) {
for (Location l : var.locations) {
......
......@@ -4210,25 +4210,6 @@ Box* rearrangeArgumentsAndCallInternal(ParamReceiveSpec paramspec, const ParamNa
memset(oargs, 0, sizeof(Box*) * (num_output_args - 3));
}
// Clear any increfs we did for when we throw an exception:
int positional_to_positional = std::min(argspec.num_args, paramspec.num_args);
auto clear_refs = [&]() {
switch (positional_to_positional) {
case 0:
Py_XDECREF(oarg1);
case 1:
Py_XDECREF(oarg2);
case 2:
Py_XDECREF(oarg3);
default:
for (int i = std::max(positional_to_positional - 3, 0); i < num_output_args - 3; i++) {
Py_XDECREF(oargs[i]);
}
}
};
ExceptionCleanup<decltype(clear_refs)> cleanup(
clear_refs); // I feel like there should be some way to automatically infer the decltype
static StatCounter slowpath_rearrangeargs_slowpath("slowpath_rearrangeargs_slowpath");
slowpath_rearrangeargs_slowpath.log();
......@@ -4276,6 +4257,8 @@ Box* rearrangeArgumentsAndCallInternal(ParamReceiveSpec paramspec, const ParamNa
varargs_size = PySequence_Fast_GET_SIZE(varargs);
}
int positional_to_positional = std::min(argspec.num_args, paramspec.num_args);
////
// First, match up positional parameters to positional/varargs:
for (int i = 0; i < positional_to_positional; i++) {
......@@ -4285,9 +4268,29 @@ Box* rearrangeArgumentsAndCallInternal(ParamReceiveSpec paramspec, const ParamNa
int varargs_to_positional = std::min((int)varargs_size, paramspec.num_args - positional_to_positional);
for (int i = 0; i < varargs_to_positional; i++) {
assert(!rewrite_args && "would need to be handled here");
getArg(i + positional_to_positional, oarg1, oarg2, oarg3, oargs) = incref(PySequence_Fast_GET_ITEM(varargs, i));
getArg(i + positional_to_positional, oarg1, oarg2, oarg3, oargs) = PySequence_Fast_GET_ITEM(varargs, i);
}
// Clear any increfs we did for when we throw an exception:
auto clear_refs = [&]() {
switch (positional_to_positional + varargs_to_positional) {
case 0:
Py_XDECREF(oarg1);
case 1:
Py_XDECREF(oarg2);
case 2:
Py_XDECREF(oarg3);
default:
for (int i = std::max(positional_to_positional + varargs_to_positional - 3, 0); i < num_output_args - 3;
i++) {
Py_XDECREF(oargs[i]);
}
}
};
ExceptionCleanup<decltype(clear_refs)> cleanup(
clear_refs); // I feel like there should be some way to automatically infer the decltype
llvm::SmallVector<bool, 8> params_filled(num_output_args);
for (int i = 0; i < positional_to_positional + varargs_to_positional; i++) {
params_filled[i] = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment