Skip to content

Commit 625cb5a

Browse files
authored
[libc] Share hdrgen declarations between stdlib.h and malloc.h (#127278)
This uses the new merge_yaml_files feature in hdrgen to share the source of truth for the malloc suite of functions declared in both stdlib.h and in malloc.h (without either header including the other). It also modernizes the malloc.yaml definition a bit, including dropping the custom template malloc.h.def file in favor of using the explicit macros list to generate the includes.
1 parent caaa288 commit 625cb5a

File tree

4 files changed

+56
-56
lines changed

4 files changed

+56
-56
lines changed

libc/include/malloc.h.def

Lines changed: 0 additions & 17 deletions
This file was deleted.

libc/include/malloc.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
header: malloc.h
2-
header_template: malloc.h.def
3-
macros: []
4-
types: []
5-
enums: []
6-
objects: []
2+
standards:
3+
- gnu
4+
merge_yaml_files:
5+
- stdlib-malloc.yaml
6+
macros:
7+
- macro_name: M_PURGE
8+
macro_header: malloc-macros.h
9+
- macro_name: M_PURGE_ALL
10+
macro_header: malloc-macros.h
711
functions:
812
- name: mallopt
913
standards:
10-
- GNUExtensions
14+
- gnu
1115
return_type: int
1216
arguments:
1317
- type: int

libc/include/stdlib-malloc.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This file has declarations that appear both in <stdlib.h> and in <malloc.h>.
2+
3+
functions:
4+
- name: aligned_alloc
5+
standards:
6+
- stdc
7+
return_type: void *
8+
arguments:
9+
- type: size_t
10+
- type: size_t
11+
- name: calloc
12+
standards:
13+
- stdc
14+
return_type: void *
15+
arguments:
16+
- type: size_t
17+
- type: size_t
18+
- name: free
19+
standards:
20+
- stdc
21+
return_type: void
22+
arguments:
23+
- type: void *
24+
- name: malloc
25+
standards:
26+
- stdc
27+
return_type: void *
28+
arguments:
29+
- type: size_t
30+
- name: realloc
31+
standards:
32+
- stdc
33+
return_type: void *
34+
arguments:
35+
- type: void *
36+
- type: size_t
37+
38+
# Note: glibc's <stdlib.h> and <malloc.h> both have these, which are
39+
# currently missing here:
40+
# - name: reallocarray
41+
# - name: memalign
42+
# - name: valloc
43+
# Each of those glibc headers also has related functions the other lacks.
44+
# Only the common subset is mentioned here for future consideration.

libc/include/stdlib.yaml

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ header: stdlib.h
22
header_template: stdlib.h.def
33
standards:
44
- stdc
5+
merge_yaml_files:
6+
- stdlib-malloc.yaml
57
macros: []
68
types:
79
- type_name: __atexithandler_t
@@ -34,13 +36,6 @@ functions:
3436
return_type: int
3537
arguments:
3638
- type: int
37-
- name: aligned_alloc
38-
standards:
39-
- stdc
40-
return_type: void *
41-
arguments:
42-
- type: size_t
43-
- type: size_t
4439
- name: at_quick_exit
4540
standards:
4641
- stdc
@@ -87,13 +82,6 @@ functions:
8782
- type: size_t
8883
- type: size_t
8984
- type: __bsearchcompare_t
90-
- name: calloc
91-
standards:
92-
- stdc
93-
return_type: void *
94-
arguments:
95-
- type: size_t
96-
- type: size_t
9785
- name: div
9886
standards:
9987
- stdc
@@ -107,12 +95,6 @@ functions:
10795
return_type: _Noreturn void
10896
arguments:
10997
- type: int
110-
- name: free
111-
standards:
112-
- stdc
113-
return_type: void
114-
arguments:
115-
- type: void *
11698
- name: getenv
11799
standards:
118100
- stdc
@@ -145,12 +127,6 @@ functions:
145127
arguments:
146128
- type: long long
147129
- type: long long
148-
- name: malloc
149-
standards:
150-
- stdc
151-
return_type: void *
152-
arguments:
153-
- type: size_t
154130
- name: qsort
155131
standards:
156132
- stdc
@@ -182,13 +158,6 @@ functions:
182158
return_type: int
183159
arguments:
184160
- type: void
185-
- name: realloc
186-
standards:
187-
- stdc
188-
return_type: void *
189-
arguments:
190-
- type: void *
191-
- type: size_t
192161
- name: srand
193162
standards:
194163
- stdc

0 commit comments

Comments
 (0)