libbio
Loading...
Searching...
No Matches
IsMemcpySafe.h
Go to the documentation of this file.
1/*
2 * This file is a part of the Biology project by eons LLC.
3 * Biology (aka Develop Biology) is a framework for approaching software
4 * development from a natural sciences perspective.
5 *
6 * Copyright (C) 2026 Séon O'Shannon & eons LLC
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
27
28namespace bio {
29
30class String;
31class Bytes;
32class ByteStream;
33class Iterator;
34
35namespace physical {
36class Linear;
37} //physical namespace
38
39namespace type {
40
45template < typename T >
47{
48 //@formatter:off
49 #if BIO_CPP_VERSION < 11
50 // LANDMINE (cpp98): this is UNCONDITIONALLY true — there is no trait-based
51 // triviality detection pre-cpp11, so EVERY type reports memcpy-safe here,
52 // including non-trivial heap owners (anything with a CowPtr / String /
53 // owning member). Arrangement< T > then selects its memcpy specialization
54 // on the cpp98 build and byte-copies T WITHOUT running its copy ctor/dtor
55 // → refcount is not bumped on copy and the dtor never runs → double-free /
56 // premature delete / leak. The SAME source is silently correct on cpp20
57 // (where the trait below excludes non-trivial T) and silently corrupting
58 // here. Therefore: any by-value Arrangement< NonTrivialT > MUST add an
59 // explicit IsMemcpySafeImplementation< T > { sValue = false; } opt-out
60 // (see the String/Bytes/ByteStream/Iterator/Linear specializations below).
61 static const bool sValue = true;
62 #else
63 static const bool sValue = IsPrimitive< T >() || IsPointer< T >();
64 #endif
65 //@formatter:on
66};
67
71template < typename T >
73{
74 static const bool sValue = true;
75};
76
81template < typename T >
86
87template <>
89{
90 // String owns heap memory; memcpy duplicates pointers and will double-free.
91 static const bool sValue = false;
92};
93
94template <>
96{
97 // Bytes owns heap memory; memcpy duplicates internal pointers and will double-free.
98 static const bool sValue = false;
99};
100
101template <>
103{
104 // ByteStream manages heap memory + type metadata; memcpy would corrupt ownership.
105 static const bool sValue = false;
106};
107
108template <>
110{
111 // Iterator has internal state; memcpy is undefined.
112 static const bool sValue = false;
113};
114
115template <>
117{
118 // Linear manages ownership; memcpy can corrupt and double-free.
119 static const bool sValue = false;
120};
121
122} //type namespace
123} //bio namespace
#define BIO_CONSTEXPR
Definition KeywordMacros.h:29
Definition ByteStream.h:63
Definition Bytes.h:73
Definition Iterator.h:41
Definition Pointer.h:115
Definition String.h:55
Definition Linear.h:59
Property Linear()
SymmetryType Bytes()
BIO_CONSTEXPR bool IsMemcpySafe()
Definition IsMemcpySafe.h:82
Definition FinalCell.h:29
Definition IsMemcpySafe.h:47
static const bool sValue
Definition IsMemcpySafe.h:61