Skip to content

Commit 12300bb

Browse files
authored
build: fix build on NetBSD (#4857)
1 parent 79e7e39 commit 12300bb

10 files changed

Lines changed: 40 additions & 17 deletions

File tree

src/include/OpenImageIO/strutil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#pragma once
1616

1717
#include <cstdio>
18+
#include <cstdarg>
1819
#include <map>
1920
#include <sstream>
2021
#include <string>

src/include/OpenImageIO/typedesc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ template<> struct BaseTypeFromC<uint64_t> { static constexpr TypeDesc::BASETYPE
409409
template<> struct BaseTypeFromC<const uint64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::UINT64; };
410410
template<> struct BaseTypeFromC<int64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::INT64; };
411411
template<> struct BaseTypeFromC<const int64_t> { static constexpr TypeDesc::BASETYPE value = TypeDesc::INT64; };
412-
#if defined(__GNUC__) && __WORDSIZE == 64 && !(defined(__APPLE__) && defined(__MACH__))
412+
#if defined(__GNUC__) && __WORDSIZE == 64 && !(defined(__APPLE__) && defined(__MACH__)) || defined(__NetBSD__)
413413
// Some platforms consider int64_t and long long to be different types, even
414414
// though they are actually the same size.
415415
static_assert(!std::is_same_v<unsigned long long, uint64_t>);

