]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file | |
3 | // distributed with this work for additional information | |
4 | // regarding copyright ownership. The ASF licenses this file | |
5 | // to you under the Apache License, Version 2.0 (the | |
6 | // "License"); you may not use this file except in compliance | |
7 | // with the License. You may obtain a copy of the License at | |
8 | // | |
9 | // http://www.apache.org/licenses/LICENSE-2.0 | |
10 | // | |
11 | // Unless required by applicable law or agreed to in writing, | |
12 | // software distributed under the License is distributed on an | |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | // KIND, either express or implied. See the License for the | |
15 | // specific language governing permissions and limitations | |
16 | // under the License. | |
17 | ||
18 | #pragma once | |
19 | ||
20 | #include <assert.h> | |
21 | #include <string.h> | |
22 | ||
23 | #include "arrow/c/abi.h" | |
24 | ||
25 | #ifdef __cplusplus | |
26 | extern "C" { | |
27 | #endif | |
28 | ||
29 | /// Query whether the C schema is released | |
30 | inline int ArrowSchemaIsReleased(const struct ArrowSchema* schema) { | |
31 | return schema->release == NULL; | |
32 | } | |
33 | ||
34 | /// Mark the C schema released (for use in release callbacks) | |
35 | inline void ArrowSchemaMarkReleased(struct ArrowSchema* schema) { | |
36 | schema->release = NULL; | |
37 | } | |
38 | ||
39 | /// Move the C schema from `src` to `dest` | |
40 | /// | |
41 | /// Note `dest` must *not* point to a valid schema already, otherwise there | |
42 | /// will be a memory leak. | |
43 | inline void ArrowSchemaMove(struct ArrowSchema* src, struct ArrowSchema* dest) { | |
44 | assert(dest != src); | |
45 | assert(!ArrowSchemaIsReleased(src)); | |
46 | memcpy(dest, src, sizeof(struct ArrowSchema)); | |
47 | ArrowSchemaMarkReleased(src); | |
48 | } | |
49 | ||
50 | /// Release the C schema, if necessary, by calling its release callback | |
51 | inline void ArrowSchemaRelease(struct ArrowSchema* schema) { | |
52 | if (!ArrowSchemaIsReleased(schema)) { | |
53 | schema->release(schema); | |
54 | assert(ArrowSchemaIsReleased(schema)); | |
55 | } | |
56 | } | |
57 | ||
58 | /// Query whether the C array is released | |
59 | inline int ArrowArrayIsReleased(const struct ArrowArray* array) { | |
60 | return array->release == NULL; | |
61 | } | |
62 | ||
63 | /// Mark the C array released (for use in release callbacks) | |
64 | inline void ArrowArrayMarkReleased(struct ArrowArray* array) { array->release = NULL; } | |
65 | ||
66 | /// Move the C array from `src` to `dest` | |
67 | /// | |
68 | /// Note `dest` must *not* point to a valid array already, otherwise there | |
69 | /// will be a memory leak. | |
70 | inline void ArrowArrayMove(struct ArrowArray* src, struct ArrowArray* dest) { | |
71 | assert(dest != src); | |
72 | assert(!ArrowArrayIsReleased(src)); | |
73 | memcpy(dest, src, sizeof(struct ArrowArray)); | |
74 | ArrowArrayMarkReleased(src); | |
75 | } | |
76 | ||
77 | /// Release the C array, if necessary, by calling its release callback | |
78 | inline void ArrowArrayRelease(struct ArrowArray* array) { | |
79 | if (!ArrowArrayIsReleased(array)) { | |
80 | array->release(array); | |
81 | assert(ArrowArrayIsReleased(array)); | |
82 | } | |
83 | } | |
84 | ||
85 | /// Query whether the C array stream is released | |
86 | inline int ArrowArrayStreamIsReleased(const struct ArrowArrayStream* stream) { | |
87 | return stream->release == NULL; | |
88 | } | |
89 | ||
90 | /// Mark the C array stream released (for use in release callbacks) | |
91 | inline void ArrowArrayStreamMarkReleased(struct ArrowArrayStream* stream) { | |
92 | stream->release = NULL; | |
93 | } | |
94 | ||
95 | /// Move the C array stream from `src` to `dest` | |
96 | /// | |
97 | /// Note `dest` must *not* point to a valid stream already, otherwise there | |
98 | /// will be a memory leak. | |
99 | inline void ArrowArrayStreamMove(struct ArrowArrayStream* src, | |
100 | struct ArrowArrayStream* dest) { | |
101 | assert(dest != src); | |
102 | assert(!ArrowArrayStreamIsReleased(src)); | |
103 | memcpy(dest, src, sizeof(struct ArrowArrayStream)); | |
104 | ArrowArrayStreamMarkReleased(src); | |
105 | } | |
106 | ||
107 | /// Release the C array stream, if necessary, by calling its release callback | |
108 | inline void ArrowArrayStreamRelease(struct ArrowArrayStream* stream) { | |
109 | if (!ArrowArrayStreamIsReleased(stream)) { | |
110 | stream->release(stream); | |
111 | assert(ArrowArrayStreamIsReleased(stream)); | |
112 | } | |
113 | } | |
114 | ||
115 | #ifdef __cplusplus | |
116 | } | |
117 | #endif |