-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc] Share hdrgen declarations between stdlib.h and malloc.h #127278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@llvm/pr-subscribers-libc Author: Roland McGrath (frobtech) ChangesThis uses the new merge_yaml_files feature in hdrgen to share the Full diff: https://github.com/llvm/llvm-project/pull/127278.diff 4 Files Affected:
diff --git a/libc/include/malloc.h.def b/libc/include/malloc.h.def
deleted file mode 100644
index 2a2bad0f13c3e..0000000000000
--- a/libc/include/malloc.h.def
+++ /dev/null
@@ -1,17 +0,0 @@
-//===-- C standard library header malloc.h --------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_MALLOC_H
-#define LLVM_LIBC_MALLOC_H
-
-#include "__llvm-libc-common.h"
-#include "llvm-libc-macros/malloc-macros.h"
-
-%%public_api()
-
-#endif // LLVM_LIBC_MALLOC_H
diff --git a/libc/include/malloc.yaml b/libc/include/malloc.yaml
index ec73c9090f729..bf7678797c023 100644
--- a/libc/include/malloc.yaml
+++ b/libc/include/malloc.yaml
@@ -1,13 +1,17 @@
header: malloc.h
-header_template: malloc.h.def
-macros: []
-types: []
-enums: []
-objects: []
+standards:
+ - gnu
+merge_yaml_files:
+ - stdlib-malloc.yaml
+macros:
+ - macro_name: M_PURGE
+ macro_header: malloc-macros.h
+ - macro_name: M_PURGE_ALL
+ macro_header: malloc-macros.h
functions:
- name: mallopt
standards:
- - GNUExtensions
+ - gnu
return_type: int
arguments:
- type: int
diff --git a/libc/include/stdlib-malloc.yaml b/libc/include/stdlib-malloc.yaml
new file mode 100644
index 0000000000000..648a6e58a90a0
--- /dev/null
+++ b/libc/include/stdlib-malloc.yaml
@@ -0,0 +1,44 @@
+# This file has declarations that appear both in <stdlib.h> and in <malloc.h>.
+
+functions:
+ - name: aligned_alloc
+ standards:
+ - stdc
+ return_type: void *
+ arguments:
+ - type: size_t
+ - type: size_t
+ - name: calloc
+ standards:
+ - stdc
+ return_type: void *
+ arguments:
+ - type: size_t
+ - type: size_t
+ - name: free
+ standards:
+ - stdc
+ return_type: void
+ arguments:
+ - type: void *
+ - name: malloc
+ standards:
+ - stdc
+ return_type: void *
+ arguments:
+ - type: size_t
+ - name: realloc
+ standards:
+ - stdc
+ return_type: void *
+ arguments:
+ - type: void *
+ - type: size_t
+
+# Note: glibc's <stdlib.h> and <malloc.h> both have these, which are
+# currently missing here:
+# - name: reallocarray
+# - name: memalign
+# - name: valloc
+# Each of those glibc headers also has related functions the other lacks.
+# Only the common subset is mentioned here for future consideration.
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index c231a797bd445..6ada26f020179 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -2,6 +2,8 @@ header: stdlib.h
header_template: stdlib.h.def
standards:
- stdc
+merge_yaml_files:
+ - stdlib-malloc.yaml
macros: []
types:
- type_name: __atexithandler_t
@@ -34,13 +36,6 @@ functions:
return_type: int
arguments:
- type: int
- - name: aligned_alloc
- standards:
- - stdc
- return_type: void *
- arguments:
- - type: size_t
- - type: size_t
- name: at_quick_exit
standards:
- stdc
@@ -87,13 +82,6 @@ functions:
- type: size_t
- type: size_t
- type: __bsearchcompare_t
- - name: calloc
- standards:
- - stdc
- return_type: void *
- arguments:
- - type: size_t
- - type: size_t
- name: div
standards:
- stdc
@@ -107,12 +95,6 @@ functions:
return_type: _Noreturn void
arguments:
- type: int
- - name: free
- standards:
- - stdc
- return_type: void
- arguments:
- - type: void *
- name: getenv
standards:
- stdc
@@ -145,12 +127,6 @@ functions:
arguments:
- type: long long
- type: long long
- - name: malloc
- standards:
- - stdc
- return_type: void *
- arguments:
- - type: size_t
- name: qsort
standards:
- stdc
@@ -182,13 +158,6 @@ functions:
return_type: int
arguments:
- type: void
- - name: realloc
- standards:
- - stdc
- return_type: void *
- arguments:
- - type: void *
- - type: size_t
- name: srand
standards:
- stdc
|
# - name: memalign | ||
# - name: valloc | ||
# Each of those glibc headers also has related functions the other lacks. | ||
# Only the common subset is mentioned here for future consideration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this comment!
…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.
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.