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

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

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