romainfrancois commented on pull request #8365:
URL: https://github.com/apache/arrow/pull/8365#issuecomment-725971159


   I think failing asap is better, either with the current code, or with an 
`unwind_protect()` outside the loop. 
   
   ```cpp
   StringArrayType* string_array = static_cast<StringArrayType*>(array.get());
       auto unsafe_r_string = [](const std::string& s) {
         return Rf_mkCharCE(s.c_str(), CE_UTF8);
       };
       cpp11::unwind_protect([&] {
         if (array->null_count()) {
           // need to watch for nulls
           arrow::internal::BitmapReader null_reader(array->null_bitmap_data(),
                                                     array->offset(), n);
           for (int i = 0; i < n; i++, null_reader.Next()) {
             if (null_reader.IsSet()) {
               SET_STRING_ELT(data, start + i, 
unsafe_r_string(string_array->GetString(i)));
             } else {
               SET_STRING_ELT(data, start + i, NA_STRING);
             }
           }
   
         } else {
           for (int i = 0; i < n; i++) {
             SET_STRING_ELT(data, start + i, 
unsafe_r_string(string_array->GetString(i)));
           }
         }
       });
   
       return Status::OK();
   ```


----------------------------------------------------------------
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.

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


Reply via email to