tools/nxstyle.c: Fix error in conditional logic that was preventing detection bad brace alignment. Add logic to handle alignment of braces in data initializators which following slightly different indentation rules.

This commit is contained in:
Gregory Nutt 2019-06-30 10:35:10 -06:00
parent 5653b9a2af
commit bde0509cae
10 changed files with 122 additions and 90 deletions

View file

@ -120,7 +120,7 @@ int env_dup(FAR struct task_group_s *group)
}
else
{
/* Duplicate the parent environment. */
/* Duplicate the parent environment. */
memcpy(envp, ptcb->group->tg_envp, envlen);
}

View file

@ -90,6 +90,7 @@
****************************************************************************/
/* Task Lists ***************************************************************/
/* The state of a task is indicated both by the task_state field of the TCB
* and by a series of task lists. All of these tasks lists are declared
* below. Although it is not always necessary, most of these lists are
@ -401,6 +402,7 @@ void nx_start(void)
g_nx_initstate = OSINIT_BOOT;
/* Initialize RTOS Data ***************************************************/
/* Initialize all task lists */
dq_init(&g_readytorun);
@ -747,6 +749,7 @@ void nx_start(void)
#endif
/* IDLE Group Initialization **********************************************/
/* Announce that the CPU0 IDLE task has started */
sched_note_start(&g_idletcb[0].cmn);
@ -788,6 +791,7 @@ void nx_start(void)
}
/* Start SYSLOG ***********************************************************/
/* Late initialization of the system logging device. Some SYSLOG channel
* must be initialized late in the initialization sequence because it may
* depend on having IDLE task file structures setup.
@ -815,6 +819,7 @@ void nx_start(void)
#endif /* CONFIG_SMP */
/* Bring Up the System ****************************************************/
/* The OS is fully initialized and we are beginning multi-tasking */
g_nx_initstate = OSINIT_OSREADY;
@ -831,6 +836,7 @@ void nx_start(void)
#endif /* CONFIG_SMP */
/* The IDLE Loop **********************************************************/
/* When control is return to this point, the system is idle. */
sinfo("CPU0: Beginning Idle Loop\n");

View file

@ -57,8 +57,8 @@ struct irqchain_s
* Private Data
****************************************************************************/
/* g_irqchainpool is a list of pre-allocated irq chain. The number of irq chains
* in the pool is a configuration item.
/* g_irqchainpool is a list of pre-allocated irq chain. The number of irq
* chains in the pool is a configuration item.
*/
static struct irqchain_s g_irqchainpool[CONFIG_PREALLOC_IRQCHAIN];
@ -176,7 +176,7 @@ int irqchain_attach(int ndx, xcpt_t isr, FAR void *arg)
g_irqvector[ndx].handler = irqchain_dispatch;
g_irqvector[ndx].arg = node;
}
}
node = (FAR struct irqchain_s *)sq_remfirst(&g_irqchainfreelist);
if (node == NULL)
@ -255,14 +255,16 @@ int irqchain_detach(int irq, xcpt_t isr, FAR void *arg)
prev->next = curr->next;
}
sq_addlast((FAR struct sq_entry_s *)curr, &g_irqchainfreelist);
sq_addlast((FAR struct sq_entry_s *)curr,
&g_irqchainfreelist);
first = g_irqvector[ndx].arg;
if (first->next == NULL)
{
g_irqvector[ndx].handler = first->handler;
g_irqvector[ndx].arg = first->arg;
sq_addlast((FAR struct sq_entry_s *)first, &g_irqchainfreelist);
sq_addlast((FAR struct sq_entry_s *)first,
&g_irqchainfreelist);
}
ret = OK;

View file

