On Tue, 21 Jun 2016, Reinhard Max wrote:

I found that this has been discussed already back in 2007 and Daniel seemed to be positive about it, but then the discussion ended without a visible decision one way or the other, so I am picking this up again.

Oh man, that's an old goldie. But thanks for digging it up and moving it back into the daylight.

I changed the definition of these types to be opaque structures:

typedef struct CURL   CURL;
typedef struct CURLM  CURLM;
typedef struct CURLSH CURLSH;

Using dummy names has the advantage of not revealing additional details about libcurl internals, but people can read the source code anyway, so it doesn't really hide anyting. I think using the internal names would have the advantage of extending the typechecking into libcurl itself, because functions that take one of these types would not need an explicit cast to the internal type, but I haven't checked this thoroughly.

Using fake names has the obvious downside that it will require changes to libcurl code which at points actually passes in pointers to the real structs and not using the typedef'ed void pointers.

By using the real struct names it becomes a much smaller change - with no impact on the libcurl code at all. See attachment for a patch that does this.

My only minor concern with this patch is if we should take the opportunity and rename the SessionHandle struct before we hang it out on public display like this...

--

 / daniel.haxx.se
From 7fe48d453f50808c30c1d9769109b1fdc9728a0d Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <[email protected]>
Date: Tue, 21 Jun 2016 14:39:33 +0200
Subject: [PATCH] headers: forward declare CURL, CURLM and CURLSH as structs

Instead of typedef'ing to void, typedef to their corresponding actual
struct names to allow compilers to type-check.

Assistance-by: Reinhard Max
---
 include/curl/curl.h  | 4 ++--
 include/curl/multi.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/curl/curl.h b/include/curl/curl.h
index b9bd8b7..b91f02c 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -89,11 +89,11 @@
 
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
-typedef void CURL;
+typedef struct SessionHandle CURL;
 
 /*
  * libcurl external API function linkage decorations.
  */
 
@@ -2256,11 +2256,11 @@ typedef void (*curl_lock_function)(CURL *handle,
                                    void *userptr);
 typedef void (*curl_unlock_function)(CURL *handle,
                                      curl_lock_data data,
                                      void *userptr);
 
-typedef void CURLSH;
+typedef struct Curl_share CURLSH;
 
 typedef enum {
   CURLSHE_OK,  /* all is fine */
   CURLSHE_BAD_OPTION, /* 1 */
   CURLSHE_IN_USE,     /* 2 */
diff --git a/include/curl/multi.h b/include/curl/multi.h
index 0fbbd96..7a1040f 100644
--- a/include/curl/multi.h
+++ b/include/curl/multi.h
@@ -5,11 +5,11 @@
  *  Project                     ___| | | |  _ \| |
  *                             / __| | | | |_) | |
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <[email protected]>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
  * are also available at https://curl.haxx.se/docs/copyright.html.
  *
@@ -50,11 +50,11 @@
 
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
-typedef void CURLM;
+typedef struct Curl_multi CURLM;
 
 typedef enum {
   CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
                                     curl_multi_socket*() soon */
   CURLM_OK,
-- 
2.8.1

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html

Reply via email to