Nuitka
The Python compiler
Loading...
Searching...
No Matches
HelpersHeapStorage.c
1// Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
9// This file is included from another C file, help IDEs to still parse it on
10// its own.
11#ifdef __IDE_ONLY__
12#include "nuitka/prelude.h"
13#endif
14
15void Nuitka_PreserveHeap(void *dest, ...) {
16 va_list(ap);
17 va_start(ap, dest);
18
19 char *w = (char *)dest;
20
21 for (;;) {
22 void *source = va_arg(ap, void *);
23 if (source == NULL) {
24 break;
25 }
26
27 size_t size = va_arg(ap, size_t);
28 memcpy(w, source, size);
29 w += size;
30 }
31
32 va_end(ap);
33}
34
35void Nuitka_RestoreHeap(void *source, ...) {
36 va_list(ap);
37 va_start(ap, source);
38
39 char *w = (char *)source;
40
41 for (;;) {
42 void *dest = va_arg(ap, void *);
43 if (dest == NULL) {
44 break;
45 }
46
47 size_t size = va_arg(ap, size_t);
48 memcpy(dest, w, size);
49 w += size;
50 }
51
52 va_end(ap);
53}
54
55// Part of "Nuitka", an optimizing Python compiler that is compatible and
56// integrates with CPython, but also works on its own.
57//
58// Licensed under the Apache License, Version 2.0 (the "License");
59// you may not use this file except in compliance with the License.
60// You may obtain a copy of the License at
61//
62// http://www.apache.org/licenses/LICENSE-2.0
63//
64// Unless required by applicable law or agreed to in writing, software
65// distributed under the License is distributed on an "AS IS" BASIS,
66// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67// See the License for the specific language governing permissions and
68// limitations under the License.