@ -59,12 +59,12 @@
* Description:
* The function pthread_mutex_trylock() is identical to pthread_mutex_lock()
* except that if the mutex object referenced by mutex is currently locked
* (by any thread, including the current thread), the call returns immediately
* with the errno EBUSY.
* (by any thread, including the current thread), the call returns
* immediately with the errno EBUSY.
*
* If a signal is delivered to a thread waiting for a mutex, upon return from
* the signal handler the thread resumes waiting for the mutex as if it was
* not interrupted.
* If a signal is delivered to a thread waiting for a mutex, upon return
* from the signal handler the thread resumes waiting for the mutex as if
* it was not interrupted.
*
* Input Parameters:
* mutex - A reference to the mutex to be locked.
@ -147,55 +147,55 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex)
#endif
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
/* The calling thread does not hold the semaphore. The correct
* behavior for the 'robust' mutex is to verify that the holder of
* the mutex is still valid. This is protection from the case
* where the holder of the mutex has exitted without unlocking it.
*/
/* The calling thread does not hold the semaphore. The correct
* behavior for the 'robust' mutex is to verify that the holder of
* the mutex is still valid. This is protection from the case
* where the holder of the mutex has exitted without unlocking it.
*/
#ifdef CONFIG_PTHREAD_MUTEX_BOTH
#ifdef CONFIG_PTHREAD_MUTEX_TYPES
/* Check if this NORMAL mutex is robust */
/* Check if this NORMAL mutex is robust */
if (mutex->pid > 0 &&
((mutex->flags & _PTHREAD_MFLAGS_ROBUST) != 0 ||
mutex->type != PTHREAD_MUTEX_NORMAL) &&
sched_gettcb(mutex->pid) == NULL)
if (mutex->pid > 0 &&
((mutex->flags & _PTHREAD_MFLAGS_ROBUST) != 0 ||
mutex->type != PTHREAD_MUTEX_NORMAL) &&
sched_gettcb(mutex->pid) == NULL)
#else /* CONFIG_PTHREAD_MUTEX_TYPES */
/* Check if this NORMAL mutex is robust */
/* Check if this NORMAL mutex is robust */
if (mutex->pid > 0 &&
(mutex->flags & _PTHREAD_MFLAGS_ROBUST) != 0 &&
sched_gettcb(mutex->pid) == NULL)
if (mutex->pid > 0 &&
(mutex->flags & _PTHREAD_MFLAGS_ROBUST) != 0 &&
sched_gettcb(mutex->pid) == NULL)
#endif /* CONFIG_PTHREAD_MUTEX_TYPES */
#else /* CONFIG_PTHREAD_MUTEX_ROBUST */
/* This mutex is always robust, whatever type it is. */
/* This mutex is always robust, whatever type it is. */
if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
#endif
{
DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */
DEBUGASSERT((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0);
{
DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */
DEBUGASSERT((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0);
/* A thread holds the mutex, but there is no such thread.
* POSIX requires that the 'robust' mutex return EOWNERDEAD
* in this case. It is then the caller's responsibility to
* call pthread_mutx_consistent() fo fix the mutex.
*/
/* A thread holds the mutex, but there is no such thread.
* POSIX requires that the 'robust' mutex return EOWNERDEAD
* in this case. It is then the caller's responsibility to
* call pthread_mutx_consistent() fo fix the mutex.
*/
mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT;
ret = EOWNERDEAD;
}
mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT;
ret = EOWNERDEAD;
}
/* The mutex is locked by another, active thread */
else
else
#endif /* CONFIG_PTHREAD_MUTEX_UNSAFE */
{
ret = EBUSY;
}
{
ret = EBUSY;
}
}
/* Some other, unhandled error occurred */

View file

@ -94,13 +94,14 @@ static inline bool pthread_mutex_islocked(FAR struct pthread_mutex_s *mutex)
* mutex's type attribute. If there are threads blocked on the mutex object
* referenced by mutex when pthread_mutex_unlock() is called, resulting in
* the mutex becoming available, the scheduling policy is used to determine
* which thread shall acquire the mutex. (In the case of PTHREAD_MUTEX_RECURSIVE
* mutexes, the mutex becomes available when the count reaches zero and the
* calling thread no longer has any locks on this mutex).
* which thread shall acquire the mutex. (In the case of
* PTHREAD_MUTEX_RECURSIVE mutexes, the mutex becomes available when the
* count reaches zero and the calling thread no longer has any locks on
* this mutex).
*
* If a signal is delivered to a thread waiting for a mutex, upon return from
* the signal handler the thread resumes waiting for the mutex as if it was
* not interrupted.
* If a signal is delivered to a thread waiting for a mutex, upon return
* from the signal handler the thread resumes waiting for the mutex as if
* it was not interrupted.
*
* Input Parameters:
* None
@ -203,9 +204,9 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->nlocks > 1)
{
/* This is a recursive mutex and we there are multiple locks held. Retain
* the mutex lock, just decrement the count of locks held, and return
* success.
/* This is a recursive mutex and we there are multiple locks held.
* Retain the mutex lock, just decrement the count of locks held,
* and return success.
*/
mutex->nlocks--;
@ -215,14 +216,14 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
#endif /* CONFIG_PTHREAD_MUTEX_TYPES */
/* This is either a non-recursive mutex or is the outermost unlock of
* a recursive mutex.
*
* In the case where the calling thread is NOT the holder of the thread,
* the behavior is undefined per POSIX. Here we do the same as GLIBC:
* We allow the other thread to release the mutex even though it does
* not own it.
*/
/* This is either a non-recursive mutex or is the outermost unlock of
* a recursive mutex.
*
* In the case where the calling thread is NOT the holder of the thread,
* the behavior is undefined per POSIX. Here we do the same as GLIBC:
* We allow the other thread to release the mutex even though it does
* not own it.
*/
{
/* Nullify the pid and lock count then post the semaphore */

View file

@ -110,25 +110,25 @@ static void nxsig_setup_default_action(FAR struct task_group_s *group,
static const struct nxsig_defaction_s g_defactions[] =
{
#ifdef CONFIG_SIG_SIGUSR1_ACTION
{ SIGUSR1, 0, nxsig_abnormal_termination },
{ SIGUSR1, 0, nxsig_abnormal_termination },
#endif
#ifdef CONFIG_SIG_SIGUSR2_ACTION
{ SIGUSR2, 0, nxsig_abnormal_termination },
{ SIGUSR2, 0, nxsig_abnormal_termination },
#endif
#ifdef CONFIG_SIG_SIGALRM_ACTION
{ SIGALRM, 0, nxsig_abnormal_termination },
{ SIGALRM, 0, nxsig_abnormal_termination },
#endif
#ifdef CONFIG_SIG_SIGPOLL_ACTION
{ SIGPOLL, 0, nxsig_abnormal_termination },
{ SIGPOLL, 0, nxsig_abnormal_termination },
#endif
#ifdef CONFIG_SIG_SIGSTOP_ACTION
{ SIGSTOP, SIG_FLAG_NOCATCH, nxsig_stop_task },
{ SIGSTP, 0, nxsig_stop_task },
{ SIGCONT, SIG_FLAG_NOCATCH, nxsig_null_action },
{ SIGSTOP, SIG_FLAG_NOCATCH, nxsig_stop_task },
{ SIGSTP, 0, nxsig_stop_task },
{ SIGCONT, SIG_FLAG_NOCATCH, nxsig_null_action },
#endif
#ifdef CONFIG_SIG_SIGKILL_ACTION
{ SIGINT, 0, nxsig_abnormal_termination },
{ SIGKILL, SIG_FLAG_NOCATCH, nxsig_abnormal_termination }
{ SIGINT, 0, nxsig_abnormal_termination },
{ SIGKILL, SIG_FLAG_NOCATCH, nxsig_abnormal_termination }
#endif
};
@ -204,13 +204,14 @@ static void nxsig_abnormal_termination(int signo)
* "When cancelability is disabled, all cancels are held pending
* in the target thread until the thread changes the cancelability.
* When cancelability is deferred, all cancels are held pending in
* the target thread until the thread changes the cancelability, calls
* a function which is a cancellation point or calls pthread_testcancel(),
* thus creating a cancellation point. When cancelability is asynchronous,
* all cancels are acted upon immediately, interrupting the thread with its
* processing."
* the target thread until the thread changes the cancelability,
* calls a function which is a cancellation point or calls
* pthread_testcancel(), thus creating a cancellation point. When
* cancelability is asynchronous, all cancels are acted upon
* immediately, interrupting the thread with its processing."
*
* REVISIT: Does this rule apply to equally to both SIGKILL and SIGINT?
* REVISIT: Does this rule apply to equally to both SIGKILL and
* SIGINT?
*/
rtcb->flags |= TCB_FLAG_CANCEL_PENDING;
@ -243,7 +244,7 @@ static void nxsig_abnormal_termination(int signo)
}
#endif
sched_unlock();
sched_unlock();
/* Careful: In the multi-threaded task, the signal may be handled on a
* child pthread.
@ -352,7 +353,7 @@ static void nxsig_stop_task(int signo)
/* Wake up the thread */
nxsem_post(&group->tg_exitsem);
}
}
}
#endif
@ -538,7 +539,7 @@ bool nxsig_iscatchable(int signo)
*
****************************************************************************/
_sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction)
_sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction)
{
FAR struct task_group_s *group;
_sa_handler_t handler = SIG_IGN;
@ -584,8 +585,8 @@ bool nxsig_iscatchable(int signo)
* Name: nxsig_default_initialize
*
* Description:
* Set all signals to their default action. This is called from nxtask_start
* to configure the newly started task.
* Set all signals to their default action. This is called from
* nxtask_start() to configure the newly started task.
*
* Input Parameters:
* tcb - Identifies the thread associated with the default handlers

View file

@ -129,9 +129,10 @@ int ppoll(FAR struct pollfd *fds, nfds_t nfds,
/* And call poll to do the real work */
if (timeout_ts)
{
timeout = timeout_ts->tv_sec * 1000 + timeout_ts->tv_nsec / 1000000;
}
{
timeout = timeout_ts->tv_sec * 1000 +
timeout_ts->tv_nsec / 1000000;
}
ret = poll(fds, nfds, timeout);

View file

@ -307,7 +307,7 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
leave_critical_section(flags);
return -ECANCELED;
}
}
#endif
/* Save the set of pending signals to wait for */