src/libOpenImageIO/imagebufalgo_compare.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ ImageBufAlgo::PixelStats::operator=(PixelStats&& other)
8080
inline void
8181
val(ImageBufAlgo::PixelStats& p, int c, float value)
8282
{
83-
if (isnan(value)) {
83+
if (std::isnan(value)) {
8484
++p.nancount[c];
8585
return;
8686
}
87-
if (isinf(value)) {
87+
if (std::isinf(value)) {
8888
++p.infcount[c];
8989
return;
9090
}
@@ -217,10 +217,11 @@ compare_value(ImageBuf::ConstIterator<BUFT, float>& a, int chan, VALT aval,
217217
bool& warned, float failthresh, float warnthresh,
218218
float failrelative, float warnrelative)
219219
{
220-
if (!isfinite(aval) || !isfinite(bval)) {
221-
if (isnan(aval) == isnan(bval) && isinf(aval) == isinf(bval))
220+
if (!std::isfinite(aval) || !std::isfinite(bval)) {
221+
if (std::isnan(aval) == std::isnan(bval)
222+
&& std::isinf(aval) == std::isinf(bval))
222223
return; // NaN may match NaN, Inf may match Inf
223-
if (isfinite(result.maxerror)) {
224+
if (std::isfinite(result.maxerror)) {
224225
// non-finite errors trump finite ones
225226
result.maxerror = std::numeric_limits<float>::infinity();
226227
result.maxx = a.x();

src/libOpenImageIO/maketexture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ check_nan_block(const ImageBuf& src, ROI roi, int& found_nonfinite)
347347
for (int x = x0; x < x1; ++x) {
348348
src.getpixel(x, y, pel);
349349
for (int c = 0; c < spec.nchannels; ++c) {
350-
if (!isfinite(pel[c])) {
350+
if (!std::isfinite(pel[c])) {
351351
spin_lock lock(maketx_mutex);
352352
// if (found_nonfinite < 3)
353353
// std::cerr << "maketx ERROR: Found " << pel[c]

src/libOpenImageIO/printinfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ stats_num(float val, int maxval, bool round)
7878
// Ensure uniform printing of NaN and Inf on all platforms
7979
using Strutil::fmt::format;
8080
std::string result;
81-
if (isnan(val))
81+
if (std::isnan(val))
8282
result = "nan";
83-
else if (isinf(val))
83+
else if (std::isinf(val))
8484
result = "inf";
8585
else if (maxval == 0) {
8686
result = format("{:f}", val);
@@ -245,7 +245,7 @@ print_deep_stats(std::ostream& out, string_view indent, const ImageBuf& input,
245245
for (unsigned int s = 0; s < samples; ++s) {
246246
for (int c = 0; c < nchannels; ++c) {
247247
float d = input.deep_value(x, y, z, c, s);
248-
if (!isfinite(d)) {
248+
if (!std::isfinite(d)) {
249249
if (nonfinites++ == 0) {
250250
nonfinite_pixel.setValue(x, y, z);
251251
nonfinite_pixel_samp = s;

src/libtexture/environment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ vector_to_latlong(const Imath::V3f& R, bool y_is_up, float& s, float& t)
268268
t = 0.5f - atan2f(R.z, hypotf(R.x, R.y)) / (float)M_PI;
269269
}
270270
// learned from experience, beware NaNs
271-
if (isnan(s))
271+
if (std::isnan(s))
272272
s = 0.0f;
273-
if (isnan(t))
273+
if (std::isnan(t))
274274
t = 0.0f;
275275
}
276276

src/libutil/fmath_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ test_half_convert_accuracy()
550550
&& Imath::finitef(H[i])) {
551551
++nwrong;
552552
Strutil::print("wrong {} 0b{} h={}, f={} {}\n", i, bin16(i), H[i],
553-
F[i], isnan(f) ? "(nan)" : "");
553+
F[i], std::isnan(f) ? "(nan)" : "");
554554
}
555555
}
556556

src/libutil/strutil.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static std::mutex output_mutex;
6767
// On systems that support it, get a location independent locale.
6868
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) \
6969
|| defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
70-
|| defined(__GLIBC__)
70+
|| defined(__GLIBC__) || defined(__NetBSD__)
7171
static locale_t c_loc = newlocale(LC_ALL_MASK, "C", nullptr);
7272
#elif defined(_WIN32)
7373
static _locale_t c_loc = _create_locale(LC_ALL, "C");
@@ -526,6 +526,14 @@ strcasecmp(const char* a, const char* b)
526526
return strcasecmp_l(a, b, c_loc);
527527
#elif defined(_WIN32)
528528
return _stricmp_l(a, b, c_loc);
529+
#elif defined(__NetBSD__)
530+
const unsigned char *us1 = (const unsigned char*)a,
531+
*us2 = (const unsigned char*)b;
532+
533+
while (tolower_l(*us1, c_loc) == tolower_l(*us2++, c_loc))
534+
if (*us1++ == '\0')
535+
return (0);
536+
return (tolower_l(*us1, c_loc) - tolower_l(*--us2, c_loc));
529537
#else
530538
# error("need equivalent of strcasecmp_l on this platform");
531539
#endif
@@ -541,6 +549,19 @@ strncasecmp(const char* a, const char* b, size_t size)
541549
return strncasecmp_l(a, b, size, c_loc);
542550
#elif defined(_WIN32)
543551
return _strnicmp_l(a, b, size, c_loc);
552+
#elif defined(__NetBSD__)
553+
if (size != 0) {
554+
const unsigned char *us1 = (const unsigned char*)a,
555+
*us2 = (const unsigned char*)b;
556+
557+
do {
558+
if (tolower_l(*us1, c_loc) != tolower_l(*us2++, c_loc))
559+
return (tolower_l(*us1, c_loc) - tolower_l(*--us2, c_loc));
560+
if (*us1++ == '\0')
561+
break;
562+
} while (--size != 0);
563+
}
564+
return (0);
544565
#else
545566
# error("need equivalent of strncasecmp_l on this platform");
546567
#endif

src/oiiotool/printinfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ print_nums(std::ostream& out, int n, const T* val, string_view sep = " ",
5858
if (i)
5959
Strutil::print(out, "{}", sep);
6060
float v = float(val[i]);
61-
if (isnan(v))
61+
if (std::isnan(v))
6262
Strutil::print(out, "nan");
63-
else if (isinf(v))
63+
else if (std::isinf(v))
6464
Strutil::print(out, "inf");
6565
else
6666
Strutil::print(out, "{:.9f}", v);

src/testtex/testtex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ do_tex_thread_workout(int iterations, int mythread)
15571557
}
15581558
// Force the compiler to not optimize away the "other work"
15591559
for (int c = 0; c < nchannels; ++c)
1560-
OIIO_ASSERT(!isnan(result[c]));
1560+
OIIO_ASSERT(!std::isnan(result[c]));
15611561
}
15621562

15631563

0 commit comments

Comments
 (0)