Compare commits

...

17 Commits

Author SHA1 Message Date
Philip Withnall
90ad49e901 Merge branch 'wfloat-conversion' into 'main'
build: Enable -Wfloat-conversion and fix warnings

See merge request GNOME/glib!4126
2024-07-15 21:23:58 +00:00
Philip Withnall
d3cb9d638d Merge branch 'traverse-diagrams' into 'main'
docs(GNode): Traversal diagrams, color & dark-mode

See merge request GNOME/glib!4157
2024-07-15 15:58:45 +00:00
Philip Withnall
a931a75c4f docs(GNode): Traversal diagrams, color & dark-mode
* Create a dark-mode variant of each traversal diagram, with the
  traversal path colorized `--primary` blue, instead of the original
  black.
* Apply the same colorizations to the light-mode diagrams, but
  using the light-theme `--primary` blue.
* Add SPDX license/copyright comments to all eight SVG files.
* Add new files to documentation configs in `glib.toml.in`.
* Update documentation comment in `gnode.c` to embed both color
  variants via picture tags, instead of markdown image embeds.
* Add alt text to all four images.
* Add additional blank lines to documentation comment, so that
  a. First item in bulleted list does not get folded into
     preceding intro paragraph
  b. Intro paragraph and diagrams are not part of first paragraph
     in documentation. (This also gets them out of the top-level
     table-of-contents/index list, where they previously appeared
     in full.)
