| 280 | } |
| 281 | |
| 282 | txInteger _xsmcGetBuffer(txMachine *the, txSlot *slot, void **data, txUnsigned *count, txBoolean writable) |
| 283 | { |
| 284 | txSlot* instance; |
| 285 | |
| 286 | if (slot->kind != XS_REFERENCE_KIND) |
| 287 | goto bail; |
| 288 | |
| 289 | instance = slot->value.reference; |
| 290 | if (!(((slot = instance->next)) && (slot->flag & XS_INTERNAL_FLAG))) |
| 291 | goto bail; |
| 292 | |
| 293 | if (slot->kind == XS_ARRAY_BUFFER_KIND) { |
| 294 | txSlot* bufferInfo = slot->next; |
| 295 | if (slot->value.arrayBuffer.address == C_NULL) |
| 296 | mxTypeError("detached buffer"); |
| 297 | if (writable && (slot->flag & XS_DONT_SET_FLAG)) |
| 298 | mxTypeError("read-only buffer"); |
| 299 | *data = slot->value.arrayBuffer.address; |
| 300 | *count = bufferInfo->value.bufferInfo.length; |
| 301 | return xsBufferRelocatable; |
| 302 | } |
| 303 | |
| 304 | if (slot->kind == XS_TYPED_ARRAY_KIND) { |
| 305 | txSlot* view = slot->next; |
| 306 | txSlot* buffer = view->next; |
| 307 | if (1 != slot->value.typedArray.dispatch->size) |
| 308 | goto bail; |
| 309 | return _xsmcGetViewBuffer(the, view, buffer, data, count, writable); |
| 310 | } |
| 311 | |
| 312 | if (slot->kind == XS_HOST_KIND) { |
| 313 | txSlot* bufferInfo = slot->next; |
| 314 | if (slot->flag & XS_HOST_CHUNK_FLAG) |
| 315 | goto bail; |
| 316 | if (writable && (slot->flag & XS_DONT_SET_FLAG)) |
| 317 | mxTypeError("read-only buffer"); |
| 318 | if (bufferInfo && (bufferInfo->kind == XS_BUFFER_INFO_KIND)) { |
| 319 | *data = (uint8_t *)slot->value.host.data; |
| 320 | *count = bufferInfo->value.bufferInfo.length; |
| 321 | } |
| 322 | else |
| 323 | mxTypeError("not host buffer"); // Use xsmcSetHostBuffer instead of xsmcSetHostData |
| 324 | return xsBufferNonrelocatable; |
| 325 | } |
| 326 | |
| 327 | if (slot->kind == XS_DATA_VIEW_KIND) { |
| 328 | txSlot* view = slot; |
| 329 | txSlot* buffer = view->next; |
| 330 | return _xsmcGetViewBuffer(the, view, buffer, data, count, writable); |
| 331 | } |
| 332 | |
| 333 | bail: |
| 334 | mxTypeError("invalid buffer"); |
| 335 | return xsBufferNonrelocatable; |
| 336 | } |
no test coverage detected