View file

@ -252,7 +252,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
ret = nxsched_setparam(pid, &param);
if (ret < 0)
{
return ret;
return ret;
}
}
}

View file

@ -429,6 +429,11 @@ int main(int argc, char **argv, char **envp)
strncmp(&line[indent], "void ", 5) == 0 ||
strncmp(&line[indent], "volatile ", 9) == 0)
{
/* bfunctions: True: Processing private or public functions.
* bnest: Brace nesting level on this line
* dnest: Data declaration nesting level on this line
*/
/* REVISIT: Also picks up function return types */
/* REVISIT: Logic problem for nested data/function declarations */
@ -843,7 +848,7 @@ int main(int argc, char **argv, char **envp)
{
if (n > indent)
{
/* REVISIT: dest is always > 0 here if bfunctions == false */
/* REVISIT: dnest is always > 0 here if bfunctions == false */
if (dnest == 0 || !bfunctions)
{
@ -1525,7 +1530,7 @@ int main(int argc, char **argv, char **envp)
/* Check for various alignment outside of the comment block */
else if ((ncomment > 0 || prevncomment > 0) && !bstring)
else if ((ncomment == 0 && prevncomment == 0) && !bstring)
{
if (indent == 0 && strchr("\n#{}", line[0]) == NULL)
{
@ -1564,9 +1569,17 @@ int main(int argc, char **argv, char **envp)
}
else if (line[indent] == '{')
{
/* REVISIT: False alarms in data initializers and switch statements */
/* REVISIT: Possible false alarms in compound statements
* without a preceding conditional. That usage often violates
* the coding standard.
*/
if ((indent & 3) != 0 && !bswitch && dnest == 0)
if (!bfunctions && (indent & 1) != 0)
{
fprintf(stderr, "Bad left brace alignment at line %d:%d\n",
lineno, indent);
}
else if ((indent & 3) != 0 && !bswitch && dnest == 0)
{
fprintf(stderr, "Bad left brace alignment at line %d:%d\n",
lineno, indent);
@ -1574,9 +1587,17 @@ int main(int argc, char **argv, char **envp)
}
else if (line[indent] == '}')
{
/* REVISIT: False alarms in data initializers and switch statements */
/* REVISIT: Possible false alarms in compound statements
* without a preceding conditional. That usage often violates
* the coding standard.
*/
if ((indent & 3) != 0 && !bswitch && prevdnest == 0)
if (!bfunctions && (indent & 1) != 0)
{
fprintf(stderr, "right left brace alignment at line %d:%d\n",
lineno, indent);
}
else if ((indent & 3) != 0 && !bswitch && prevdnest == 0)
{
fprintf(stderr, "Bad right brace alignment at line %d:%d\n",
lineno, indent);