Skip to content

Commit

Permalink
Updated documentation for functions that return temporary memory
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 19, 2024
1 parent 8aa9d63 commit 211387e
Show file tree
Hide file tree
Showing 24 changed files with 84 additions and 145 deletions.
59 changes: 0 additions & 59 deletions docs/README-strings.md

This file was deleted.

16 changes: 8 additions & 8 deletions include/SDL3/SDL_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
* "coreaudio" or "wasapi". These never have Unicode characters, and are not
* meant to be proper names.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param index the index of the audio driver; the value ranges from 0 to
* SDL_GetNumAudioDrivers() - 1.
Expand All @@ -423,7 +423,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);
* "coreaudio" or "wasapi". These never have Unicode characters, and are not
* meant to be proper names.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \returns the name of the current audio driver or NULL if no driver has been
* initialized.
Expand All @@ -448,7 +448,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void);
* If this function returns NULL, to signify an error, `*count` will be set to
* zero.
*
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param count a pointer filled in with the number of devices returned, may be NULL.
* \returns a 0 terminated array of device instance IDs or NULL on error; call SDL_GetError() for more
Expand Down Expand Up @@ -477,7 +477,7 @@ extern SDL_DECLSPEC const SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackDevice
* If this function returns NULL, to signify an error, `*count` will be set to
* zero.
*
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param count a pointer filled in with the number of devices returned, may be NULL.
* \returns a 0 terminated array of device instance IDs, or NULL on failure; call SDL_GetError() for more
Expand All @@ -495,7 +495,7 @@ extern SDL_DECLSPEC const SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevic
/**
* Get the human-readable name of a specific audio device.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param devid the instance ID of the device to query.
* \returns the name of the audio device, or NULL on failure; call
Expand Down Expand Up @@ -555,7 +555,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid
* Audio devices usually have no remapping applied. This is represented by
* returning NULL, and does not signify an error.
*
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param devid the instance ID of the device to query.
* \param count On output, set to number of channels in the map. Can be NULL.
Expand Down Expand Up @@ -1105,7 +1105,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream,
* Audio streams default to no remapping applied. This is represented by
* returning NULL, and does not signify an error.
*
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param stream the SDL_AudioStream to query.
* \param count On output, set to number of channels in the map. Can be NULL.
Expand All @@ -1130,7 +1130,7 @@ extern SDL_DECLSPEC const int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_Au
* Audio streams default to no remapping applied. This is represented by
* returning NULL, and does not signify an error.
*
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param stream the SDL_AudioStream to query.
* \param count On output, set to number of channels in the map. Can be NULL.
Expand Down
10 changes: 5 additions & 5 deletions include/SDL3/SDL_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumCameraDrivers(void);
* "coremedia" or "android". These never have Unicode characters, and are not
* meant to be proper names.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param index the index of the camera driver; the value ranges from 0 to
* SDL_GetNumCameraDrivers() - 1.
Expand All @@ -156,7 +156,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDriver(int index);
* "coremedia" or "android". These never have Unicode characters, and are not
* meant to be proper names.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \returns the name of the current camera driver or NULL if no driver has
* been initialized.
Expand All @@ -170,7 +170,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentCameraDriver(void);
/**
* Get a list of currently connected camera devices.
*
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param count a pointer filled in with the number of cameras returned, may be
* NULL.
Expand Down Expand Up @@ -207,7 +207,7 @@ extern SDL_DECLSPEC const SDL_CameraID * SDLCALL SDL_GetCameras(int *count);
* _is_ a camera until the user has given you permission to check through a
* scary warning popup.
*
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param devid the camera device instance ID to query.
* \param count a pointer filled in with the number of elements in the list, may be NULL.
Expand All @@ -226,7 +226,7 @@ extern SDL_DECLSPEC const SDL_CameraSpec * const * SDLCALL SDL_GetCameraSupporte
/**
* Get the human-readable device name for a camera.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param instance_id the camera device instance ID.
* \returns a human-readable device name or NULL on failure; call
Expand Down
4 changes: 2 additions & 2 deletions include/SDL3/SDL_clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
* This functions returns empty string if there was not enough memory left for
* a copy of the clipboard's content.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \returns the clipboard text on success or an empty string on failure; call
* SDL_GetError() for more information.
Expand Down Expand Up @@ -106,7 +106,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPrimarySelectionText(const char *text);
* This functions returns empty string if there was not enough memory left for
* a copy of the primary selection's content.
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \returns the primary selection text on success or an empty string on
* failure; call SDL_GetError() for more information.
Expand Down
6 changes: 2 additions & 4 deletions include/SDL3/SDL_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_OutOfMemory(void);
* Error strings are set per-thread, so an error set in a different thread
* will not interfere with the current thread's operation.
*
* The returned string does **NOT** follow the SDL_GetStringRule! The pointer
* is valid until the current thread's error string is changed, so the caller
* should make a copy if the string is to be used after calling into SDL
* again.
* The returned value is a thread-local string which will remain valid until the current thread's error string is changed. The caller
* should make a copy if the value is needed after the next SDL API call.
*
* \returns a message with information about the specific error that occurred,
* or an empty string if there hasn't been an error message set since
Expand Down
16 changes: 8 additions & 8 deletions include/SDL3/SDL_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ typedef struct SDL_KeyboardEvent
* will be inserted into the editing text. The length is the number of UTF-8
* characters that will be replaced by new typing.
*
* The text string follows the SDL_GetStringRule, and will be automatically freed later.
* The text string is temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \since This struct is available since SDL 3.0.0.
*/
Expand All @@ -368,7 +368,7 @@ typedef struct SDL_TextEditingEvent
/**
* Keyboard IME candidates event structure (event.edit_candidates.*)
*
* The candidates follow the SDL_GetStringRule, and will be automatically freed later.
* The candidates are temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \since This struct is available since SDL 3.0.0.
*/
Expand All @@ -387,7 +387,7 @@ typedef struct SDL_TextEditingCandidatesEvent
/**
* Keyboard text input event structure (event.text.*)
*
* The text string follows the SDL_GetStringRule, and will be automatically freed later.
* The text string is temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* This event will never be delivered unless text input is enabled by calling
* SDL_StartTextInput(). Text input is disabled by default!
Expand Down Expand Up @@ -784,7 +784,7 @@ typedef struct SDL_PenButtonEvent
* An event used to drop text or request a file open by the system
* (event.drop.*)
*
* The source and data strings follow the SDL_GetStringRule, and will be automatically freed later.
* The source and data strings are temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \since This struct is available since SDL 3.0.0.
*/
Expand Down Expand Up @@ -1425,7 +1425,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
extern SDL_DECLSPEC void * SDLCALL SDL_AllocateTemporaryMemory(size_t size);

