1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
//! Bindings to C for SQL UDF-related types
//!
//! Types in this module were autogenerated. Documentation mostly comes from the
//! C header file, but some clarifications were added. Some mut -> const changes
//! were done as makes sense.
//!
//! To regenerate this file, run:
//!
//! ```sh
//! bindgen udf_registration_types.c \
//!     --default-enum-style=rust_non_exhaustive \
//!     --no-derive-copy
//! ```
//!
//! _You're off the edge of the map, mate. Here there be monsters!_

/* automatically generated by rust-bindgen 0.60.1 */

#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused)]

/// C builtin
pub const true_: u32 = 1;

/// C builtin
pub const false_: u32 = 0;

/// C builtin
pub const __bool_true_false_are_defined: u32 = 1;

/// Type of the user defined function return slot and arguments
///
// This is `repr(C)` to ensure it is represented the same as C enums.
#[repr(C)]
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Item_result {
    /// Invalid value (not valid for UDFs)
    INVALID_RESULT = -1,

    /// Value representing a string (char *)
    STRING_RESULT = 0,

    /// Value representing a real (double)
    REAL_RESULT = 1,

    /// Value representing an int (long long)
    INT_RESULT = 2,

    /// Value representing a row (not valid for UDFs)
    ROW_RESULT = 3,

    /// Value representing a decimal (char *)
    DECIMAL_RESULT = 4,
}

/// Representation of a sequence of SQL arguments
#[repr(C)]
#[derive(Debug, Clone)]
pub struct UDF_ARGS {
    /// Number of arguments present
    pub arg_count: ::std::ffi::c_uint,

    /// Buffer of item_result pointers that indicate argument type
    ///
    /// Remains mutable because it can be set in `xxx_init`
    pub arg_type: *mut Item_result,

    /// Buffer of pointers to the arguments. Arguments may be of any type
    /// (specified in `arg_type`).
    pub args: *const *const ::std::ffi::c_char,

    /// Buffer of lengths for string arguments
    pub lengths: *const ::std::ffi::c_ulong,

    /// Indicates whether the argument may be null or not
    pub maybe_null: *const ::std::ffi::c_char,

    /// Buffer of string pointers that hold variable names, for use with error
    /// messages
    pub attributes: *const *const ::std::ffi::c_char,

    /// Buffer of lengths of attributes
    pub attribute_lengths: *const ::std::ffi::c_ulong,

    /// Extension is currently unused
    pub extension: *const ::std::ffi::c_void,
}

/// Information about the result of a user defined function
#[repr(C)]
#[derive(Debug, Clone)]
pub struct UDF_INIT {
    /// True if the function can return NULL
    pub maybe_null: bool,

    /// This is used for real-returning functions
    pub decimals: ::std::ffi::c_uint,

    /// This is used for string functions
    pub max_length: ::std::ffi::c_ulong,

    /// free pointer for function data
    pub ptr: *mut ::std::ffi::c_char,

    /// True if function always returns the same value
    pub const_item: bool,

    /// Unused at this time
    pub extension: *mut ::std::ffi::c_void,
}

/// A UDF function type indicator, currently unused
#[repr(u32)]
#[non_exhaustive]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum Item_udftype {
    UDFTYPE_FUNCTION = 1,
    UDFTYPE_AGGREGATE = 2,
}

/// Function signature of an `xxx_init(...)` function
pub type Udf_func_init = Option<
    unsafe extern "C" fn(
        initid: *mut UDF_INIT,
        args: *mut UDF_ARGS,
        message: *mut ::std::ffi::c_char,
    ) -> bool,
>;

/// Function signature of an `xxx_deinit(...)` function
pub type Udf_func_deinit = Option<unsafe extern "C" fn(arg1: *mut UDF_INIT)>;

/// Function signature of an `xxx_add(...)` aggregate function
pub type Udf_func_add = Option<
    unsafe extern "C" fn(
        initid: *mut UDF_INIT,
        args: *const UDF_ARGS,
        is_null: *mut ::std::ffi::c_uchar,
        error: *mut ::std::ffi::c_uchar,
    ),
>;

/// Function signature of an `xxx_clear(...)` aggregate function
pub type Udf_func_clear = Option<
    unsafe extern "C" fn(
        initid: *mut UDF_INIT,
        is_null: *mut ::std::ffi::c_uchar,
        error: *mut ::std::ffi::c_uchar,
    ),
>;

/// Function signature of an `xxx(...)` function returning a SQL real
pub type Udf_func_double = Option<
    unsafe extern "C" fn(
        initid: *mut UDF_INIT,
        args: *const UDF_ARGS,
        is_null: *mut ::std::ffi::c_uchar,
        error: *mut ::std::ffi::c_uchar,
    ) -> ::std::ffi::c_double,
