1 /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_C_TF_BUFFER_H_ 17 #define TENSORFLOW_C_TF_BUFFER_H_ 18 19 #include <stddef.h> 20 21 // Macro to control visibility of exported symbols in the shared library (.so, 22 // .dylib, .dll). 23 // This duplicates the TF_EXPORT macro definition in 24 // tensorflow/core/platform/macros.h in order to keep this .h file independent 25 // of any other includes. 26 #ifdef SWIG 27 #define TF_CAPI_EXPORT 28 #else 29 #if defined(_WIN32) 30 #ifdef TF_COMPILE_LIBRARY 31 #define TF_CAPI_EXPORT __declspec(dllexport) 32 #else 33 #define TF_CAPI_EXPORT __declspec(dllimport) 34 #endif // TF_COMPILE_LIBRARY 35 #else 36 #define TF_CAPI_EXPORT __attribute__((visibility("default"))) 37 #endif // _WIN32 38 #endif // SWIG 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 // -------------------------------------------------------------------------- 45 // TF_Buffer holds a pointer to a block of data and its associated length. 46 // Typically, the data consists of a serialized protocol buffer, but other data 47 // may also be held in a buffer. 48 // 49 // By default, TF_Buffer itself does not do any memory management of the 50 // pointed-to block. If need be, users of this struct should specify how to 51 // deallocate the block by setting the `data_deallocator` function pointer. 52 typedef struct TF_Buffer { 53 const void* data; 54 size_t length; 55 void (*data_deallocator)(void* data, size_t length); 56 } TF_Buffer; 57 58 // Makes a copy of the input and sets an appropriate deallocator. Useful for 59 // passing in read-only, input protobufs. 60 TF_CAPI_EXPORT extern TF_Buffer* TF_NewBufferFromString(const void* proto, 61 size_t proto_len); 62 63 // Useful for passing *out* a protobuf. 64 TF_CAPI_EXPORT extern TF_Buffer* TF_NewBuffer(void); 65 66 TF_CAPI_EXPORT extern void TF_DeleteBuffer(TF_Buffer*); 67 68 TF_CAPI_EXPORT extern TF_Buffer TF_GetBuffer(TF_Buffer* buffer); 69 70 #ifdef __cplusplus 71 } /* end extern "C" */ 72 #endif 73 74 #endif // TENSORFLOW_C_TF_BUFFER_H_ 75