/**
* Claim ownership of temporary memory allocated by SDL.
* Claim ownership of temporary memory.
*
* This function changes ownership of temporary memory allocated for events and APIs that
* return temporary memory. If this function succeeds, the memory will no longer be automatically freed by SDL, it must be freed using SDL_free() by the application.
Expand All @@ -1445,10 +1445,10 @@ extern SDL_DECLSPEC void * SDLCALL SDL_AllocateTemporaryMemory(size_t size);
extern SDL_DECLSPEC void * SDLCALL SDL_ClaimTemporaryMemory(const void *mem);

/**
* Free temporary memory allocated by SDL.
* Free temporary memory.
*
* This function frees temporary memory allocated for events and APIs that
* follow the SDL_GetStringRule. This memory is local to the thread that creates
* This function frees temporary memory allocated for events and functions that
* return temporary memory. This memory is local to the thread that creates
* it and is automatically freed for the main thread when processing events.
* For other threads you may call this function periodically to
* free any temporary memory created by that thread.
Expand Down
8 changes: 4 additions & 4 deletions include/SDL3/SDL_filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern "C" {
* The returned path is guaranteed to end with a path separator ('\\' on
* Windows, '/' on most other platforms).
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \returns an absolute path in UTF-8 encoding to the application data
* directory. NULL will be returned on error or when the platform
Expand Down Expand Up @@ -123,7 +123,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetBasePath(void);
* The returned path is guaranteed to end with a path separator ('\\' on
* Windows, '/' on most other platforms).
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param org the name of your organization.
* \param app the name of your application.
Expand Down Expand Up @@ -223,7 +223,7 @@ typedef enum SDL_Folder
* The returned path is guaranteed to end with a path separator ('\\' on
* Windows, '/' on most other platforms).
*
* The returned string follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* If NULL is returned, the error may be obtained with SDL_GetError().
*
Expand Down Expand Up @@ -354,7 +354,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *
* convenience, but if `count` is non-NULL, on return it will contain the
* number of items in the array, not counting the NULL terminator.
*
* The returned pointer follows the SDL_GetStringRule, and will be automatically freed later.
* This returns temporary memory which will be automatically freed later, and can be claimed with SDL_ClaimTemporaryMemory().
*
* \param path the path of the directory to enumerate.
* \param pattern the pattern that files in the directory must match. Can be
Expand Down
Loading

0 comments on commit 211387e

Please sign in to comment.