You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/10/05 19:56:57 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7198: libs/libc: add obstack

pkarashchenko commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r985290481


##########
include/obstack.h:
##########
@@ -0,0 +1,459 @@
+/****************************************************************************
+ * include/obstack.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.
+ *
+ ****************************************************************************/
+
+/* This is based on the GlibC API but the implementation is not exactly same.
+ * The major difference is how required memory is allocated. The GlibC
+ * implementation starts with 4KB of allocated space. That would make it
+ * impossible to use this on MCUs. This implementation rather tries to
+ * allocated only required amount of space and it won't allocate chunk unless
+ * grow functions are used and even then it uses realloc to release unused
+ * space. It also in default won't use 4KB per chunk but rather just BUFSIZ.
+ *
+ * Not implemented interface:
+ *   obstack_alignment_mask:
+ *     The current implementation does not provide any alignment guaranties.
+ *   obstack_chunk_alloc and obstack_chunk_free:
+ *     Internal implementation uses not only alloc and free but also realloc
+ *     and thus standard implementations are used unconditionally instead of
+ *     requiring users to provide declaration for these functions.
+ */
+
+#ifndef __INCLUDE_OBSTACK_H
+#define __INCLUDE_OBSTACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: obstack_chunk_size
+ *
+ * Description:
+ *   The access to the obstack configuration specifying the size of the
+ *   single chunk used when growing object.
+ *   It is documented t hat this is macro and that it is possible to use
+ *   assignment to change the chunk size (eq.: obstack_chunk_size(h) = 1024).
+ *
+ *   The default chunk size is set to BUFSIZ.
+ *
+ *   The chunks size has to be always power of two due to the limitations of
+ *   the obstack_make_room implementation!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the single chunk.
+ *
+ ****************************************************************************/
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/****************************************************************************
+ * Name: obstack_base
+ *
+ * Description:
+ *   Provides access to the tentative starting address of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Tentative starting address of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_base(h) ((h)->object_base)
+
+/****************************************************************************
+ * Name: obstack_next_free
+ *
+ * Description:
+ *   Provides access to the tentative address just after the end of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_next_free(h) ((h)->next_free)
+
+/****************************************************************************
+ * Name: obstack_blank_fast
+ *
+ * Description:
+ *   Moves the end of the currently growing object by given size and thus
+ *   adding given number of uninitialized bytes to the growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   size: number of bytes
+ *
+ * Returned Value:
+ *   The new address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_blank_fast(h, size) ((h)->next_free += size)
+
+/****************************************************************************
+ * Name: obstack_1grow_fast
+ *
+ * Description:
+ *   Adds one byte to the currently growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   data: byte to be added
+ *
+ * Returned Value:
+ *   Added byte.
+ *
+ ****************************************************************************/
+#define obstack_1grow_fast(h, data) (*((h)->next_free++) = data)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct _obstack_chunk           /* Chunk head. */
+{
+  char *limit;                  /* address of char after this chunk */

Review Comment:
   ```suggestion
     FAR char *limit;              /* address of char after this chunk */
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,459 @@
+/****************************************************************************
+ * include/obstack.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.
+ *
+ ****************************************************************************/
+
+/* This is based on the GlibC API but the implementation is not exactly same.
+ * The major difference is how required memory is allocated. The GlibC
+ * implementation starts with 4KB of allocated space. That would make it
+ * impossible to use this on MCUs. This implementation rather tries to
+ * allocated only required amount of space and it won't allocate chunk unless
+ * grow functions are used and even then it uses realloc to release unused
+ * space. It also in default won't use 4KB per chunk but rather just BUFSIZ.
+ *
+ * Not implemented interface:
+ *   obstack_alignment_mask:
+ *     The current implementation does not provide any alignment guaranties.
+ *   obstack_chunk_alloc and obstack_chunk_free:
+ *     Internal implementation uses not only alloc and free but also realloc
+ *     and thus standard implementations are used unconditionally instead of
+ *     requiring users to provide declaration for these functions.
+ */
+
+#ifndef __INCLUDE_OBSTACK_H
+#define __INCLUDE_OBSTACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: obstack_chunk_size
+ *
+ * Description:
+ *   The access to the obstack configuration specifying the size of the
+ *   single chunk used when growing object.
+ *   It is documented t hat this is macro and that it is possible to use
+ *   assignment to change the chunk size (eq.: obstack_chunk_size(h) = 1024).
+ *
+ *   The default chunk size is set to BUFSIZ.
+ *
+ *   The chunks size has to be always power of two due to the limitations of
+ *   the obstack_make_room implementation!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the single chunk.
+ *
+ ****************************************************************************/
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/****************************************************************************
+ * Name: obstack_base
+ *
+ * Description:
+ *   Provides access to the tentative starting address of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Tentative starting address of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_base(h) ((h)->object_base)
+
+/****************************************************************************
+ * Name: obstack_next_free
+ *
+ * Description:
+ *   Provides access to the tentative address just after the end of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_next_free(h) ((h)->next_free)
+
+/****************************************************************************
+ * Name: obstack_blank_fast
+ *
+ * Description:
+ *   Moves the end of the currently growing object by given size and thus
+ *   adding given number of uninitialized bytes to the growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   size: number of bytes
+ *
+ * Returned Value:
+ *   The new address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_blank_fast(h, size) ((h)->next_free += size)
+
+/****************************************************************************
+ * Name: obstack_1grow_fast
+ *
+ * Description:
+ *   Adds one byte to the currently growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   data: byte to be added
+ *
+ * Returned Value:
+ *   Added byte.
+ *
+ ****************************************************************************/
+#define obstack_1grow_fast(h, data) (*((h)->next_free++) = data)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct _obstack_chunk           /* Chunk head. */
+{
+  char *limit;                  /* address of char after this chunk */
+  struct _obstack_chunk *prev;  /* address of prior chunk or NULL */
+};
+
+struct obstack
+{
+  size_t chunk_size;            /* preferred size to allocate chunks in */
+  struct _obstack_chunk *chunk; /* address of current struct _obstack_chunk */
+  char *object_base;            /* address of object we are building */
+  char *next_free;              /* where to add next char to current object */

Review Comment:
   ```suggestion
     FAR char *object_base;        /* address of object we are building */
     FAR char *next_free;          /* where to add next char to current object */
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,459 @@
+/****************************************************************************
+ * include/obstack.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.
+ *
+ ****************************************************************************/
+
+/* This is based on the GlibC API but the implementation is not exactly same.
+ * The major difference is how required memory is allocated. The GlibC
+ * implementation starts with 4KB of allocated space. That would make it
+ * impossible to use this on MCUs. This implementation rather tries to
+ * allocated only required amount of space and it won't allocate chunk unless
+ * grow functions are used and even then it uses realloc to release unused
+ * space. It also in default won't use 4KB per chunk but rather just BUFSIZ.
+ *
+ * Not implemented interface:
+ *   obstack_alignment_mask:
+ *     The current implementation does not provide any alignment guaranties.
+ *   obstack_chunk_alloc and obstack_chunk_free:
+ *     Internal implementation uses not only alloc and free but also realloc
+ *     and thus standard implementations are used unconditionally instead of
+ *     requiring users to provide declaration for these functions.
+ */
+
+#ifndef __INCLUDE_OBSTACK_H
+#define __INCLUDE_OBSTACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: obstack_chunk_size
+ *
+ * Description:
+ *   The access to the obstack configuration specifying the size of the
+ *   single chunk used when growing object.
+ *   It is documented t hat this is macro and that it is possible to use
+ *   assignment to change the chunk size (eq.: obstack_chunk_size(h) = 1024).
+ *
+ *   The default chunk size is set to BUFSIZ.
+ *
+ *   The chunks size has to be always power of two due to the limitations of
+ *   the obstack_make_room implementation!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the single chunk.
+ *
+ ****************************************************************************/
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/****************************************************************************
+ * Name: obstack_base
+ *
+ * Description:
+ *   Provides access to the tentative starting address of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Tentative starting address of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_base(h) ((h)->object_base)
+
+/****************************************************************************
+ * Name: obstack_next_free
+ *
+ * Description:
+ *   Provides access to the tentative address just after the end of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_next_free(h) ((h)->next_free)
+
+/****************************************************************************
+ * Name: obstack_blank_fast
+ *
+ * Description:
+ *   Moves the end of the currently growing object by given size and thus
+ *   adding given number of uninitialized bytes to the growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   size: number of bytes
+ *
+ * Returned Value:
+ *   The new address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_blank_fast(h, size) ((h)->next_free += size)
+
+/****************************************************************************
+ * Name: obstack_1grow_fast
+ *
+ * Description:
+ *   Adds one byte to the currently growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   data: byte to be added
+ *
+ * Returned Value:
+ *   Added byte.
+ *
+ ****************************************************************************/
+#define obstack_1grow_fast(h, data) (*((h)->next_free++) = data)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct _obstack_chunk           /* Chunk head. */
+{
+  char *limit;                  /* address of char after this chunk */
+  struct _obstack_chunk *prev;  /* address of prior chunk or NULL */
+};
+
+struct obstack
+{
+  size_t chunk_size;            /* preferred size to allocate chunks in */
+  struct _obstack_chunk *chunk; /* address of current struct _obstack_chunk */
+  char *object_base;            /* address of object we are building */
+  char *next_free;              /* where to add next char to current object */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/****************************************************************************
+ * Name: obstack_init
+ *
+ * Description:
+ *   Initialize obstack for allocation of objects.
+ *   Compared to the GlibC version this won't initialize a first chunk.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to initialize
+ *
+ ****************************************************************************/
+
+void obstack_init (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_alloc
+ *
+ * Description:
+ *   Allocate an object of given size with uninitialized bytes.
+ *   Compared to the GlibC version this uses malloc to allocate exactly
+ *   required space (plus overhead) and nothing more.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   size: number of bytes to allocate
+ *
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size);

Review Comment:
   ```suggestion
   FAR void *obstack_alloc(FAR struct obstack *h, size_t size);
   ```



##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_alloc.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size)

Review Comment:
   ```suggestion
   FAR void *obstack_alloc(FAR struct obstack *h, size_t size)
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,459 @@
+/****************************************************************************
+ * include/obstack.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.
+ *
+ ****************************************************************************/
+
+/* This is based on the GlibC API but the implementation is not exactly same.
+ * The major difference is how required memory is allocated. The GlibC
+ * implementation starts with 4KB of allocated space. That would make it
+ * impossible to use this on MCUs. This implementation rather tries to
+ * allocated only required amount of space and it won't allocate chunk unless
+ * grow functions are used and even then it uses realloc to release unused
+ * space. It also in default won't use 4KB per chunk but rather just BUFSIZ.
+ *
+ * Not implemented interface:
+ *   obstack_alignment_mask:
+ *     The current implementation does not provide any alignment guaranties.
+ *   obstack_chunk_alloc and obstack_chunk_free:
+ *     Internal implementation uses not only alloc and free but also realloc
+ *     and thus standard implementations are used unconditionally instead of
+ *     requiring users to provide declaration for these functions.
+ */
+
+#ifndef __INCLUDE_OBSTACK_H
+#define __INCLUDE_OBSTACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: obstack_chunk_size
+ *
+ * Description:
+ *   The access to the obstack configuration specifying the size of the
+ *   single chunk used when growing object.
+ *   It is documented t hat this is macro and that it is possible to use
+ *   assignment to change the chunk size (eq.: obstack_chunk_size(h) = 1024).
+ *
+ *   The default chunk size is set to BUFSIZ.
+ *
+ *   The chunks size has to be always power of two due to the limitations of
+ *   the obstack_make_room implementation!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the single chunk.
+ *
+ ****************************************************************************/
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/****************************************************************************
+ * Name: obstack_base
+ *
+ * Description:
+ *   Provides access to the tentative starting address of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Tentative starting address of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_base(h) ((h)->object_base)
+
+/****************************************************************************
+ * Name: obstack_next_free
+ *
+ * Description:
+ *   Provides access to the tentative address just after the end of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_next_free(h) ((h)->next_free)
+
+/****************************************************************************
+ * Name: obstack_blank_fast
+ *
+ * Description:
+ *   Moves the end of the currently growing object by given size and thus
+ *   adding given number of uninitialized bytes to the growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   size: number of bytes
+ *
+ * Returned Value:
+ *   The new address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_blank_fast(h, size) ((h)->next_free += size)
+
+/****************************************************************************
+ * Name: obstack_1grow_fast
+ *
+ * Description:
+ *   Adds one byte to the currently growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   data: byte to be added
+ *
+ * Returned Value:
+ *   Added byte.
+ *
+ ****************************************************************************/
+#define obstack_1grow_fast(h, data) (*((h)->next_free++) = data)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct _obstack_chunk           /* Chunk head. */
+{
+  char *limit;                  /* address of char after this chunk */
+  struct _obstack_chunk *prev;  /* address of prior chunk or NULL */
+};
+
+struct obstack
+{
+  size_t chunk_size;            /* preferred size to allocate chunks in */
+  struct _obstack_chunk *chunk; /* address of current struct _obstack_chunk */
+  char *object_base;            /* address of object we are building */
+  char *next_free;              /* where to add next char to current object */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/****************************************************************************
+ * Name: obstack_init
+ *
+ * Description:
+ *   Initialize obstack for allocation of objects.
+ *   Compared to the GlibC version this won't initialize a first chunk.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to initialize
+ *
+ ****************************************************************************/
+
+void obstack_init (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_alloc
+ *
+ * Description:
+ *   Allocate an object of given size with uninitialized bytes.
+ *   Compared to the GlibC version this uses malloc to allocate exactly
+ *   required space (plus overhead) and nothing more.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   size: number of bytes to allocate
+ *
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size);
+
+/****************************************************************************
+ * Name: obstack_copy
+ *
+ * Description:
+ *   Allocate an object of given size with contents copied from address.
+ *   The same remarks regarding the allocation apply here as for
+ *   obstack_alloc.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   address: pointer to the bytes to be used to initialize new object
+ *   size: number of bytes to allocate
+ *
+ ****************************************************************************/
+
+FAR void *obstack_copy (FAR struct obstack *h,

Review Comment:
   ```suggestion
   FAR void *obstack_copy(FAR struct obstack *h,
   ```



##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_alloc.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size)
+{
+  FAR struct _obstack_chunk *prev;
+  FAR void *res;
+
+  if (h->chunk == NULL || (h->chunk->limit - h->object_base) < size)
+    {
+      /* TODO: could we just expand current allocation? */
+
+      prev = h->chunk;
+      h->chunk = malloc(size + sizeof(struct _obstack_chunk));
+      h->chunk->limit =
+        (void *)h->chunk + sizeof(struct _obstack_chunk) + size;
+      h->chunk->prev = prev;
+      h->object_base = (void *)h->chunk + sizeof(struct _obstack_chunk);

Review Comment:
   ```suggestion
         h->object_base = (FAR void *)h->chunk + sizeof(struct _obstack_chunk);
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,459 @@
+/****************************************************************************
+ * include/obstack.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.
+ *
+ ****************************************************************************/
+
+/* This is based on the GlibC API but the implementation is not exactly same.
+ * The major difference is how required memory is allocated. The GlibC
+ * implementation starts with 4KB of allocated space. That would make it
+ * impossible to use this on MCUs. This implementation rather tries to
+ * allocated only required amount of space and it won't allocate chunk unless
+ * grow functions are used and even then it uses realloc to release unused
+ * space. It also in default won't use 4KB per chunk but rather just BUFSIZ.
+ *
+ * Not implemented interface:
+ *   obstack_alignment_mask:
+ *     The current implementation does not provide any alignment guaranties.
+ *   obstack_chunk_alloc and obstack_chunk_free:
+ *     Internal implementation uses not only alloc and free but also realloc
+ *     and thus standard implementations are used unconditionally instead of
+ *     requiring users to provide declaration for these functions.
+ */
+
+#ifndef __INCLUDE_OBSTACK_H
+#define __INCLUDE_OBSTACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: obstack_chunk_size
+ *
+ * Description:
+ *   The access to the obstack configuration specifying the size of the
+ *   single chunk used when growing object.
+ *   It is documented t hat this is macro and that it is possible to use
+ *   assignment to change the chunk size (eq.: obstack_chunk_size(h) = 1024).
+ *
+ *   The default chunk size is set to BUFSIZ.
+ *
+ *   The chunks size has to be always power of two due to the limitations of
+ *   the obstack_make_room implementation!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the single chunk.
+ *
+ ****************************************************************************/
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/****************************************************************************
+ * Name: obstack_base
+ *
+ * Description:
+ *   Provides access to the tentative starting address of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Tentative starting address of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_base(h) ((h)->object_base)
+
+/****************************************************************************
+ * Name: obstack_next_free
+ *
+ * Description:
+ *   Provides access to the tentative address just after the end of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_next_free(h) ((h)->next_free)
+
+/****************************************************************************
+ * Name: obstack_blank_fast
+ *
+ * Description:
+ *   Moves the end of the currently growing object by given size and thus
+ *   adding given number of uninitialized bytes to the growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   size: number of bytes
+ *
+ * Returned Value:
+ *   The new address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_blank_fast(h, size) ((h)->next_free += size)
+
+/****************************************************************************
+ * Name: obstack_1grow_fast
+ *
+ * Description:
+ *   Adds one byte to the currently growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   data: byte to be added
+ *
+ * Returned Value:
+ *   Added byte.
+ *
+ ****************************************************************************/
+#define obstack_1grow_fast(h, data) (*((h)->next_free++) = data)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct _obstack_chunk           /* Chunk head. */
+{
+  char *limit;                  /* address of char after this chunk */
+  struct _obstack_chunk *prev;  /* address of prior chunk or NULL */
+};
+
+struct obstack
+{
+  size_t chunk_size;            /* preferred size to allocate chunks in */
+  struct _obstack_chunk *chunk; /* address of current struct _obstack_chunk */
+  char *object_base;            /* address of object we are building */
+  char *next_free;              /* where to add next char to current object */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/****************************************************************************
+ * Name: obstack_init
+ *
+ * Description:
+ *   Initialize obstack for allocation of objects.
+ *   Compared to the GlibC version this won't initialize a first chunk.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to initialize
+ *
+ ****************************************************************************/
+
+void obstack_init (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_alloc
+ *
+ * Description:
+ *   Allocate an object of given size with uninitialized bytes.
+ *   Compared to the GlibC version this uses malloc to allocate exactly
+ *   required space (plus overhead) and nothing more.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   size: number of bytes to allocate
+ *
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size);
+
+/****************************************************************************
+ * Name: obstack_copy
+ *
+ * Description:
+ *   Allocate an object of given size with contents copied from address.
+ *   The same remarks regarding the allocation apply here as for
+ *   obstack_alloc.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   address: pointer to the bytes to be used to initialize new object
+ *   size: number of bytes to allocate
+ *
+ ****************************************************************************/
+
+FAR void *obstack_copy (FAR struct obstack *h,
+    FAR const void *address, size_t size);
+
+/****************************************************************************
+ * Name: obstack_copy0
+ *
+ * Description:
+ *   Allocate an object of given size+1 with contents copied from address and
+ *   append null byte at the end.
+ *   The same remarks regarding the allocation apply here as for
+ *   obstack_alloc.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   address: pointer to the bytes to be used to initialize new object
+ *   size: number of bytes to allocate (excluding the null byte)
+ *
+ ****************************************************************************/
+
+FAR void *obstack_copy0 (FAR struct obstack *h,
+    FAR const void *address, size_t size);
+
+/****************************************************************************
+ * Name: obstack_free
+ *
+ * Description:
+ *   Free objects (and everything allocated in the specified obstack more
+ *   recently than object). You can pass NULL to free everything.
+ *   The buffer the allocated object was preset is kept and thus can be
+ *   immediately reused for growing. The only exception for this is when NULL
+ *   is passed as in such case even the last buffer is freed.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle object belongs to
+ *   object: the pointer to the object or NULL
+ *
+ ****************************************************************************/
+
+void obstack_free (FAR struct obstack *h, FAR void *object);
+
+/****************************************************************************
+ * Name: obstack_make_room
+ *
+ * Description:
+ *   This is non-standard function that is probably available only on NuttX!
+ *   Make sure that there is room in the buffer to fit object with given
+ *   size. The allocation performed is in multiples of chunk_size specified
+ *   for the obstack.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle where room should be made
+ *   size: number of bytes to be free for growth
+ *
+ * Assumptions/Limitations:
+ *   The obstack's chunk_size is expected to be power of two. This helps to
+ *   eliminate division that might not be implemented in the HW and thus
+ *   inefficient.
+ *
+ ****************************************************************************/
+
+void obstack_make_room(struct obstack *h, size_t size);
+
+/****************************************************************************
+ * Name: obstack_blank
+ *
+ * Description:
+ *   Grow object by given size. The bytes are uninitialized.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocated object to
+ *   size: number of bytes to grow object
+ *
+ ****************************************************************************/
+
+void obstack_blank (FAR struct obstack *h, size_t size);
+
+/****************************************************************************
+ * Name: obstack_grow
+ *
+ * Description:
+ *   Grow object by given size and allocated it with bytes from address.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocated object to
+ *   address: pointer to the bytes to be used to initialize the new object
+ *   size: number of bytes to grow object
+ *
+ ****************************************************************************/
+
+void obstack_grow (FAR struct obstack *h,
+    FAR const void *address, size_t size);
+
+/****************************************************************************
+ * Name: obstack_grow0
+ *
+ * Description:
+ *   Grow object by given size+1 and allocated it with bytes from address
+ *   plus null byte at the end.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocated object to
+ *   address: pointer to the bytes to be used to initialize the new object
+ *   size: number of bytes to grow object (excluding the null byte)
+ *
+ ****************************************************************************/
+
+void obstack_grow0 (FAR struct obstack *h,
+    FAR const void *address, size_t size);
+
+/****************************************************************************
+ * Name: obstack_1grow
+ *
+ * Description:
+ *   Grow object by single data byte.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocated object to
+ *   data: byte to be added to the growing object
+ *
+ ****************************************************************************/
+
+void obstack_1grow (FAR struct obstack *h, char data);
+
+/****************************************************************************
+ * Name: obstack_finish
+ *
+ * Description:
+ *   Finish growing object and receive address to it.
+ *   Compared to the GlibC version this uses realloc to reduce buffer size to
+ *   only allocated amount. The non-standard obstack_finish_norealloc can be
+ *   used if you want the standard behavior for ever reason.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Permanent address to the object.
+ *
+ ****************************************************************************/
+
+FAR void *obstack_finish (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_finish_norealloc
+ *
+ * Description:
+ *   Finish growing object and receive address to it without reallocating
+ *   buffer to fit the object (keeping space for more growth).
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Permanent address to the object.
+ *
+ ****************************************************************************/
+
+FAR void *obstack_finish_norealloc (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_object_size
+ *
+ * Description:
+ *   Calculate the size of the currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the object.
+ *
+ ****************************************************************************/
+
+size_t obstack_object_size (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_room
+ *
+ * Description:
+ *   Calculate the number of bytes available for growth before reallocation
+ *   is required.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Number of free bytes.
+ *
+ ****************************************************************************/
+
+size_t obstack_room (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_printf
+ *
+ * Description:
+ *   This is similar to the asprintf except it uses obstack to allocate
+ *   string on. The characters are written onto the end of the currently
+ *   growing object and terminated by null byte.
+ *
+ *   This function is defined in stdio.h in GlibC. There is no definition
+ *   that would be in stdio.h required for these here and thus it is easier
+ *   to just keep these functions here as user has to include obstack anyway
+ *   to get the full functionality.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   fmt: format string with its format inputs followed.
+ *
+ * Returned Value:
+ *   Number of characters added to the obstack excluding the null byte.
+ *
+ ****************************************************************************/
+
+int obstack_printf(FAR struct obstack *h, FAR const char *fmt, ...);
+
+/****************************************************************************
+ * Name: obstack_vprintf
+ *
+ * Description:
+ *   This is similar to the vasprintf except it uses obstack to allocate
+ *   string on. The characters are written onto the end of the currently
+ *   growing object and terminated by null byte.
+ *
+ *   The same remarks are applied here as for obstack_printf regarding the
+ *   definition location in GlibC.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   fmt: format string
+ *   ap: format string input as a variable argument list
+ *
+ * Returned Value:
+ *   Number of characters added to the obstack excluding the null byte.
+ *
+ ****************************************************************************/
+
+int obstack_vprintf(FAR struct obstack *h, FAR const char *fmt, va_list ap);
+
+#if defined(__cplusplus)
+}
+#endif

Review Comment:
   ```suggestion
   #undef EXTERN
   #if defined(__cplusplus)
   }
   #endif
   ```



##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_alloc.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size)
+{
+  FAR struct _obstack_chunk *prev;
+  FAR void *res;
+
+  if (h->chunk == NULL || (h->chunk->limit - h->object_base) < size)
+    {
+      /* TODO: could we just expand current allocation? */
+
+      prev = h->chunk;
+      h->chunk = malloc(size + sizeof(struct _obstack_chunk));

Review Comment:
   ```suggestion
         h->chunk = lib_malloc(size + sizeof(struct _obstack_chunk));
   ```



##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_make_room.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_make_room(FAR struct obstack *h, size_t size)
+{
+  unsigned i;
+  size_t mask;
+
+  DEBUGASSERT(h);
+
+  if (obstack_room(h) >= size)
+    return; /* No need to allocate anything */
+
+  size_t object_size = obstack_object_size(h);
+
+  size += object_size + sizeof(struct _obstack_chunk);
+
+  /* Note: this is rounding up to the multiple of chunk size that is power of
+   * two. Thus this creates limitation that chunks can be only power of two.
+   */
+
+  mask = h->chunk_size;
+  for (i = 1; i < sizeof(size_t); i = i << 1)
+      mask |= mask >> i;
+  size = (size + mask) & ~mask;
+
+  if (h->chunk == NULL ||
+      h->object_base != (void *)h->chunk + sizeof(struct _obstack_chunk))
+    {
+      /* Allocate new chunk if there is something in the chunk already or if
+       * there is no chunk yet.
+       */
+
+      struct _obstack_chunk *prev = h->chunk;
+      h->chunk = malloc(size);
+      h->chunk->prev = prev;
+    }
+
+  else
+    {
+      h->chunk = realloc(h->chunk, size);

Review Comment:
   ```suggestion
         h->chunk = lib_realloc(h->chunk, size);
   ```



##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_make_room.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_make_room(FAR struct obstack *h, size_t size)
+{
+  unsigned i;
+  size_t mask;
+
+  DEBUGASSERT(h);
+
+  if (obstack_room(h) >= size)
+    return; /* No need to allocate anything */

Review Comment:
   ```suggestion
     if (obstack_room(h) >= size)
       {
         return; /* No need to allocate anything */
       }
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,459 @@
+/****************************************************************************
+ * include/obstack.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.
+ *
+ ****************************************************************************/
+
+/* This is based on the GlibC API but the implementation is not exactly same.
+ * The major difference is how required memory is allocated. The GlibC
+ * implementation starts with 4KB of allocated space. That would make it
+ * impossible to use this on MCUs. This implementation rather tries to
+ * allocated only required amount of space and it won't allocate chunk unless
+ * grow functions are used and even then it uses realloc to release unused
+ * space. It also in default won't use 4KB per chunk but rather just BUFSIZ.
+ *
+ * Not implemented interface:
+ *   obstack_alignment_mask:
+ *     The current implementation does not provide any alignment guaranties.
+ *   obstack_chunk_alloc and obstack_chunk_free:
+ *     Internal implementation uses not only alloc and free but also realloc
+ *     and thus standard implementations are used unconditionally instead of
+ *     requiring users to provide declaration for these functions.
+ */
+
+#ifndef __INCLUDE_OBSTACK_H
+#define __INCLUDE_OBSTACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: obstack_chunk_size
+ *
+ * Description:
+ *   The access to the obstack configuration specifying the size of the
+ *   single chunk used when growing object.
+ *   It is documented t hat this is macro and that it is possible to use
+ *   assignment to change the chunk size (eq.: obstack_chunk_size(h) = 1024).
+ *
+ *   The default chunk size is set to BUFSIZ.
+ *
+ *   The chunks size has to be always power of two due to the limitations of
+ *   the obstack_make_room implementation!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the single chunk.
+ *
+ ****************************************************************************/
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/****************************************************************************
+ * Name: obstack_base
+ *
+ * Description:
+ *   Provides access to the tentative starting address of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Tentative starting address of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_base(h) ((h)->object_base)
+
+/****************************************************************************
+ * Name: obstack_next_free
+ *
+ * Description:
+ *   Provides access to the tentative address just after the end of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_next_free(h) ((h)->next_free)
+
+/****************************************************************************
+ * Name: obstack_blank_fast
+ *
+ * Description:
+ *   Moves the end of the currently growing object by given size and thus
+ *   adding given number of uninitialized bytes to the growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   size: number of bytes
+ *
+ * Returned Value:
+ *   The new address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_blank_fast(h, size) ((h)->next_free += size)
+
+/****************************************************************************
+ * Name: obstack_1grow_fast
+ *
+ * Description:
+ *   Adds one byte to the currently growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   data: byte to be added
+ *
+ * Returned Value:
+ *   Added byte.
+ *
+ ****************************************************************************/
+#define obstack_1grow_fast(h, data) (*((h)->next_free++) = data)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct _obstack_chunk           /* Chunk head. */
+{
+  char *limit;                  /* address of char after this chunk */
+  struct _obstack_chunk *prev;  /* address of prior chunk or NULL */
+};
+
+struct obstack
+{
+  size_t chunk_size;            /* preferred size to allocate chunks in */
+  struct _obstack_chunk *chunk; /* address of current struct _obstack_chunk */
+  char *object_base;            /* address of object we are building */
+  char *next_free;              /* where to add next char to current object */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+/****************************************************************************
+ * Name: obstack_init
+ *
+ * Description:
+ *   Initialize obstack for allocation of objects.
+ *   Compared to the GlibC version this won't initialize a first chunk.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to initialize
+ *
+ ****************************************************************************/
+
+void obstack_init (FAR struct obstack *h);
+
+/****************************************************************************
+ * Name: obstack_alloc
+ *
+ * Description:
+ *   Allocate an object of given size with uninitialized bytes.
+ *   Compared to the GlibC version this uses malloc to allocate exactly
+ *   required space (plus overhead) and nothing more.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   size: number of bytes to allocate
+ *
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size);
+
+/****************************************************************************
+ * Name: obstack_copy
+ *
+ * Description:
+ *   Allocate an object of given size with contents copied from address.
+ *   The same remarks regarding the allocation apply here as for
+ *   obstack_alloc.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   address: pointer to the bytes to be used to initialize new object
+ *   size: number of bytes to allocate
+ *
+ ****************************************************************************/
+
+FAR void *obstack_copy (FAR struct obstack *h,
+    FAR const void *address, size_t size);
+
+/****************************************************************************
+ * Name: obstack_copy0
+ *
+ * Description:
+ *   Allocate an object of given size+1 with contents copied from address and
+ *   append null byte at the end.
+ *   The same remarks regarding the allocation apply here as for
+ *   obstack_alloc.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle to allocate an object in
+ *   address: pointer to the bytes to be used to initialize new object
+ *   size: number of bytes to allocate (excluding the null byte)
+ *
+ ****************************************************************************/
+
+FAR void *obstack_copy0 (FAR struct obstack *h,

Review Comment:
   ```suggestion
   FAR void *obstack_copy0(FAR struct obstack *h,
   ```



##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_make_room.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_make_room(FAR struct obstack *h, size_t size)
+{
+  unsigned i;
+  size_t mask;
+
+  DEBUGASSERT(h);
+
+  if (obstack_room(h) >= size)
+    return; /* No need to allocate anything */
+
+  size_t object_size = obstack_object_size(h);
+
+  size += object_size + sizeof(struct _obstack_chunk);
+
+  /* Note: this is rounding up to the multiple of chunk size that is power of
+   * two. Thus this creates limitation that chunks can be only power of two.
+   */
+
+  mask = h->chunk_size;
+  for (i = 1; i < sizeof(size_t); i = i << 1)
+      mask |= mask >> i;
+  size = (size + mask) & ~mask;
+
+  if (h->chunk == NULL ||
+      h->object_base != (void *)h->chunk + sizeof(struct _obstack_chunk))
+    {
+      /* Allocate new chunk if there is something in the chunk already or if
+       * there is no chunk yet.
+       */
+
+      struct _obstack_chunk *prev = h->chunk;
+      h->chunk = malloc(size);

Review Comment:
   ```suggestion
         h->chunk = lib_malloc(size);
   ```



##########
libs/libc/obstack/lib_obstack_object_size.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_object_size.c
+ *
+ * This file is a part of NuttX:
+ *
+ *   Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ *   Ported by: Darcy Gong
+ *
+ * It derives from the Rhombus OS math library by Nick Johnson which has
+ * a compatible, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>

Review Comment:
   Where this license comes from?



##########
libs/libc/obstack/lib_obstack_room.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_room.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+size_t obstack_room (FAR struct obstack *h)
+{
+  DEBUGASSERT(h);
+
+  if (h->chunk)
+      return h->chunk->limit - h->next_free;
+
+  return 0;

Review Comment:
   ```suggestion
     return h->chunk != NULL ? h->chunk->limit - h->next_free : 0;
   ```
   Or maybe even a macro



##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_alloc.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_alloc (FAR struct obstack *h, size_t size)
+{
+  FAR struct _obstack_chunk *prev;
+  FAR void *res;
+
+  if (h->chunk == NULL || (h->chunk->limit - h->object_base) < size)
+    {
+      /* TODO: could we just expand current allocation? */
+
+      prev = h->chunk;
+      h->chunk = malloc(size + sizeof(struct _obstack_chunk));
+      h->chunk->limit =
+        (void *)h->chunk + sizeof(struct _obstack_chunk) + size;

Review Comment:
   ```suggestion
           (FAR void *)h->chunk + sizeof(struct _obstack_chunk) + size;
   ```



##########
libs/libc/obstack/lib_obstack_blank.c:
##########
@@ -0,0 +1,35 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_blank.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_blank (struct obstack *h, size_t size)

Review Comment:
   ```suggestion
   void obstack_blank(FAR struct obstack *h, size_t size)
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,459 @@
+/****************************************************************************
+ * include/obstack.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.
+ *
+ ****************************************************************************/
+
+/* This is based on the GlibC API but the implementation is not exactly same.
+ * The major difference is how required memory is allocated. The GlibC
+ * implementation starts with 4KB of allocated space. That would make it
+ * impossible to use this on MCUs. This implementation rather tries to
+ * allocated only required amount of space and it won't allocate chunk unless
+ * grow functions are used and even then it uses realloc to release unused
+ * space. It also in default won't use 4KB per chunk but rather just BUFSIZ.
+ *
+ * Not implemented interface:
+ *   obstack_alignment_mask:
+ *     The current implementation does not provide any alignment guaranties.
+ *   obstack_chunk_alloc and obstack_chunk_free:
+ *     Internal implementation uses not only alloc and free but also realloc
+ *     and thus standard implementations are used unconditionally instead of
+ *     requiring users to provide declaration for these functions.
+ */
+
+#ifndef __INCLUDE_OBSTACK_H
+#define __INCLUDE_OBSTACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <stdarg.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: obstack_chunk_size
+ *
+ * Description:
+ *   The access to the obstack configuration specifying the size of the
+ *   single chunk used when growing object.
+ *   It is documented t hat this is macro and that it is possible to use
+ *   assignment to change the chunk size (eq.: obstack_chunk_size(h) = 1024).
+ *
+ *   The default chunk size is set to BUFSIZ.
+ *
+ *   The chunks size has to be always power of two due to the limitations of
+ *   the obstack_make_room implementation!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Size of the single chunk.
+ *
+ ****************************************************************************/
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/****************************************************************************
+ * Name: obstack_base
+ *
+ * Description:
+ *   Provides access to the tentative starting address of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Tentative starting address of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_base(h) ((h)->object_base)
+
+/****************************************************************************
+ * Name: obstack_next_free
+ *
+ * Description:
+ *   Provides access to the tentative address just after the end of the
+ *   currently growing object.
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *
+ * Returned Value:
+ *   Address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_next_free(h) ((h)->next_free)
+
+/****************************************************************************
+ * Name: obstack_blank_fast
+ *
+ * Description:
+ *   Moves the end of the currently growing object by given size and thus
+ *   adding given number of uninitialized bytes to the growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   size: number of bytes
+ *
+ * Returned Value:
+ *   The new address just after the end of the currently growing object.
+ *
+ ****************************************************************************/
+#define obstack_blank_fast(h, size) ((h)->next_free += size)
+
+/****************************************************************************
+ * Name: obstack_1grow_fast
+ *
+ * Description:
+ *   Adds one byte to the currently growing object.
+ *   There is no check if there is enough room and thus it is easy to cause
+ *   buffer overrun. Use only when you are sure that there is enough room!
+ *
+ * Input Parameters:
+ *   h: pointer to the handle used to grow the object.
+ *   data: byte to be added
+ *
+ * Returned Value:
+ *   Added byte.
+ *
+ ****************************************************************************/
+#define obstack_1grow_fast(h, data) (*((h)->next_free++) = data)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct _obstack_chunk           /* Chunk head. */
+{
+  char *limit;                  /* address of char after this chunk */
+  struct _obstack_chunk *prev;  /* address of prior chunk or NULL */
+};
+
+struct obstack
+{
+  size_t chunk_size;            /* preferred size to allocate chunks in */
+  struct _obstack_chunk *chunk; /* address of current struct _obstack_chunk */
+  char *object_base;            /* address of object we are building */
+  char *next_free;              /* where to add next char to current object */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif

Review Comment:
   ```suggestion
   #undef EXTERN
   #if defined(__cplusplus)
   #define EXTERN extern "C"
   extern "C"
   {
   #else
   #define EXTERN extern
   #endif
   ```



##########
libs/libc/obstack/lib_obstack_copy.c:
##########
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_copy.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_copy (FAR struct obstack *h,

Review Comment:
   ```suggestion
   FAR void *obstack_copy(FAR struct obstack *h,
   ```



##########
libs/libc/obstack/lib_obstack_copy.c:
##########
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_copy.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_copy (FAR struct obstack *h,
+    FAR const void *address, size_t size)
+{
+  void *res = obstack_alloc(h, size);

Review Comment:
   ```suggestion
     FAR void *res = obstack_alloc(h, size);
   ```



##########
libs/libc/obstack/lib_obstack_finish.c:
##########
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_finish.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_finish (FAR struct obstack *h)
+{
+  size_t chsize;
+
+  if (((void *)h->chunk + sizeof(struct _obstack_chunk)) == h->object_base)
+    {
+      chsize = h->next_free - (char *)h->chunk;

Review Comment:
   ```suggestion
         chsize = h->next_free - (FAR char *)h->chunk;
   ```



##########
libs/libc/obstack/lib_obstack_free.c:
##########
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_free.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_free (FAR struct obstack *h, FAR void *object)

Review Comment:
   ```suggestion
   void obstack_free(FAR struct obstack *h, FAR void *object)
   ```



##########
libs/libc/obstack/lib_obstack_finish.c:
##########
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_finish.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_finish (FAR struct obstack *h)
+{
+  size_t chsize;
+
+  if (((void *)h->chunk + sizeof(struct _obstack_chunk)) == h->object_base)

Review Comment:
   ```suggestion
     if (((FAR void *)h->chunk + sizeof(struct _obstack_chunk)) == h->object_base)
   ```



##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_make_room.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_make_room(FAR struct obstack *h, size_t size)
+{
+  unsigned i;
+  size_t mask;
+
+  DEBUGASSERT(h);
+
+  if (obstack_room(h) >= size)
+    return; /* No need to allocate anything */
+
+  size_t object_size = obstack_object_size(h);
+
+  size += object_size + sizeof(struct _obstack_chunk);
+
+  /* Note: this is rounding up to the multiple of chunk size that is power of
+   * two. Thus this creates limitation that chunks can be only power of two.
+   */
+
+  mask = h->chunk_size;
+  for (i = 1; i < sizeof(size_t); i = i << 1)
+      mask |= mask >> i;
+  size = (size + mask) & ~mask;
+
+  if (h->chunk == NULL ||
+      h->object_base != (void *)h->chunk + sizeof(struct _obstack_chunk))
+    {
+      /* Allocate new chunk if there is something in the chunk already or if
+       * there is no chunk yet.
+       */
+
+      struct _obstack_chunk *prev = h->chunk;
+      h->chunk = malloc(size);
+      h->chunk->prev = prev;
+    }
+
+  else
+    {
+      h->chunk = realloc(h->chunk, size);
+    }
+
+  h->chunk->limit = (void *)h->chunk + sizeof(struct _obstack_chunk) + size;
+  h->object_base = (void *)h->chunk + sizeof(struct _obstack_chunk);

Review Comment:
   ```suggestion
     h->chunk->limit = (FAR void *)h->chunk + sizeof(struct _obstack_chunk) + size;
     h->object_base = (FAR void *)h->chunk + sizeof(struct _obstack_chunk);
   ```
   `void` pointer increment is not defined by C standard if I recall correctly, so better to use `uint8_t *` here.



##########
libs/libc/obstack/lib_obstack_free.c:
##########
@@ -0,0 +1,60 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_free.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_free (FAR struct obstack *h, FAR void *object)
+{
+  FAR struct _obstack_chunk *prev;
+
+  while (h->chunk)
+    {
+      if (object >= (void *)&h->chunk + sizeof(struct _obstack_chunk)
+          && object < (void *)h->chunk->limit)
+        {
+          /* The obect is in this chunk so just move object base.
+           * Note: this keeps the last chunk allocated. This is desirable
+           * behavior as we can decide if we want to reuse it by either
+           * passing NULL to free everything or the first returned object to
+           * keep the chunk allocated.
+           */
+
+          h->object_base = object;
+          h->next_free = object;
+          return;
+        }
+
+      prev = h->chunk->prev;
+      free(h->chunk);

Review Comment:
   ```suggestion
         lib_free(h->chunk);
   ```



##########
libs/libc/obstack/lib_obstack_finish.c:
##########
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_finish.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_finish (FAR struct obstack *h)
+{
+  size_t chsize;
+
+  if (((void *)h->chunk + sizeof(struct _obstack_chunk)) == h->object_base)
+    {
+      chsize = h->next_free - (char *)h->chunk;
+      h->chunk = realloc(h->chunk, chsize);
+      h->chunk->limit = (void *)h->chunk + chsize;
+      h->object_base = h->chunk->limit;
+      h->next_free = h->chunk->limit;
+      return (void *)h->chunk + sizeof(struct _obstack_chunk);
+    }
+
+  return obstack_finish_norealloc(h);
+}
+
+FAR void *obstack_finish_norealloc (FAR struct obstack *h)
+{
+  char *res = h->object_base;

Review Comment:
   ```suggestion
     FAR char *res = h->object_base;
   ```



##########
libs/libc/obstack/lib_obstack_finish.c:
##########
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_finish.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *obstack_finish (FAR struct obstack *h)
+{
+  size_t chsize;
+
+  if (((void *)h->chunk + sizeof(struct _obstack_chunk)) == h->object_base)
+    {
+      chsize = h->next_free - (char *)h->chunk;
+      h->chunk = realloc(h->chunk, chsize);

Review Comment:
   ```suggestion
         h->chunk = lib_realloc(h->chunk, chsize);
   ```



##########
libs/libc/obstack/lib_obstack_room.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_room.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+size_t obstack_room (FAR struct obstack *h)

Review Comment:
   ```suggestion
   size_t obstack_room(FAR struct obstack *h)
   ```



##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_make_room.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+#include <stdlib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_make_room(FAR struct obstack *h, size_t size)
+{
+  unsigned i;
+  size_t mask;
+
+  DEBUGASSERT(h);
+
+  if (obstack_room(h) >= size)
+    return; /* No need to allocate anything */
+
+  size_t object_size = obstack_object_size(h);
+
+  size += object_size + sizeof(struct _obstack_chunk);
+
+  /* Note: this is rounding up to the multiple of chunk size that is power of
+   * two. Thus this creates limitation that chunks can be only power of two.
+   */
+
+  mask = h->chunk_size;
+  for (i = 1; i < sizeof(size_t); i = i << 1)
+      mask |= mask >> i;
+  size = (size + mask) & ~mask;
+
+  if (h->chunk == NULL ||
+      h->object_base != (void *)h->chunk + sizeof(struct _obstack_chunk))
+    {
+      /* Allocate new chunk if there is something in the chunk already or if
+       * there is no chunk yet.
+       */
+
+      struct _obstack_chunk *prev = h->chunk;

Review Comment:
   ```suggestion
         FAR struct _obstack_chunk *prev = h->chunk;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org