-
Notifications
You must be signed in to change notification settings - Fork 15
/
third_party.h
19955 lines (18680 loc) · 526 KB
/
third_party.h
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Third-party code that may optionally be included with ocelotgui
Last modified: 2020-09-23
This code is not required. It does not have to be brought in for Ocelot's default
configuration as a MySQL/MariaDB client.
To see if it is brought in, see comments in ocelotgui.h before
"#ifndef OCELOT_THIRD_PARTY".
The contents of this file are copied from files in
https://github.com/tarantool/tarantool-c
The LICENSE of that directory is the BSD 2-clause license.
There are also some public domain and MIT-license files.
The copying of each file is done as follows:
There is a "COPY:" note about the file name, the copying date,
and all changes from the original (usually the only changes
are removals of #includes since now there is only one file).
Then the file contents.
Peter Gulutzan is not the primary author of the
code in this file, and only claims rights to the changes it wrote.
It was copied to make builds of ocelotgui on non-Linux platforms
easier. Anyone who wishes to use the code for any other purpose
should go to the current upstream github repository.
All notes, disclaimers, and licenses in this file apply
only to the code in this file and not to the rest of the
ocelotgui code, which is licensed as GPL version 2 unless
otherwise specified.
*/
/* COPY:
Changes: All THIRD_PARTY functions are affected by the
following #pragmas because our compiler is not basic C and
our usual assumption is that -fpermissive is on.
There is a "diagnostic pop" at the end of this file.
MinGW ignores #pragma
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431
but for MinGW we changed CMakeLists.txt.
Update August 2018: Alas GCC 7 won't let us turn off fpermissive, so explicit casts have been added
in about 100 places. But now we shouldn't need
#pragma GCC diagnostic warning "-fpermissive"
#pragma GCC diagnostic ignored "-pedantic"
Update March 2023: A warning is happening with -Wall and newish compiler on Fedora 37,
I disable -Warray-bounds because I don't understand the problem. todo: revisit soon
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-arith"
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Warray-bounds"
#if defined(__GNUC__) && (__GNUC__ >= 7)
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
/* COPY:
Changes: Windows doesn't have the same #includes as Linux.
We commented out these #includes for all file copies in this file.
We added these definitions in our attempts to work around.
This is only for MinGW.
See also https://msdn.microsoft.com/en-us/library/windows/desktop/ms737593(v=vs.85).aspx
and https://stackoverflow.com/questions/4243027/winsock-compiling-error-it-cant-find-the-addrinfo-structures-and-some-relating
We changed "#line ..." to "//#line ..." so we could see compiler errors more clearly.
Todo: "#define _WIN32_WINNT 0x0501" (Windows XP) causes warnings. Should I #undef it later?
*/
#ifndef WINDOWS_KLUDGE_H
#define WINDOWS_KLUDGE_H
#ifdef WIN32
#define _WIN32_WINNT 0x501
#include <ws2tcpip.h>
#include <Winsock2.h>
struct iovec {
void *iov_base;
unsigned long iov_len;
};
#define _POSIX_PATH_MAX 256 /* as in ./bits/posix1_lim.h */
#define NI_MAXHOST 1025 /* as in netdb.h */
struct sockaddr_un {
unsigned short sun_family;
char sun_path[108];
};
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <netinet/tcp.h>
#endif
#endif
/*
COPY: file name = third_party/base64.h.
Copying Date = 2017-09-14.
Changes: none.
*/
#ifndef BASE64_H
#define BASE64_H
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* This is part of the libb64 project, and has been placed in the
* public domain. For details, see
* http://sourceforge.net/projects/libb64
*/
#ifdef __cplusplus
//extern "C" {
#endif
#define BASE64_CHARS_PER_LINE 72
static inline int
base64_bufsize(int binsize)
{
int datasize = binsize * 4/3 + 4;
int newlines = ((datasize + BASE64_CHARS_PER_LINE - 1)/
BASE64_CHARS_PER_LINE);
return datasize + newlines;
}
/**
* Encode a binary stream into BASE64 text.
*
* @pre the buffer size is at least 4/3 of the stream
* size + stream_size/72 (newlines) + 4
*
* @param[in] in_bin the binary input stream to decode
* @param[in] in_len size of the input
* @param[out] out_base64 output buffer for the encoded data
* @param[in] out_len buffer size, must be at least
* 4/3 of the input size
*
* @return the size of encoded output
*/
int
base64_encode(const char *in_bin, int in_len,
char *out_base64, int out_len);
/**
* Decode a BASE64 text into a binary
*
* @param[in] in_base64 the BASE64 stream to decode
* @param[in] in_len size of the input
* @param[out] out_bin output buffer size
* @param[in] out_len buffer size
*
* @pre the output buffer size must be at least
* 3/4 + 1 of the size of the input
*
* @return the size of decoded output
*/
int base64_decode(const char *in_base64, int in_len,
char *out_bin, int out_len);
#ifdef __cplusplus
//} /* extern "C" */
#endif
#endif /* BASE64_H */
/*
COPY: file name = third_party/PMurHash.h.
Copying Date = 2017-09-14.
Changes: none.
*/
#ifndef THIRD_PARTY_PMURHASH_H_
#define THIRD_PARTY_PMURHASH_H_
/*-----------------------------------------------------------------------------
* MurmurHash3 was written by Austin Appleby, and is placed in the public
* domain.
*
* This implementation was written by Shane Day, and is also public domain.
*
* This is a portable ANSI C implementation of MurmurHash3_x86_32 (Murmur3A)
* with support for progressive processing.
*/
/* ------------------------------------------------------------------------- */
/* Determine what native type to use for uint32_t */
/* We can't use the name 'uint32_t' here because it will conflict with
* any version provided by the system headers or application. */
/* First look for special cases */
#if defined(_MSC_VER)
#define MH_UINT32 unsigned long
#endif
/* If the compiler says it's C99 then take its word for it */
#if !defined(MH_UINT32) && ( \
defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L )
#include <stdint.h>
#define MH_UINT32 uint32_t
#endif
/* Otherwise try testing against max value macros from limit.h */
#if !defined(MH_UINT32)
#include <limits.h>
#if (USHRT_MAX == 0xffffffffUL)
#define MH_UINT32 unsigned short
#elif (UINT_MAX == 0xffffffffUL)
#define MH_UINT32 unsigned int
#elif (ULONG_MAX == 0xffffffffUL)
#define MH_UINT32 unsigned long
#endif
#endif
#if !defined(MH_UINT32)
#error Unable to determine type name for unsigned 32-bit int
#endif
/* I'm yet to work on a platform where 'unsigned char' is not 8 bits */
#define MH_UINT8 unsigned char
/* ------------------------------------------------------------------------- */
/* Prototypes */
#ifdef __cplusplus
//extern "C" {
#endif
void PMurHash32_Process(MH_UINT32 *ph1, MH_UINT32 *pcarry, const void *key, int len);
MH_UINT32 PMurHash32_Result(MH_UINT32 h1, MH_UINT32 carry, MH_UINT32 total_length);
MH_UINT32 PMurHash32(MH_UINT32 seed, const void *key, int len);
void PMurHash32_test(const void *key, int len, MH_UINT32 seed, void *out);
#ifdef __cplusplus
//}
#endif
#endif
/*
COPY: file name = include/tarantool/tnt_call.h.
Copying Date = 2017-09-14.
Changes: none.
*/
#ifndef TNT_CALL_H_INCLUDED
#define TNT_CALL_H_INCLUDED
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/**
* \file tnt_call.h
* \brief Call request
*/
/**
* \brief Construct call request and write it into stream
*
* \param s stream object to write request to
* \param proc procedure to call
* \param plen procedure length
* \param args tnt_object instance with messagepack array with args to call
* procedure with
*
* \retval number of bytes written to stream
*/
ssize_t
tnt_call(struct tnt_stream *s, const char *proc, size_t plen,
struct tnt_stream *args);
/**
* \brief Construct call request and write it into stream
* Version for Tarantool 1.6
*
* \param s stream object to write request to
* \param proc procedure to call
* \param plen procedure length
* \param args tnt_object instance with messagepack array with args to call
* procedure with
*
* \retval number of bytes written to stream
*/
ssize_t
tnt_call_16(struct tnt_stream *s, const char *proc, size_t proc_len,
struct tnt_stream *args);
/**
* \brief Construct eval request and write it into stream
*
* \param s stream object to write request to
* \param expr expression to evaluate
* \param elen expression length
* \param args tnt_object instance with messagepack array with args to eval
* expression with
*
* \retval number of bytes written to stream
*/
ssize_t
tnt_eval(struct tnt_stream *s, const char *expr, size_t elen,
struct tnt_stream *args);
#endif /* TNT_CALL_H_INCLUDED */
/*
COPY: file name = include/tarantool/tnt_delete.h.
Copying Date = 2017-09-14.
Changes: none.
*/
#ifndef TNT_DELETE_H_INCLUDED
#define TNT_DELETE_H_INCLUDED
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/**
* \file tnt_delete.h
* \brief Delete request
*/
/**
* \brief Write delete request to stream
*
* \param s stream instance
* \param space space number to delete object from
* \param index index to search key in
* \param key key to delete tuple with
*
* \retval number of bytes written to stream
*/
ssize_t
tnt_delete(struct tnt_stream *s, uint32_t space, uint32_t index,
struct tnt_stream *key);
#endif /* TNT_DELETE_H_INCLUDED */
/*
COPY: file name = include/tarantool/tnt_execute.h.
Copying date = 2020-09-23.
Changes: none.
*/
#ifndef TNT_EXECUTE_H_INCLUDED
#define TNT_EXECUTE_H_INCLUDED
/**
* \file tnt_execute.h
* \brief SQL execution request
*/
/**
* \brief Construct SQL request and write it into stream
*
* \param s stream object to write request to
* \param expr SQL query string
* \param elen query length
* \param args tnt_object instance with messagepack array with params
* to bind to the request
*
* \retval number of bytes written to stream
*/
ssize_t
tnt_execute(struct tnt_stream *s, const char *expr, size_t elen,
struct tnt_stream *params);
#endif /* TNT_EXECUTE_H_INCLUDED */
/*
COPY: file name = include/tarantool/tnt_insert.h.
Copying Date = 2017-09-14.
Changes: none.
*/
#ifndef TNT_INSERT_H_INCLUDED
#define TNT_INSERT_H_INCLUDED
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/**
* \file tnt_insert.h
* \brief Insert/Replace request
*/
/**
* \brief Construct insert request and write it into stream
*
* \param s stream object to write request to
* \param space space no to insert tuple into
* \param tuple (tnt_object instance) msgpack array with tuple to insert to
*
* \retval number of bytes written to stream
*/
ssize_t
tnt_insert(struct tnt_stream *s, uint32_t space, struct tnt_stream *tuple);
/**
* \brief Construct replace request and write it into stream
*
* \param s stream object to write request to
* \param space space no to replace tuple into
* \param tuple (tnt_object instance) msgpack array with tuple to replace to
*
* \retval number of bytes written to stream
*/
ssize_t
tnt_replace(struct tnt_stream *s, uint32_t space, struct tnt_stream *tuple);
#endif /* TNT_INSERT_H_INCLUDED */
/*
COPY: file name = include/tarantool/tnt_update.h.
Copying Date = 2017-09-14.
Changes: none.
*/
#ifndef TNT_UPDATE_H_INCLUDED
#define TNT_UPDATE_H_INCLUDED
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
//#include <tarantool/tnt_stream.h>
/**
* \file tnt_update.h
* \brief Update operation
*/
/**
* \brief Generate and write update operation with predefined
*
* \param s stream pointer
* \param space space no
* \param index index no
* \param key key to update
* \param ops ops to update (tnt_object)
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update(struct tnt_stream *s, uint32_t space, uint32_t index,
struct tnt_stream *key, struct tnt_stream *ops);
/**
* \brief Add bit operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param op operation ('&', '|', '^')
* \param value value for update op
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_bit(struct tnt_stream *ops, uint32_t fieldno, char op,
uint64_t value);
/**
* \brief Add int arithmetic operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param op operation ('+', '-')
* \param value value for update op
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_arith_int(struct tnt_stream *ops, uint32_t fieldno, char op,
int64_t value);
/**
* \brief Add float arithmetic operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param op operation ('+', '-')
* \param value value for update op
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_arith_float(struct tnt_stream *ops, uint32_t fieldno, char op,
float value);
/**
* \brief Add double arithmetic operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param op operation ('+', '-')
* \param value value for update op
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_arith_double(struct tnt_stream *ops, uint32_t fieldno, char op,
double value);
/**
* \brief Add delete operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param fieldco field count
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_delete(struct tnt_stream *ops, uint32_t fieldno,
uint32_t fieldco);
/**
* \brief Add insert before operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param val value to insert (tnt_object)
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_insert(struct tnt_stream *ops, uint32_t fieldno,
struct tnt_stream *val);
/**
* \brief Add assign operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param val value to assign (tnt_object)
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_assign(struct tnt_stream *ops, uint32_t fieldno,
struct tnt_stream *val);
/**
* \brief Add splice operation for update to tnt_object
*
* \param ops operation container
* \param fieldno field number
* \param position cut from
* \param offset number of bytes to cut
* \param buffer buffer to insert instead
* \param buffer_len buffer length
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_update_splice(struct tnt_stream *ops, uint32_t fieldno,
uint32_t position, uint32_t offset,
const char *buffer, size_t buffer_len);
/**
* \brief shortcut for tnt_object() with type == TNT_SBO_SPARSE
*/
struct tnt_stream *tnt_update_container(struct tnt_stream *ops);
/**
* \brief shortcut for tnt_object_container_close()
*/
struct tnt_stream *
tnt_update_container(struct tnt_stream *ops);
int tnt_update_container_close(struct tnt_stream *ops);
int tnt_update_container_reset(struct tnt_stream *ops);
/**
* \brief Generate and write upsert operation with predefined
*
* \param s stream pointer
* \param space space no
* \param tuple (tnt_object instance) msgpack array with tuple to insert to
* \param ops ops to update (tnt_object)
*
* \returns count of bytes written
* \retval -1 oom
* \sa tnt_update_cointainer
* \sa tnt_update_cointainer_close
*/
ssize_t
tnt_upsert(struct tnt_stream *s, uint32_t space,
struct tnt_stream *tuple, struct tnt_stream *ops);
#endif /* TNT_UPDATE_H_INCLUDED */
/*
COPY: file name = include/tarantool/tnt_mem.h.
Copying Date = 2017-09-14.
Changes: none.
*/
#ifndef TNT_MEM_H_INCLUDED
#define TNT_MEM_H_INCLUDED
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/**
* \internal
* \file tnt_mem.h
* \brief Basic memory functions
*/
#define tntfunction_unused __attribute__((unused))
#if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || \
defined __SUNPRO_C || defined __SUNPRO_CC
#define TNT_GCC_VERSION(major, minor) 0
#else
#define TNT_GCC_VERSION(major, minor) (__GNUC__ > (major) || \
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
#endif
#if !defined(__has_builtin)
#define __has_builtin(x) 0 /* clang */
#endif
#if TNT_GCC_VERSION(2, 9) || __has_builtin(__builtin_expect)
#define tntlikely(x) __builtin_expect(!!(x), 1)
#define tntunlikely(x) __builtin_expect(!!(x), 0)
#else
#define tntlikely(x) (x)
#define tntunlikely(x) (x)
#endif
/**
* \brief basic allocation function type
*
* \param ptr pointer to allocation/deallocation block
* \param size size of block to allocat/reallocate
*
* \retval pointer to newly alloced/realloced block
* \retval NULL on error/free
*/
typedef void *(tnt_allocator_t)(void *ptr, size_t size);
/**
* \brief initialize memory allocation function
*/
void *
tnt_mem_init(tnt_allocator_t alloc);
/**
* \brief Internal function
*/
void *
tnt_mem_alloc(size_t size);
/**
* \brief Internal function
*/
void *
tnt_mem_realloc(void *ptr, size_t size);
/**
* \brief Internal function
*/
char *
tnt_mem_dup(char *sz);
/**
* \brief Internal function
*/
void
tnt_mem_free(void *ptr);
#endif /* TNT_MEM_H_INCLUDED */
/*
COPY: file name = /tnt/tnt_assoc.h.
Copying Date = 2017-09-14.
Changes: added ifndef ... endif
Commented out three #undefs.
#include <mhash.h> is included in the middle of tnt_assoc.h
The MH_SOURCE section of tnt/tnt_assoc.h is copied to tnt/tnt_assoc.c.
*/
#ifndef TS_ASSOC_H_INCLUDED
#define TS_ASSOC_H_INCLUDED
#if defined(__cplusplus)
//extern "C" {
#endif /* defined(__cplusplus) */
struct assoc_key {
const char *id;
uint32_t id_len;
};
struct assoc_val {
struct assoc_key key;
void *data;
};
static inline int
mh_cmp_eq(
const struct assoc_val **lval,
const struct assoc_val **rval,
void *arg) {
(void )arg;
if ((*lval)->key.id_len != (*rval)->key.id_len) return 0;
return !memcmp((*lval)->key.id, (*rval)->key.id, (*rval)->key.id_len);
}
static inline int
mh_cmp_key_eq(
const struct assoc_key *key,
const struct assoc_val **val,
void *arg) {
(void )arg;
if (key->id_len != (*val)->key.id_len) return 0;
return !memcmp(key->id, (*val)->key.id, key->id_len);
}
static inline void *
tnt_mem_calloc(size_t count, size_t size) {
size_t sz = count * size;
void *alloc = tnt_mem_alloc(sz);
if (!alloc) return 0;
memset(alloc, 0, sz);
return alloc;
}
#define mh_arg_t void *
#define mh_eq(a, b, arg) mh_cmp_eq(a, b, arg)
#define mh_eq_key(a, b, arg) mh_cmp_key_eq(a, b, arg)
#define mh_hash(x, arg) PMurHash32(MUR_SEED, (*x)->key.id, (*x)->key.id_len)
#define mh_hash_key(x, arg) PMurHash32(MUR_SEED, (x)->id, (x)->id_len);
/* type for hash value */
#define mh_node_t struct assoc_val *
/* type for hash key */
#define mh_key_t const struct assoc_key *
#define MH_CALLOC(x, y) tnt_mem_calloc((x), (y))
#define MH_FREE(x) tnt_mem_free((x))
#define mh_name _assoc
#define MUR_SEED 13
//#include <PMurHash.h>
//#include <mhash.h>
/*
COPY: file name = mhash.h.
Copying Date = 2017-09-14.
Changes: none.
#include <mhash.h> is included in the middle of tnt_assoc.h
*/
#ifndef MHASH_H_INCLUDED
#define MHASH_H_INCLUDED
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* The MIT License
Copyright (c) 2008, by Attractive Chaos <attractivechaos@aol.co.uk>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef MH_INCREMENTAL_RESIZE
#define MH_INCREMENTAL_RESIZE 1
#endif
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
#define mh_cat(a, b) mh##a##_##b
#define mh_ecat(a, b) mh_cat(a, b)
#define _mh(x) mh_ecat(mh_name, x)