tools/nxstyle.c: Fix logic that detects if an operator is correctly delimited with spaces. sched/: Various changes because sched/ C files were used as Guinea Pigs to test nstyle.c.

This commit is contained in:
Gregory Nutt
2019-03-01 10:50:02 -06:00
parent 4942867fcf
commit f914ec6e2b
28 changed files with 362 additions and 233 deletions
+9
View File
@@ -903,15 +903,24 @@ o pthreads (sched/pthreads libs/libc/pthread)
1. The Use is not fully verified. How are these interfaces
used? How should they be tested?
2. These interfaces depend on architecture specific support
support fraom each architecture that support is not be
fully available to the pthread library in all cases.
There should a setting, say CONFIG_ARCH_HAVE_TESTSET=y
that indicates if the architect provides up_testset().
3. It is also restricted to CONFIG_BUILD_FLAT because the
critical test and set function (up_testset()) as
prototyped in include/nuttx/spinlock() does not permit an
inline function or macro to be used in user-mode
application space.
Update: A better alternative would be to move the CPU-
depending up_testset() implementation from the arch/
directories and into libs/libc/machine.
For these reasons, the selection is marked EXPERIMENTAL.
Status: Open
Priority: Low. These are new interfaces and not yet in wide use. The
+4 -1
View File
@@ -51,7 +51,10 @@
/* 23 * (month + 1) / 9, month = 0..11 */
static const uint8_t g_lookup[12] = {2, 5, 7, 10, 12, 15, 17, 20, 23, 25, 28, 30};
static const uint8_t g_lookup[12] =
{
2, 5, 7, 10, 12, 15, 17, 20, 23, 25, 28, 30
};
/****************************************************************************
* Public Functions
+3 -1
View File
@@ -293,7 +293,9 @@ void clock_synchronize(void)
#if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS)
void clock_resynchronize(FAR struct timespec *rtc_diff)
{
struct timespec rtc_time, bias, curr_ts;
struct timespec rtc_time;
struct timespec bias;
struct timespec curr_ts;
struct timespec rtc_diff_tmp;
irqstate_t flags;
int32_t carry;
-3
View File
@@ -137,6 +137,3 @@ int env_dup(FAR struct task_group_s *group)
}
#endif /* CONFIG_DISABLE_ENVIRON */
-3
View File
@@ -114,6 +114,3 @@ errout:
}
#endif /* CONFIG_DISABLE_ENVIRON */
-3
View File
@@ -95,6 +95,3 @@ void env_release(FAR struct task_group_s *group)
}
#endif /* CONFIG_DISABLE_ENVIRON */
-3
View File
@@ -115,6 +115,3 @@ int env_removevar(FAR struct task_group_s *group, FAR char *pvar)
}
#endif /* CONFIG_DISABLE_ENVIRON */
-3
View File
@@ -133,6 +133,3 @@ int unsetenv(FAR const char *name)
}
#endif /* CONFIG_DISABLE_ENVIRON */
+1
View File
@@ -56,6 +56,7 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Is this worth making a configuration option? */
#define GROUP_REALLOC_MEMBERS 4
+1 -1
View File
@@ -116,7 +116,7 @@ static int group_killchildren_handler(pid_t pid, FAR void *arg)
}
}
/* Always return zero. We need to visit each member of the group*/
/* Always return zero. We need to visit each member of the group. */
return OK;
}
+1 -1
View File
@@ -87,7 +87,7 @@ static int group_suspendchildren_handler(pid_t pid, FAR void *arg)
}
}
/* Always return zero. We need to visit each member of the group*/
/* Always return zero. We need to visit each member of the group. */
return OK;
}
-2
View File
@@ -121,5 +121,3 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond)
sinfo("Returning %d\n", ret);
return ret;
}
-2
View File
@@ -113,5 +113,3 @@ int pthread_cond_signal(FAR pthread_cond_t *cond)
sinfo("Returning %d\n", ret);
return ret;
}
-3
View File
@@ -211,6 +211,3 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex)
sinfo("Returning %d\n", ret);
return ret;
}
-2
View File
@@ -239,5 +239,3 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
sinfo("Returning %d\n", ret);
return ret;
}
-2
View File
@@ -90,5 +90,3 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg)
leave_critical_section(flags);
}
}
-2
View File
@@ -72,5 +72,3 @@ FAR struct socketlist *sched_getsockets(void)
return &group->tg_socketlist;
}
#endif
+2 -1
View File
@@ -83,7 +83,8 @@ FAR sigq_t *nxsig_alloc_pendingsigaction(void)
}
/* If we were not called from an interrupt handler, then we are
* free to allocate pending signal action structures if necessary. */
* free to allocate pending signal action structures if necessary.
*/
else
{
+3 -2
View File
@@ -512,8 +512,9 @@ bool nxsig_iscatchable(int signo)
if (handler == SIG_IGN)
{
/* We are unsetting the default action */
/* sigdelset() is not atomic (but neither is sigaction()) */
/* We are unsetting the default action. NOTE that sigdelset() is not
* atomic (but neither is sigaction()).
*/
flags = spin_lock_irqsave();
(void)sigdelset(&group->tg_sigdefault, signo);
+2 -1
View File
@@ -93,7 +93,8 @@ static int nxsig_queue_action(FAR struct tcb_s *stcb, siginfo_t *info)
{
/* Allocate a new element for the signal queue. NOTE:
* nxsig_alloc_pendingsigaction will force a system crash if it is
* unable to allocate memory for the signal data */
* unable to allocate memory for the signal data.
*/
sigq = nxsig_alloc_pendingsigaction();
if (!sigq)
+4 -2
View File
@@ -68,7 +68,8 @@ void nxsig_release_pendingsigaction(FAR sigq_t *sigq)
if (sigq->type == SIG_ALLOC_FIXED)
{
/* Make sure we avoid concurrent access to the free
* list from interrupt handlers. */
* list from interrupt handlers.
*/
flags = enter_critical_section();
sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingaction);
@@ -82,7 +83,8 @@ void nxsig_release_pendingsigaction(FAR sigq_t *sigq)
else if (sigq->type == SIG_ALLOC_IRQ)
{
/* Make sure we avoid concurrent access to the free
* list from interrupt handlers. */
* list from interrupt handlers.
*/
flags = enter_critical_section();
sq_addlast((FAR sq_entry_t *)sigq, &g_sigpendingirqaction);
-2
View File
@@ -152,5 +152,3 @@ int atexit(void (*func)(void))
}
#endif /* CONFIG_SCHED_ATEXIT */
-2
View File
@@ -149,5 +149,3 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg)
}
#endif /* CONFIG_SCHED_ONEXIT */
+2 -1
View File
@@ -324,7 +324,8 @@ void work_notifier_signal(enum work_evtype_e evtype,
sched_lock();
/* Process the notification at the head of the pending list until the
* pending list is empty */
* pending list is empty
*/
for (entry = dq_peek(&g_notifier_pending);
entry != NULL;
+239 -99
View File
@@ -61,6 +61,38 @@ static void show_usage(char *progname, int exitcode)
exit(exitcode);
}
static void check_spaces_left(char *line, int lineno, int ndx)
{
/* Unary operator should generally be preceded by a space but make also
* follow a left parenthesis at the beginning of a parthentical list or
* expression or follow a right parentheses in the case of a cast.
*/
if (ndx > 0 && line[ndx - 1] != ' ' && line[ndx - 1] != '(' && line[ndx - 1] != ')')
{
fprintf(stderr,
"Operator/assignment must be preceded with whitespace at line %d:%d\n",
lineno, ndx);
}
}
static void check_spaces_leftright(char *line, int lineno, int ndx1, int ndx2)
{
if (ndx1 > 0 && line[ndx1 - 1] != ' ')
{
fprintf(stderr,
"Operator/assignment must be preceded with whitespace at line %d:%d\n",
lineno, ndx1);
}
if (line[ndx2 + 1] != '\0' && line[ndx2 + 1] != '\n' && line[ndx2 + 1] != ' ')
{
fprintf(stderr,
"Operator/assignment must be followed with whitespace at line %d:%d\n",
lineno, ndx2);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -876,80 +908,112 @@ int main(int argc, char **argv, char **envp)
/* Check for space around various operators */
case '-':
/* -> */
/* ->, -- */
if (line[n + 1] == '>')
if (line[n + 1] == '>' || line[n + 1] == '-')
{
n++;
break;
}
/* -= */
else if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
/* '-' may function as a unary operator and snuggle
* on the left.
*/
check_spaces_left(line, lineno, n);
}
break;
case '+':
/* ++, -- */
/* ++ */
if (line[n + 1] == line[n])
if (line[n + 1] == '+')
{
n++;
break;
}
/* += */
else if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
/* '+' may function as a unary operator and snuggle
* on the left.
*/
check_spaces_left(line, lineno, n);
}
break;
case '&':
/* && */
if (line[n] == '&' && line[n + 1] == line[n])
{
int curr;
int next;
curr = n;
n++;
next = n + 1;
if (line[curr-1] != ' ')
{
fprintf(stderr,
"Operator/assignment must be preceded with whitespace at line %d:%d\n",
lineno, curr);
}
if (line[next] != ' ' && line[next] != '\n')
{
fprintf(stderr,
"Operator/assignment needs whitespace separation at line %d:%d\n",
lineno, curr);
}
break;
}
/* &<variable> OR &(<expression>) */
else if (isalpha((int)line[n + 1]) || line[n + 1] == '_' || line[n + 1] == '(')
if (isalpha((int)line[n + 1]) || line[n + 1] == '_' ||
line[n + 1] == '(')
{
break;
}
case '/':
/* &&, &= */
else if (line[n + 1] == '=' || line[n + 1] == '&')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
check_spaces_leftright(line, lineno, n, n);
}
break;
case '/':
/* C++-style comment */
if (line[n] == '/')
{
if (line[n - 1] == '*')
{
n++;
break;
}
else if (line[n + 1] == '/')
{
fprintf(stderr, "C++ style comment on at %d:%d\n",
lineno, n);
n++;
break;
}
}
}
case '*':
/* /= */
else if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
check_spaces_leftright(line, lineno, n, n);
}
break;
case '*':
/* *\/, ** */
if (line[n] == '*' &&
@@ -984,96 +1048,172 @@ int main(int argc, char **argv, char **envp)
break;
}
/* *= */
else if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
/* A single '*' may be an binary operator, but
* it could also be a unary operator when used to deference
* a pointer.
*/
check_spaces_left(line, lineno, n);
}
break;
case '%':
/* %= */
if (line[n + 1] == '=')
{
if (isalnum((int)line[n + 1]))
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
check_spaces_leftright(line, lineno, n, n);
}
break;
}
}
case '<':
/* <=, <<, <<= */
if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else if (line[n + 1] == '<')
{
if (line[n + 2] == '=')
{
check_spaces_leftright(line, lineno, n, n + 2);
n += 2;
}
else
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
}
else
{
check_spaces_leftright(line, lineno, n, n);
}
break;
case '>':
/* >=, >>, >>= */
if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else if (line[n + 1] == '>')
{
if (line[n + 2] == '=')
{
check_spaces_leftright(line, lineno, n, n + 2);
n += 2;
}
else
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
}
else
{
check_spaces_leftright(line, lineno, n, n);
}
break;
case '|':
/* |=, || */
if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else if (line[n + 1] == '|')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
check_spaces_leftright(line, lineno, n, n);
}
break;
case '^':
/* ^= */
if (line[n + 1] == '=')
{
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
else
{
check_spaces_leftright(line, lineno, n, n);
}
break;
case '=':
{
int curr;
int next;
/* == */
curr = n;
if (line[curr - 1] != ' ')
if (line[n + 1] == '=')
{
fprintf(stderr,
"Operator/assignment must be preceded with whitespace at line %d:%d\n",
lineno, curr);
}
next = n + 1;
/* <<, >>, <<=, >>= */
if (line[curr] == '>' || line[curr] == '<')
{
if (line[next] == line[curr])
{
next++;
check_spaces_leftright(line, lineno, n, n + 1);
n++;
}
if (line[next] == '=')
else
{
next++;
n++;
}
}
else if (line[next] == '=' || line[next] == line[n])
{
next++;
n++;
check_spaces_leftright(line, lineno, n, n);
}
/* REVISIT: This gives false alarms on syntax like *--ptr */
if (line[curr] != '-' && line[next] != ' ' && line[next] != '\n')
{
fprintf(stderr,
"Operator/assignment needs whitespace separation at line %d:%d\n",
lineno, curr);
}
}
break;
case '~':
check_spaces_left(line, lineno, n);
break;
case '!':
{
int curr;
int next;
/* != */
curr = n;
next = n + 1;
if (line[next] == '=' || line[next] == line[n])
if (line[n + 1] == '=')
{
next++;
check_spaces_leftright(line, lineno, n, n + 1);
n++;
if (line[next] != ' ' && line[next] != '\n')
{
fprintf(stderr,
"Operator/assignment needs whitespace separation at line %d:%d\n",
lineno, curr);
}
}
if (line[curr-1] != ' ' && line[curr-1] != '(')
/* !! */
else if (line[n + 1] == '!')
{
fprintf(stderr,
"Operator/assignment must be preceded with whitespace at line %d:%d\n",
lineno, curr);
check_spaces_left(line, lineno, n);
n++;
}
else
{
check_spaces_left(line, lineno, n);
}
break;
default: