unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Re: `SCM_MAKE_CHAR ()' signedness issue
@ 2009-08-18 18:39 carlo.bramix
  2009-08-18 18:54 ` Mike Gran
  0 siblings, 1 reply; 13+ messages in thread
From: carlo.bramix @ 2009-08-18 18:39 UTC (permalink / raw)
  To: guile-devel

Hello,
unfortunately that code still fails into libguile/print.c
Infact, a signed char just arrives to 127 and the " < 128" causes:

../../guile-git/libguile/print.c:1101: warning: comparison is always true due to limited range of data type
../../guile-git/libguile/print.c:1108: warning: comparison is always true due to limited range of data type

But in this manner it seems ok:

#define SCM_MAKE_CHAR(x)                                               \
  (((scm_t_int32) (x) + 128) < 128                                     \
   ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (x), scm_tc8_char)   \
   : SCM_MAKE_ITAG8 ((scm_t_bits) (x), scm_tc8_char))

Sincerely,

Carlo Bramini.

---------- Initial Header -----------

From      : guile-devel-bounces+carlo.bramix=libero.it@gnu.org
To          : "Ludovic Courtès" ludo@gnu.org, guile-devel@gnu.org
Cc          :
Date      : Tue, 18 Aug 2009 10:32:29 -0700 (PDT)
Subject : Re: `SCM_MAKE_CHAR ()' signedness issue

> > From: Ludovic Courtès <ludo@gnu.org>
> > To: guile-devel@gnu.org
> > Sent: Monday, August 17, 2009 8:33:03 AM
> > Subject: Re: `SCM_MAKE_CHAR ()' signedness issue
> >
> > I'm fairly confident that for such a small piece of code inlining is
> > always a good idea.
>
> OK.  If the comparison is modified to become
>
> 35 #define SCM_MAKE_CHAR(x)                                               \
> 36   (((x) < 128)                                               \
> 37    ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (x), scm_tc8_char)   \
> 38    : SCM_MAKE_ITAG8 ((scm_t_bits) (x), scm_tc8_char))
>
> Then hopefully that will solve all the build problems.
>
> > Thanks,
> > Ludo'.
>
> -Mike
>
>
>
>





^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: `SCM_MAKE_CHAR ()' signedness issue
@ 2009-08-17 18:52 carlo.bramix
  2009-08-17 19:41 ` Ken Raeburn
  0 siblings, 1 reply; 13+ messages in thread
From: carlo.bramix @ 2009-08-17 18:52 UTC (permalink / raw)
  To: guile-devel

Hello,
if I understood the problem, I think it can be easily fixed without using an inline function.

For example:

#ifdef __GNUC__

#define SCM_MAKE_CHAR(__x)                                            \
({ scm_t_int32 __t = (scm_t_int32)(__x);                              \
  (__t < 0)                                                           \
  ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (__x), scm_tc8_char) \
  : SCM_MAKE_ITAG8 ((scm_t_bits) (__x), scm_tc8_char);                \
  __t;                                                                \
})

#else

#define SCM_MAKE_CHAR(x)                                              \
  ((scm_t_int32) (x) < 0                                              \
  ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (x), scm_tc8_char)   \
  : SCM_MAKE_ITAG8 ((scm_t_bits) (x), scm_tc8_char))

#endif

solves the problem.
Actually a much more efficient solution specifically designed for GCC may use __builtin_types_compatible_p() and __builtin_choose_expr() intrinsic functions, but this will force you to support GCC 3.x or newer.

Something like:
#if defined __GNUC__ && __GNUC__ >= 3
...
#elif ...

will need to be written.

Sincerely,

Carlo Bramini.

---------- Initial Header -----------

From      : guile-devel-bounces+carlo.bramix=libero.it@gnu.org
To          : guile-devel@gnu.org
Cc          :
Date      : Mon, 17 Aug 2009 17:33:03 +0200
Subject : Re: `SCM_MAKE_CHAR ()' signedness issue

> Mike Gran <spk121@yahoo.com> writes:
>
> > On my system I ran a test with SCM_MAKE_CHAR as a macro, an an inline,
> > and as a never inlined function.  I ran ./check-guile twice for each.
>
> You're cheating!  ;-)
>
> The test suite does lots of things besides calling `SCM_MAKE_CHAR ()',
> so I'm not sure if it's a good benchmark.
>
> I'm fairly confident that for such a small piece of code inlining is
> always a good idea.
>
> Thanks,
> Ludo'.
>






^ permalink raw reply	[flat|nested] 13+ messages in thread
* `SCM_MAKE_CHAR ()' signedness issue
@ 2009-08-15 12:00 Ludovic Courtès
  2009-08-16 21:58 ` Ken Raeburn
  0 siblings, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2009-08-15 12:00 UTC (permalink / raw)
  To: guile-devel

Hello,

We still have troubles with the `(scm_t_int32) (x) < 0' test in
`SCM_MAKE_CHAR ()':

--8<---------------cut here---------------start------------->8---
ludo@gcc54:~/guile-1.9.1/+build$ cat ,,t.c
int
foo (unsigned char x)
{
  return (((int)x) < 0 ? 1 : -1);
}
ludo@gcc54:~/guile-1.9.1/+build$ gcc -Wall -c ,,t.c
,,t.c: In function ‘foo’:
,,t.c:4: warning: comparison is always false due to limited range of data type
ludo@gcc54:~/guile-1.9.1/+build$ ../build-aux/config.guess 
sparc64-unknown-linux-gnu
ludo@gcc54:~/guile-1.9.1/+build$ gcc --version
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
--8<---------------cut here---------------end--------------->8---

The problem occurs, e.g., in `string_titlecase_x ()'.

Surprisingly, GCC 4.4 on x86_64-linux-gnu doesn't yield any warning for
the example above.

I'm not sure how to fix it, so we'll see for the next release.

Thanks,
Ludo'.





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

end of thread, other threads:[~2009-08-18 23:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-18 18:39 `SCM_MAKE_CHAR ()' signedness issue carlo.bramix
2009-08-18 18:54 ` Mike Gran
2009-08-18 23:36   ` Greg Troxel
  -- strict thread matches above, loose matches on Subject: below --
2009-08-17 18:52 carlo.bramix
2009-08-17 19:41 ` Ken Raeburn
2009-08-15 12:00 Ludovic Courtès
2009-08-16 21:58 ` Ken Raeburn
2009-08-16 22:13   ` Ludovic Courtès
2009-08-16 22:25     ` Ken Raeburn
2009-08-17  8:26       ` Ludovic Courtès
2009-08-17 13:05         ` Mike Gran
2009-08-17 15:33           ` Ludovic Courtès
2009-08-18 17:32             ` Mike Gran

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 read-only IMAP folder(s) and NNTP newsgroup(s).