Skip to content

Commit 2aa5a16

Browse files
c: fix compilation, use C-style initializer list cast in a C program
1 parent 4844bb6 commit 2aa5a16

File tree

7 files changed

+10
-8
lines changed

7 files changed

+10
-8
lines changed

lang/c/include/sourceppc/API.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#ifdef __cplusplus
1212
#define SOURCEPP_API extern "C" SOURCEPP_EXPORT
13+
#define SOURCEPP_CAST_CTOR(name) name
1314
#include <cstddef>
1415
#include <cstdint>
1516
using std::size_t;
@@ -23,6 +24,7 @@
2324
using std::uint64_t;
2425
#else
2526
#define SOURCEPP_API SOURCEPP_EXPORT
27+
#define SOURCEPP_CAST_CTOR(name) (name)
2628
#include <stddef.h>
2729
#include <stdint.h>
2830
#endif

lang/c/include/sourceppc/Buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ typedef struct {
1111
void* data;
1212
} sourcepp_buffer_t;
1313

14-
#define SOURCEPP_BUFFER_INVALID (sourcepp_buffer_t{.size = -1, .data = NULL})
14+
#define SOURCEPP_BUFFER_INVALID (SOURCEPP_CAST_CTOR(sourcepp_buffer_t) {.size = -1, .data = NULL})
1515

1616
// Aliases
1717
typedef sourcepp_buffer_t sourcepp_buffer_uint32_t;

lang/c/include/sourceppc/String.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ typedef struct {
1111
uint8_t* data;
1212
} sourcepp_string_t;
1313

14-
#define SOURCEPP_STRING_INVALID (sourcepp_string_t{.size = -1, .data = NULL})
14+
#define SOURCEPP_STRING_INVALID (SOURCEPP_CAST_CTOR(sourcepp_string_t) {.size = -1, .data = NULL})
1515

1616
typedef struct {
1717
int64_t size;
1818
char** data;
1919
} sourcepp_string_array_t;
2020

21-
#define SOURCEPP_STRING_ARRAY_INVALID (sourcepp_string_array_t{.size = -1, .data = NULL})
21+
#define SOURCEPP_STRING_ARRAY_INVALID (SOURCEPP_CAST_CTOR(sourcepp_string_array_t) {.size = -1, .data = NULL})
2222

2323
#ifdef __cplusplus
2424
} // extern "C"

