SDL_GetSensors() follows the SDL_GetStringRule

This commit is contained in:
Sam Lantinga 2024-07-18 22:10:29 -07:00
parent 4f8c348402
commit 856d598d6e
6 changed files with 10 additions and 15 deletions

View file

@ -1564,7 +1564,7 @@ Rather than iterating over sensors using device index, there is a new function S
{ {
if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) { if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) {
int i, num_sensors; int i, num_sensors;
SDL_SensorID *sensors = SDL_GetSensors(&num_sensors); const SDL_SensorID *sensors = SDL_GetSensors(&num_sensors);
if (sensors) { if (sensors) {
for (i = 0; i < num_sensors; ++i) { for (i = 0; i < num_sensors; ++i) {
SDL_Log("Sensor %" SDL_PRIu32 ": %s, type %d, platform type %d\n", SDL_Log("Sensor %" SDL_PRIu32 ": %s, type %d, platform type %d\n",
@ -1573,7 +1573,6 @@ Rather than iterating over sensors using device index, there is a new function S
SDL_GetSensorTypeForID(sensors[i]), SDL_GetSensorTypeForID(sensors[i]),
SDL_GetSensorNonPortableTypeForID(sensors[i])); SDL_GetSensorNonPortableTypeForID(sensors[i]));
} }
SDL_free(sensors);
} }
SDL_QuitSubSystem(SDL_INIT_SENSOR); SDL_QuitSubSystem(SDL_INIT_SENSOR);
} }

View file

@ -146,14 +146,13 @@ typedef enum SDL_SensorType
/** /**
* Get a list of currently connected sensors. * Get a list of currently connected sensors.
* *
* \param count a pointer filled in with the number of sensors returned. * \param count a pointer filled in with the number of sensors returned, may be NULL.
* \returns a 0 terminated array of sensor instance IDs which should be freed * \returns a 0 terminated array of sensor instance IDs or NULL on failure; call SDL_GetError() for more
* with SDL_free(), or NULL on failure; call SDL_GetError() for more
* information. * information.
* *
* \since This function is available since SDL 3.0.0. * \since This function is available since SDL 3.0.0.
*/ */
extern SDL_DECLSPEC SDL_SensorID * SDLCALL SDL_GetSensors(int *count); extern SDL_DECLSPEC const SDL_SensorID * SDLCALL SDL_GetSensors(int *count);
/** /**
* Get the implementation dependent name of a sensor. * Get the implementation dependent name of a sensor.

View file

@ -470,7 +470,7 @@ SDL_DYNAPI_PROC(int,SDL_GetSensorNonPortableTypeForID,(SDL_SensorID a),(a),retur
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSensorProperties,(SDL_Sensor *a),(a),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSensorProperties,(SDL_Sensor *a),(a),return)
SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorType,(SDL_Sensor *a),(a),return) SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorType,(SDL_Sensor *a),(a),return)
SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorTypeForID,(SDL_SensorID a),(a),return) SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorTypeForID,(SDL_SensorID a),(a),return)
SDL_DYNAPI_PROC(SDL_SensorID*,SDL_GetSensors,(int *a),(a),return) SDL_DYNAPI_PROC(const SDL_SensorID*,SDL_GetSensors,(int *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetSilenceValueForFormat,(SDL_AudioFormat a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetSilenceValueForFormat,(SDL_AudioFormat a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetStorageFileSize,(SDL_Storage *a, const char *b, Uint64 *c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetStorageFileSize,(SDL_Storage *a, const char *b, Uint64 *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetStoragePathInfo,(SDL_Storage *a, const char *b, SDL_PathInfo *c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetStoragePathInfo,(SDL_Storage *a, const char *b, SDL_PathInfo *c),(a,b,c),return)

View file

@ -858,7 +858,7 @@ static SDL_bool IsROGAlly(SDL_Joystick *joystick)
SDL_bool has_ally_gyro = SDL_FALSE; SDL_bool has_ally_gyro = SDL_FALSE;
if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) { if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) {
SDL_SensorID *sensors = SDL_GetSensors(NULL); const SDL_SensorID *sensors = SDL_GetSensors(NULL);
if (sensors) { if (sensors) {
int i; int i;
for (i = 0; sensors[i]; ++i) { for (i = 0; sensors[i]; ++i) {
@ -877,7 +877,6 @@ static SDL_bool IsROGAlly(SDL_Joystick *joystick)
} }
} }
} }
SDL_free(sensors);
} }
SDL_QuitSubSystem(SDL_INIT_SENSOR); SDL_QuitSubSystem(SDL_INIT_SENSOR);
} }
@ -952,7 +951,7 @@ static SDL_bool ShouldAttemptSensorFusion(SDL_Joystick *joystick, SDL_bool *inve
static void AttemptSensorFusion(SDL_Joystick *joystick, SDL_bool invert_sensors) static void AttemptSensorFusion(SDL_Joystick *joystick, SDL_bool invert_sensors)
{ {
SDL_SensorID *sensors; const SDL_SensorID *sensors;
unsigned int i, j; unsigned int i, j;
SDL_AssertJoysticksLocked(); SDL_AssertJoysticksLocked();
@ -981,7 +980,6 @@ static void AttemptSensorFusion(SDL_Joystick *joystick, SDL_bool invert_sensors)
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f); SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f);
} }
} }
SDL_free(sensors);
} }
SDL_QuitSubSystem(SDL_INIT_SENSOR); SDL_QuitSubSystem(SDL_INIT_SENSOR);

View file

@ -170,7 +170,7 @@ SDL_bool SDL_SensorsOpened(void)
return opened; return opened;
} }
SDL_SensorID *SDL_GetSensors(int *count) const SDL_SensorID *SDL_GetSensors(int *count)
{ {
int i, num_sensors, device_index; int i, num_sensors, device_index;
int sensor_index = 0, total_sensors = 0; int sensor_index = 0, total_sensors = 0;
@ -207,7 +207,7 @@ SDL_SensorID *SDL_GetSensors(int *count)
} }
SDL_UnlockSensors(); SDL_UnlockSensors();
return sensors; return SDL_FreeLater(sensors);
} }
/* /*

View file

@ -58,7 +58,7 @@ static void HandleSensorEvent(SDL_SensorEvent *event)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
SDL_SensorID *sensors; const SDL_SensorID *sensors;
int i, num_sensors, num_opened; int i, num_sensors, num_opened;
SDLTest_CommonState *state; SDLTest_CommonState *state;
@ -104,7 +104,6 @@ int main(int argc, char **argv)
} }
} }
} }
SDL_free(sensors);
} }
SDL_Log("Opened %d sensors\n", num_opened); SDL_Log("Opened %d sensors\n", num_opened);