| 147 | } |
| 148 | |
| 149 | Result<std::shared_ptr<Buffer>> EnsureAlignment(std::shared_ptr<Buffer> buffer, |
| 150 | int64_t alignment, |
| 151 | MemoryPool* memory_pool) { |
| 152 | if (alignment == kValueAlignment) { |
| 153 | return Status::Invalid( |
| 154 | "The kValueAlignment option may only be used to call EnsureAlignment on arrays " |
| 155 | "or tables and cannot be used with buffers"); |
| 156 | } |
| 157 | if (alignment <= 0) { |
| 158 | return Status::Invalid("Alignment must be a positive integer"); |
| 159 | } |
| 160 | if (!CheckAlignment(*buffer, alignment)) { |
| 161 | if (!buffer->is_cpu()) { |
| 162 | return Status::NotImplemented("Reallocating an unaligned non-CPU buffer."); |
| 163 | } |
| 164 | int64_t minimum_desired_alignment = std::max(kDefaultBufferAlignment, alignment); |
| 165 | ARROW_ASSIGN_OR_RAISE( |
| 166 | auto new_buffer, |
| 167 | AllocateBuffer(buffer->size(), minimum_desired_alignment, memory_pool)); |
| 168 | std::memcpy(new_buffer->mutable_data(), buffer->data(), buffer->size()); |
| 169 | // R build with openSUSE155 requires an explicit shared_ptr construction |
| 170 | return std::shared_ptr<Buffer>(std::move(new_buffer)); |
| 171 | } else { |
| 172 | return buffer; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | Result<std::shared_ptr<ArrayData>> EnsureAlignment(std::shared_ptr<ArrayData> array_data, |
| 177 | int64_t alignment, |