Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:26:55

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <assert.h>
0021 #include <stdio.h>
0022 #include <stdlib.h>
0023 #include <string.h>
0024 
0025 #include "arrow/c/abi.h"
0026 
0027 #define ARROW_C_ASSERT(condition, msg)                          \
0028   do {                                                          \
0029     if (!(condition)) {                                         \
0030       fprintf(stderr, "%s:%d:: %s", __FILE__, __LINE__, (msg)); \
0031       abort();                                                  \
0032     }                                                           \
0033   } while (0)
0034 
0035 #ifdef __cplusplus
0036 extern "C" {
0037 #endif
0038 
0039 /// Query whether the C schema is released
0040 inline int ArrowSchemaIsReleased(const struct ArrowSchema* schema) {
0041   return schema->release == NULL;
0042 }
0043 
0044 /// Mark the C schema released (for use in release callbacks)
0045 inline void ArrowSchemaMarkReleased(struct ArrowSchema* schema) {
0046   schema->release = NULL;
0047 }
0048 
0049 /// Move the C schema from `src` to `dest`
0050 ///
0051 /// Note `dest` must *not* point to a valid schema already, otherwise there
0052 /// will be a memory leak.
0053 inline void ArrowSchemaMove(struct ArrowSchema* src, struct ArrowSchema* dest) {
0054   assert(dest != src);
0055   assert(!ArrowSchemaIsReleased(src));
0056   memcpy(dest, src, sizeof(struct ArrowSchema));
0057   ArrowSchemaMarkReleased(src);
0058 }
0059 
0060 /// Release the C schema, if necessary, by calling its release callback
0061 inline void ArrowSchemaRelease(struct ArrowSchema* schema) {
0062   if (!ArrowSchemaIsReleased(schema)) {
0063     schema->release(schema);
0064     ARROW_C_ASSERT(ArrowSchemaIsReleased(schema),
0065                    "ArrowSchemaRelease did not cleanup release callback");
0066   }
0067 }
0068 
0069 /// Query whether the C array is released
0070 inline int ArrowArrayIsReleased(const struct ArrowArray* array) {
0071   return array->release == NULL;
0072 }
0073 
0074 inline int ArrowDeviceArrayIsReleased(const struct ArrowDeviceArray* array) {
0075   return ArrowArrayIsReleased(&array->array);
0076 }
0077 
0078 /// Mark the C array released (for use in release callbacks)
0079 inline void ArrowArrayMarkReleased(struct ArrowArray* array) { array->release = NULL; }
0080 
0081 inline void ArrowDeviceArrayMarkReleased(struct ArrowDeviceArray* array) {
0082   ArrowArrayMarkReleased(&array->array);
0083 }
0084 
0085 /// Move the C array from `src` to `dest`
0086 ///
0087 /// Note `dest` must *not* point to a valid array already, otherwise there
0088 /// will be a memory leak.
0089 inline void ArrowArrayMove(struct ArrowArray* src, struct ArrowArray* dest) {
0090   assert(dest != src);
0091   assert(!ArrowArrayIsReleased(src));
0092   memcpy(dest, src, sizeof(struct ArrowArray));
0093   ArrowArrayMarkReleased(src);
0094 }
0095 
0096 inline void ArrowDeviceArrayMove(struct ArrowDeviceArray* src,
0097                                  struct ArrowDeviceArray* dest) {
0098   assert(dest != src);
0099   assert(!ArrowDeviceArrayIsReleased(src));
0100   memcpy(dest, src, sizeof(struct ArrowDeviceArray));
0101   ArrowDeviceArrayMarkReleased(src);
0102 }
0103 
0104 /// Release the C array, if necessary, by calling its release callback
0105 inline void ArrowArrayRelease(struct ArrowArray* array) {
0106   if (!ArrowArrayIsReleased(array)) {
0107     array->release(array);
0108     ARROW_C_ASSERT(ArrowArrayIsReleased(array),
0109                    "ArrowArrayRelease did not cleanup release callback");
0110   }
0111 }
0112 
0113 inline void ArrowDeviceArrayRelease(struct ArrowDeviceArray* array) {
0114   if (!ArrowDeviceArrayIsReleased(array)) {
0115     array->array.release(&array->array);
0116     ARROW_C_ASSERT(ArrowDeviceArrayIsReleased(array),
0117                    "ArrowDeviceArrayRelease did not cleanup release callback");
0118   }
0119 }
0120 
0121 /// Query whether the C array stream is released
0122 inline int ArrowArrayStreamIsReleased(const struct ArrowArrayStream* stream) {
0123   return stream->release == NULL;
0124 }
0125 
0126 inline int ArrowDeviceArrayStreamIsReleased(const struct ArrowDeviceArrayStream* stream) {
0127   return stream->release == NULL;
0128 }
0129 
0130 /// Mark the C array stream released (for use in release callbacks)
0131 inline void ArrowArrayStreamMarkReleased(struct ArrowArrayStream* stream) {
0132   stream->release = NULL;
0133 }
0134 
0135 inline void ArrowDeviceArrayStreamMarkReleased(struct ArrowDeviceArrayStream* stream) {
0136   stream->release = NULL;
0137 }
0138 
0139 /// Move the C array stream from `src` to `dest`
0140 ///
0141 /// Note `dest` must *not* point to a valid stream already, otherwise there
0142 /// will be a memory leak.
0143 inline void ArrowArrayStreamMove(struct ArrowArrayStream* src,
0144                                  struct ArrowArrayStream* dest) {
0145   assert(dest != src);
0146   assert(!ArrowArrayStreamIsReleased(src));
0147   memcpy(dest, src, sizeof(struct ArrowArrayStream));
0148   ArrowArrayStreamMarkReleased(src);
0149 }
0150 
0151 inline void ArrowDeviceArrayStreamMove(struct ArrowDeviceArrayStream* src,
0152                                        struct ArrowDeviceArrayStream* dest) {
0153   assert(dest != src);
0154   assert(!ArrowDeviceArrayStreamIsReleased(src));
0155   memcpy(dest, src, sizeof(struct ArrowDeviceArrayStream));
0156   ArrowDeviceArrayStreamMarkReleased(src);
0157 }
0158 
0159 /// Release the C array stream, if necessary, by calling its release callback
0160 inline void ArrowArrayStreamRelease(struct ArrowArrayStream* stream) {
0161   if (!ArrowArrayStreamIsReleased(stream)) {
0162     stream->release(stream);
0163     ARROW_C_ASSERT(ArrowArrayStreamIsReleased(stream),
0164                    "ArrowArrayStreamRelease did not cleanup release callback");
0165   }
0166 }
0167 
0168 inline void ArrowDeviceArrayStreamRelease(struct ArrowDeviceArrayStream* stream) {
0169   if (!ArrowDeviceArrayStreamIsReleased(stream)) {
0170     stream->release(stream);
0171     ARROW_C_ASSERT(ArrowDeviceArrayStreamIsReleased(stream),
0172                    "ArrowDeviceArrayStreamRelease did not cleanup release callback");
0173   }
0174 }
0175 
0176 #ifdef __cplusplus
0177 }
0178 #endif