MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / _xsmcGetBuffer

Function _xsmcGetBuffer

xs/sources/xsmc.c:282–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282txInteger _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
333bail:
334 mxTypeError("invalid buffer");
335 return xsBufferNonrelocatable;
336}

Callers 3

xs_computeLevelFunction · 0.85
PiuSVGImageBindFunction · 0.85
PiuImageBufferDrawAuxFunction · 0.85

Calls 1

_xsmcGetViewBufferFunction · 0.85

Tested by

no test coverage detected