| 268 | // ============================================================================ |
| 269 | |
| 270 | static Error CodeHolder_reserveInternal(CodeHolder* self, CodeBuffer* cb, size_t n) noexcept { |
| 271 | uint8_t* oldData = cb->_data; |
| 272 | uint8_t* newData; |
| 273 | |
| 274 | if (oldData && !cb->isExternal()) |
| 275 | newData = static_cast<uint8_t*>(Internal::reallocMemory(oldData, n)); |
| 276 | else |
| 277 | newData = static_cast<uint8_t*>(Internal::allocMemory(n)); |
| 278 | |
| 279 | if (ASMJIT_UNLIKELY(!newData)) |
| 280 | return DebugUtils::errored(kErrorNoHeapMemory); |
| 281 | |
| 282 | cb->_data = newData; |
| 283 | cb->_capacity = n; |
| 284 | |
| 285 | // Update the `Assembler` pointers if attached. Maybe we should introduce an |
| 286 | // event for this, but since only one Assembler can be attached at a time it |
| 287 | // should not matter how these pointers are updated. |
| 288 | Assembler* a = self->_cgAsm; |
| 289 | if (a && &a->_section->_buffer == cb) { |
| 290 | size_t offset = a->getOffset(); |
| 291 | |
| 292 | a->_bufferData = newData; |
| 293 | a->_bufferEnd = newData + n; |
| 294 | a->_bufferPtr = newData + offset; |
| 295 | } |
| 296 | |
| 297 | return kErrorOk; |
| 298 | } |
| 299 | |
| 300 | Error CodeHolder::growBuffer(CodeBuffer* cb, size_t n) noexcept { |
| 301 | // This is most likely called by `Assembler` so `sync()` shouldn't be needed, |
no test coverage detected