zsh-workers
 help / color / mirror / code / Atom feed
* 4.3.12-dev-1 compile warning on MacOS
@ 2011-07-18 14:34 Bart Schaefer
  2011-07-18 14:50 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2011-07-18 14:34 UTC (permalink / raw)
  To: zsh-workers

rlimits.c: In function 'showlimitvalue':
rlimits.c:105: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'
rlimits.c:126: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'
rlimits.c:142: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'
rlimits.c:161: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'long long unsigned int'
rlimits.c:163: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'long long unsigned int'
rlimits.c: In function 'printulimit':
rlimits.c:401: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 4.3.12-dev-1 compile warning on MacOS
  2011-07-18 14:34 4.3.12-dev-1 compile warning on MacOS Bart Schaefer
@ 2011-07-18 14:50 ` Peter Stephenson
  2011-07-18 16:11   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2011-07-18 14:50 UTC (permalink / raw)
  To: zsh-workers

On Mon, 18 Jul 2011 07:34:31 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> rlimits.c: In function 'showlimitvalue':
> rlimits.c:105: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'
> rlimits.c:126: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'
> rlimits.c:142: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'
> rlimits.c:161: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'long long unsigned int'
> rlimits.c:163: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'long long unsigned int'
> rlimits.c: In function 'printulimit':
> rlimits.c:401: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'

Sounds like RLIMT_T_IS_LONG_LONG should be defined but isn't.
This is the test the shell is running to check the size:

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/resource.h>
main(){struct rlimit r;exit(sizeof(r.rlim_cur) <= sizeof(long));}

Is rlim_cur not rlim_t, for some reason?  Or are the some flags
missing when this is compiled?

However, even that's not good enough since code doesn't currently
handle the combination of unsigned and long long.  That should be
easier to fix.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 4.3.12-dev-1 compile warning on MacOS
  2011-07-18 14:50 ` Peter Stephenson
@ 2011-07-18 16:11   ` Bart Schaefer
  2011-10-31  8:51     ` Jun T.
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2011-07-18 16:11 UTC (permalink / raw)
  To: zsh-workers

On Jul 18,  3:50pm, Peter Stephenson wrote:
} Subject: Re: 4.3.12-dev-1 compile warning on MacOS
}
} > rlimits.c:401: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'rlim_t'
} 
} Sounds like RLIMT_T_IS_LONG_LONG should be defined but isn't.
} 
} Is rlim_cur not rlim_t, for some reason?  Or are the some flags
} missing when this is compiled?

config.log fragment:

configure:14214: checking where the RLIMIT macros are located
configure:14247: result: /usr/include/sys/resource.h
configure:14263: checking if rlim_t is longer than a long

[...]

| #ifdef HAVE_SYS_TIME_H
| #include <sys/time.h>
| #endif
| #include <sys/resource.h>
| main(){struct rlimit r;exit(sizeof(r.rlim_cur) <= sizeof(long));}
configure:14318: result: no
configure:14399: checking if the rlim_t is unsigned
configure:14426: gcc -o conftest  -Wall -Wmissing-prototypes -O2  -Wl,-x
conftest.c -liconv -ldl -ltermcap -lm  -lc >&5
conftest.c:223: warning: return type defaults to 'int'
conftest.c: In function 'main':
conftest.c:223: warning: implicit declaration of function 'exit'
conftest.c:223: warning: incompatible implicit declaration of built-in function
'exit'
configure:14429: $? = 0
configure:14435: ./conftest
configure:14438: $? = 0
configure:14454: result: yes
configure:14465: checking for rlim_t
configure:14496: gcc -c  -Wall -Wmissing-prototypes -O2  conftest.c >&5
conftest.c: In function 'main':
conftest.c:228: warning: unused variable 'l'
configure:14502: $? = 0
configure:14517: result: yes

Why does it check for the existence of rlim_t after checking for the
type?

/usr/include/sys/resource.h:typedef __uint64_t  rlim_t;
/usr/include/i386/_types.h:typedef unsigned long long   __uint64_t;

I can only conclude that long and long long are both 64 bits but that
the compiler treats %ul as incompabible with the latter.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 4.3.12-dev-1 compile warning on MacOS
  2011-07-18 16:11   ` Bart Schaefer
@ 2011-10-31  8:51     ` Jun T.
  0 siblings, 0 replies; 4+ messages in thread
From: Jun T. @ 2011-10-31  8:51 UTC (permalink / raw)
  To: zsh-workers

Sorry for a _very_ late reply.

At 9:11 AM -0700 11.7.18, Bart Schaefer wrote:
>I can only conclude that long and long long are both 64 bits but that
>the compiler treats %ul as incompabible with the latter.

