1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-08 08:58:00 +00:00
putty-source/ldisc.h
Simon Tatham e0a76971cc New array-growing macros: sgrowarray and sgrowarrayn.
The idea of these is that they centralise the common idiom along the
lines of

   if (logical_array_len >= physical_array_size) {
       physical_array_size = logical_array_len * 5 / 4 + 256;
       array = sresize(array, physical_array_size, ElementType);
   }

which happens at a zillion call sites throughout this code base, with
different random choices of the geometric factor and additive
constant, sometimes forgetting them completely, and generally doing a
lot of repeated work.

The new macro sgrowarray(array,size,n) has the semantics: here are the
array pointer and its physical size for you to modify, now please
ensure that the nth element exists, so I can write into it. And
sgrowarrayn(array,size,n,m) is the same except that it ensures that
the array has size at least n+m (so sgrowarray is just the special
case where m=1).

Now that this is a single centralised implementation that will be used
everywhere, I've also gone to more effort in the implementation, with
careful overflow checks that would have been painful to put at all the
previous call sites.

This commit also switches over every use of sresize(), apart from a
few where I really didn't think it would gain anything. A consequence
of that is that a lot of array-size variables have to have their types
changed to size_t, because the macros require that (they address-take
the size to pass to the underlying function).
2019-02-28 20:15:38 +00:00

28 lines
593 B
C

/*
* ldisc.h: defines the Ldisc data structure used by ldisc.c and
* ldiscucs.c. (Unfortunately it was necessary to split the ldisc
* module in two, to avoid unnecessarily linking in the Unicode
* stuff in tools that don't require it.)
*/
#ifndef PUTTY_LDISC_H
#define PUTTY_LDISC_H
struct Ldisc_tag {
Terminal *term;
Backend *backend;
Seat *seat;
/*
* Values cached out of conf.
*/
bool telnet_keyboard, telnet_newline;
int protocol, localecho, localedit;
char *buf;
size_t buflen, bufsiz;
bool quotenext;
};
#endif /* PUTTY_LDISC_H */