Skip to content

Commit

Permalink
Replace usage of EM_BOOL with C/C++ bool type. NFC
Browse files Browse the repository at this point in the history
These macros were already updated to expand to the C/C++ `bool` type
back in #22157.  This is the natural NFC followup to that change.
  • Loading branch information
sbc100 committed Sep 3, 2024
1 parent 4036606 commit da70c4b
Show file tree
Hide file tree
Showing 76 changed files with 466 additions and 462 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ See docs/process.md for more on how version tagging works.
added to `console.h`. The former simply maps directly to `console.trace`.
The latter uses `dbg()` so it writes directly to stderr under node (better for
multi-threaded apps).
- The usage of `EM_BOOL` in the emscripten API has been repalced with C/C++
bool. This change should not be observable since `EM_BOOL` has been
equivilent to `bool` since #22157. (#22155)

3.1.65 - 08/22/24
-----------------
Expand Down
282 changes: 133 additions & 149 deletions site/source/docs/api_reference/html5.h.rst

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions site/source/docs/api_reference/wasm_audio_worklets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ own noise generator AudioWorkletProcessor node type:

.. code-block:: cpp
void AudioThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData)
void AudioThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, bool success, void *userData)
{
if (!success) return; // Check browser console in a debug build for detailed errors
WebAudioWorkletProcessorCreateOptions opts = {
Expand All @@ -110,7 +110,7 @@ which resumes the audio context when the user clicks on the DOM Canvas element t

.. code-block:: cpp
void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData)
void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, bool success, void *userData)
{
if (!success) return; // Check browser console in a debug build for detailed errors
Expand All @@ -137,13 +137,13 @@ which resumes the audio context when the user clicks on the DOM Canvas element t

.. code-block:: cpp
EM_BOOL OnCanvasClick(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
bool OnCanvasClick(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
{
EMSCRIPTEN_WEBAUDIO_T audioContext = (EMSCRIPTEN_WEBAUDIO_T)userData;
if (emscripten_audio_context_state(audioContext) != AUDIO_CONTEXT_STATE_RUNNING) {
emscripten_resume_audio_context_sync(audioContext);
}
return EM_FALSE;
return false;
}
5. Finally we can implement the audio callback that is to generate the noise:
Expand All @@ -152,7 +152,7 @@ which resumes the audio context when the user clicks on the DOM Canvas element t
#include <emscripten/em_math.h>
EM_BOOL GenerateNoise(int numInputs, const AudioSampleFrame *inputs,
bool GenerateNoise(int numInputs, const AudioSampleFrame *inputs,
int numOutputs, AudioSampleFrame *outputs,
int numParams, const AudioParamFrame *params,
void *userData)
Expand All @@ -161,7 +161,7 @@ which resumes the audio context when the user clicks on the DOM Canvas element t
for(int j = 0; j < 128*outputs[i].numberOfChannels; ++j)
outputs[i].data[j] = emscripten_random() * 0.2 - 0.1; // Warning: scale down audio volume by factor of 0.2, raw noise can be really loud otherwise
return EM_TRUE; // Keep the graph output going
return true; // Keep the graph output going
}
And that's it! Compile the code with the linker flags ``-sAUDIO_WORKLET=1 -sWASM_WORKERS=1`` to enable targeting AudioWorklets.
Expand Down
4 changes: 2 additions & 2 deletions site/source/docs/porting/emscripten-runtime-environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ Typically you will have a small section with ``#ifdef __EMSCRIPTEN__`` for the t
// Our "main loop" function. This callback receives the current time as
// reported by the browser, and the user data we provide in the call to
// emscripten_request_animation_frame_loop().
EM_BOOL one_iter(double time, void* userData) {
bool one_iter(double time, void* userData) {
// Can render to the screen here, etc.
puts("one iteration");
// Return true to keep the loop running.
return EM_TRUE;
return true;
}
int main() {
Expand Down
8 changes: 6 additions & 2 deletions system/include/emscripten/em_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* found in the LICENSE file.
*/

#include <stdbool.h>

#pragma once

#include <stdbool.h>
Expand All @@ -31,9 +33,11 @@ typedef void (*em_callback_func)(void);
typedef void (*em_arg_callback_func)(void*);
typedef void (*em_str_callback_func)(const char *);

/* Legacy EM_BOOL type. Emscripten no longer uses this */
#define EM_BOOL bool
#define EM_TRUE 1
#define EM_FALSE 0
#define EM_TRUE true
#define EM_FALSE false

#define EM_UTF8 char

#define EMSCRIPTEN_RESULT int
Expand Down
6 changes: 3 additions & 3 deletions system/include/emscripten/eventloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ void emscripten_unwind_to_js_event_loop(void) __attribute__((__noreturn__));

int emscripten_set_timeout(void (*cb)(void *user_data) __attribute__((nonnull)), double msecs, void *user_data);
void emscripten_clear_timeout(int id);
void emscripten_set_timeout_loop(EM_BOOL (*cb)(double time, void *user_data) __attribute__((nonnull)), double interval_ms, void *user_data);
void emscripten_set_timeout_loop(bool (*cb)(double time, void *user_data) __attribute__((nonnull)), double interval_ms, void *user_data);

int emscripten_set_immediate(void (*cb)(void *user_data) __attribute__((nonnull)), void *user_data);
void emscripten_clear_immediate(int id);
void emscripten_set_immediate_loop(EM_BOOL (*cb)(void *user_data), void *user_data);
void emscripten_set_immediate_loop(bool (*cb)(void *user_data), void *user_data);

int emscripten_set_interval(void (*cb)(void *user_data) __attribute__((nonnull)), double interval_ms, void *user_data);
void emscripten_clear_interval(int id);

void emscripten_runtime_keepalive_push(void);
void emscripten_runtime_keepalive_pop(void);
EM_BOOL emscripten_runtime_keepalive_check(void);
bool emscripten_runtime_keepalive_check(void);

#ifdef __cplusplus
}
Expand Down
5 changes: 3 additions & 2 deletions system/include/emscripten/fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#pragma once

#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <emscripten/html5.h>
#include <emscripten/em_types.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -88,7 +89,7 @@ typedef struct emscripten_fetch_attr_t {

// Indicates whether cross-site access control requests should be made using
// credentials.
EM_BOOL withCredentials;
bool withCredentials;

// Specifies the destination path in IndexedDB where to store the downloaded
// content body. If this is empty, the transfer is not stored to IndexedDB at
Expand Down
Loading

0 comments on commit da70c4b

Please sign in to comment.