* (Accidental change I didn't realize I was making): Convert line
  endings in breadth-first diagram from CRLF to LF.
2024-07-15 15:58:45 +00:00
Philip Withnall
f24bb8dc19
gutilsprivate: Factor out g_isnan() helper
There are a couple of places in the code which use `isnan()` and have
platform-specific workarounds for it. Unify those, and extend the
workaround to work for msys2-mingw32.

It seems that msys2-mingw32 can’t automatically use `isnan()` in a wider
mode than `float`:
```
In file included from ../glib/gdatetime.c:60:
../glib/gdatetime.c: In function 'g_date_time_new':
../glib/gdatetime.c:1648:14: error: conversion from 'gdouble' {aka 'double'} to 'float' may change value [-Werror=float-conversion]
 1648 |       isnan (seconds) ||
      |              ^~~~~~~
cc1.exe: all warnings being treated as errors
```

See: https://gitlab.gnome.org/pwithnall/glib/-/jobs/4022715

Using it in float mode on all platforms should not change behaviour, as
a conversion from `(double) NAN` to `float` should still give `NAN`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-07-07 17:53:19 +01:00
Philip Withnall
4d31fe6b7d
gnulib: Disable -Wfloat-conversion by default
gnulib doesn’t work with it, and if we try and enable it then mingw
versions of `signbit()` start causing problems.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 16:34:08 +01:00
Philip Withnall
692a50b78e
build: Enable -Wfloat-conversion by default
GLib now compiles without emitting any float conversion warnings, so
let’s keep it that way.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:44:01 +01:00
Philip Withnall
e35cfef509
performance: Add explicit casts for some double → other numeric type conversions
If we enable `-Wfloat-conversion`, these warn about a possible loss of
precision due to an implicit conversion from `double` to some other
numeric type.

The warning is correct: there is a possible loss of precision here. In
these instances, we don’t care, as the floating point arithmetic is
being done to do some imprecise scaling or imprecise timing. A loss of
precision is not a problem.

So, add an explicit cast to squash the warning.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:43:26 +01:00
Philip Withnall
b7153f5072
performance: Fix signedness of ints throughout
The tests were using a lot of signed `int`s when actually the values
being handled were always non-negative. Use `unsigned int` consistently
throughout.

Take the opportunity to move declarations of loop iterator variables
into the loops.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:41:48 +01:00
Philip Withnall
6129f6f244
tests: Use correct numeric comparison assertions in param tests
There were various places where (signed or unsigned) integer assertions
were being used to compare `double` or `float` values, resulting in an
implicit integer conversion.

This causes a warning when building with `-Wfloat-conversion`.

Improve the specificity of the tests by using the most-specific numeric
assertions through all `param` tests.

For the conversion tests, this means using the assertion function
associated with the target type, not the source type.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:38:22 +01:00
Philip Withnall
665292006e
gvalue: Add explicit casts in numeric transform functions
Compiling with `-Wfloat-conversion` warns about a few implicit
conversions from `double`/`float` to other numeric types in the `GValue`
transform functions.

These warnings are correct: value transformations can result in loss of
precision. That loss of precision is understood and expected, so add
some explicit casts to squash the warnings.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:35:57 +01:00
Philip Withnall
cdbfef3842
gparamspecs: Define G_FLOAT_EPSILON as a float constant
Rather than defining it as a double constant. This introduces no
functional changes, but does squash some `-Wfloat-conversion` warnings.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:35:00 +01:00
Philip Withnall
b69fe111ec
tests: Use a correct-typed constant in gdatetime tests
This makes no functional changes, but does avoid a warning from
`-Wfloat-conversion` due to implicitly switching from `guint64` to
`gdouble` and then back to `guint64`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:34:04 +01:00
Philip Withnall
412aed7c70
gtestutils: Add some explicit double casts
This avoids some false positive warnings from `-Wfloat-conversion`.

The code in `gtestutils.c` is a bit odd: it uses an array of `long
double` elements, with specific indices of that array storing specific
meaningful numbers, each of which has a type which is representable as a
`long double`, but which actually isn’t.

This is a prime candidate for refactoring to not use such a type-unsafe
API where everything is marshalled through `long double`. Unfortunately,
the array is declared in `GTestLogMsg`, which is defined in the public
`gtestutils.h` header, so we can’t change it. Boo.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:31:18 +01:00
Philip Withnall
d0cba9e6ec
girnode: Explicitly lose precision on parsed float values
When building a typelib, the values of constants need to be converted
from a string format (from the GIR) to a binary format. This is
currently done, for all numeric types, using `g_ascii_strto*()`
functions, but with minimal validation. String values which are not
representable as binary numbers are either silently truncated or
clamped.

`-Wfloat-conversion` has flagged that this happens for floats – a
double-precision return from `g_ascii_strtod()` is implicitly cast down
to a float.

While we should ideally have some better error handling so that
conversion to a typelib fails if a constant is not representable in the
typelib, this is a problem for *all* numeric types and not just `float`,
so add an explicit cast to ignore the error for now.

In practice there probably isn’t a problem for any numeric types here,
as there should be validation of the string value when the GIR is
generated anyway.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:27:23 +01:00
Philip Withnall
ebe609eeef
tests: Rearrange double/int comparisons in srvtarget to avoid casts
By keeping `expected` as a `double` for longer, we avoid having to cast
when populating the elements of `ordering`, to avoid
`-Wfloat-conversion` warnings.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:25:38 +01:00
Philip Withnall
2713255574
glib: Add explicit casts for some double → other numeric type conversions
If we enable `-Wfloat-conversion`, these warn about a possible loss of
precision due to an implicit conversion from `double` to some other
numeric type.

The warning is correct: there is a possible loss of precision here. In
these instances, we don’t care, as the floating point arithmetic is
being done to do some imprecise scaling or imprecise timing. A loss of
precision is not a problem.

So, add an explicit cast to squash the warning.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:24:55 +01:00
Philip Withnall
ad5948bbf5
gparamspecs: Fix loss of precision when validating a double-typed pspec
As spotted by `-Wfloat-conversion`. Doubles which could not be
accurately represented as floats may have erroneously failed bounds
validation.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2024-06-28 14:24:39 +01:00
27 changed files with 2903 additions and 428 deletions

View File

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: Rory O'Kane at Wikimedia Commons
<https://commons.wikimedia.org/wiki/File:Sorted_binary_tree_breadth-first_traversal.svg>
SPDX-FileCopyrightText: 2024 Frank Dana
-->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="266px" height="212px" viewBox="0 0 266 212" enable-background="new 0 0 266 212" xml:space="preserve">
<g>
<g>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" x1="27.23" y1="23.192" x2="29.23" y2="23.192"/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9562,3.9562" x1="33.187" y1="23.192" x2="236.932" y2="23.192"/>
<polyline fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" points="238.91,23.192 240.91,23.192
238.97,23.677 "/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="24.646" x2="27.971" y2="76.427"/>
<polyline fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" points="26.035,76.912 24.095,77.396
26.095,77.396 "/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0154,4.0154" x1="30.11" y1="77.396" x2="236.902" y2="77.396"/>
<polyline fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" points="238.91,77.396 240.91,77.396
238.97,77.881 "/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="78.85" x2="27.971" y2="130.631"/>
<polyline fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" points="26.035,131.114 24.095,131.6
26.095,131.6 "/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0154,4.0154" x1="30.11" y1="131.6" x2="236.902" y2="131.6"/>
<polyline fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" points="238.91,131.6 240.91,131.6
238.97,132.085 "/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="133.053" x2="27.971" y2="184.835"/>
<polyline fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" points="26.035,185.318 24.095,185.804
26.095,185.804 "/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0086,4.0086" x1="30.104" y1="185.804" x2="228.53" y2="185.804"/>
<line fill="none" stroke="#90c2ff" stroke-width="2" stroke-miterlimit="10" x1="230.534" y1="185.804" x2="232.534" y2="185.804"/>
<g>
<rect fill="#90c2ff" x="24.095" y="19.892" width="6.602" height="6.602"/>
</g>
<g>
<path fill="#90c2ff" d="M238.569,185.804c-2.84,1.054-6.363,2.852-8.548,4.756l1.721-4.756l-1.721-4.755
C232.206,182.953,235.729,184.751,238.569,185.804z"/>
</g>
</g>
</g>
<g id="graph0">
<title>sorted_binary_tree</title>
<g id="node1">
<title>C</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="60.23" cy="185.804" rx="18.067" ry="18.067"/>
<text transform="matrix(1 0 0 1 55.5435 190.8223)" font-family="'Times-Roman'" font-size="14.0528">C</text>
</g>
<g id="node2">
<title>E</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="132.502" cy="185.804" rx="18.067" ry="18.067"/>
<text transform="matrix(1 0 0 1 128.21 190.8223)" font-family="'Times-Roman'" font-size="14.0528">E</text>
</g>
<g id="node3">
<title>H</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="204.773" cy="185.804" rx="17.064" ry="18.067"/>
<text transform="matrix(1 0 0 1 199.6992 190.8223)" font-family="'Times-Roman'" font-size="14.0528">H</text>
</g>
<g id="node4">
<title>A</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="24.094" cy="131.6" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 19.02 136.6191)" font-family="'Times-Roman'" font-size="14.0528">A</text>
</g>
<g id="node5">
<title>D</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="96.366" cy="131.6" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 91.292 136.6191)" font-family="'Times-Roman'" font-size="14.0528">D</text>
</g>
<g id="edge6">
<title>D-&gt;C</title>
<path fill="none" stroke="#ffffff" d="M86.328,147.66c-3.011,4.016-7.026,9.034-10.038,14.053"/>
<polygon fill="#ffffff" stroke="#ffffff" points="78.298,164.725 70.268,170.747 73.279,160.709 "/>
</g>
<g id="edge8">
<title>D-&gt;E</title>
<path fill="none" stroke="#ffffff" d="M106.404,147.66c3.011,4.016,7.026,9.034,10.038,14.053"/>
<polygon fill="#ffffff" stroke="#ffffff" points="119.453,160.709 122.464,170.747 114.434,164.725 "/>
</g>
<g id="node6">
<title>I</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="240.909" cy="131.6" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 238.5693 136.6191)" font-family="'Times-Roman'" font-size="14.0528">I</text>
</g>
<g id="edge12">
<title>I-&gt;H</title>
<path fill="none" stroke="#ffffff" d="M230.871,146.656c-3.011,5.02-6.021,10.038-10.037,15.057"/>
<polygon fill="#ffffff" stroke="#ffffff" points="223.846,163.721 214.812,169.743 217.822,159.705 "/>
</g>
<g id="node7">
<title>B</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="60.23" cy="77.396" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 55.5435 82.415)" font-family="'Times-Roman'" font-size="14.0528">B</text>
</g>
<g id="edge3">
<title>B-&gt;A</title>
<path fill="none" stroke="#ffffff" d="M50.192,92.453c-3.011,5.019-6.022,10.038-10.038,15.057"/>
<polygon fill="#ffffff" stroke="#ffffff" points="43.166,109.518 34.132,115.539 37.144,105.502 "/>
</g>
<g id="edge5">
<title>B-&gt;D</title>
<path fill="none" stroke="#ffffff" d="M70.268,92.453c3.011,5.019,6.022,10.038,10.038,15.057"/>
<polygon fill="#ffffff" stroke="#ffffff" points="83.317,105.502 86.328,115.539 77.294,109.518 "/>
</g>
<g id="node8">
<title>G</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="204.773" cy="77.396" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 199.6992 82.415)" font-family="'Times-Roman'" font-size="14.0528">G</text>
</g>
<g id="edge11">
<title>G-&gt;I</title>
<path fill="none" stroke="#ffffff" d="M214.812,93.457c3.011,4.015,7.026,9.034,10.038,14.053"/>
<polygon fill="#ffffff" stroke="#ffffff" points="227.86,106.506 230.871,116.543 222.842,110.521 "/>
</g>
<g id="node9">
<title>F</title>
<ellipse fill="#FFFFFF" stroke="#ffffff" cx="132.502" cy="23.192" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 128.5942 28.2109)" font-family="'Times-Roman'" font-size="14.0528">F</text>
</g>
<g id="edge2">
<title>F-&gt;B</title>
<path fill="none" stroke="#ffffff" d="M117.445,34.234c-11.042,8.03-23.087,17.064-34.128,26.098"/>
<polygon fill="#ffffff" stroke="#ffffff" points="85.325,63.343 75.287,66.354 81.31,57.321 "/>
</g>
<g id="edge10">
<title>F-&gt;G</title>
<path fill="none" stroke="#ffffff" d="M147.559,34.234c11.041,8.03,23.087,17.064,34.129,26.098"/>
<polygon fill="#ffffff" stroke="#ffffff" points="183.694,57.321 189.717,66.354 179.68,63.343 "/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@ -1,134 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="266px" height="212px" viewBox="0 0 266 212" enable-background="new 0 0 266 212" xml:space="preserve">
<g>
<g>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" x1="27.23" y1="23.192" x2="29.23" y2="23.192"/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9562,3.9562" x1="33.187" y1="23.192" x2="236.932" y2="23.192"/>
<polyline fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="238.91,23.192 240.91,23.192
238.97,23.677 "/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="24.646" x2="27.971" y2="76.427"/>
<polyline fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="26.035,76.912 24.095,77.396
26.095,77.396 "/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0154,4.0154" x1="30.11" y1="77.396" x2="236.902" y2="77.396"/>
<polyline fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="238.91,77.396 240.91,77.396
238.97,77.881 "/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="78.85" x2="27.971" y2="130.631"/>
<polyline fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="26.035,131.114 24.095,131.6
26.095,131.6 "/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0154,4.0154" x1="30.11" y1="131.6" x2="236.902" y2="131.6"/>
<polyline fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="238.91,131.6 240.91,131.6
238.97,132.085 "/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="133.053" x2="27.971" y2="184.835"/>
<polyline fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="26.035,185.318 24.095,185.804
26.095,185.804 "/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0086,4.0086" x1="30.104" y1="185.804" x2="228.53" y2="185.804"/>
<line fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" x1="230.534" y1="185.804" x2="232.534" y2="185.804"/>
<g>
<rect x="24.095" y="19.892" width="6.602" height="6.602"/>
</g>
<g>
<path d="M238.569,185.804c-2.84,1.054-6.363,2.852-8.548,4.756l1.721-4.756l-1.721-4.755
C232.206,182.953,235.729,184.751,238.569,185.804z"/>
</g>
</g>
</g>
<g id="graph0">
<title>sorted_binary_tree</title>
<g id="node1">
<title>C</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="60.23" cy="185.804" rx="18.067" ry="18.067"/>
<text transform="matrix(1 0 0 1 55.5435 190.8223)" font-family="'Times-Roman'" font-size="14.0528">C</text>
</g>
<g id="node2">
<title>E</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="132.502" cy="185.804" rx="18.067" ry="18.067"/>
<text transform="matrix(1 0 0 1 128.21 190.8223)" font-family="'Times-Roman'" font-size="14.0528">E</text>
</g>
<g id="node3">
<title>H</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="204.773" cy="185.804" rx="17.064" ry="18.067"/>
<text transform="matrix(1 0 0 1 199.6992 190.8223)" font-family="'Times-Roman'" font-size="14.0528">H</text>
</g>
<g id="node4">
<title>A</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="24.094" cy="131.6" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 19.02 136.6191)" font-family="'Times-Roman'" font-size="14.0528">A</text>
</g>
<g id="node5">
<title>D</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="96.366" cy="131.6" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 91.292 136.6191)" font-family="'Times-Roman'" font-size="14.0528">D</text>
</g>
<g id="edge6">
<title>D-&gt;C</title>
<path fill="none" stroke="#000000" d="M86.328,147.66c-3.011,4.016-7.026,9.034-10.038,14.053"/>
<polygon stroke="#000000" points="78.298,164.725 70.268,170.747 73.279,160.709 "/>
</g>
<g id="edge8">
<title>D-&gt;E</title>
<path fill="none" stroke="#000000" d="M106.404,147.66c3.011,4.016,7.026,9.034,10.038,14.053"/>
<polygon stroke="#000000" points="119.453,160.709 122.464,170.747 114.434,164.725 "/>
</g>
<g id="node6">
<title>I</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="240.909" cy="131.6" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 238.5693 136.6191)" font-family="'Times-Roman'" font-size="14.0528">I</text>
</g>
<g id="edge12">
<title>I-&gt;H</title>
<path fill="none" stroke="#000000" d="M230.871,146.656c-3.011,5.02-6.021,10.038-10.037,15.057"/>
<polygon stroke="#000000" points="223.846,163.721 214.812,169.743 217.822,159.705 "/>
</g>
<g id="node7">
<title>B</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="60.23" cy="77.396" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 55.5435 82.415)" font-family="'Times-Roman'" font-size="14.0528">B</text>
</g>
<g id="edge3">
<title>B-&gt;A</title>
<path fill="none" stroke="#000000" d="M50.192,92.453c-3.011,5.019-6.022,10.038-10.038,15.057"/>
<polygon stroke="#000000" points="43.166,109.518 34.132,115.539 37.144,105.502 "/>
</g>
<g id="edge5">
<title>B-&gt;D</title>
<path fill="none" stroke="#000000" d="M70.268,92.453c3.011,5.019,6.022,10.038,10.038,15.057"/>
<polygon stroke="#000000" points="83.317,105.502 86.328,115.539 77.294,109.518 "/>
</g>
<g id="node8">
<title>G</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="204.773" cy="77.396" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 199.6992 82.415)" font-family="'Times-Roman'" font-size="14.0528">G</text>
</g>
<g id="edge11">
<title>G-&gt;I</title>
<path fill="none" stroke="#000000" d="M214.812,93.457c3.011,4.015,7.026,9.034,10.038,14.053"/>
<polygon stroke="#000000" points="227.86,106.506 230.871,116.543 222.842,110.521 "/>
</g>
<g id="node9">
<title>F</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="132.502" cy="23.192" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 128.5942 28.2109)" font-family="'Times-Roman'" font-size="14.0528">F</text>
</g>
<g id="edge2">
<title>F-&gt;B</title>
<path fill="none" stroke="#000000" d="M117.445,34.234c-11.042,8.03-23.087,17.064-34.128,26.098"/>
<polygon stroke="#000000" points="85.325,63.343 75.287,66.354 81.31,57.321 "/>
</g>
<g id="edge10">
<title>F-&gt;G</title>
<path fill="none" stroke="#000000" d="M147.559,34.234c11.041,8.03,23.087,17.064,34.129,26.098"/>
<polygon stroke="#000000" points="183.694,57.321 189.717,66.354 179.68,63.343 "/>
</g>
</g>
</svg>
<?xml version="1.0" encoding="utf-8"?>
<!--
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: Rory O'Kane at Wikimedia Commons
<https://commons.wikimedia.org/wiki/File:Sorted_binary_tree_breadth-first_traversal.svg>
SPDX-FileCopyrightText: 2024 Frank Dana
-->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="266px" height="212px" viewBox="0 0 266 212" enable-background="new 0 0 266 212" xml:space="preserve">
<g>
<g>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" x1="27.23" y1="23.192" x2="29.23" y2="23.192"/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9562,3.9562" x1="33.187" y1="23.192" x2="236.932" y2="23.192"/>
<polyline fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" points="238.91,23.192 240.91,23.192
238.97,23.677 "/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="24.646" x2="27.971" y2="76.427"/>
<polyline fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" points="26.035,76.912 24.095,77.396
26.095,77.396 "/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0154,4.0154" x1="30.11" y1="77.396" x2="236.902" y2="77.396"/>
<polyline fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" points="238.91,77.396 240.91,77.396
238.97,77.881 "/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="78.85" x2="27.971" y2="130.631"/>
<polyline fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" points="26.035,131.114 24.095,131.6
26.095,131.6 "/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0154,4.0154" x1="30.11" y1="131.6" x2="236.902" y2="131.6"/>
<polyline fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" points="238.91,131.6 240.91,131.6
238.97,132.085 "/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="3.9907,3.9907" x1="235.099" y1="133.053" x2="27.971" y2="184.835"/>
<polyline fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" points="26.035,185.318 24.095,185.804
26.095,185.804 "/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="4.0086,4.0086" x1="30.104" y1="185.804" x2="228.53" y2="185.804"/>
<line fill="none" stroke="#1c76e4" stroke-width="2" stroke-miterlimit="10" x1="230.534" y1="185.804" x2="232.534" y2="185.804"/>
<g>
<rect fill="#1c76e4" x="24.095" y="19.892" width="6.602" height="6.602"/>
</g>
<g>
<path fill="#1c76e4" d="M238.569,185.804c-2.84,1.054-6.363,2.852-8.548,4.756l1.721-4.756l-1.721-4.755
C232.206,182.953,235.729,184.751,238.569,185.804z"/>
</g>
</g>
</g>
<g id="graph0">
<title>sorted_binary_tree</title>
<g id="node1">
<title>C</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="60.23" cy="185.804" rx="18.067" ry="18.067"/>
<text transform="matrix(1 0 0 1 55.5435 190.8223)" font-family="'Times-Roman'" font-size="14.0528">C</text>
</g>
<g id="node2">
<title>E</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="132.502" cy="185.804" rx="18.067" ry="18.067"/>
<text transform="matrix(1 0 0 1 128.21 190.8223)" font-family="'Times-Roman'" font-size="14.0528">E</text>
</g>
<g id="node3">
<title>H</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="204.773" cy="185.804" rx="17.064" ry="18.067"/>
<text transform="matrix(1 0 0 1 199.6992 190.8223)" font-family="'Times-Roman'" font-size="14.0528">H</text>
</g>
<g id="node4">
<title>A</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="24.094" cy="131.6" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 19.02 136.6191)" font-family="'Times-Roman'" font-size="14.0528">A</text>
</g>
<g id="node5">
<title>D</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="96.366" cy="131.6" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 91.292 136.6191)" font-family="'Times-Roman'" font-size="14.0528">D</text>
</g>
<g id="edge6">
<title>D-&gt;C</title>
<path fill="none" stroke="#000000" d="M86.328,147.66c-3.011,4.016-7.026,9.034-10.038,14.053"/>
<polygon stroke="#000000" points="78.298,164.725 70.268,170.747 73.279,160.709 "/>
</g>
<g id="edge8">
<title>D-&gt;E</title>
<path fill="none" stroke="#000000" d="M106.404,147.66c3.011,4.016,7.026,9.034,10.038,14.053"/>
<polygon stroke="#000000" points="119.453,160.709 122.464,170.747 114.434,164.725 "/>
</g>
<g id="node6">
<title>I</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="240.909" cy="131.6" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 238.5693 136.6191)" font-family="'Times-Roman'" font-size="14.0528">I</text>
</g>
<g id="edge12">
<title>I-&gt;H</title>
<path fill="none" stroke="#000000" d="M230.871,146.656c-3.011,5.02-6.021,10.038-10.037,15.057"/>
<polygon stroke="#000000" points="223.846,163.721 214.812,169.743 217.822,159.705 "/>
</g>
<g id="node7">
<title>B</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="60.23" cy="77.396" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 55.5435 82.415)" font-family="'Times-Roman'" font-size="14.0528">B</text>
</g>
<g id="edge3">
<title>B-&gt;A</title>
<path fill="none" stroke="#000000" d="M50.192,92.453c-3.011,5.019-6.022,10.038-10.038,15.057"/>
<polygon stroke="#000000" points="43.166,109.518 34.132,115.539 37.144,105.502 "/>
</g>
<g id="edge5">
<title>B-&gt;D</title>
<path fill="none" stroke="#000000" d="M70.268,92.453c3.011,5.019,6.022,10.038,10.038,15.057"/>
<polygon stroke="#000000" points="83.317,105.502 86.328,115.539 77.294,109.518 "/>
</g>
<g id="node8">
<title>G</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="204.773" cy="77.396" rx="17.064" ry="18.068"/>
<text transform="matrix(1 0 0 1 199.6992 82.415)" font-family="'Times-Roman'" font-size="14.0528">G</text>
</g>
<g id="edge11">
<title>G-&gt;I</title>
<path fill="none" stroke="#000000" d="M214.812,93.457c3.011,4.015,7.026,9.034,10.038,14.053"/>
<polygon stroke="#000000" points="227.86,106.506 230.871,116.543 222.842,110.521 "/>
</g>
<g id="node9">
<title>F</title>
<ellipse fill="#FFFFFF" stroke="#000000" cx="132.502" cy="23.192" rx="18.068" ry="18.068"/>
<text transform="matrix(1 0 0 1 128.5942 28.2109)" font-family="'Times-Roman'" font-size="14.0528">F</text>
</g>
<g id="edge2">
<title>F-&gt;B</title>
<path fill="none" stroke="#000000" d="M117.445,34.234c-11.042,8.03-23.087,17.064-34.128,26.098"/>
<polygon stroke="#000000" points="85.325,63.343 75.287,66.354 81.31,57.321 "/>
</g>
<g id="edge10">
<title>F-&gt;G</title>
<path fill="none" stroke="#000000" d="M147.559,34.234c11.041,8.03,23.087,17.064,34.129,26.098"/>
<polygon stroke="#000000" points="183.694,57.321 189.717,66.354 179.68,63.343 "/>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 36 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 36 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 36 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -99,6 +99,10 @@ content_images = [
"Sorted_binary_tree_inorder.svg",
"Sorted_binary_tree_postorder.svg",
"Sorted_binary_tree_preorder.svg",
"Sorted_binary_tree_breadth-first_traversal-dark.svg",
"Sorted_binary_tree_inorder-dark.svg",
"Sorted_binary_tree_postorder-dark.svg",
"Sorted_binary_tree_preorder-dark.svg",
]
[[object]]

