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-unsubscr...@nuttx.apache.org

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

Reply via email to