obsproject / obs-websocket

Remote-control of OBS Studio through WebSocket
GNU General Public License v2.0
3.86k stars 707 forks source link

lib: Fix compile errors on C and warnings on C++ #1194

Closed norihiro closed 8 months ago

norihiro commented 9 months ago

Description

Fix compile errors and warnings in lib/obs-websocket-api.h so that the file can be included from both C and C++ code.

Motivation and Context

Using C++ on GCC, there was warnings below. We need to add remaining initializers.

lib/obs-websocket-api.h:56:27: warning: missing initializer for member ‘calldata::size’ [-Wmissing-field-initializers]
   56 |         calldata_t cd = {0};
      |                           ^

Using C on Clang,

obs-websocket-api.h:47:1: error: 'inline' can only appear on functions inline proc_handler_t *_ph;
obs-websocket-api.h:107:15: error: must use 'struct' tag to refer to type 'obs_websocket_request_response'
static inline obs_websocket_request_response *obs_websocket_call_request(const char *request_type, obs_data_t *request_data = NULL)
              ^
              struct 
obs-websocket-api.h:107:125: error: C does not support default arguments
static inline obs_websocket_request_response *obs_websocket_call_request(const char *request_type, obs_data_t *request_data = NULL)
                                                                                                                            ^ ~~~~
obs-websocket-api.h:123:7: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
        auto ret = (struct obs_websocket_request_response *)calldata_ptr(&cd, "response");
        ~~~~ ^

Using C on VC++,

obs-websocket-api.h(173,46): error C2059: syntax error: '}' 

How Has This Been Tested?

Tested OS(s): Both C and C++ compilations are tested on Fedora 38, macOS 12, Windows 2022, Ubuntu 22.04.

Types of changes

Checklist:

tt2468 commented 8 months ago

I see the checklist hasn't been touched, is this ready to be merged?

norihiro commented 8 months ago

I'm sorry, I have forgot the checklist. Now all the items are checked. I used clang-format version 16.0.6 to check the code format. I hope this should be fine.