From 9b9a151d43598bbbf564eb221a311d124bb61c0a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 11 Jul 2004 18:19:54 +0000 Subject: [PATCH] gst/gstclock.h: GST_SECOND shouldn't cause a conversion to unsigned. Original commit message from CVS: * gst/gstclock.h: GST_SECOND shouldn't cause a conversion to unsigned. * testsuite/clock/.cvsignore: * testsuite/clock/Makefile.am: * testsuite/clock/signedness.c: (main): make sure it never will again --- ChangeLog | 9 ++++++ gst/gstclock.h | 8 +++--- tests/old/testsuite/clock/.gitignore | 1 + tests/old/testsuite/clock/Makefile.am | 2 +- tests/old/testsuite/clock/signedness.c | 40 ++++++++++++++++++++++++++ testsuite/clock/.gitignore | 1 + testsuite/clock/Makefile.am | 2 +- testsuite/clock/signedness.c | 40 ++++++++++++++++++++++++++ 8 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 tests/old/testsuite/clock/signedness.c create mode 100644 testsuite/clock/signedness.c diff --git a/ChangeLog b/ChangeLog index f5c5a9c67e..9600d3c43a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-07-11 Benjamin Otte + + * gst/gstclock.h: + GST_SECOND shouldn't cause a conversion to unsigned. + * testsuite/clock/.cvsignore: + * testsuite/clock/Makefile.am: + * testsuite/clock/signedness.c: (main): + make sure it never will again + 2004-07-11 Andy Wingo * gst/gstbin.c (gst_bin_add_func): If we're adding an element diff --git a/gst/gstclock.h b/gst/gstclock.h index 58b7dd4a86..dabb624bd7 100644 --- a/gst/gstclock.h +++ b/gst/gstclock.h @@ -42,10 +42,10 @@ typedef gpointer GstClockID; #define GST_CLOCK_TIME_NONE ((GstClockTime)-1) #define GST_CLOCK_TIME_IS_VALID(time) ((time) != GST_CLOCK_TIME_NONE) -#define GST_SECOND ((guint64) G_USEC_PER_SEC * G_GINT64_CONSTANT (1000)) -#define GST_MSECOND ((guint64) GST_SECOND / G_GINT64_CONSTANT (1000)) -#define GST_USECOND ((guint64) GST_SECOND / G_GINT64_CONSTANT (1000000)) -#define GST_NSECOND ((guint64) GST_SECOND / G_GINT64_CONSTANT (1000000000)) +#define GST_SECOND (G_USEC_PER_SEC * G_GINT64_CONSTANT (1000)) +#define GST_MSECOND (GST_SECOND / G_GINT64_CONSTANT (1000)) +#define GST_USECOND (GST_SECOND / G_GINT64_CONSTANT (1000000)) +#define GST_NSECOND (GST_SECOND / G_GINT64_CONSTANT (1000000000)) #define GST_CLOCK_DIFF(s, e) (GstClockTimeDiff)((s) - (e)) #define GST_TIMEVAL_TO_TIME(tv) ((tv).tv_sec * GST_SECOND + (tv).tv_usec * GST_USECOND) diff --git a/tests/old/testsuite/clock/.gitignore b/tests/old/testsuite/clock/.gitignore index 0ed89cda75..523c8846de 100644 --- a/tests/old/testsuite/clock/.gitignore +++ b/tests/old/testsuite/clock/.gitignore @@ -1,2 +1,3 @@ clock1 clock2 +signedness diff --git a/tests/old/testsuite/clock/Makefile.am b/tests/old/testsuite/clock/Makefile.am index 4d05b65a1d..ffa2a73c75 100644 --- a/tests/old/testsuite/clock/Makefile.am +++ b/tests/old/testsuite/clock/Makefile.am @@ -1,6 +1,6 @@ include ../Rules -tests_pass = clock1 clock2 +tests_pass = signedness clock1 clock2 tests_fail = tests_ignore = diff --git a/tests/old/testsuite/clock/signedness.c b/tests/old/testsuite/clock/signedness.c new file mode 100644 index 0000000000..14c19d0d75 --- /dev/null +++ b/tests/old/testsuite/clock/signedness.c @@ -0,0 +1,40 @@ +/* + * testsuite program to make sure GST_SECOND doesn't cause signedness + * conversions + */ + +#include + +int +main (int argc, char *argv[]) +{ + GstClockTime time[] = { 0, 1, G_MAXUINT64 / GST_SECOND }; + GstClockTimeDiff diff[] = + { 0, 1, -1, G_MAXINT64 / GST_SECOND, G_MININT64 / GST_SECOND }; + guint i; + + gst_init (&argc, &argv); + + for (i = 0; i < G_N_ELEMENTS (time); i++) { + g_print ("%" G_GUINT64_FORMAT " != %" G_GUINT64_FORMAT + " * GST_SECOND / GST_SECOND ? ... ", time[i], time[i]); + if (time[i] != (time[i] * GST_SECOND / GST_SECOND)) { + g_print ("NO\n"); + g_assert_not_reached (); + return 1; + } + g_print ("yes\n"); + } + for (i = 0; i < G_N_ELEMENTS (diff); i++) { + g_print ("%" G_GINT64_FORMAT " != %" G_GINT64_FORMAT + " * GST_SECOND / GST_SECOND ? ... ", diff[i], diff[i]); + if (diff[i] != (diff[i] * GST_SECOND / GST_SECOND)) { + g_print ("NO\n"); + g_assert_not_reached (); + return 1; + } + g_print ("yes\n"); + } + + return 0; +} diff --git a/testsuite/clock/.gitignore b/testsuite/clock/.gitignore index 0ed89cda75..523c8846de 100644 --- a/testsuite/clock/.gitignore +++ b/testsuite/clock/.gitignore @@ -1,2 +1,3 @@ clock1 clock2 +signedness diff --git a/testsuite/clock/Makefile.am b/testsuite/clock/Makefile.am index 4d05b65a1d..ffa2a73c75 100644 --- a/testsuite/clock/Makefile.am +++ b/testsuite/clock/Makefile.am @@ -1,6 +1,6 @@ include ../Rules -tests_pass = clock1 clock2 +tests_pass = signedness clock1 clock2 tests_fail = tests_ignore = diff --git a/testsuite/clock/signedness.c b/testsuite/clock/signedness.c new file mode 100644 index 0000000000..14c19d0d75 --- /dev/null +++ b/testsuite/clock/signedness.c @@ -0,0 +1,40 @@ +/* + * testsuite program to make sure GST_SECOND doesn't cause signedness + * conversions + */ + +#include + +int +main (int argc, char *argv[]) +{ + GstClockTime time[] = { 0, 1, G_MAXUINT64 / GST_SECOND }; + GstClockTimeDiff diff[] = + { 0, 1, -1, G_MAXINT64 / GST_SECOND, G_MININT64 / GST_SECOND }; + guint i; + + gst_init (&argc, &argv); + + for (i = 0; i < G_N_ELEMENTS (time); i++) { + g_print ("%" G_GUINT64_FORMAT " != %" G_GUINT64_FORMAT + " * GST_SECOND / GST_SECOND ? ... ", time[i], time[i]); + if (time[i] != (time[i] * GST_SECOND / GST_SECOND)) { + g_print ("NO\n"); + g_assert_not_reached (); + return 1; + } + g_print ("yes\n"); + } + for (i = 0; i < G_N_ELEMENTS (diff); i++) { + g_print ("%" G_GINT64_FORMAT " != %" G_GINT64_FORMAT + " * GST_SECOND / GST_SECOND ? ... ", diff[i], diff[i]); + if (diff[i] != (diff[i] * GST_SECOND / GST_SECOND)) { + g_print ("NO\n"); + g_assert_not_reached (); + return 1; + } + g_print ("yes\n"); + } + + return 0; +}