bug#58883: CC Mode 5.35.1 (C/*l); Incorrect fontification of X function
Alan Mackenzie <[email protected]> Sun, 30 Oct 2022 14:05:15 +0000
| Newsgroups | gmane.emacs.cc-mode.general |
|---|---|
| Message-ID | <Y16EmxgLuG0Pq2Nx@ACM> |
Hello, Po.
Thanks for yet another bug report!
On Sun, Oct 30, 2022 at 09:22:45 +0800, Po Lu via CC-Mode-help wrote:
> Package: cc-mode
> In the following Xlib function:
> Bool XCheckIfEvent (
> register Display *dpy,
> register XEvent *event, /* XEvent to be filled in. */
> Bool (*predicate)(
> Display* /* display */,
> XEvent* /* event */,
> char* /* arg */
> ), /* function to call */
> char *arg)
> {
> register _XQEvent *prev, *qelt;
> unsigned long qe_serial = 0;
> int n; /* time through count */
> LockDisplay(dpy);
> prev = NULL;
> for (n = 3; --n >= 0;) {
> for (qelt = prev ? prev->next : dpy->head;
> qelt;
> prev = qelt, qelt = qelt->next) {
> if(qelt->qserial_num > qe_serial
> && (*predicate)(dpy, &qelt->event, arg)) {
> *event = qelt->event;
> _XDeq(dpy, prev, qelt);
> _XStoreEventCookie(dpy, event);
> UnlockDisplay(dpy);
> return True;
> }
> }
> if (prev)
> qe_serial = prev->qserial_num;
> switch (n) {
> case 2:
> _XEventsQueued(dpy, QueuedAfterReading);
> break;
> case 1:
> _XFlush(dpy);
> break;
> }
> if (prev && prev->qserial_num != qe_serial)
> /* another thread has snatched this event */
> prev = NULL;
> }
> UnlockDisplay(dpy);
> return False;
> }
> "Display" and "XEvent" are not fontified as types, inside both the
> function prototype and that of the predcate argument.
> "_XQEvent" also fails to be fontified as a type.
Yes. This was an unwanted consequence of the fix to bug #58537 two
weeks ago. There, things were being fontified as types and, at the same
time, being wrongly added to c-found-types. That fix prevented Display,
etc., from being fontified.
The attached patch allows the fontification of these types, but doesn't
add them to c-found-types. Would you please do the usual with the
patch, and let me know if there are any problems with it. Thanks!
> Emacs : GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu)
> of 2022-10-29
> Package: CC Mode 5.35.1 (C/*l)
> Buffer Style: gnu
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-string-delim gen-comment-delim syntax-properties category-properties 1-bit)
[ .... ]
--
Alan Mackenzie (Nuremberg, Germany).
diff.20221030.diff
(text/plain, 1.2 KB)
diff -r 53717eda724c cc-engine.el
--- a/cc-engine.el Sat Oct 29 09:42:47 2022 +0000
+++ b/cc-engine.el Sun Oct 30 13:32:23 2022 +0000
@@ -10227,7 +10227,11 @@
(save-rec-ref-ids c-record-ref-identifiers)
;; Set when we parse a declaration which might also be an expression,
;; such as "a *b". See CASE 16 and CASE 17.
- maybe-expression)
+ maybe-expression
+ ;; Set for the type when `c-forward-type' returned `maybe', and we
+ ;; want to fontify it as a type, but aren't confident enough to enter
+ ;; it into `c-found-types'.
+ unsafe-maybe)
(save-excursion
(goto-char preceding-token-end)
@@ -10923,7 +10927,7 @@
;; a statement beginning with an identifier.
(when (and (eq at-type 'maybe)
(not (eq context 'top)))
- (setq c-record-type-identifiers nil))
+ (setq unsafe-maybe t))
(throw 'at-decl-or-cast t))
;; CASE 11
@@ -11226,7 +11230,8 @@
;; fontification just because it's "a known type that can't
;; be a name or other expression". 2013-09-18.
)
- (let ((c-promote-possible-types t))
+ (let ((c-promote-possible-types
+ (if unsafe-maybe 'just-one t)))
(save-excursion
(goto-char type-start)
(c-forward-type))))