lang/c/include/vtfppc/ImageConversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ SOURCEPP_API void vtfpp_image_conversion_set_resized_dims(uint16_t* width, vtfpp
7777
SOURCEPP_API sourcepp_buffer_t vtfpp_image_conversion_resize_image_data(const unsigned char* buffer, size_t bufferLen, vtfpp_image_format_e format, uint16_t width, uint16_t newWidth, uint16_t height, uint16_t newHeight, int srgb, vtfpp_image_conversion_resize_filter_e filter, vtfpp_image_conversion_resize_edge_e edge);
7878

7979
// REQUIRES MANUAL FREE: sourcepp_buffer_free
80-
SOURCEPP_API sourcepp_buffer_t vtfpp_image_conversion_resize_image_data_strict(const unsigned char* buffer, size_t bufferLen, vtfpp_image_format_e format, uint16_t width, uint16_t newWidth, uint16_t* widthOut, vtfpp_image_conversion_resize_method_e widthResize, uint16_t height, uint16_t newHeight, uint16_t* heightOut, vtfpp_image_conversion_resize_method_e heightResize, bool srgb, vtfpp_image_conversion_resize_filter_e filter, vtfpp_image_conversion_resize_edge_e edge);
80+
SOURCEPP_API sourcepp_buffer_t vtfpp_image_conversion_resize_image_data_strict(const unsigned char* buffer, size_t bufferLen, vtfpp_image_format_e format, uint16_t width, uint16_t newWidth, uint16_t* widthOut, vtfpp_image_conversion_resize_method_e widthResize, uint16_t height, uint16_t newHeight, uint16_t* heightOut, vtfpp_image_conversion_resize_method_e heightResize, int srgb, vtfpp_image_conversion_resize_filter_e filter, vtfpp_image_conversion_resize_edge_e edge);
8181

8282
// REQUIRES MANUAL FREE: sourcepp_buffer_free
8383
SOURCEPP_API sourcepp_buffer_t vtfpp_image_conversion_crop_image_data(const unsigned char* buffer, size_t bufferLen, vtfpp_image_format_e format, uint16_t width, uint16_t newWidth, uint16_t xOffset, uint16_t height, uint16_t newHeight, uint16_t yOffset);

lang/c/include/vtfppc/SHT.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typedef struct {
1919
vtfpp_sht_frame_bounds_t bounds[4];
2020
} vtfpp_sht_frame_t;
2121

22-
#define VTFPP_SHT_FRAME_INVALID (vtfpp_sht_frame_t{.duration = 0.f})
22+
#define VTFPP_SHT_FRAME_INVALID (SOURCEPP_CAST_CTOR(vtfpp_sht_frame_t) {.duration = 0.f})
2323

2424
typedef struct {
2525
uint32_t id;
@@ -28,7 +28,7 @@ typedef struct {
2828
float durationTotal;
2929
} vtfpp_sht_sequence_t;
3030

31-
#define VTFPP_SHT_SEQUENCE_INVALID (vtfpp_sht_sequence_t{.id = 0, .loop = 0, .frameCount = 0, .durationTotal = 0.f})
31+
#define VTFPP_SHT_SEQUENCE_INVALID (SOURCEPP_CAST_CTOR(vtfpp_sht_sequence_t) {.id = 0, .loop = 0, .frameCount = 0, .durationTotal = 0.f})
3232

3333
typedef void* vtfpp_sht_handle_t;
3434

lang/c/include/vtfppc/VTF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef struct {
112112
float bumpMapScale;
113113
} vtfpp_vtf_creation_options_t;
114114

115-
#define VTFPP_VTF_CREATION_OPTIONS_DEFAULT (vtfpp_vtf_creation_options_t{ \
115+
#define VTFPP_VTF_CREATION_OPTIONS_DEFAULT (SOURCEPP_CAST_CTOR(vtfpp_vtf_creation_options_t) { \
116116
.majorVersion = 7, \
117117
.minorVersion = 4, \
118118
.outputFormat = VTFPP_VTF_FORMAT_DEFAULT, \

lang/c/src/vtfppc/ImageConversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ SOURCEPP_API sourcepp_buffer_t vtfpp_image_conversion_resize_image_data(const un
111111
return Convert::toBuffer(ImageConversion::resizeImageData({reinterpret_cast<const std::byte*>(buffer), bufferLen}, static_cast<ImageFormat>(format), width, newWidth, height, newHeight, srgb, static_cast<ImageConversion::ResizeFilter>(filter), static_cast<ImageConversion::ResizeEdge>(edge)));
112112
}
113113

114-
SOURCEPP_API sourcepp_buffer_t vtfpp_image_conversion_resize_image_data_strict(const unsigned char* buffer, size_t bufferLen, vtfpp_image_format_e format, uint16_t width, uint16_t newWidth, uint16_t* widthOut, vtfpp_image_conversion_resize_method_e widthResize, uint16_t height, uint16_t newHeight, uint16_t* heightOut, vtfpp_image_conversion_resize_method_e heightResize, bool srgb, vtfpp_image_conversion_resize_filter_e filter, vtfpp_image_conversion_resize_edge_e edge) {
114+
SOURCEPP_API sourcepp_buffer_t vtfpp_image_conversion_resize_image_data_strict(const unsigned char* buffer, size_t bufferLen, vtfpp_image_format_e format, uint16_t width, uint16_t newWidth, uint16_t* widthOut, vtfpp_image_conversion_resize_method_e widthResize, uint16_t height, uint16_t newHeight, uint16_t* heightOut, vtfpp_image_conversion_resize_method_e heightResize, int srgb, vtfpp_image_conversion_resize_filter_e filter, vtfpp_image_conversion_resize_edge_e edge) {
115115
SOURCEPP_EARLY_RETURN_VAL(buffer, SOURCEPP_BUFFER_INVALID);
116116
SOURCEPP_EARLY_RETURN_VAL(bufferLen, SOURCEPP_BUFFER_INVALID);
117117
SOURCEPP_EARLY_RETURN_VAL(format != VTFPP_IMAGE_FORMAT_EMPTY, SOURCEPP_BUFFER_INVALID);

0 commit comments

Comments
 (0)