Repository navigation
use ssize_t in substdio - #84
Conversation
|
I wonder if we should go for C89 function prototypes here if we touch these lines anyway. A collision is a collision, it's not harder to solve with a C89 function prototype than with a K&R one. |
I am broadly wondering the same. I was going to ask it as "What led you to decide not to also change the type of the various If you wanted to stage a series of commits showing each step, we can squash them together after review and put them in 1.08, optionally leaving work (not squashing all commits) to 1.9. I definitely think we're doing ourselves a portability favor by cleaning up this subsystem, now that we're using system-provided function declarations for |
46f71eb to
c5056eb
Compare
c5056eb to
09c35a9
Compare
09c35a9 to
180ee24
Compare
0c80a67 to
d5870d7
Compare
21a168f to
ccab760
Compare
ccab760 to
91b241e
Compare
91b241e to
0f41fcd
Compare
3b4afdf to
814ceb3
Compare
814ceb3 to
8d0f315
Compare
8d0f315 to
48dac9f
Compare
daa71e5 to
7472c9a
Compare
josuah
left a comment
There was a problem hiding this comment.
It looks like we have two great things here:
factorizing ad-hoc read/write wrappers, and conversion of register native type to ssize_t.
If we are ok with defines, then we reached destination.
If we wat to get rid of the defines later on, maybe using a global variable will do (there is a global variable qqt/qq already for instance), andthere is always one struct qmail per program, so this :
#define GEN_QMAILPUT_WRITE(qq) \
ssize_t qmail_put_write(int fd, const void *buf, size_t len) \
{ \
qmail_put(qq,buf,len); \
return len; \
}
Could become this:
ssize_t qmail_put_write(int fd, const void *buf, size_t len)
{
qmail_put(qqt,buf,len);
return len;
}
I'm doing a patch and testing it after this is merged.
07d83d2 to
ac1ce75
Compare
schmonz
left a comment
There was a problem hiding this comment.
When we merge this PR, I'll be seeing 0 compile warnings on macOS Big Sur. 😃
The abstraction used to be invoked equally for reads and writes, and breaking that symmetry by introducing a write-specific path turns this into rather a large change. I'd like help understanding the tradeoff here.
Prototypes for read() and write() are indeed distinct, and the abstraction has until now chosen to blur that distinction. It seems the write-specific macro and function become necessary when we decide to make the distinction explicit. What benefits do we expect to gain by doing this? (Inversely, as I noted on typedef struct substdio, what would we lose if we chose to continue not specifying our I/O operation's prototype?)
The generator macros for timeout{read,write}() need fixing. It's good they don't need an fd passed in, because some of the callers were even out of order ;-)
ac1ce75 to
995c791
Compare
Adapt the prototypes of all op functions used in substdio to match the interface of read() and write(). In summary this is: - the return type is ssize_t - the buffer is void* for read and const void* for write functions - the length parameter is size_t
This is what would happen internally anyway, but this way many of the calls can be optimized away as the string is often constant. It also avoids the code duplication to implement the function itself.
From the OpenBSD man page of read() ...some platforms allow for nbytes to range between SSIZE_MAX and SIZE_MAX - 2, in which case the return value of an error-free read() may appear as a negative number distinct from -1.
If substdio_get() return -1 this would decrease the length setting in the passed substdio.
Both styles were used in the codebase, stick to one that seems less fragile.
995c791 to
80e4f07
Compare
schmonz
left a comment
There was a problem hiding this comment.
Looks great. Let’s get this merged!
No description provided.