xiaoxiang781216 commented on code in PR #15326:
URL: https://github.com/apache/nuttx/pull/15326#discussion_r1896853483


##########
include/nuttx/lib/lib.h:
##########
@@ -38,6 +38,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#if CONFIG_PATH_MAX > CONFIG_LINE_MAX

Review Comment:
   keep in the soure code



##########
libs/libc/misc/lib_tempbuffer.c:
##########
@@ -63,58 +63,61 @@ static struct pathbuffer_s g_pathbuffer =
  ****************************************************************************/
 
 /****************************************************************************
- * Name: lib_get_pathbuffer
+ * Name: lib_get_tempbuffer
  *
  * Description:
- *   The lib_get_pathbuffer() function returns a pointer to a temporary
+ *   The lib_get_tempbuffer() function returns a pointer to a temporary
  *   buffer.  The buffer is allocated from a pool of pre-allocated buffers
  *   and if the pool is exhausted, a new buffer is allocated through
- *   kmm_malloc(). The size of the buffer is PATH_MAX, and must freed by
- *   calling lib_put_pathbuffer().
+ *   kmm_malloc(). The size of the buffer is nbytes, and must freed by
+ *   calling lib_put_tempbuffer().
  *
  * Returned Value:
- *   On success, lib_get_pathbuffer() returns a pointer to a temporary
+ *   On success, lib_get_tempbuffer() returns a pointer to a temporary
  *   buffer.  On failure, NULL is returned.
  *
  ****************************************************************************/
 
-FAR char *lib_get_pathbuffer(void)
+FAR char *lib_get_tempbuffer(size_t nbytes)
 {
-  for (; ; )
+  if (nbytes <= TEMP_MAX_SIZE)

Review Comment:
   many places (especially in nsh) need allocate temp buffer (e.g. path or 
line) only in function scope, both follow approach isn't perfect:
   
   1. Allocate from stack, which already cause the default 2KB stack is 
unusable in many cases:
       https://github.com/apache/nuttx/pull/15173
       https://github.com/apache/nuttx/pull/14501
   2. Allocate from heap, which may increase memory fragment and impact 
performance
   
   so, it's reasonable to extend pathbuffer to tempbuffer, and let's caller 
utilize the general buffer facility when they find some function occupy too 
much stack space.
   
   > You should call malloc in nshlib instead of making the interface so ugly
   
   It's natural to add size argument to a buffer allocation function. Do you 
feel ugly malloc with size or not strange malloc without size?



##########
include/nuttx/lib/lib.h:
##########
@@ -120,14 +126,14 @@ FAR struct file_struct *lib_get_stream(int fd);
 
 unsigned long nrand(unsigned long limit);
 
-/* Functions defined in lib_pathbuffer.c ************************************/
+/* Functions defined in lib_tempbuffer.c ************************************/
 
-#ifdef CONFIG_LIBC_PATHBUFFER
-FAR char *lib_get_pathbuffer(void);
-void lib_put_pathbuffer(FAR char *buffer);
+#ifdef CONFIG_LIBC_TEMPBUFFER
+FAR char *lib_get_tempbuffer(size_t nbytes);
+void lib_put_tempbuffer(FAR char *buffer);
 #else
-#  define lib_get_pathbuffer() alloca(PATH_MAX)
-#  define lib_put_pathbuffer(b)
+#  define lib_get_tempbuffer(f) alloca(TEMP_MAX_SIZE)

Review Comment:
   ```
   #  define lib_get_tempbuffer(n) alloca(n)
   ```



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