[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

preferring ptrdiff_t to size_t for object counts

From: Paul Eggert
Subject: preferring ptrdiff_t to size_t for object counts
Date: Sun, 4 Jun 2017 23:45:38 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

GNU Emacs has long been using signed types (typically ptrdiff_t) to count objects. This has the advantage that signed integer overflow can be detected automatically on some platforms (unfortunately, size_t arithmetic silently wraps around). I would like to change the Gnulib modules that GNU Emacs uses, to use this style. The main effect on these modules' non-Emacs users would be:

* They accept ptrdiff_t counts, not size_t counts. Normally sizes are computed by new functions like xwgrowalloc. When the caller computes sizes by hand, it is the caller's responsibility to check for integer overflow.

* They report errors via xwalloc_die, not xalloc_die.

I've also changed the modules that GNU grep uses, as a test that this idea works on non-Emacs applications.

As this is a nontrivial change, I'll post the Gnulib patches first without installing them, for discussion.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]