pitrou commented on code in PR #13635:
URL: https://github.com/apache/arrow/pull/13635#discussion_r981256133


##########
r/src/safe-call-into-r.h:
##########
@@ -165,22 +262,30 @@ arrow::Result<T> 
RunWithCapturedR(std::function<arrow::Future<T>()> make_arrow_c
     return arrow::Status::NotImplemented("RunWithCapturedR() without 
UnwindProtect");
   }
 
-  if (GetMainRThread().Executor() != nullptr) {
+  if (MainRThread::GetInstance().Executor() != nullptr) {
     return arrow::Status::AlreadyExists("Attempt to use more than one R 
Executor()");
   }
 
-  GetMainRThread().ResetError();
+  RunWithCapturedRContext context;
+  ARROW_RETURN_NOT_OK(context.Init());
+  MainRThread::GetInstance().ResetError();
 
   arrow::Result<T> result = 
arrow::internal::SerialExecutor::RunInSerialExecutor<T>(
       [make_arrow_call](arrow::internal::Executor* executor) {
-        GetMainRThread().Executor() = executor;
+        MainRThread::GetInstance().Executor() = executor;
         return make_arrow_call();
       });
 
-  GetMainRThread().Executor() = nullptr;
-  GetMainRThread().ClearError();
+  MainRThread::GetInstance().Executor() = nullptr;
 
-  return result;
+  // A StatusUnwindProtect error, if it was thrown, lives in the MainRThread 
and
+  // should be returned if possible.
+  arrow::Status global_status = 
MainRThread::GetInstance().ReraiseErrorIfExists();
+  if (!global_status.ok()) {
+    return global_status;
+  } else {
+    return result;
+  }

Review Comment:
   Or simply:
   ```suggestion
     ARROW_RETURN_NOT_OK(MainRThread::GetInstance().ReraiseErrorIfExists());
     return result;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to