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


##########
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:
   The implementation of pathbuffer is a memory pool with a limited length. 
Currently, all the kernel code is using the length of PATH_MAX. From the kernel 
perspective, increasing the length parameter is a strange design, because the 
kernel code can ensure that all locations(100%) that call pathbuffer only use 
PATH_MAX:
   
   FAR char *lib_get_pathbuffer(void);
   -> FAR char *lib_get_tempbuffer(size_t nbytes);   <- why?
   
   If the customized length in the application exceeds PATH_MAX, we should 
manage the life cycle of this memory segment by application self. If the stack 
occupies too much, we can choose to define it statically or call malloc:
   
   https://github.com/apache/nuttx-apps/blob/master/nshlib/nsh_console.h#L157
   
   The design of the API should be more reasonable and easy to use. If 99% of 
the code is using PATH_MAX as the expected value, why should these codes bear 
the overhead of parameter passing and parameter checking? This is unreasonable



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