>;

/// Function signature of an `xxx(...)` function returning a SQL int
pub type Udf_func_longlong = Option<
    unsafe extern "C" fn(
        initid: *mut UDF_INIT,
        args: *const UDF_ARGS,
        is_null: *mut ::std::ffi::c_uchar,
        error: *mut ::std::ffi::c_uchar,
    ) -> ::std::ffi::c_longlong,
>;

/// Function signature of an `xxx(...)` function returning a SQL string
pub type Udf_func_string = Option<
    unsafe extern "C" fn(
        initid: *mut UDF_INIT,
        args: *const UDF_ARGS,
        result: *mut ::std::ffi::c_char,
        length: *mut ::std::ffi::c_ulong,
        is_null: *mut ::std::ffi::c_uchar,
        error: *mut ::std::ffi::c_uchar,
    ) -> *mut ::std::ffi::c_char,
>;

/// Function signature of a void functin (unused)
pub type Udf_func_any = Option<unsafe extern "C" fn()>;

#[cfg(test)]
mod tests {

    use super::*;

    #[test]
    fn bindgen_test_layout_UDF_ARGS() {
        assert_eq!(
            ::std::mem::size_of::<UDF_ARGS>(),
            64usize,
            concat!("Size of: ", stringify!(UDF_ARGS))
        );
        assert_eq!(
            ::std::mem::align_of::<UDF_ARGS>(),
            8usize,
            concat!("Alignment of ", stringify!(UDF_ARGS))
        );
        fn test_field_arg_count() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).arg_count) as usize - ptr as usize
                },
                0usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(arg_count)
                )
            );
        }
        test_field_arg_count();
        fn test_field_arg_type() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).arg_type) as usize - ptr as usize
                },
                8usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(arg_type)
                )
            );
        }
        test_field_arg_type();
        fn test_field_args() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).args) as usize - ptr as usize
                },
                16usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(args)
                )
            );
        }
        test_field_args();
        fn test_field_lengths() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).lengths) as usize - ptr as usize
                },
                24usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(lengths)
                )
            );
        }
        test_field_lengths();
        fn test_field_maybe_null() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).maybe_null) as usize - ptr as usize
                },
                32usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(maybe_null)
                )
            );
        }
        test_field_maybe_null();
        fn test_field_attributes() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).attributes) as usize - ptr as usize
                },
                40usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(attributes)
                )
            );
        }
        test_field_attributes();
        fn test_field_attribute_lengths() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).attribute_lengths) as usize - ptr as usize
                },
                48usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(attribute_lengths)
                )
            );
        }
        test_field_attribute_lengths();
        fn test_field_extension() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_ARGS>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).extension) as usize - ptr as usize
                },
                56usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_ARGS),
                    "::",
                    stringify!(extension)
                )
            );
        }
        test_field_extension();
    }

    #[test]
    fn bindgen_test_layout_UDF_INIT() {
        assert_eq!(
            ::std::mem::size_of::<UDF_INIT>(),
            40usize,
            concat!("Size of: ", stringify!(UDF_INIT))
        );
        assert_eq!(
            ::std::mem::align_of::<UDF_INIT>(),
            8usize,
            concat!("Alignment of ", stringify!(UDF_INIT))
        );
        fn test_field_maybe_null() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_INIT>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).maybe_null) as usize - ptr as usize
                },
                0usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_INIT),
                    "::",
                    stringify!(maybe_null)
                )
            );
        }
        test_field_maybe_null();
        fn test_field_decimals() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_INIT>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).decimals) as usize - ptr as usize
                },
                4usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_INIT),
                    "::",
                    stringify!(decimals)
                )
            );
        }
        test_field_decimals();
        fn test_field_max_length() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_INIT>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).max_length) as usize - ptr as usize
                },
                8usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_INIT),
                    "::",
                    stringify!(max_length)
                )
            );
        }
        test_field_max_length();
        fn test_field_ptr() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_INIT>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize
                },
                16usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_INIT),
                    "::",
                    stringify!(ptr)
                )
            );
        }
        test_field_ptr();
        fn test_field_const_item() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_INIT>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).const_item) as usize - ptr as usize
                },
                24usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_INIT),
                    "::",
                    stringify!(const_item)
                )
            );
        }
        test_field_const_item();
        fn test_field_extension() {
            assert_eq!(
                unsafe {
                    let uninit = ::std::mem::MaybeUninit::<UDF_INIT>::uninit();
                    let ptr = uninit.as_ptr();
                    ::std::ptr::addr_of!((*ptr).extension) as usize - ptr as usize
                },
                32usize,
                concat!(
                    "Offset of field: ",
                    stringify!(UDF_INIT),
                    "::",
                    stringify!(extension)
                )
            );
        }
        test_field_extension();
    }
}