OSDN Git Service

03283de718021b672db78478182a679a515c8a13
[android-x86/external-mesa.git] / src / util / ralloc.c
1 /*
2  * Copyright © 2010 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdint.h>
30
31 /* Android defines SIZE_MAX in limits.h, instead of the standard stdint.h */
32 #ifdef ANDROID
33 #include <limits.h>
34 #endif
35
36 /* Some versions of MinGW are missing _vscprintf's declaration, although they
37  * still provide the symbol in the import library. */
38 #ifdef __MINGW32__
39 _CRTIMP int _vscprintf(const char *format, va_list argptr);
40 #endif
41
42 #include "ralloc.h"
43
44 #ifndef va_copy
45 #ifdef __va_copy
46 #define va_copy(dest, src) __va_copy((dest), (src))
47 #else
48 #define va_copy(dest, src) (dest) = (src)
49 #endif
50 #endif
51
52 #define CANARY 0x5A1106
53
54 /* Align the header's size so that ralloc() allocations will return with the
55  * same alignment as a libc malloc would have (8 on 32-bit GLIBC, 16 on
56  * 64-bit), avoiding performance penalities on x86 and alignment faults on
57  * ARM.
58  */
59 struct
60 #ifdef _MSC_VER
61  __declspec(align(8))
62 #else
63  __attribute__((aligned))
64 #endif
65    ralloc_header
66 {
67 #ifdef DEBUG
68    /* A canary value used to determine whether a pointer is ralloc'd. */
69    unsigned canary;
70 #endif
71
72    struct ralloc_header *parent;
73
74    /* The first child (head of a linked list) */
75    struct ralloc_header *child;
76
77    /* Linked list of siblings */
78    struct ralloc_header *prev;
79    struct ralloc_header *next;
80
81    void (*destructor)(void *);
82 };
83
84 typedef struct ralloc_header ralloc_header;
85
86 static void unlink_block(ralloc_header *info);
87 static void unsafe_free(ralloc_header *info);
88
89 static ralloc_header *
90 get_header(const void *ptr)
91 {
92    ralloc_header *info = (ralloc_header *) (((char *) ptr) -
93                                             sizeof(ralloc_header));
94 #ifdef DEBUG
95    assert(info->canary == CANARY);
96 #endif
97    return info;
98 }
99
100 #define PTR_FROM_HEADER(info) (((char *) info) + sizeof(ralloc_header))
101
102 static void
103 add_child(ralloc_header *parent, ralloc_header *info)
104 {
105    if (parent != NULL) {
106       info->parent = parent;
107       info->next = parent->child;
108       parent->child = info;
109
110       if (info->next != NULL)
111          info->next->prev = info;
112    }
113 }
114
115 void *
116 ralloc_context(const void *ctx)
117 {
118    return ralloc_size(ctx, 0);
119 }
120
121 void *
122 ralloc_size(const void *ctx, size_t size)
123 {
124    void *block = malloc(size + sizeof(ralloc_header));
125    ralloc_header *info;
126    ralloc_header *parent;
127
128    if (unlikely(block == NULL))
129       return NULL;
130
131    info = (ralloc_header *) block;
132    /* measurements have shown that calloc is slower (because of
133     * the multiplication overflow checking?), so clear things
134     * manually
135     */
136    info->parent = NULL;
137    info->child = NULL;
138    info->prev = NULL;
139    info->next = NULL;
140    info->destructor = NULL;
141
142    parent = ctx != NULL ? get_header(ctx) : NULL;
143
144    add_child(parent, info);
145
146 #ifdef DEBUG
147    info->canary = CANARY;
148 #endif
149
150    return PTR_FROM_HEADER(info);
151 }
152
153 void *
154 rzalloc_size(const void *ctx, size_t size)
155 {
156    void *ptr = ralloc_size(ctx, size);
157
158    if (likely(ptr))
159       memset(ptr, 0, size);
160
161    return ptr;
162 }
163
164 /* helper function - assumes ptr != NULL */
165 static void *
166 resize(void *ptr, size_t size)
167 {
168    ralloc_header *child, *old, *info;
169
170    old = get_header(ptr);
171    info = realloc(old, size + sizeof(ralloc_header));
172
173    if (info == NULL)
174       return NULL;
175
176    /* Update parent and sibling's links to the reallocated node. */
177    if (info != old && info->parent != NULL) {
178       if (info->parent->child == old)
179          info->parent->child = info;
180
181       if (info->prev != NULL)
182          info->prev->next = info;
183
184       if (info->next != NULL)
185          info->next->prev = info;
186    }
187
188    /* Update child->parent links for all children */
189    for (child = info->child; child != NULL; child = child->next)
190       child->parent = info;
191
192    return PTR_FROM_HEADER(info);
193 }
194
195 void *
196 reralloc_size(const void *ctx, void *ptr, size_t size)
197 {
198    if (unlikely(ptr == NULL))
199       return ralloc_size(ctx, size);
200
201    assert(ralloc_parent(ptr) == ctx);
202    return resize(ptr, size);
203 }
204
205 void *
206 ralloc_array_size(const void *ctx, size_t size, unsigned count)
207 {
208    if (count > SIZE_MAX/size)
209       return NULL;
210
211    return ralloc_size(ctx, size * count);
212 }
213
214 void *
215 rzalloc_array_size(const void *ctx, size_t size, unsigned count)
216 {
217    if (count > SIZE_MAX/size)
218       return NULL;
219
220    return rzalloc_size(ctx, size * count);
221 }
222
223 void *
224 reralloc_array_size(const void *ctx, void *ptr, size_t size, unsigned count)
225 {
226    if (count > SIZE_MAX/size)
227       return NULL;
228
229    return reralloc_size(ctx, ptr, size * count);
230 }
231
232 void
233 ralloc_free(void *ptr)
234 {
235    ralloc_header *info;
236
237    if (ptr == NULL)
238       return;
239
240    info = get_header(ptr);
241    unlink_block(info);
242    unsafe_free(info);
243 }
244
245 static void
246 unlink_block(ralloc_header *info)
247 {
248    /* Unlink from parent & siblings */
249    if (info->parent != NULL) {
250       if (info->parent->child == info)
251          info->parent->child = info->next;
252
253       if (info->prev != NULL)
254          info->prev->next = info->next;
255
256       if (info->next != NULL)
257          info->next->prev = info->prev;
258    }
259    info->parent = NULL;
260    info->prev = NULL;
261    info->next = NULL;
262 }
263
264 static void
265 unsafe_free(ralloc_header *info)
266 {
267    /* Recursively free any children...don't waste time unlinking them. */
268    ralloc_header *temp;
269    while (info->child != NULL) {
270       temp = info->child;
271       info->child = temp->next;
272       unsafe_free(temp);
273    }
274
275    /* Free the block itself.  Call the destructor first, if any. */
276    if (info->destructor != NULL)
277       info->destructor(PTR_FROM_HEADER(info));
278
279    free(info);
280 }
281
282 void
283 ralloc_steal(const void *new_ctx, void *ptr)
284 {
285    ralloc_header *info, *parent;
286
287    if (unlikely(ptr == NULL))
288       return;
289
290    info = get_header(ptr);
291    parent = get_header(new_ctx);
292
293    unlink_block(info);
294
295    add_child(parent, info);
296 }
297
298 void
299 ralloc_adopt(const void *new_ctx, void *old_ctx)
300 {
301    ralloc_header *new_info, *old_info, *child;
302
303    if (unlikely(old_ctx == NULL))
304       return;
305
306    old_info = get_header(old_ctx);
307    new_info = get_header(new_ctx);
308
309    /* If there are no children, bail. */
310    if (unlikely(old_info->child == NULL))
311       return;
312
313    /* Set all the children's parent to new_ctx; get a pointer to the last child. */
314    for (child = old_info->child; child->next != NULL; child = child->next) {
315       child->parent = new_info;
316    }
317
318    /* Connect the two lists together; parent them to new_ctx; make old_ctx empty. */
319    child->next = new_info->child;
320    child->parent = new_info;
321    new_info->child = old_info->child;
322    old_info->child = NULL;
323 }
324
325 void *
326 ralloc_parent(const void *ptr)
327 {
328    ralloc_header *info;
329
330    if (unlikely(ptr == NULL))
331       return NULL;
332
333    info = get_header(ptr);
334    return info->parent ? PTR_FROM_HEADER(info->parent) : NULL;
335 }
336
337 void
338 ralloc_set_destructor(const void *ptr, void(*destructor)(void *))
339 {
340    ralloc_header *info = get_header(ptr);
341    info->destructor = destructor;
342 }
343
344 char *
345 ralloc_strdup(const void *ctx, const char *str)
346 {
347    size_t n;
348    char *ptr;
349
350    if (unlikely(str == NULL))
351       return NULL;
352
353    n = strlen(str);
354    ptr = ralloc_array(ctx, char, n + 1);
355    memcpy(ptr, str, n);
356    ptr[n] = '\0';
357    return ptr;
358 }
359
360 char *
361 ralloc_strndup(const void *ctx, const char *str, size_t max)
362 {
363    size_t n;
364    char *ptr;
365
366    if (unlikely(str == NULL))
367       return NULL;
368
369    n = strnlen(str, max);
370    ptr = ralloc_array(ctx, char, n + 1);
371    memcpy(ptr, str, n);
372    ptr[n] = '\0';
373    return ptr;
374 }
375
376 /* helper routine for strcat/strncat - n is the exact amount to copy */
377 static bool
378 cat(char **dest, const char *str, size_t n)
379 {
380    char *both;
381    size_t existing_length;
382    assert(dest != NULL && *dest != NULL);
383
384    existing_length = strlen(*dest);
385    both = resize(*dest, existing_length + n + 1);
386    if (unlikely(both == NULL))
387       return false;
388
389    memcpy(both + existing_length, str, n);
390    both[existing_length + n] = '\0';
391
392    *dest = both;
393    return true;
394 }
395
396
397 bool
398 ralloc_strcat(char **dest, const char *str)
399 {
400    return cat(dest, str, strlen(str));
401 }
402
403 bool
404 ralloc_strncat(char **dest, const char *str, size_t n)
405 {
406    /* Clamp n to the string length */
407    size_t str_length = strlen(str);
408    if (str_length < n)
409       n = str_length;
410
411    return cat(dest, str, n);
412 }
413
414 char *
415 ralloc_asprintf(const void *ctx, const char *fmt, ...)
416 {
417    char *ptr;
418    va_list args;
419    va_start(args, fmt);
420    ptr = ralloc_vasprintf(ctx, fmt, args);
421    va_end(args);
422    return ptr;
423 }
424
425 /* Return the length of the string that would be generated by a printf-style
426  * format and argument list, not including the \0 byte.
427  */
428 static size_t
429 printf_length(const char *fmt, va_list untouched_args)
430 {
431    int size;
432    char junk;
433
434    /* Make a copy of the va_list so the original caller can still use it */
435    va_list args;
436    va_copy(args, untouched_args);
437
438 #ifdef _WIN32
439    /* We need to use _vcsprintf to calculate the size as vsnprintf returns -1
440     * if the number of characters to write is greater than count.
441     */
442    size = _vscprintf(fmt, args);
443    (void)junk;
444 #else
445    size = vsnprintf(&junk, 1, fmt, args);
446 #endif
447    assert(size >= 0);
448
449    va_end(args);
450
451    return size;
452 }
453
454 char *
455 ralloc_vasprintf(const void *ctx, const char *fmt, va_list args)
456 {
457    size_t size = printf_length(fmt, args) + 1;
458
459    char *ptr = ralloc_size(ctx, size);
460    if (ptr != NULL)
461       vsnprintf(ptr, size, fmt, args);
462
463    return ptr;
464 }
465
466 bool
467 ralloc_asprintf_append(char **str, const char *fmt, ...)
468 {
469    bool success;
470    va_list args;
471    va_start(args, fmt);
472    success = ralloc_vasprintf_append(str, fmt, args);
473    va_end(args);
474    return success;
475 }
476
477 bool
478 ralloc_vasprintf_append(char **str, const char *fmt, va_list args)
479 {
480    size_t existing_length;
481    assert(str != NULL);
482    existing_length = *str ? strlen(*str) : 0;
483    return ralloc_vasprintf_rewrite_tail(str, &existing_length, fmt, args);
484 }
485
486 bool
487 ralloc_asprintf_rewrite_tail(char **str, size_t *start, const char *fmt, ...)
488 {
489    bool success;
490    va_list args;
491    va_start(args, fmt);
492    success = ralloc_vasprintf_rewrite_tail(str, start, fmt, args);
493    va_end(args);
494    return success;
495 }
496
497 bool
498 ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt,
499                               va_list args)
500 {
501    size_t new_length;
502    char *ptr;
503
504    assert(str != NULL);
505
506    if (unlikely(*str == NULL)) {
507       // Assuming a NULL context is probably bad, but it's expected behavior.
508       *str = ralloc_vasprintf(NULL, fmt, args);
509       *start = strlen(*str);
510       return true;
511    }
512
513    new_length = printf_length(fmt, args);
514
515    ptr = resize(*str, *start + new_length + 1);
516    if (unlikely(ptr == NULL))
517       return false;
518
519    vsnprintf(ptr + *start, new_length + 1, fmt, args);
520    *str = ptr;
521    *start += new_length;
522    return true;
523 }
524
525 /***************************************************************************
526  * Linear allocator for short-lived allocations.
527  ***************************************************************************
528  *
529  * The allocator consists of a parent node (2K buffer), which requires
530  * a ralloc parent, and child nodes (allocations). Child nodes can't be freed
531  * directly, because the parent doesn't track them. You have to release
532  * the parent node in order to release all its children.
533  *
534  * The allocator uses a fixed-sized buffer with a monotonically increasing
535  * offset after each allocation. If the buffer is all used, another buffer
536  * is allocated, sharing the same ralloc parent, so all buffers are at
537  * the same level in the ralloc hierarchy.
538  *
539  * The linear parent node is always the first buffer and keeps track of all
540  * other buffers.
541  */
542
543 #define ALIGN_POT(x, y) (((x) + (y) - 1) & ~((y) - 1))
544
545 #define MIN_LINEAR_BUFSIZE 2048
546 #define SUBALLOC_ALIGNMENT sizeof(uintptr_t)
547 #define LMAGIC 0x87b9c7d3
548
549 struct linear_header {
550 #ifdef DEBUG
551    unsigned magic;   /* for debugging */
552 #endif
553    unsigned offset;  /* points to the first unused byte in the buffer */
554    unsigned size;    /* size of the buffer */
555    void *ralloc_parent;          /* new buffers will use this */
556    struct linear_header *next;   /* next buffer if we have more */
557    struct linear_header *latest; /* the only buffer that has free space */
558
559    /* After this structure, the buffer begins.
560     * Each suballocation consists of linear_size_chunk as its header followed
561     * by the suballocation, so it goes:
562     *
563     * - linear_size_chunk
564     * - allocated space
565     * - linear_size_chunk
566     * - allocated space
567     * etc.
568     *
569     * linear_size_chunk is only needed by linear_realloc.
570     */
571 };
572
573 struct linear_size_chunk {
574    unsigned size; /* for realloc */
575    unsigned _padding;
576 };
577
578 typedef struct linear_header linear_header;
579 typedef struct linear_size_chunk linear_size_chunk;
580
581 #define LINEAR_PARENT_TO_HEADER(parent) \
582    (linear_header*) \
583    ((char*)(parent) - sizeof(linear_size_chunk) - sizeof(linear_header))
584
585 /* Allocate the linear buffer with its header. */
586 static linear_header *
587 create_linear_node(void *ralloc_ctx, unsigned min_size)
588 {
589    linear_header *node;
590
591    min_size += sizeof(linear_size_chunk);
592
593    if (likely(min_size < MIN_LINEAR_BUFSIZE))
594       min_size = MIN_LINEAR_BUFSIZE;
595
596    node = ralloc_size(ralloc_ctx, sizeof(linear_header) + min_size);
597    if (unlikely(!node))
598       return NULL;
599
600 #ifdef DEBUG
601    node->magic = LMAGIC;
602 #endif
603    node->offset = 0;
604    node->size = min_size;
605    node->ralloc_parent = ralloc_ctx;
606    node->next = NULL;
607    node->latest = node;
608    return node;
609 }
610
611 void *
612 linear_alloc_child(void *parent, unsigned size)
613 {
614    linear_header *first = LINEAR_PARENT_TO_HEADER(parent);
615    linear_header *latest = first->latest;
616    linear_header *new_node;
617    linear_size_chunk *ptr;
618    unsigned full_size;
619
620    assert(first->magic == LMAGIC);
621    assert(!latest->next);
622
623    size = ALIGN_POT(size, SUBALLOC_ALIGNMENT);
624    full_size = sizeof(linear_size_chunk) + size;
625
626    if (unlikely(latest->offset + full_size > latest->size)) {
627       /* allocate a new node */
628       new_node = create_linear_node(latest->ralloc_parent, size);
629       if (unlikely(!new_node))
630          return NULL;
631
632       first->latest = new_node;
633       latest->latest = new_node;
634       latest->next = new_node;
635       latest = new_node;
636    }
637
638    ptr = (linear_size_chunk *)((char*)&latest[1] + latest->offset);
639    ptr->size = size;
640    latest->offset += full_size;
641    return &ptr[1];
642 }
643
644 void *
645 linear_alloc_parent(void *ralloc_ctx, unsigned size)
646 {
647    linear_header *node;
648
649    if (unlikely(!ralloc_ctx))
650       return NULL;
651
652    size = ALIGN_POT(size, SUBALLOC_ALIGNMENT);
653
654    node = create_linear_node(ralloc_ctx, size);
655    if (unlikely(!node))
656       return NULL;
657
658    return linear_alloc_child((char*)node +
659                              sizeof(linear_header) +
660                              sizeof(linear_size_chunk), size);
661 }
662
663 void *
664 linear_zalloc_child(void *parent, unsigned size)
665 {
666    void *ptr = linear_alloc_child(parent, size);
667
668    if (likely(ptr))
669       memset(ptr, 0, size);
670    return ptr;
671 }
672
673 void *
674 linear_zalloc_parent(void *parent, unsigned size)
675 {
676    void *ptr = linear_alloc_parent(parent, size);
677
678    if (likely(ptr))
679       memset(ptr, 0, size);
680    return ptr;
681 }
682
683 void
684 linear_free_parent(void *ptr)
685 {
686    linear_header *node;
687
688    if (unlikely(!ptr))
689       return;
690
691    node = LINEAR_PARENT_TO_HEADER(ptr);
692    assert(node->magic == LMAGIC);
693
694    while (node) {
695       void *ptr = node;
696
697       node = node->next;
698       ralloc_free(ptr);
699    }
700 }
701
702 void
703 ralloc_steal_linear_parent(void *new_ralloc_ctx, void *ptr)
704 {
705    linear_header *node;
706
707    if (unlikely(!ptr))
708       return;
709
710    node = LINEAR_PARENT_TO_HEADER(ptr);
711    assert(node->magic == LMAGIC);
712
713    while (node) {
714       ralloc_steal(new_ralloc_ctx, node);
715       node->ralloc_parent = new_ralloc_ctx;
716       node = node->next;
717    }
718 }
719
720 void *
721 ralloc_parent_of_linear_parent(void *ptr)
722 {
723    linear_header *node = LINEAR_PARENT_TO_HEADER(ptr);
724    assert(node->magic == LMAGIC);
725    return node->ralloc_parent;
726 }
727
728 void *
729 linear_realloc(void *parent, void *old, unsigned new_size)
730 {
731    unsigned old_size = 0;
732    ralloc_header *new_ptr;
733
734    new_ptr = linear_alloc_child(parent, new_size);
735
736    if (unlikely(!old))
737       return new_ptr;
738
739    old_size = ((linear_size_chunk*)old)[-1].size;
740
741    if (likely(new_ptr && old_size))
742       memcpy(new_ptr, old, MIN2(old_size, new_size));
743
744    return new_ptr;
745 }
746
747 /* All code below is pretty much copied from ralloc and only the alloc
748  * calls are different.
749  */
750
751 char *
752 linear_strdup(void *parent, const char *str)
753 {
754    unsigned n;
755    char *ptr;
756
757    if (unlikely(!str))
758       return NULL;
759
760    n = strlen(str);
761    ptr = linear_alloc_child(parent, n + 1);
762    if (unlikely(!ptr))
763       return NULL;
764
765    memcpy(ptr, str, n);
766    ptr[n] = '\0';
767    return ptr;
768 }
769
770 char *
771 linear_asprintf(void *parent, const char *fmt, ...)
772 {
773    char *ptr;
774    va_list args;
775    va_start(args, fmt);
776    ptr = linear_vasprintf(parent, fmt, args);
777    va_end(args);
778    return ptr;
779 }
780
781 char *
782 linear_vasprintf(void *parent, const char *fmt, va_list args)
783 {
784    unsigned size = printf_length(fmt, args) + 1;
785
786    char *ptr = linear_alloc_child(parent, size);
787    if (ptr != NULL)
788       vsnprintf(ptr, size, fmt, args);
789
790    return ptr;
791 }
792
793 bool
794 linear_asprintf_append(void *parent, char **str, const char *fmt, ...)
795 {
796    bool success;
797    va_list args;
798    va_start(args, fmt);
799    success = linear_vasprintf_append(parent, str, fmt, args);
800    va_end(args);
801    return success;
802 }
803
804 bool
805 linear_vasprintf_append(void *parent, char **str, const char *fmt, va_list args)
806 {
807    size_t existing_length;
808    assert(str != NULL);
809    existing_length = *str ? strlen(*str) : 0;
810    return linear_vasprintf_rewrite_tail(parent, str, &existing_length, fmt, args);
811 }
812
813 bool
814 linear_asprintf_rewrite_tail(void *parent, char **str, size_t *start,
815                              const char *fmt, ...)
816 {
817    bool success;
818    va_list args;
819    va_start(args, fmt);
820    success = linear_vasprintf_rewrite_tail(parent, str, start, fmt, args);
821    va_end(args);
822    return success;
823 }
824
825 bool
826 linear_vasprintf_rewrite_tail(void *parent, char **str, size_t *start,
827                               const char *fmt, va_list args)
828 {
829    size_t new_length;
830    char *ptr;
831
832    assert(str != NULL);
833
834    if (unlikely(*str == NULL)) {
835       *str = linear_vasprintf(parent, fmt, args);
836       *start = strlen(*str);
837       return true;
838    }
839
840    new_length = printf_length(fmt, args);
841
842    ptr = linear_realloc(parent, *str, *start + new_length + 1);
843    if (unlikely(ptr == NULL))
844       return false;
845
846    vsnprintf(ptr + *start, new_length + 1, fmt, args);
847    *str = ptr;
848    *start += new_length;
849    return true;
850 }
851
852 /* helper routine for strcat/strncat - n is the exact amount to copy */
853 static bool
854 linear_cat(void *parent, char **dest, const char *str, unsigned n)
855 {
856    char *both;
857    unsigned existing_length;
858    assert(dest != NULL && *dest != NULL);
859
860    existing_length = strlen(*dest);
861    both = linear_realloc(parent, *dest, existing_length + n + 1);
862    if (unlikely(both == NULL))
863       return false;
864
865    memcpy(both + existing_length, str, n);
866    both[existing_length + n] = '\0';
867
868    *dest = both;
869    return true;
870 }
871
872 bool
873 linear_strcat(void *parent, char **dest, const char *str)
874 {
875    return linear_cat(parent, dest, str, strlen(str));
876 }