Re: curses_trace() - version 6.6

"G. Branden Robinson" <[email protected]>
Newsgroups gmane.comp.lib.ncurses.bugs
Message-ID <20260815165209.42b5tvm627t6u6wg@illithid>
At 2026-08-05T15:09:13-0400, Thomas Dickey wrote:
> On Wed, Aug 05, 2026 at 07:41:24PM +0200, Björn Försterling wrote:
> > And `curses_trace(TRACE_MAXIMUM)` seems to return 0 even when
> > tracing is available and writing to a file called "trace" works.
> > Probably because the previous bitmask was 0.
> 
> yes :-)
> 
> > But how do you check if tracing is available?
> 
> call the function twice:
> 
> 	curses_trace(TRACE_MAXIMUM);
> 	rc = trace(TRACE_NORMAL);
> 
> curs_set and umask do something like that with return-codes.

Ah, but you don't have to call curs_set twice.

kernel(3NCURSES)              Library calls             kernel(3NCURSES)
...
     int curs_set(int visibility);
...
   curs_set
     curs_set adjusts the cursor visibility to “invisible”, “visible”,
     “very visible”, as its argument is 0, 1, or 2, respectively.  It
     returns the previous visibility if the requested one is supported,
     and ERR otherwise.

curs_set returns a _signed_ integral value, with negative values
reserved as an error indication.

Since ncurses ABI 7 appears to be open for business,[1] I propose that
curses_trace() change its return type to a "regular" signed `int`; that
way this pattern of calling curses_trace() twice to decide whether the
feature is enabled becomes unnecessary.

If the tracing feature is disabled, curses_trace() can return ERR.

There are only 13 distinct event types.

$ sed -n 209,210p include/curses.tail
#define TRACE_SHIFT     13      /* number of bits in the trace masks */
#define TRACE_MAXIMUM   ((1 << TRACE_SHIFT) - 1) /* maximum trace level */

Even with a PDP-11 sized `int`, you could convert `result` to `int` and
have 2 bits to spare.  On a 32-bit machine I don't think you'll ever run
out of room, to say nothing of 64-bit hosts.

What do you think?

Regards,
Branden

[1] https://lists.gnu.org/archive/html/bug-ncurses/2025-05/msg00015.html

[2] It's not a "mask", but rather a bit vector; each set bit _enables_ a
    feature rather than disabling it or "masking it off".  Early Unix
    hackers were apparently so fascinated by the operation of umask(2)
    and bitwise arithmetic that they extrapolated any collection of bits
    with orthogonal meaning as a "mask".  I've been slowly cleaning the
    same abuse of terminology out of groff's code and documentation.
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEh3PWHWjjDgcrENwa0Z6cfXEmbc4FAmqAmTEACgkQ0Z6cfXEm
bc5LNA/7Bq+oyscr92HnjvltQ8NPSbS40pIOy2yTWW1ynby4QqFimdtK0GcUx1aK
EqpzmCNCKvACvz5kycmSH1NhpB8eZ9l6d5W1vwA81ETPBXhalUDWPVUijHwcWMgf
GYYtf5mcm/cpXQQabToTL70fO97gd6Baykt0NXT6U2ux4cRyHw5ELuM6yHTCBcQb
oZI8MS7AaPisEbRD0ck5VmN6kM4bo4T1/D+JC7FQ0Uz4kpZOAOuq26wMY0pIpC+E
zQejig1t+kt3+zdKXfKLzFi7p38A8vSTRsIII2GnvReEl1tX5ixwu5dvqHJd16ES
FzhuzoMKxUGh7lpwYAkxQF837hmzqASrqphbMQkn4B05nO4ifc84Mh46y0RUQ3QX
bwNNYx9Zljb18zvn5vMy8nm7S+UvmJeg+qgB4A6GXyuXRcFlbVlVZriYNZ1Yvzmx
P7QGdzWqgMKUgfFzr1W3Mi5QGQibfdeOIFMLpmxnCVKpoLrDB7ZzgGxcb0go4Y4S
pXnzNJsLiYbYQ3PJGCJU8zbEfadUUq2minyxZOsoaHPvOEYvrefTzJe06iNqvfU7
uzVn/wu99gcjpTaDOl82cOH0NrktiNNYc5Kpzcfj3Qf0W3HBXbAA8WiXEa+cKw4T
1DNOWkMg6qDLJ0oWMfsT3bJF+cENQof6cimW7e6X81EaAUA9Ysc=
=vlLq
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.