| Ticket UUID: | fb97352ad918fa08578a2c0cbbd2af38831cb32a | |||
| Title: | chase compiler warnings | |||
| Type: | Patch | Version: | ||
| Submitter: | anonymous | Created on: | 2014-08-07 08:12:12 | |
| Subsystem: | pt (parsetools) | Assigned To: | aku | |
| Priority: | 6 | Severity: | Minor | |
| Status: | Open | Last Modified: | 2014-08-11 05:19:24 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
Most of the chunks are related to casting variables to void* for use in rde_stack_push or Tcl_*Hash* function calls. There are a few removals of unused variables and (void)var; of unused parameters. | |||
| User Comments: |
aku added on 2014-08-11 05:19:24:
Applied the parts about unused variables, missing initialization. Not applied the chunks doing casting. Commit [5d35be9b3a]. Pushed. aku added on 2014-08-11 05:07:28: Patch removed and re-added as proper attachment aku added on 2014-08-08 16:49:29: > Perhaps a safer way would be to add a check for > sizeof(int) == sizeof(void *) in tclInt.h [...] You might wish to propose this on the tcl-core mailing list. If there are any portability issues with that type of check somebody there should know. anonymous added on 2014-08-08 07:41:56: Perhaps a safer way would be to add a check for sizeof(int) == sizeof(void *) in tclInt.h and if not, cast first using size_t. I conjecture that if there's an integral type the same size of a pointer, that's size_t on any sensible machine nowadays. --- generic/tclInt.h +++ generic/tclInt.h @@ -102,21 +102,31 @@ #if !defined(INT2PTR) && !defined(PTR2INT) # if defined(HAVE_INTPTR_T) || defined(intptr_t) # define INT2PTR(p) ((void *)(intptr_t)(p)) # define PTR2INT(p) ((int)(intptr_t)(p)) # else -# define INT2PTR(p) ((void *)(p)) -# define PTR2INT(p) ((int)(p)) +# if sizeof(int) == sizeof(void *) +# define INT2PTR(p) ((void *)(p)) +# define PTR2INT(p) ((int)(p)) +# else +# define INT2PTR(p) ((void *)(size_t)(p)) +# define PTR2INT(p) ((int)(size_t)(p)) +# endif # endif #endif #if !defined(UINT2PTR) && !defined(PTR2UINT) # if defined(HAVE_UINTPTR_T) || defined(uintptr_t) # define UINT2PTR(p) ((void *)(uintptr_t)(p)) # define PTR2UINT(p) ((unsigned int)(uintptr_t)(p)) # else -# define UINT2PTR(p) ((void *)(p)) -# define PTR2UINT(p) ((unsigned int)(p)) +# if sizeof(unsigned int) == sizeof(void *) +# define UINT2PTR(p) ((void *)(p)) +# define PTR2UINT(p) ((unsigned int)(p)) +# else +# define UINT2PTR(p) ((void *)(size_t)(p)) +# define PTR2UINT(p) ((unsigned int)(size_t)(p)) +# endif # endif #endif #if defined(_WIN32) && defined(_MSC_VER) # define vsnprintf _vsnprintf aku added on 2014-08-07 23:05:16: Just checked and the macros are defined even when HAVE_INTPTR_T is not defined. In that case they pretty much look what I did with my casting, i.e. only (void*) etc, without going through the intptr_t et al. I guess I simply have to check each chunk if it still applies or not. critcl does not check by itself to ascertain what is in the environment or not. I.e. it is not autotools. The critcl::utils package has some commands which allow the package getting compiled to make such checks. I might look into that. Still have to bring Tcllib's C parts up to critcl 3.x anyway. anonymous added on 2014-08-07 22:18:33: You do have a point about inttypes.h not being universally available. Using INT2PTR is a good idea, provided that critcl compiles the files with -DHAVE_INTPTR_T. The only place where I see that declaration is in tclConfig.sh. Anyway, I probably cooked this patch before you committed your long / void * fixes. The current source code compiles without warnings on FreeBSD, amd64, clang 3.4.1. So, as long as sizeof(long) == sizeof(void *) all is good. aku added on 2014-08-07 16:48:28: Thank you for the report and patch. The parts about superfluous and uninitialized variables look good and I see no problem with applying them as is. The chunks adding cast to (uintptr_t) etc. in various places however will need more work. There are still machines around which do not have inttypes.h, and related header files. IOW, these are not portable. It might be useful to check if using the tcl.h macros INT2PTR() and PTR2INT() will work for these. I would also be interested in knowing which compiler/platform is throwing the warnings. Because if I have access to such a machine myself I could work things out myself instead of going through you to test any changes I may make. anonymous added on 2014-08-07 08:19:54: Update patch to updated checkout. | |||
Attachments:
- warnings.patch [download] added by aku on 2014-08-11 05:05:52. [details]
