You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/06/15 13:21:28 UTC

[incubator-nuttx] 01/02: Move mallinfo from stdlib.h to malloc.h

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit f1814dfca8c7a5334e60330b179028b10c934158
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jun 15 11:38:55 2020 +0900

    Move mallinfo from stdlib.h to malloc.h
    
    mallinfo is meant to be API compatible with Linux,
    where it's provided by malloc.h.
    
    Make stdlib.h include malloc.h for now. It can be removed
    once all users are updated to include malloc.h instead of
    stdlib.h.
    
    I have some app code which uses mallinfo(). I want to share
    it between platforms. This commit allows me to reduce
    platform-ifdefs.
    
    (I think the API actually originated with System V. I don't
    remember how it was there though. Anyway, I guess the
    compatibility with Linux is more important than System V
    these days.)
---
 include/malloc.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/stdlib.h | 15 +-------------
 2 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/include/malloc.h b/include/malloc.h
new file mode 100644
index 0000000..0862df9
--- /dev/null
+++ b/include/malloc.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * include/malloc.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_MALLOC_H
+#define __INCLUDE_MALLOC_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct mallinfo
+{
+  int arena;    /* This is the total size of memory allocated
+                 * for use by malloc in bytes. */
+  int ordblks;  /* This is the number of free (not in use) chunks */
+  int mxordblk; /* Size of the largest free (not in use) chunk */
+  int uordblks; /* This is the total size of memory occupied by
+                 * chunks handed out by malloc. */
+  int fordblks; /* This is the total size of memory occupied
+                 * by free (not in use) chunks. */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+struct mallinfo mallinfo(void);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __INCLUDE_MALLOC_H */
diff --git a/include/stdlib.h b/include/stdlib.h
index 811cacd..502dc4c 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -30,6 +30,7 @@
 
 #include <sys/types.h>
 #include <errno.h>
+#include <malloc.h>
 #include <stdint.h>
 #include <limits.h>
 
@@ -71,18 +72,6 @@
  * Public Type Definitions
  ****************************************************************************/
 
-struct mallinfo
-{
-  int arena;    /* This is the total size of memory allocated
-                 * for use by malloc in bytes. */
-  int ordblks;  /* This is the number of free (not in use) chunks */
-  int mxordblk; /* Size of the largest free (not in use) chunk */
-  int uordblks; /* This is the total size of memory occupied by
-                 * chunks handed out by malloc. */
-  int fordblks; /* This is the total size of memory occupied
-                 * by free (not in use) chunks. */
-};
-
 /* Structure type returned by the div() function. */
 
 struct div_s
@@ -274,8 +263,6 @@ static inline int posix_memalign(FAR void **m, size_t a, size_t s)
 #define posix_memalign(m, a, s) ((*(m) = memalign((a), (s))) ? OK : ENOMEM)
 #endif
 
-struct mallinfo mallinfo(void);
-
 /* Pseudo-Terminals */
 
 #ifdef CONFIG_PSEUDOTERM_SUSV1