View File

@ -1537,7 +1537,7 @@ g_task_thread_setup (void)
if (tasks_running == G_TASK_POOL_SIZE)
task_wait_time = G_TASK_WAIT_TIME_BASE;
else if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
task_wait_time *= G_TASK_WAIT_TIME_MULTIPLIER;
task_wait_time = (guint64) (task_wait_time * G_TASK_WAIT_TIME_MULTIPLIER);
if (tasks_running >= G_TASK_POOL_SIZE)
g_source_set_ready_time (task_pool_manager, g_get_monotonic_time () + task_wait_time);
@ -1562,7 +1562,7 @@ g_task_thread_cleanup (void)
g_source_set_ready_time (task_pool_manager, -1);
if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
task_wait_time /= G_TASK_WAIT_TIME_MULTIPLIER;
task_wait_time = (guint64) (task_wait_time / G_TASK_WAIT_TIME_MULTIPLIER);
tasks_running--;

View File

@ -30,7 +30,8 @@
struct {
const char *order;
int expected, seen;
gdouble expected;
unsigned int seen;
} ordering[] = {
/* There are 32 legitimate orderings; the result always has to start
* with either "fe" (usually) or "ef" (rarely). For the remaining
@ -141,8 +142,8 @@ test_srv_target_ordering (void)
*/
for (o = 0; o < NUM_ORDERINGS; o++)
{
g_assert_cmpint (ordering[o].seen, >, ordering[o].expected / 2);
g_assert_cmpint (ordering[o].seen, <, ordering[o].expected * 2);
g_assert_cmpuint (ordering[o].seen, >, (guint64) (ordering[o].expected / 2));
g_assert_cmpuint (ordering[o].seen, <, (guint64) (ordering[o].expected * 2));
}
g_resolver_free_targets (targets);

View File

@ -2371,7 +2371,7 @@ gi_ir_node_build_typelib (GIIrNode *node,
break;
case GI_TYPE_TAG_FLOAT:
blob->size = sizeof (float);
DO_ALIGNED_COPY (&data[blob->offset], parse_float_value (constant->value), float);
DO_ALIGNED_COPY (&data[blob->offset], (float) parse_float_value (constant->value), float);
break;
case GI_TYPE_TAG_DOUBLE:
blob->size = sizeof (double);

View File

@ -82,15 +82,11 @@
#include "gtestutils.h"
#include "gthread.h"
#include "gtimezone.h"
#include "gutilsprivate.h"
#ifndef G_OS_WIN32
#include <sys/time.h>
#include <time.h>
#else
#if defined (_MSC_VER) && (_MSC_VER < 1800)
/* fallback implementation for isnan() on VS2012 and earlier */
#define isnan _isnan
#endif
#endif /* !G_OS_WIN32 */
struct _GDateTime
@ -1645,7 +1641,7 @@ g_date_time_new (GTimeZone *tz,
day < 1 || day > days_in_months[GREGORIAN_LEAP (year)][month] ||
hour < 0 || hour > 23 ||
minute < 0 || minute > 59 ||
isnan (seconds) ||
g_isnan (seconds) ||
seconds < 0.0 || seconds >= 60.0)
return NULL;
@ -1670,7 +1666,7 @@ g_date_time_new (GTimeZone *tz,
* is 1000000. This is not a problem with precision, it's just how
* FP numbers work.
* See https://bugzilla.gnome.org/show_bug.cgi?id=697715. */
usec = seconds * USEC_PER_SECOND;
usec = (gint64) (seconds * USEC_PER_SECOND);
usecd = (usec + 1) * 1e-6;
if (usecd <= seconds) {
usec++;
@ -1973,7 +1969,7 @@ GDateTime*
g_date_time_add_seconds (GDateTime *datetime,
gdouble seconds)
{
return g_date_time_add (datetime, seconds * USEC_PER_SECOND);
return g_date_time_add (datetime, (GTimeSpan) (seconds * USEC_PER_SECOND));
}
/**

View File

@ -813,7 +813,7 @@ g_hash_table_resize (GHashTable *hash_table)
* Immediately after growing, the load factor will be in the range
* .375 .. .469. After shrinking, it will be exactly .5. */
g_hash_table_set_shift_from_size (hash_table, hash_table->nnodes * 1.333);
g_hash_table_set_shift_from_size (hash_table, (gint) (hash_table->nnodes * 1.333));
if (hash_table->size > old_size)
{

View File

@ -800,16 +800,38 @@ g_node_depth_traverse_level (GNode *node,
* efficient than the other orders.
*
* Specifies the type of traversal performed by g_tree_traverse(),
* g_node_traverse() and g_node_find(). The different orders are
* illustrated here:
* g_node_traverse() and g_node_find().
*
* The different orders are illustrated here:
*
* - In order: A, B, C, D, E, F, G, H, I
* ![](Sorted_binary_tree_inorder.svg)
* <picture>
* <source srcset="Sorted_binary_tree_inorder-dark.svg"
* media="(prefers-color-scheme: dark)">
* <img src="Sorted_binary_tree_inorder.svg"
* alt="Sorted binary tree, in-order traversal">
* </picture>
* - Pre order: F, B, A, D, C, E, G, I, H
* ![](Sorted_binary_tree_preorder.svg)
* <picture>
* <source srcset="Sorted_binary_tree_preorder-dark.svg"
* media="(prefers-color-scheme: dark)">
* <img src="Sorted_binary_tree_preorder.svg"
* alt="Sorted binary tree, pre-order traversal">
* </picture>
* - Post order: A, C, E, D, B, H, I, G, F
* ![](Sorted_binary_tree_postorder.svg)
* <picture>
* <source srcset="Sorted_binary_tree_postorder-dark.svg"
* media="(prefers-color-scheme: dark)">
* <img src="Sorted_binary_tree_postorder.svg"
* alt="Sorted binary tree, post-order traversal">
* </picture>
* - Level order: F, B, G, A, D, I, C, E, H
* ![](Sorted_binary_tree_breadth-first_traversal.svg)
* <picture>
* <source srcset="Sorted_binary_tree_breadth-first_traversal-dark.svg"
* media="(prefers-color-scheme: dark)">
* <img src="Sorted_binary_tree_breadth-first_traversal.svg"
* alt="Sorted binary tree, breadth-first level order traversal">
* </picture>
*/
/**

View File

@ -1,7 +1,10 @@
# glib enables -Werror=format-nonliteral by default, but the embedded gnulib
# needs to handle user provided format strings.
extra_gnulib_args = cc.get_supported_arguments([
'-Wno-format-nonliteral', '-Wno-duplicated-branches'])
'-Wno-format-nonliteral',
'-Wno-float-conversion',
'-Wno-duplicated-branches',
])
if host_system == 'windows' and cc.get_id() == 'clang'
extra_gnulib_args += cc.get_supported_arguments([

View File

@ -747,9 +747,9 @@ static GPrintFunc g_default_print_func = NULL;
enum
{
G_TEST_CASE_LARGS_RESULT = 0,
G_TEST_CASE_LARGS_RUN_FORKS = 1,
G_TEST_CASE_LARGS_EXECUTION_TIME = 2,
G_TEST_CASE_LARGS_RESULT = 0, /* a GTestResult */
G_TEST_CASE_LARGS_RUN_FORKS = 1, /* a gint */
G_TEST_CASE_LARGS_EXECUTION_TIME = 2, /* a gdouble */
G_TEST_CASE_LARGS_MAX
};
@ -974,7 +974,7 @@ g_test_log (GTestLogType lbit,
break;
case G_TEST_LOG_STOP_CASE:
result = largs[G_TEST_CASE_LARGS_RESULT];
timing = largs[G_TEST_CASE_LARGS_EXECUTION_TIME];
timing = (gdouble) largs[G_TEST_CASE_LARGS_EXECUTION_TIME];
fail = result == G_TEST_RUN_FAILURE;
if (test_tap_log)
{
@ -4373,7 +4373,7 @@ g_test_log_dump (GTestLogMsg *msg,
g_string_append_len (gstring, msg->strings[ui], l);
}
for (ui = 0; ui < msg->n_nums; ui++)
gstring_append_double (gstring, msg->nums[ui]);
gstring_append_double (gstring, (gdouble) msg->nums[ui]);
*len = gstring->len;
gstring_overwrite_int (gstring, 0, *len); /* message length */
return (guint8*) g_string_free (gstring, FALSE);

View File

@ -2703,7 +2703,7 @@ g_uri_escape_string (const gchar *unescaped,
g_return_val_if_fail (unescaped != NULL, NULL);
s = g_string_sized_new (strlen (unescaped) * 1.25);
s = g_string_sized_new ((size_t) (strlen (unescaped) * 1.25));
g_string_append_uri_escaped (s, unescaped, reserved_chars_allowed, allow_utf8);
@ -2797,7 +2797,7 @@ g_uri_escape_bytes (const guint8 *unescaped,
g_return_val_if_fail (unescaped != NULL, NULL);
string = g_string_sized_new (length * 1.25);
string = g_string_sized_new ((size_t) (length * 1.25));
_uri_encoder (string, unescaped, length,
reserved_chars_allowed, FALSE);

View File

@ -26,6 +26,7 @@
#include "gtypes.h"
#include "gtestutils.h"
#include <math.h>
#include <time.h>
G_BEGIN_DECLS
@ -61,6 +62,23 @@ gboolean _g_localtime (time_t timet, struct tm *tm);
gboolean g_set_prgname_once (const gchar *prgname);
/* Although isnan() is defined as a type-independent macro in C99, mingw32
* doesnt seem to support that (it defines `isnan (float d)` only). Older
* MSVC toolchains dont support C99 either. So we provide an internal
* abstraction macro.
*
* This should not be made public; toolchains will soon enough catch up with
* C99, so third party code should just use isnan(). */
static inline int
g_isnan (double d)
{
#if (defined (_MSC_VER) && (_MSC_VER < 1800)) || defined(__MINGW32__)
return _isnan (d);
#else
return isnan (d);
#endif
}
G_END_DECLS
#endif /* __G_UTILS_PRIVATE_H__ */

View File

@ -1409,7 +1409,7 @@ test_GDateTime_new_from_unix_utc (void)
g_assert (dt == NULL);
#endif
t = t / 1e6; /* oops, this was microseconds */
t = t / G_USEC_PER_SEC; /* oops, this was microseconds */
dt = g_date_time_new_from_unix_utc (t);
g_assert (dt != NULL);

View File

@ -34,11 +34,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "glib.h"
#include "gutilsprivate.h"
#if defined (_MSC_VER) && (_MSC_VER <= 1800)
#define isnan(x) _isnan(x)
#ifndef NAN
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
#define NAN (*(const float *) __nan)
@ -1625,7 +1625,7 @@ check_strtod_string (gchar *number,
setlocale (LC_NUMERIC, locales[l]);
d = g_ascii_strtod (number, &end);
g_assert_true (isnan (res) ? isnan (d) : (d == res));
g_assert_true (g_isnan (res) ? g_isnan (d) : (d == res));
g_assert_true ((gsize) (end - number) ==
(check_end ? correct_len : strlen (number)));
}
@ -1660,7 +1660,7 @@ test_ascii_strtod (void)
/* Do this before any call to setlocale. */
our_nan = atof ("NaN");
#endif
g_assert_true (isnan (our_nan));
g_assert_true (g_isnan (our_nan));
#ifdef INFINITY
our_inf = INFINITY;

View File

@ -37,7 +37,7 @@
#include "gvaluearray.h"
#define G_FLOAT_EPSILON (1e-30)
#define G_FLOAT_EPSILON (1e-30f)
#define G_DOUBLE_EPSILON (1e-90)
@ -691,7 +691,7 @@ param_double_is_valid (GParamSpec *pspec,
const GValue *value)
{
GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
gfloat oval = value->data[0].v_double;
gdouble oval = value->data[0].v_double;
return dspec->minimum <= oval && oval <= dspec->maximum;
}

View File

@ -51,7 +51,7 @@ static void \
value_transform_##func_name (const GValue *src_value, \
GValue *dest_value) \
{ \
ctype c_value = src_value->data[0].from_member; \
ctype c_value = (ctype) src_value->data[0].from_member; \
dest_value->data[0].to_member = c_value; \
} extern void glib_dummy_decl (void)
DEFINE_CAST (int_s8, v_int, gint8, v_int);

View File

@ -190,7 +190,8 @@ value_collect_float (GValue *value,
GTypeCValue *collect_values,
guint collect_flags)
{
value->data[0].v_float = collect_values[0].v_double;
/* This necessarily loses precision */
value->data[0].v_float = (gfloat) collect_values[0].v_double;
return NULL;
}

View File

@ -267,7 +267,7 @@ test_param_spec_float (void)
g_value_set_float (&value, 0.0);
g_assert_false (g_param_value_is_valid (pspec, &value));
g_assert_true (g_param_value_validate (pspec, &value));
g_assert_cmpint (g_value_get_float (&value), ==, 20.0);
g_assert_cmpfloat (g_value_get_float (&value), ==, 20.0);
g_param_spec_unref (pspec);
}
@ -289,7 +289,21 @@ test_param_spec_double (void)
g_value_set_double (&value, 0.0);
g_assert_false (g_param_value_is_valid (pspec, &value));
g_assert_true (g_param_value_validate (pspec, &value));
g_assert_cmpint (g_value_get_double (&value), ==, 20.0);
g_assert_cmpfloat (g_value_get_double (&value), ==, 20.0);
g_param_spec_unref (pspec);
/* Test validation with some larger values, which fit in a double but not in a float.
* In particular, check there are no double float conversions in the pipeline,
* by using a valid range which is entirely outside the range of numbers
* representable in a float. */
pspec = g_param_spec_double ("double", NULL, NULL,
1.2e308, 1.3e308, 1.21e308, G_PARAM_READWRITE);
g_param_value_set_default (pspec, &value);
g_assert_true (g_param_value_is_valid (pspec, &value));
g_assert_false (g_param_value_validate (pspec, &value));
g_assert_cmpfloat (g_value_get_double (&value), ==, 1.21e308);
g_param_spec_unref (pspec);
}
@ -805,13 +819,13 @@ test_value_transform (void)
GValue src = G_VALUE_INIT;
GValue dest = G_VALUE_INIT;
#define CHECK_INT_CONVERSION(type, getter, value) \
#define CHECK_INT_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_INT, type)); \
g_value_init (&src, G_TYPE_INT); \
g_value_init (&dest, type); \
g_value_set_int (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpint (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
@ -820,197 +834,197 @@ test_value_transform (void)
* https://bugzilla.gnome.org/show_bug.cgi?id=659870
* for why it is broken.
*/
CHECK_INT_CONVERSION(G_TYPE_CHAR, char, 124)
CHECK_INT_CONVERSION(G_TYPE_CHAR, g_assert_cmpuint, char, 124)
CHECK_INT_CONVERSION(G_TYPE_CHAR, schar, -124)
CHECK_INT_CONVERSION(G_TYPE_CHAR, schar, 124)
CHECK_INT_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_INT_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_INT_CONVERSION(G_TYPE_INT, int, -12345)
CHECK_INT_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_INT_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_INT_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_INT_CONVERSION(G_TYPE_LONG, long, -12345678)
CHECK_INT_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_INT_CONVERSION(G_TYPE_INT64, int64, -12345678)
CHECK_INT_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_INT_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_INT_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_INT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, -124)
CHECK_INT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, 124)
CHECK_INT_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_INT_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_INT_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, -12345)
CHECK_INT_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_INT_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_INT_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_INT_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, -12345678)
CHECK_INT_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_INT_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, -12345678)
CHECK_INT_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_INT_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_INT_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_UINT_CONVERSION(type, getter, value) \
#define CHECK_UINT_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_UINT, type)); \
g_value_init (&src, G_TYPE_UINT); \
g_value_init (&dest, type); \
g_value_set_uint (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpuint (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
CHECK_UINT_CONVERSION(G_TYPE_CHAR, char, 124)
CHECK_UINT_CONVERSION(G_TYPE_CHAR, char, 124)
CHECK_UINT_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_UINT_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_UINT_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_UINT_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_UINT_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_UINT_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_UINT_CONVERSION(G_TYPE_LONG, long, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_INT64, int64, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, char, 124)
CHECK_UINT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, char, 124)
CHECK_UINT_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_UINT_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_UINT_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_UINT_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_UINT_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_UINT_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_UINT_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_UINT_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_LONG_CONVERSION(type, getter, value) \
#define CHECK_LONG_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_LONG, type)); \
g_value_init (&src, G_TYPE_LONG); \
g_value_init (&dest, type); \
g_value_set_long (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpint (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
CHECK_LONG_CONVERSION(G_TYPE_CHAR, schar, -124)
CHECK_LONG_CONVERSION(G_TYPE_CHAR, schar, 124)
CHECK_LONG_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_LONG_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_LONG_CONVERSION(G_TYPE_INT, int, -12345)
CHECK_LONG_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_LONG_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_LONG_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_LONG_CONVERSION(G_TYPE_LONG, long, -12345678)
CHECK_LONG_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_LONG_CONVERSION(G_TYPE_INT64, int64, -12345678)
CHECK_LONG_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_LONG_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_LONG_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_LONG_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, -124)
CHECK_LONG_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, 124)
CHECK_LONG_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_LONG_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_LONG_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, -12345)
CHECK_LONG_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_LONG_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_LONG_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_LONG_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, -12345678)
CHECK_LONG_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_LONG_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, -12345678)
CHECK_LONG_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_LONG_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_LONG_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_ULONG_CONVERSION(type, getter, value) \
#define CHECK_ULONG_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_ULONG, type)); \
g_value_init (&src, G_TYPE_ULONG); \
g_value_init (&dest, type); \
g_value_set_ulong (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpuint (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
CHECK_ULONG_CONVERSION(G_TYPE_CHAR, char, 124)
CHECK_ULONG_CONVERSION(G_TYPE_CHAR, char, 124)
CHECK_ULONG_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_ULONG_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_ULONG_CONVERSION(G_TYPE_INT, int, -12345)
CHECK_ULONG_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_ULONG_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_ULONG_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_ULONG_CONVERSION(G_TYPE_LONG, long, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_INT64, int64, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, char, 124)
CHECK_ULONG_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, char, 124)
CHECK_ULONG_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_ULONG_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_ULONG_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, -12345)
CHECK_ULONG_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_ULONG_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_ULONG_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_ULONG_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_ULONG_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_INT64_CONVERSION(type, getter, value) \
#define CHECK_INT64_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_INT64, type)); \
g_value_init (&src, G_TYPE_INT64); \
g_value_init (&dest, type); \
g_value_set_int64 (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpint (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
CHECK_INT64_CONVERSION(G_TYPE_CHAR, schar, -124)
CHECK_INT64_CONVERSION(G_TYPE_CHAR, schar, 124)
CHECK_INT64_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_INT64_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_INT64_CONVERSION(G_TYPE_INT, int, -12345)
CHECK_INT64_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_INT64_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_INT64_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_INT64_CONVERSION(G_TYPE_LONG, long, -12345678)
CHECK_INT64_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_INT64_CONVERSION(G_TYPE_INT64, int64, -12345678)
CHECK_INT64_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_INT64_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_INT64_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_INT64_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, -124)
CHECK_INT64_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, 124)
CHECK_INT64_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_INT64_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_INT64_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, -12345)
CHECK_INT64_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_INT64_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_INT64_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_INT64_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, -12345678)
CHECK_INT64_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_INT64_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, -12345678)
CHECK_INT64_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_INT64_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_INT64_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_UINT64_CONVERSION(type, getter, value) \
#define CHECK_UINT64_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_UINT64, type)); \
g_value_init (&src, G_TYPE_UINT64); \
g_value_init (&dest, type); \
g_value_set_uint64 (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpuint (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
CHECK_UINT64_CONVERSION(G_TYPE_CHAR, schar, -124)
CHECK_UINT64_CONVERSION(G_TYPE_CHAR, schar, 124)
CHECK_UINT64_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_UINT64_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_UINT64_CONVERSION(G_TYPE_INT, int, -12345)
CHECK_UINT64_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_UINT64_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_UINT64_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_UINT64_CONVERSION(G_TYPE_LONG, long, -12345678)
CHECK_UINT64_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_UINT64_CONVERSION(G_TYPE_INT64, int64, -12345678)
CHECK_UINT64_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_UINT64_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_UINT64_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_UINT64_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, -124)
CHECK_UINT64_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, 124)
CHECK_UINT64_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_UINT64_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_UINT64_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, -12345)
CHECK_UINT64_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_UINT64_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_UINT64_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_UINT64_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, -12345678)
CHECK_UINT64_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_UINT64_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, -12345678)
CHECK_UINT64_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_UINT64_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_UINT64_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_FLOAT_CONVERSION(type, getter, value) \
#define CHECK_FLOAT_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_FLOAT, type)); \
g_value_init (&src, G_TYPE_FLOAT); \
g_value_init (&dest, type); \
g_value_set_float (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpfloat (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
CHECK_FLOAT_CONVERSION(G_TYPE_CHAR, schar, -124)
CHECK_FLOAT_CONVERSION(G_TYPE_CHAR, schar, 124)
CHECK_FLOAT_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_FLOAT_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_FLOAT_CONVERSION(G_TYPE_INT, int, -12345)
CHECK_FLOAT_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_FLOAT_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_FLOAT_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_FLOAT_CONVERSION(G_TYPE_LONG, long, -12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_INT64, int64, -12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, -124)
CHECK_FLOAT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, 124)
CHECK_FLOAT_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_FLOAT_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_FLOAT_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, -12345)
CHECK_FLOAT_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_FLOAT_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_FLOAT_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_FLOAT_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, -12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, -12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_FLOAT_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_DOUBLE_CONVERSION(type, getter, value) \
#define CHECK_DOUBLE_CONVERSION(type, cmpfunc, getter, value) \
g_assert_true (g_value_type_transformable (G_TYPE_DOUBLE, type)); \
g_value_init (&src, G_TYPE_DOUBLE); \
g_value_init (&dest, type); \
g_value_set_double (&src, value); \
g_assert_true (g_value_transform (&src, &dest)); \
g_assert_cmpfloat (g_value_get_##getter (&dest), ==, value); \
cmpfunc (g_value_get_##getter (&dest), ==, value); \
g_value_unset (&src); \
g_value_unset (&dest);
CHECK_DOUBLE_CONVERSION(G_TYPE_CHAR, schar, -124)
CHECK_DOUBLE_CONVERSION(G_TYPE_CHAR, schar, 124)
CHECK_DOUBLE_CONVERSION(G_TYPE_UCHAR, uchar, 0)
CHECK_DOUBLE_CONVERSION(G_TYPE_UCHAR, uchar, 255)
CHECK_DOUBLE_CONVERSION(G_TYPE_INT, int, -12345)
CHECK_DOUBLE_CONVERSION(G_TYPE_INT, int, 12345)
CHECK_DOUBLE_CONVERSION(G_TYPE_UINT, uint, 0)
CHECK_DOUBLE_CONVERSION(G_TYPE_UINT, uint, 12345)
CHECK_DOUBLE_CONVERSION(G_TYPE_LONG, long, -12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_ULONG, ulong, 12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_INT64, int64, -12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_UINT64, uint64, 12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_FLOAT, float, 12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_DOUBLE, double, 12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, -124)
CHECK_DOUBLE_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, 124)
CHECK_DOUBLE_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 0)
CHECK_DOUBLE_CONVERSION(G_TYPE_UCHAR, g_assert_cmpuint, uchar, 255)
CHECK_DOUBLE_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, -12345)
CHECK_DOUBLE_CONVERSION(G_TYPE_INT, g_assert_cmpint, int, 12345)
CHECK_DOUBLE_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 0)
CHECK_DOUBLE_CONVERSION(G_TYPE_UINT, g_assert_cmpuint, uint, 12345)
CHECK_DOUBLE_CONVERSION(G_TYPE_LONG, g_assert_cmpint, long, -12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_ULONG, g_assert_cmpuint, ulong, 12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_INT64, g_assert_cmpint, int64, -12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_UINT64, g_assert_cmpuint, uint64, 12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_FLOAT, g_assert_cmpfloat, float, 12345678)
CHECK_DOUBLE_CONVERSION(G_TYPE_DOUBLE, g_assert_cmpfloat, double, 12345678)
#define CHECK_BOOLEAN_CONVERSION(type, setter, value) \
g_assert_true (g_value_type_transformable (type, G_TYPE_BOOLEAN)); \

