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/09/27 08:55:47 UTC

[GitHub] [incubator-nuttx] Cynerd opened a new pull request, #7198: libs/libc: add obstack

Cynerd opened a new pull request, #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198

   ## Summary
   Implementation of GlibC's Obstacks (https://www.gnu.org/software/libc/manual/html_node/Obstacks.html) tweaked to be less memory-consuming (although it is way less efficient for a lot of small allocations).
   
   ## Testing
   Tested with a custom application, as well as outside NuttX (except for `printf` part, of course).


-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1003277823


##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream
+{
+  struct lib_outstream_s public;
+  FAR struct obstack *h;
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int lib_puts(FAR struct lib_outstream_s *this,
+    FAR const void *buf, int len)
+{
+  FAR struct outstream *mthis = (FAR struct outstream *)this;
+
+  DEBUGASSERT(this);
+
+  obstack_grow(mthis->h, buf, len);
+
+  return len;
+}
+
+static void lib_putc(FAR struct lib_outstream_s *this, int ch)

Review Comment:
   Oh..  I see. It was in hidden comments for me because I responded to it. The changes got stuck in the stash for these two files. My fault.



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream
+{
+  struct lib_outstream_s public;
+  FAR struct obstack *h;
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int lib_puts(FAR struct lib_outstream_s *this,

Review Comment:
   Same here



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream

Review Comment:
   Same here



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001596110


##########
include/obstack.h:
##########
@@ -0,0 +1,466 @@
+/****************************************************************************
+ * 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)

Review Comment:
   Good catch.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1003278101


##########
libs/libc/obstack/lib_obstack_printf.c:
##########
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_printf.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 <stdio.h>
+#include <assert.h>

Review Comment:
   Same here



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>

Review Comment:
   Sane gere,



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>

Review Comment:
   Sane here



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #7198: libs/libc: add obstack

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198


-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r993202325


##########
libs/libc/obstack/Make.defs:
##########
@@ -0,0 +1,30 @@
+############################################################################
+# libs/libc/obstack/Make.defs
+#
+# 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.
+#
+############################################################################
+
+CSRCS += lib_obstack_init.c lib_obstack_alloc.c lib_obstack_copy.c
+CSRCS += lib_obstack_free.c lib_obstack_make_room.c lib_obstack_blank.c
+CSRCS += lib_obstack_grow.c lib_obstack_finish.c
+CSRCS += lib_obstack_object_size.c lib_obstack_room.c
+CSRCS += lib_obstack_printf.c lib_obstack_vprintf.c
+
+# Add the floating point math directory to the build

Review Comment:
   Ups...



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001587648


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

Review Comment:
   That is the question..
   
   Honestly, the point of even having this "non-standard" behaviour is to reduce the number of unused bytes when growing objects. The default `BUFSIZ` in the case of NuttX is `64`, which is not much but also can be too much-unused space. The overhead of creating the new chunk in terms of memory is two words (thus `8` bytes on 32bit). The memory overhead of growing small and big objects in tandem can be "pretty big". Let's consider the worst case of growing one byte, finishing, growing 57 (`64 - 8 + 1`) bytes and finishing that. That results in three allocated blocks and thus 192 bytes with 110 unused bytes (if I calculated correctly). Compare that with reallocating finish which would use 74 bytes (`8+1+8+57`). On the other hand, the worst the case scenario for the reallocating finish is, of course, allocating a lot of single bytes. You can fit 56 of such bytes into the single block while reallocating would add 8 bytes overhead to every such allocation. Thus we would use `504` bytes i
 nstead of `64`.  
   The question is how often the code is going to be using obstack for allocating single bytes (I think that it is unlikely, and the first case is more likely). At the same time, the worst-case scenario for the reallocating finish looks simply terrible.
   
   Another way to look at it, I think, is the question if we want to keep the original behaviour or change it. I see reasons for changing it here, especially because I appreciate the memory reduction if you allocate data with varied sizes.
   
   My last remark is that the best solution is a reallocation that won't move the base (fails if that is impossible). I could not get this with nuttx's allocator, but that might be just that I missed that in the code somewhere. The advantage would be that we could try to increase chunk size even if there is already a finished object. If that fails, we could use it to reduce allocation size and thus free those bytes we cannot use.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001595589


##########
include/obstack.h:
##########
@@ -0,0 +1,466 @@
+/****************************************************************************
+ * 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)

Review Comment:
   Good catch



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001600815


##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 = lib_malloc(size + sizeof(struct _obstack_chunk));
+      h->chunk->limit =
+        (char *)h->chunk + sizeof(struct _obstack_chunk) + size;

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001588205


##########
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 <nuttx/lib/lib.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.

Review Comment:
   👍



-- 
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


[GitHub] [incubator-nuttx] Cynerd commented on pull request #7198: libs/libc: add obstack

Posted by GitBox <gi...@apache.org>.
Cynerd commented on PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#issuecomment-1288944123

   > @Cynerd my last comment isn't resolved.
   
   The last comment I see is this one https://github.com/apache/incubator-nuttx/pull/7198#discussion_r987280006, and that is resolved by you without any response. I do not understand probably to which comment you are referring to.


-- 
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


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

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1003258152


##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream
+{
+  struct lib_outstream_s public;
+  FAR struct obstack *h;
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int lib_puts(FAR struct lib_outstream_s *this,
+    FAR const void *buf, int len)
+{
+  FAR struct outstream *mthis = (FAR struct outstream *)this;
+
+  DEBUGASSERT(this);
+
+  obstack_grow(mthis->h, buf, len);
+
+  return len;
+}
+
+static void lib_putc(FAR struct lib_outstream_s *this, int ch)

Review Comment:
   Not change



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream
+{
+  struct lib_outstream_s public;
+  FAR struct obstack *h;
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int lib_puts(FAR struct lib_outstream_s *this,

Review Comment:
   ditto



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream

Review Comment:
   ditto



-- 
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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1003314673


##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct obstack_stream
+{
+  struct lib_outstream_s public;
+  FAR struct obstack *h;
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int obstack_puts(FAR struct lib_outstream_s *this,
+    FAR const void *buf, int len)
+{
+  FAR struct obstack_stream *mthis = (FAR struct obstack_stream *)this;
+
+  DEBUGASSERT(this);
+
+  obstack_grow(mthis->h, buf, len);
+
+  return len;
+}
+
+static void obstack_putc(FAR struct lib_outstream_s *this, int ch)
+{
+  char tmp = ch;
+  lib_puts(this, &tmp, 1);

Review Comment:
   obstack_puts



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r993209357


##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r993212361


##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001593451


##########
libs/libc/obstack/lib_obstack_init.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_init.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 <stdio.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_init (struct obstack *h)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001602412


##########
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 <nuttx/lib/lib.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)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1002297711


##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+/****************************************************************************
+ * 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)

Review Comment:
   ```suggestion
                     FAR const void *address, size_t size)
   ```



##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+/****************************************************************************
+ * 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)
+{
+  obstack_make_room(h, size);
+  memcpy(h->next_free, address, size);
+  h->next_free += 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)

Review Comment:
   ```suggestion
                     FAR const void *address, size_t size)
   ```



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001540115


##########
libs/libc/obstack/lib_obstack_copy.c:
##########
@@ -0,0 +1,47 @@
+/****************************************************************************
+ * 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)
+{
+  FAR void *res = obstack_alloc(h, size);

Review Comment:
   Should not return `NULL` now.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r981581158


##########
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);

Review Comment:
   ditto



##########
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);

Review Comment:
   ```suggestion
   void obstack_init(FAR struct obstack *h);
   ```
   remove all space before (



##########
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);

Review Comment:
   ditto



##########
libs/libc/obstack/Kconfig:
##########
@@ -0,0 +1,14 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config OBSTACK

Review Comment:
   since the linker can optimize the unused function, how about we remove OBSTACK option?



##########
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)

Review Comment:
   ```suggestion
     for (i = 1; i < sizeof(size_t); i =<< 1)
   ```



##########
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>
+

Review Comment:
   remove the blank line



##########
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);

Review Comment:
   ```suggestion
                         FAR const void *address, 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,
+    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);

Review Comment:
   align



##########
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>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <obstack.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+size_t obstack_object_size (FAR struct obstack *h)

Review Comment:
   change to macro?



##########
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, ...);

Review Comment:
   add printflike



-- 
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


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

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r996491755


##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+void obstack_grow(FAR struct obstack *h,
+    FAR const void *address, size_t size)
+{
+  obstack_make_room(h, size);
+  memcpy(h->next_free, address, size);
+  h->next_free += size;
+}
+
+void obstack_grow0(FAR struct obstack *h,
+    FAR const void *address, size_t size)
+{
+  obstack_make_room(h, size + 1);
+  memcpy(h->next_free, address, size);
+  h->next_free += size;
+  *h->next_free = '\0';
+  h->next_free++;
+}
+
+void obstack_1grow(FAR struct obstack *h, char data)

Review Comment:
   Ditto



##########
libs/libc/obstack/lib_obstack_init.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_init.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 <stdio.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_init (struct obstack *h)

Review Comment:
   Please include a description for this function



##########
libs/libc/obstack/lib_obstack_room.c:
##########
@@ -0,0 +1,36 @@
+/****************************************************************************
+ * 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:
   Ditto



##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+void obstack_grow(FAR struct obstack *h,

Review Comment:
   Please include a description for this function



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

Review Comment:
   Please include a comment explaning the idea behind this chbase == object_base



##########
libs/libc/obstack/lib_obstack_object_size.c:
##########
@@ -0,0 +1,34 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_object_size.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
+ ****************************************************************************/
+
+size_t obstack_object_size(FAR struct obstack *h)

Review Comment:
   Please include a description for this function



##########
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 <nuttx/lib/lib.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.

Review Comment:
   ```suggestion
             /* The object is in this chunk so just move object base.
   ```



##########
libs/libc/obstack/lib_obstack_printf.c:
##########
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_printf.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 <stdio.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int obstack_printf(FAR struct obstack *h, FAR const char *fmt, ...)

Review Comment:
   Please include a description for this function



##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+void obstack_grow(FAR struct obstack *h,
+    FAR const void *address, size_t size)
+{
+  obstack_make_room(h, size);
+  memcpy(h->next_free, address, size);
+  h->next_free += size;
+}
+
+void obstack_grow0(FAR struct obstack *h,

Review Comment:
   Please include a description for this function



##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_make_room(FAR struct obstack *h, size_t size)

Review Comment:
   Please include a description for this function



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #7198: libs/libc: add obstack

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#issuecomment-1287576327

   @Cynerd my last comment isn't resolved.


-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #7198: libs/libc: add obstack

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#issuecomment-1288965053

   Let's me reply in the related comment.


-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001602118


##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 = lib_malloc(size + sizeof(struct _obstack_chunk));
+      h->chunk->limit =
+        (char *)h->chunk + sizeof(struct _obstack_chunk) + size;
+      h->chunk->prev = prev;
+      h->object_base = (char *)h->chunk + sizeof(struct _obstack_chunk);

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001595150


##########
libs/libc/obstack/lib_obstack_room.c:
##########
@@ -0,0 +1,36 @@
+/****************************************************************************
+ * 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:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001591886


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

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001542849


##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 <<= 1)
+      mask |= mask >> i;
+  size = (size + mask) & ~mask;
+
+  if (h->chunk == NULL ||
+      h->object_base != (FAR char *)h->chunk + sizeof(struct _obstack_chunk))
+    {
+      /* Allocate new chunk if there is something in the chunk already or if
+       * there is no chunk yet.
+       */
+
+      FAR struct _obstack_chunk *prev = h->chunk;
+      h->chunk = lib_malloc(size);

Review Comment:
   Replaced by `lib_obstack_malloc`.



##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 <<= 1)
+      mask |= mask >> i;
+  size = (size + mask) & ~mask;
+
+  if (h->chunk == NULL ||
+      h->object_base != (FAR char *)h->chunk + sizeof(struct _obstack_chunk))
+    {
+      /* Allocate new chunk if there is something in the chunk already or if
+       * there is no chunk yet.
+       */
+
+      FAR struct _obstack_chunk *prev = h->chunk;
+      h->chunk = lib_malloc(size);
+      h->chunk->prev = prev;
+    }
+
+  else
+    {
+      h->chunk = lib_realloc(h->chunk, size);

Review Comment:
   Replaced by `lib_obstack_malloc`.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1003258369


##########
libs/libc/obstack/lib_obstack_printf.c:
##########
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_printf.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 <stdio.h>
+#include <assert.h>

Review Comment:
   ditto



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>

Review Comment:
   ditto



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r993208741


##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream
+{
+  struct lib_outstream_s public;
+  FAR struct obstack *h;
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int lib_puts(FAR struct lib_outstream_s *this,
+    FAR const void *buf, int len)
+{
+  FAR struct outstream *mthis = (FAR struct outstream *)this;
+
+  DEBUGASSERT(this);
+
+  obstack_grow(mthis->h, buf, len);
+
+  return len;
+}
+
+static void lib_putc(FAR struct lib_outstream_s *this, int ch)

Review Comment:
   Ok



##########
libs/libc/obstack/lib_obstack_vprintf.c:
##########
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_vprintf.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 <stdio.h>
+#include <assert.h>
+#include <nuttx/streams.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct outstream
+{
+  struct lib_outstream_s public;
+  FAR struct obstack *h;
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int lib_puts(FAR struct lib_outstream_s *this,

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r993210210


##########
libs/libc/obstack/lib_obstack_printf.c:
##########
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_printf.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 <stdio.h>
+#include <assert.h>

Review Comment:
   Yep



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001592978


##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+void obstack_grow(FAR struct obstack *h,

Review Comment:
   Ok



##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+void obstack_grow(FAR struct obstack *h,
+    FAR const void *address, size_t size)
+{
+  obstack_make_room(h, size);
+  memcpy(h->next_free, address, size);
+  h->next_free += size;
+}
+
+void obstack_grow0(FAR struct obstack *h,

Review Comment:
   Ok



##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+void obstack_grow(FAR struct obstack *h,
+    FAR const void *address, size_t size)
+{
+  obstack_make_room(h, size);
+  memcpy(h->next_free, address, size);
+  h->next_free += size;
+}
+
+void obstack_grow0(FAR struct obstack *h,
+    FAR const void *address, size_t size)
+{
+  obstack_make_room(h, size + 1);
+  memcpy(h->next_free, address, size);
+  h->next_free += size;
+  *h->next_free = '\0';
+  h->next_free++;
+}
+
+void obstack_1grow(FAR struct obstack *h, char data)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001593858


##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_make_room(FAR struct obstack *h, size_t size)

Review Comment:
   Ok



##########
libs/libc/obstack/lib_obstack_object_size.c:
##########
@@ -0,0 +1,34 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_object_size.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
+ ****************************************************************************/
+
+size_t obstack_object_size(FAR struct obstack *h)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001594863


##########
libs/libc/obstack/lib_obstack_printf.c:
##########
@@ -0,0 +1,43 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_printf.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 <stdio.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int obstack_printf(FAR struct obstack *h, FAR const char *fmt, ...)

Review Comment:
   ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001602677


##########
libs/libc/obstack/lib_obstack_init.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_init.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 <stdio.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_init (struct obstack *h)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001078355


##########
include/obstack.h:
##########
@@ -0,0 +1,466 @@
+/****************************************************************************
+ * 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)

Review Comment:
   ```suggestion
   #define obstack_1grow_fast(h, data) (*((h)->next_free++) = (data))
   ```



##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 = lib_malloc(size + sizeof(struct _obstack_chunk));
+      h->chunk->limit =
+        (char *)h->chunk + sizeof(struct _obstack_chunk) + size;

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



##########
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 <nuttx/lib/lib.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)

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



##########
libs/libc/obstack/lib_obstack_init.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_init.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 <stdio.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_init (struct obstack *h)

Review Comment:
   ```suggestion
   void obstack_init(FAR struct obstack *h)
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,466 @@
+/****************************************************************************
+ * 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)

Review Comment:
   ```suggestion
   #define obstack_blank_fast(h, size) ((h)->next_free += (size))
   ```



##########
include/obstack.h:
##########
@@ -0,0 +1,466 @@
+/****************************************************************************
+ * 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. */

Review Comment:
   Why do we need `_` prefix here?



##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 = lib_malloc(size + sizeof(struct _obstack_chunk));
+      h->chunk->limit =
+        (char *)h->chunk + sizeof(struct _obstack_chunk) + size;
+      h->chunk->prev = prev;
+      h->object_base = (char *)h->chunk + sizeof(struct _obstack_chunk);

Review Comment:
   ```suggestion
         h->object_base = (FAR char *)h->chunk + sizeof(struct _obstack_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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r993213435


##########
libs/libc/obstack/lib_obstack_init.c:
##########
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_init.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 <stdio.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void obstack_init (struct obstack *h)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r993207564


##########
libs/libc/obstack/lib_obstack_copy.c:
##########
@@ -0,0 +1,47 @@
+/****************************************************************************
+ * 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)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001529879


##########
libs/libc/obstack/lib_obstack_alloc.c:
##########
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 = lib_malloc(size + sizeof(struct _obstack_chunk));

Review Comment:
   I introduced the handler as described in GLibC documentation.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001556567


##########
libs/libc/obstack/lib_obstack_make_room.c:
##########
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * 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 <nuttx/lib/lib.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 <<= 1)
+      mask |= mask >> i;
+  size = (size + mask) & ~mask;
+
+  if (h->chunk == NULL ||
+      h->object_base != (FAR char *)h->chunk + sizeof(struct _obstack_chunk))
+    {
+      /* Allocate new chunk if there is something in the chunk already or if
+       * there is no chunk yet.
+       */
+
+      FAR struct _obstack_chunk *prev = h->chunk;
+      h->chunk = lib_malloc(size);
+      h->chunk->prev = prev;

Review Comment:
   Good catch. The growing object would stay here on the old 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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1001600500


##########
include/obstack.h:
##########
@@ -0,0 +1,466 @@
+/****************************************************************************
+ * 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. */

Review Comment:
   Consistency with this implementation https://github.com/void-linux/musl-obstack/blob/master/obstack.h#L156.
   
   It is an undocumented structure in GlibC. I think this is an import from Python where `_` is used to denote protected and private data. Honestly, I use it a lot. The common paradigm I am using is `_` for types I do not consider strictly part of public API and `__` for macros that are an implementation detail and not expected to be used externally.



-- 
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


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

Posted by GitBox <gi...@apache.org>.
Cynerd commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1003240966


##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+/****************************************************************************
+ * 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)

Review Comment:
   Ok



##########
libs/libc/obstack/lib_obstack_grow.c:
##########
@@ -0,0 +1,93 @@
+/****************************************************************************
+ * libs/libc/obstack/lib_obstack_grow.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
+ ****************************************************************************/
+
+/****************************************************************************
+ * 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)
+{
+  obstack_make_room(h, size);
+  memcpy(h->next_free, address, size);
+  h->next_free += 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)

Review Comment:
   Ok



-- 
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


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

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7198:
URL: https://github.com/apache/incubator-nuttx/pull/7198#discussion_r1003258629


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

Review Comment:
   Ok.



-- 
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