]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: use BIT() instead of bool in structs more
authorDaniel Stenberg <daniel@haxx.se>
Sun, 20 Apr 2025 22:08:22 +0000 (00:08 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 22 Apr 2025 06:01:08 +0000 (08:01 +0200)
Since it makes use of bitfields on supported platforms, it saves a few
bytes memory. Might as well use it consistently.

Closes #17114

15 files changed:
lib/altsvc.h
lib/formdata.h
lib/hsts.h
lib/http1.h
lib/httpsrr.h
lib/mqtt.h
lib/pingpong.h
lib/psl.h
lib/sigpipe.h
lib/vquic/curl_msh3.c
lib/vquic/curl_ngtcp2.c
lib/vquic/curl_osslq.c
lib/vssh/ssh.h
lib/vtls/schannel_int.h
lib/vtls/x509asn1.h

index 5f94f832b4e1b615aa3d10d9a0571f92268ed0e7..831cd097436aa8c95fd4f25c441cc27c894e0268 100644 (file)
@@ -39,9 +39,9 @@ struct altsvc {
   struct althost src;
   struct althost dst;
   time_t expires;
-  bool persist;
-  unsigned int prio;
   struct Curl_llist_node node;
+  unsigned int prio;
+  BIT(persist);
 };
 
 struct altsvcinfo {
index 0e35e1892bf0443648b9c7c5ab16864117c71f26..e4a2a38e8b27de270580b5072080e4e8fe7941ab 100644 (file)
@@ -43,10 +43,10 @@ struct FormInfo {
   char *userp;        /* pointer for the read callback */
   struct curl_slist *contentheader;
   struct FormInfo *more;
-  bool name_alloc;
-  bool value_alloc;
-  bool contenttype_alloc;
-  bool showfilename_alloc;
+  BIT(name_alloc);
+  BIT(value_alloc);
+  BIT(contenttype_alloc);
+  BIT(showfilename_alloc);
 };
 
 CURLcode Curl_getformdata(CURL *data,
index e8d0f9d552357b6daffb9b1e0edd5474dac03a03..8ec9637cb0c036989cf22596da9c1813c4996f9a 100644 (file)
@@ -36,8 +36,8 @@ extern time_t deltatime;
 struct stsentry {
   struct Curl_llist_node node;
   const char *host;
-  bool includeSubDomains;
   curl_off_t expires; /* the timestamp of this entry's expiry */
+  BIT(includeSubDomains);
 };
 
 /* The HSTS cache. Needs to be able to tailmatch hostnames. */
index 2de302f1f6c871453043e3b7c40beeb7b36acad9..b38b32f591150221c94c9a8400ad1a94cd45459d 100644 (file)
@@ -42,7 +42,7 @@ struct h1_req_parser {
   const char *line;
   size_t max_line_len;
   size_t line_len;
-  bool done;
+  BIT(done);
 };
 
 void Curl_h1_req_parse_init(struct h1_req_parser *parser, size_t max_line_len);
index f946282cb98f2cf57ff85c05748a2617597be39f..83119dc6bde74a4f473c130c46fedd216a9c9638 100644 (file)
@@ -53,7 +53,7 @@ struct Curl_https_rrinfo {
   /* store parsed alpnid entries in the array, end with ALPN_none */
   int port; /* -1 means not set */
   uint16_t priority;
-  bool no_def_alpn; /* keytag = 2 */
+  BIT(no_def_alpn); /* keytag = 2 */
 };
 
 CURLcode Curl_httpsrr_set(struct Curl_easy *data,
index 610aa18929f869f5a3d14ff5cbc1463fdc08452f..c824edd373ae733aebf162108046e908288dd381 100644 (file)
@@ -56,8 +56,8 @@ struct MQTT {
   size_t remaining_length;
   unsigned char pkt_hd[4]; /* for decoding the arriving packet length */
   struct curltime lastTime; /* last time we sent or received data */
-  bool pingsent; /* 1 while we wait for ping response */
   unsigned char firstbyte;
+  BIT(pingsent); /* 1 while we wait for ping response */
 };
 
 #endif /* HEADER_CURL_MQTT_H */
index d9fdbdbac2c86fed0df496c82bb7a3e5b84fb2c5..bd726046fed09fcef084e0d40ce1bd36e85e8436 100644 (file)
@@ -48,9 +48,6 @@ typedef enum {
  */
 struct pingpong {
   size_t nread_resp;  /* number of bytes currently read of a server response */
-  bool pending_resp;  /* set TRUE when a server response is pending or in
-                         progress, and is cleared once the last response is
-                         read */
   char *sendthis; /* pointer to a buffer that is to be sent to the server */
   size_t sendleft; /* number of bytes left to send from the sendthis buffer */
   size_t sendsize; /* total size of the sendthis buffer */
@@ -71,6 +68,9 @@ struct pingpong {
   bool (*endofresp)(struct Curl_easy *data, struct connectdata *conn,
                     const char *ptr, size_t len, int *code);
   BIT(initialised);
+  BIT(pending_resp);  /* set TRUE when a server response is pending or in
+                         progress, and is cleared once the last response is
+                         read */
 };
 
 #define PINGPONG_SETUP(pp,s,e)                   \
index dd5bee21fbc14ba21185305515267e4b38ae4dc0..dc11469a5248533c3b0924ed496f894e5e838c3c 100644 (file)
--- a/lib/psl.h
+++ b/lib/psl.h
@@ -34,7 +34,7 @@ struct Curl_easy;
 struct PslCache {
   const psl_ctx_t *psl; /* The PSL. */
   time_t expires; /* Time this PSL life expires. */
-  bool dynamic; /* PSL should be released when no longer needed. */
+  BIT(dynamic); /* PSL should be released when no longer needed. */
 };
 
 const psl_ctx_t *Curl_psl_use(struct Curl_easy *easy);
index c57580f434a972c0c9d60f6de61f10172c41fd96..1be3a111e9580028f314ae10aa58ce53aa95283a 100644 (file)
@@ -31,7 +31,7 @@
 
 struct sigpipe_ignore {
   struct sigaction old_pipe_act;
-  bool no_signal;
+  BIT(no_signal);
 };
 
 #define SIGPIPE_VARIABLE(x) struct sigpipe_ignore x
index 53cfc03ae3917ed03a8a3bbd43623d29ceb053ff..331bc375108922094e4ba6e07eaba628fff7f086 100644 (file)
@@ -122,9 +122,9 @@ struct cf_msh3_ctx {
   struct curltime handshake_at;      /* time connect handshake finished */
   struct uint_hash streams;          /* hash `data->mid` to `stream_ctx` */
   /* Flags written by msh3/msquic thread */
-  bool handshake_complete;
-  bool handshake_succeeded;
-  bool connected;
+  BIT(handshake_complete);
+  BIT(handshake_succeeded);
+  BIT(connected);
   BIT(initialized);
   /* Flags written by curl thread */
   BIT(verbose);
@@ -181,11 +181,11 @@ struct stream_ctx {
   uint64_t error3; /* HTTP/3 stream error code */
   int status_code; /* HTTP status code */
   CURLcode recv_error;
-  bool closed;
-  bool reset;
-  bool upload_done;
-  bool firstheader;  /* FALSE until headers arrive */
-  bool recv_header_complete;
+  BIT(closed);
+  BIT(reset);
+  BIT(upload_done);
+  BIT(firstheader);  /* FALSE until headers arrive */
+  BIT(recv_header_complete);
 };
 
 #define H3_STREAM_CTX(ctx,data)   ((struct stream_ctx *)((data && ctx)? \
index 8b6d53857017206fe2f01b6ca4a6ebc6ed068a5c..3909a8b74f4f842a61c23bd4c570248bb76a41a7 100644 (file)
@@ -246,10 +246,10 @@ struct h3_stream_ctx {
   curl_off_t upload_left; /* number of request bytes left to upload */
   int status_code; /* HTTP status code */
   CURLcode xfer_result; /* result from xfer_resp_write(_hd) */
-  bool resp_hds_complete; /* we have a complete, final response */
-  bool closed; /* TRUE on stream close */
-  bool reset;  /* TRUE on stream reset */
-  bool send_closed; /* stream is local closed */
+  BIT(resp_hds_complete); /* we have a complete, final response */
+  BIT(closed); /* TRUE on stream close */
+  BIT(reset);  /* TRUE on stream reset */
+  BIT(send_closed); /* stream is local closed */
   BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */
 };
 
index 6d1f85e3d554bb43034e1fa1c8520925cd9263f6..f7409ad3d88908a82444c0ee50c5279688869391 100644 (file)
@@ -583,10 +583,10 @@ struct h3_stream_ctx {
   curl_off_t upload_left; /* number of request bytes left to upload */
   curl_off_t download_recvd; /* number of response DATA bytes received */
   int status_code; /* HTTP status code */
-  bool resp_hds_complete; /* we have a complete, final response */
-  bool closed; /* TRUE on stream close */
-  bool reset;  /* TRUE on stream reset */
-  bool send_closed; /* stream is local closed */
+  BIT(resp_hds_complete); /* we have a complete, final response */
+  BIT(closed); /* TRUE on stream close */
+  BIT(reset);  /* TRUE on stream reset */
+  BIT(send_closed); /* stream is local closed */
   BIT(quic_flow_blocked); /* stream is blocked by QUIC flow control */
 };
 
index 3c88c4e0b08de10a403c873e0702aea2269c94d6..a43179871954cb5e155fc2da440a2be302d9da6c 100644 (file)
@@ -141,9 +141,6 @@ struct ssh_conn {
   const char *passphrase;     /* pass-phrase to use */
   char *rsa_pub;              /* strdup'ed public key file */
   char *rsa;                  /* strdup'ed private key file */
-  bool authed;                /* the connection has been authenticated fine */
-  bool acceptfail;            /* used by the SFTP_QUOTE (continue if
-                                 quote command fails) */
   sshstate state;             /* always use ssh.c:state() to change state! */
   sshstate nextstate;         /* the state to goto after stopping */
   CURLcode actualcode;        /* the actual error code */
@@ -213,6 +210,9 @@ struct ssh_conn {
   curl_off_t offset;
 #endif /* USE_LIBSSH */
   BIT(initialised);
+  BIT(authed);                /* the connection has been authenticated fine */
+  BIT(acceptfail);            /* used by the SFTP_QUOTE (continue if
+                                 quote command fails) */
 };
 
 #ifdef USE_LIBSSH
index f9513b31f9bcc046c3537e7127bdb00a1a6d157f..fe10125456745bcfe634343fa02b130ae2838f6e 100644 (file)
@@ -150,17 +150,17 @@ struct schannel_ssl_backend_data {
      cannot be decrypted without another recv() (that is, status is
      SEC_E_INCOMPLETE_MESSAGE) then set this true. after an recv() adds
      more bytes into encdata then set this back to false. */
-  bool encdata_is_incomplete;
   unsigned long req_flags, ret_flags;
   CURLcode recv_unrecoverable_err; /* schannel_recv had an unrecoverable err */
-  bool recv_sspi_close_notify; /* true if connection closed by close_notify */
-  bool recv_connection_closed; /* true if connection closed, regardless how */
-  bool recv_renegotiating;     /* true if recv is doing renegotiation */
-  bool use_alpn; /* true if ALPN is used for this connection */
+  BIT(recv_sspi_close_notify); /* true if connection closed by close_notify */
+  BIT(recv_connection_closed); /* true if connection closed, regardless how */
+  BIT(recv_renegotiating);     /* true if recv is doing renegotiation */
+  BIT(use_alpn); /* true if ALPN is used for this connection */
 #ifdef HAS_MANUAL_VERIFY_API
-  bool use_manual_cred_validation; /* true if manual cred validation is used */
+  BIT(use_manual_cred_validation); /* true if manual cred validation is used */
 #endif
   BIT(sent_shutdown);
+  BIT(encdata_is_incomplete);
 };
 
 /* key to use at `multi->proto_hash` */
index ef2e8c369cb8c57a6fe9250f6abc8c329e44aed8..1c9c35c3d4edbeb6f043263c1a10a9cf9221a4ca 100644 (file)
@@ -45,7 +45,7 @@ struct Curl_asn1Element {
   const char *end;            /* Pointer to 1st byte after element. */
   unsigned char class;        /* ASN.1 element class. */
   unsigned char tag;          /* ASN.1 element tag. */
-  bool          constructed;  /* Element is constructed. */
+  BIT(constructed);           /* Element is constructed. */
 };
 
 /* X509 certificate: RFC 5280. */