View File

@ -169,7 +169,7 @@ run_test (PerformanceTest *test)
g_print ("Uncorrected round time: %.4f msecs, correction factor %.2f\n", 1000*min_elapsed, factor);
/* Calculate number of rounds needed */
num_rounds = (test_length / TARGET_ROUND_TIME) + 1;
num_rounds = (guint64) (test_length / TARGET_ROUND_TIME) + 1;
if (verbose)
g_print ("Running %"G_GINT64_MODIFIER"d rounds\n", num_rounds);
@ -505,7 +505,7 @@ complex_object_init (ComplexObject *complex_object)
struct ConstructionTest {
GObject **objects;
int n_objects;
unsigned int n_objects;
GType type;
};
@ -526,9 +526,9 @@ test_construction_init (PerformanceTest *test,
double count_factor)
{
struct ConstructionTest *data = _data;
int n;
unsigned int n;
n = NUM_OBJECT_TO_CONSTRUCT * count_factor;
n = (unsigned int) (NUM_OBJECT_TO_CONSTRUCT * count_factor);
if (data->n_objects != n)
{
data->n_objects = n;
@ -543,10 +543,10 @@ test_construction_run (PerformanceTest *test,
struct ConstructionTest *data = _data;
GObject **objects = data->objects;
GType type = data->type;
int i, n_objects;
unsigned int n_objects;
n_objects = data->n_objects;
for (i = 0; i < n_objects; i++)
for (unsigned int i = 0; i < n_objects; i++)
objects[i] = g_object_new (type, NULL);
}
@ -556,10 +556,10 @@ test_construction_run1 (PerformanceTest *test,
{
struct ConstructionTest *data = _data;
GObject **objects = data->objects;
int i, n_objects;
unsigned int n_objects;
n_objects = data->n_objects;
for (i = 0; i < n_objects; i++)
for (unsigned int i = 0; i < n_objects; i++)
objects[i] = (GObject *) g_slice_new0 (SimpleObject);
}
@ -570,10 +570,10 @@ test_complex_construction_run (PerformanceTest *test,
struct ConstructionTest *data = _data;
GObject **objects = data->objects;
GType type = data->type;
int i, n_objects;
unsigned int n_objects;
n_objects = data->n_objects;
for (i = 0; i < n_objects; i++)
for (unsigned int i = 0; i < n_objects; i++)
objects[i] = g_object_new (type, "val1", 5, "val2", "thousand", NULL);
}
@ -584,10 +584,10 @@ test_complex_construction_run1 (PerformanceTest *test,
struct ConstructionTest *data = _data;
GObject **objects = data->objects;
GType type = data->type;
int i, n_objects;
unsigned int n_objects;
n_objects = data->n_objects;
for (i = 0; i < n_objects; i++)
for (unsigned int i = 0; i < n_objects; i++)
{
ComplexObject *object;
object = (ComplexObject *)g_object_new (type, NULL);
@ -604,10 +604,10 @@ test_complex_construction_run2 (PerformanceTest *test,
struct ConstructionTest *data = _data;
GObject **objects = data->objects;
GType type = data->type;
int i, n_objects;
unsigned int n_objects;
n_objects = data->n_objects;
for (i = 0; i < n_objects; i++)
for (unsigned int i = 0; i < n_objects; i++)
{
objects[i] = g_object_new (type, NULL);
}
@ -618,9 +618,8 @@ test_construction_finish (PerformanceTest *test,
gpointer _data)
{
struct ConstructionTest *data = _data;
int i;
for (i = 0; i < data->n_objects; i++)
for (unsigned int i = 0; i < data->n_objects; i++)
g_object_unref (data->objects[i]);
}
@ -629,9 +628,8 @@ test_construction_finish1 (PerformanceTest *test,
gpointer _data)
{
struct ConstructionTest *data = _data;
int i;
for (i = 0; i < data->n_objects; i++)
for (unsigned int i = 0; i < data->n_objects; i++)
g_slice_free (SimpleObject, (SimpleObject *)data->objects[i]);
}
@ -650,16 +648,16 @@ test_finalization_init (PerformanceTest *test,
double count_factor)
{
struct ConstructionTest *data = _data;
int n;
unsigned int n;
n = NUM_OBJECT_TO_CONSTRUCT * count_factor;
n = (unsigned int) (NUM_OBJECT_TO_CONSTRUCT * count_factor);
if (data->n_objects != n)
{
data->n_objects = n;
data->objects = g_renew (GObject *, data->objects, n);
}
for (int i = 0; i < data->n_objects; i++)
for (unsigned int i = 0; i < data->n_objects; i++)
{
data->objects[i] = g_object_new (data->type, NULL);
}
@ -671,10 +669,10 @@ test_finalization_run (PerformanceTest *test,
{
struct ConstructionTest *data = _data;
GObject **objects = data->objects;
int i, n_objects;
unsigned int n_objects;
n_objects = data->n_objects;
for (i = 0; i < n_objects; i++)
for (unsigned int i = 0; i < n_objects; i++)
{
g_object_unref (objects[i]);
}
@ -716,7 +714,7 @@ test_finalization_print_result (PerformanceTest *test,
struct TypeCheckTest {
GObject *object;
int n_checks;
unsigned int n_checks;
};
static gpointer
@ -737,7 +735,7 @@ test_type_check_init (PerformanceTest *test,
{
struct TypeCheckTest *data = _data;
data->n_checks = factor * NUM_KILO_CHECKS_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_KILO_CHECKS_PER_ROUND);
}
@ -753,7 +751,6 @@ test_type_check_run (PerformanceTest *test,
struct TypeCheckTest *data = _data;
GObject *object = data->object;
GType type, types[5];
int i, j;
types[0] = test_iface1_get_type ();
types[1] = test_iface2_get_type ();
@ -761,10 +758,10 @@ test_type_check_run (PerformanceTest *test,
types[3] = test_iface4_get_type ();
types[4] = test_iface5_get_type ();
for (i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
{
type = types[i%5];
for (j = 0; j < 1000; j++)
for (unsigned int j = 0; j < 1000; j++)
{
my_type_check_instance_is_a ((GTypeInstance *)object,
type);
@ -806,8 +803,8 @@ test_type_check_teardown (PerformanceTest *test,
struct EmissionTest {
GObject *object;
int n_checks;
int signal_id;
unsigned int n_checks;
unsigned int signal_id;
};
static void
@ -816,9 +813,8 @@ test_emission_run (PerformanceTest *test,
{
struct EmissionTest *data = _data;
GObject *object = data->object;
int i;
for (i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
g_signal_emit (object, data->signal_id, 0);
}
@ -828,9 +824,8 @@ test_emission_run_args (PerformanceTest *test,
{
struct EmissionTest *data = _data;
GObject *object = data->object;
int i;
for (i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
g_signal_emit (object, data->signal_id, 0, 0, NULL);
}
@ -845,7 +840,7 @@ test_emission_unhandled_setup (PerformanceTest *test)
data = g_new0 (struct EmissionTest, 1);
data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL);
data->signal_id = complex_signals[GPOINTER_TO_INT (test->extra_data)];
data->signal_id = complex_signals[GPOINTER_TO_UINT (test->extra_data)];
return data;
}
@ -856,7 +851,7 @@ test_emission_unhandled_init (PerformanceTest *test,
{
struct EmissionTest *data = _data;
data->n_checks = factor * NUM_EMISSIONS_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_EMISSIONS_PER_ROUND);
}
static void
@ -902,7 +897,7 @@ test_emission_handled_setup (PerformanceTest *test)
data = g_new0 (struct EmissionTest, 1);
data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL);
data->signal_id = complex_signals[GPOINTER_TO_INT (test->extra_data)];
data->signal_id = complex_signals[GPOINTER_TO_UINT (test->extra_data)];
g_signal_connect (data->object, "signal",
G_CALLBACK (test_emission_handled_handler),
NULL);
@ -929,7 +924,7 @@ test_emission_handled_init (PerformanceTest *test,
{
struct EmissionTest *data = _data;
data->n_checks = factor * NUM_EMISSIONS_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_EMISSIONS_PER_ROUND);
}
static void
@ -967,7 +962,7 @@ test_emission_handled_teardown (PerformanceTest *test,
struct NotifyTest {
GObject *object;
unsigned n_checks;
unsigned int n_checks;
};
static void
@ -977,7 +972,7 @@ test_notify_run (PerformanceTest *test,
struct NotifyTest *data = _data;
GObject *object = data->object;
for (unsigned i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
g_object_notify (object, "val1");
}
@ -988,7 +983,7 @@ test_notify_by_pspec_run (PerformanceTest *test,
struct NotifyTest *data = _data;
GObject *object = data->object;
for (unsigned i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
g_object_notify_by_pspec (object, pspecs[PROP_VAL1]);
}
@ -1013,7 +1008,7 @@ test_notify_unhandled_init (PerformanceTest *test,
{
struct NotifyTest *data = _data;
data->n_checks = factor * NUM_NOTIFY_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_NOTIFY_PER_ROUND);
}
static void
@ -1075,7 +1070,7 @@ test_notify_handled_init (PerformanceTest *test,
{
struct NotifyTest *data = _data;
data->n_checks = factor * NUM_NOTIFY_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_NOTIFY_PER_ROUND);
}
static void
@ -1117,7 +1112,7 @@ test_notify_handled_teardown (PerformanceTest *test,
struct SetTest {
GObject *object;
unsigned n_checks;
unsigned int n_checks;
};
static void
@ -1127,7 +1122,7 @@ test_set_run (PerformanceTest *test,
struct SetTest *data = _data;
GObject *object = data->object;
for (unsigned i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
g_object_set (object, "val1", i, NULL);
}
@ -1155,7 +1150,7 @@ test_set_init (PerformanceTest *test,
{
struct SetTest *data = _data;
data->n_checks = factor * NUM_SET_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_SET_PER_ROUND);
}
static void
@ -1194,7 +1189,7 @@ test_set_teardown (PerformanceTest *test,
struct GetTest {
GObject *object;
unsigned n_checks;
unsigned int n_checks;
};
static void
@ -1205,7 +1200,7 @@ test_get_run (PerformanceTest *test,
GObject *object = data->object;
int val;
for (unsigned i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
g_object_get (object, "val1", &val, NULL);
}
@ -1233,7 +1228,7 @@ test_get_init (PerformanceTest *test,
{
struct GetTest *data = _data;
data->n_checks = factor * NUM_GET_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_GET_PER_ROUND);
}
static void
@ -1272,7 +1267,7 @@ test_get_teardown (PerformanceTest *test,
struct RefcountTest {
GObject *object;
int n_checks;
unsigned int n_checks;
gboolean is_toggle_ref;
};
@ -1308,7 +1303,7 @@ test_refcount_init (PerformanceTest *test,
{
struct RefcountTest *data = _data;
data->n_checks = factor * NUM_KILO_REFS_PER_ROUND;
data->n_checks = (unsigned int) (factor * NUM_KILO_REFS_PER_ROUND);
}
static void
@ -1317,9 +1312,8 @@ test_refcount_run (PerformanceTest *test,
{
struct RefcountTest *data = _data;
GObject *object = data->object;
int i;
for (i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
{
g_object_ref (object);
g_object_ref (object);
@ -1341,9 +1335,8 @@ test_refcount_1_run (PerformanceTest *test,
{
struct RefcountTest *data = _data;
GObject *object = data->object;
int i;
for (i = 0; i < data->n_checks; i++)
for (unsigned int i = 0; i < data->n_checks; i++)
{
g_object_ref (object);
g_object_unref (object);
@ -1457,7 +1450,7 @@ static PerformanceTest tests[] = {
},
{
"emit-unhandled",
GINT_TO_POINTER (COMPLEX_SIGNAL),
GUINT_TO_POINTER (COMPLEX_SIGNAL),
test_emission_unhandled_setup,
test_emission_unhandled_init,
test_emission_run,
@ -1467,7 +1460,7 @@ static PerformanceTest tests[] = {
},
{
"emit-unhandled-empty",
GINT_TO_POINTER (COMPLEX_SIGNAL_EMPTY),
GUINT_TO_POINTER (COMPLEX_SIGNAL_EMPTY),
test_emission_unhandled_setup,
test_emission_unhandled_init,
test_emission_run,
@ -1477,7 +1470,7 @@ static PerformanceTest tests[] = {
},
{
"emit-unhandled-generic",
GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC),
GUINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC),
test_emission_unhandled_setup,
test_emission_unhandled_init,
test_emission_run,
@ -1487,7 +1480,7 @@ static PerformanceTest tests[] = {
},
{
"emit-unhandled-generic-empty",
GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC_EMPTY),
GUINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC_EMPTY),
test_emission_unhandled_setup,
test_emission_unhandled_init,
test_emission_run,
@ -1497,7 +1490,7 @@ static PerformanceTest tests[] = {
},
{
"emit-unhandled-args",
GINT_TO_POINTER (COMPLEX_SIGNAL_ARGS),
GUINT_TO_POINTER (COMPLEX_SIGNAL_ARGS),
test_emission_unhandled_setup,
test_emission_unhandled_init,
test_emission_run_args,
@ -1507,7 +1500,7 @@ static PerformanceTest tests[] = {
},
{
"emit-handled",
GINT_TO_POINTER (COMPLEX_SIGNAL),
GUINT_TO_POINTER (COMPLEX_SIGNAL),
test_emission_handled_setup,
test_emission_handled_init,
test_emission_run,
@ -1517,7 +1510,7 @@ static PerformanceTest tests[] = {
},
{
"emit-handled-empty",
GINT_TO_POINTER (COMPLEX_SIGNAL_EMPTY),
GUINT_TO_POINTER (COMPLEX_SIGNAL_EMPTY),
test_emission_handled_setup,
test_emission_handled_init,
test_emission_run,
@ -1527,7 +1520,7 @@ static PerformanceTest tests[] = {
},
{
"emit-handled-generic",
GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC),
GUINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC),
test_emission_handled_setup,
test_emission_handled_init,
test_emission_run,
@ -1537,7 +1530,7 @@ static PerformanceTest tests[] = {
},
{
"emit-handled-generic-empty",
GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC_EMPTY),
GUINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC_EMPTY),
test_emission_handled_setup,
test_emission_handled_init,
test_emission_run,
@ -1547,7 +1540,7 @@ static PerformanceTest tests[] = {
},
{
"emit-handled-args",
GINT_TO_POINTER (COMPLEX_SIGNAL_ARGS),
GUINT_TO_POINTER (COMPLEX_SIGNAL_ARGS),
test_emission_handled_setup,
test_emission_handled_init,
test_emission_run_args,
@ -1650,8 +1643,7 @@ static PerformanceTest tests[] = {
static PerformanceTest *
find_test (const char *name)
{
gsize i;
for (i = 0; i < G_N_ELEMENTS (tests); i++)
for (size_t i = 0; i < G_N_ELEMENTS (tests); i++)
{
if (strcmp (tests[i].name, name) == 0)
return &tests[i];
@ -1666,7 +1658,6 @@ main (int argc,
GOptionContext *context;
GError *error = NULL;
const char *str;
int i;
if ((str = g_getenv ("GLIB_PERFORMANCE_FACTOR")) && str[0])
{
@ -1691,7 +1682,7 @@ main (int argc,
if (argc > 1)
{
for (i = 1; i < argc; i++)
for (int i = 1; i < argc; i++)
{
test = find_test (argv[i]);
if (test)
@ -1700,8 +1691,7 @@ main (int argc,
}
else
{
gsize k;
for (k = 0; k < G_N_ELEMENTS (tests); k++)
for (size_t k = 0; k < G_N_ELEMENTS (tests); k++)
run_test (&tests[k]);
}

View File

@ -551,6 +551,7 @@ endforeach
if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
warning_common_args = [
'-Wduplicated-branches',
'-Wfloat-conversion',
'-Wimplicit-fallthrough',
'-Wmisleading-indentation',
'-Wmissing-field-initializers',