Yes.

The only workaround I can think of is to cast rlim_t to long 
(or unsigned long) as in a possible patch below.
This cast is safe because if sizeof(rlim_t) > sizeof(long) then
either RLIM_T_IS_QUAD_T or RLIM_T_IS_LONG_LONG should have been
defined.

Similar fix in zftp.c is also included.


Index: Src/Builtins/rlimits.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Builtins/rlimits.c,v
retrieving revision 1.24
diff -u -r1.24 rlimits.c
--- Src/Builtins/rlimits.c	19 Jun 2011 00:10:34 -0000	1.24
+++ Src/Builtins/rlimits.c	31 Oct 2011 08:33:36 -0000
@@ -102,9 +102,9 @@
 	printf("%lld\n", val);
 #  else
 #   ifdef RLIM_T_IS_UNSIGNED
-	printf("%lu\n", val);
+	printf("%lu\n", (unsigned long)val);
 #   else
-	printf("%ld\n", val);
+	printf("%ld\n", (long)val);
 #   endif /* RLIM_T_IS_UNSIGNED */
 #  endif /* RLIM_T_IS_LONG_LONG */
 # endif /* RLIM_T_IS_QUAD_T */
@@ -123,9 +123,9 @@
 	printf("%lldus\n", val);
 #  else
 #   ifdef RLIM_T_IS_UNSIGNED
-	printf("%luus\n", val);
+	printf("%luus\n", (unsigned long)val);
 #   else
-	printf("%ldus\n", val);
+	printf("%ldus\n", (long)val);
 #   endif /* RLIM_T_IS_UNSIGNED */
 #  endif /* RLIM_T_IS_LONG_LONG */
 # endif /* RLIM_T_IS_QUAD_T */
@@ -139,9 +139,9 @@
 	printf("%lld\n", val);
 #  else
 #   ifdef RLIM_T_IS_UNSIGNED
-	printf("%lu\n", val);
+	printf("%lu\n", (unsigned long)val);
 #   else
-	printf("%ld\n", val);
+	printf("%ld\n", (long)val);
 #   endif /* RLIM_T_IS_UNSIGNED */
 #  endif /* RLIM_T_IS_LONG_LONG */
 # endif /* RLIM_T_IS_QUAD_T */
@@ -158,13 +158,13 @@
 	printf("%lldkB\n", val / 1024L);
 #  else
 #   ifdef RLIM_T_IS_UNSIGNED
-    printf("%luMB\n", val / (1024L * 1024L));
+    printf("%luMB\n", (unsigned long)(val / (1024L * 1024L)));
     else
-	printf("%lukB\n", val / 1024L);
+	printf("%lukB\n", (unsigned long)(val / 1024L));
 #   else
-    printf("%ldMB\n", val / (1024L * 1024L));
+    printf("%ldMB\n", (long)val / (1024L * 1024L));
     else
-	printf("%ldkB\n", val / 1024L);
+	printf("%ldkB\n", (long)val / 1024L);
 #   endif /* RLIM_T_IS_UNSIGNED */
 #  endif /* RLIM_T_IS_LONG_LONG */
 # endif /* RLIM_T_IS_QUAD_T */
@@ -398,9 +398,9 @@
 	printf("%lld\n", limit);
 #  else
 #   ifdef RLIM_T_IS_UNSIGNED
-	printf("%lu\n", limit);
+	printf("%lu\n", (unsigned long)limit);
 #   else
-	printf("%ld\n", limit);
+	printf("%ld\n", (long)limit);
 #   endif /* RLIM_T_IS_UNSIGNED */
 #  endif /* RLIM_T_IS_LONG_LONG */
 # endif /* RLIM_T_IS_QUAD_T */

Index: Src/Modules/zftp.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/zftp.c,v
retrieving revision 1.54
diff -u -r1.54 zftp.c
--- Src/Modules/zftp.c	13 May 2011 18:12:06 -0000	1.54
+++ Src/Modules/zftp.c	31 Oct 2011 08:36:40 -0000
@@ -2520,7 +2520,7 @@
 	printf("%s %s\n", output64(sz), mt);
 #else
 	DPUTS(sizeof(sz) > 4, "Shell compiled with wrong off_t size");
-	printf("%ld %s\n", sz, mt);
+	printf("%ld %s\n", (long)sz, mt);
 #endif
 	zsfree(mt);
 	if (dofd)



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-10-31  8:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-18 14:34 4.3.12-dev-1 compile warning on MacOS Bart Schaefer
2011-07-18 14:50 ` Peter Stephenson
2011-07-18 16:11   ` Bart Schaefer
2011-10-31  8:51     ` Jun T.

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).