onnxruntime/js/web/lib/wasm/string-utils.ts
Yulong Wang 896f32ec09
[js/web] support string tensor for wasm backend (#7891)
* [js/web] support string tensor for wasm backend

* disable v9/test_cast_STRING_to_FLOAT: test data is wrong

* add non-string check

* Update session-handler.ts

* Update session-handler.ts
2021-06-03 00:44:50 -07:00

15 lines
453 B
TypeScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import {getInstance} from './wasm-factory';
export const allocWasmString = (data: string, allocs: number[]): number => {
const wasm = getInstance();
const dataLength = wasm.lengthBytesUTF8(data) + 1;
const dataOffset = wasm._malloc(dataLength);
wasm.stringToUTF8(data, dataOffset, dataLength);
allocs.push(dataOffset);
return dataOffset;
};