Skip to content

Commit b32c961

Browse files
committed
SDL_GetHaptics() follows the SDL_GetStringRule
1 parent 9de8cb8 commit b32c961

File tree

7 files changed

+12
-23
lines changed

7 files changed

+12
-23
lines changed

Diff for: docs/README-migration.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ Rather than iterating over haptic devices using device index, there is a new fun
695695
{
696696
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0) {
697697
int i, num_haptics;
698-
SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics);
698+
const SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics);
699699
if (haptics) {
700700
for (i = 0; i < num_haptics; ++i) {
701701
SDL_HapticID instance_id = haptics[i];
@@ -704,7 +704,6 @@ Rather than iterating over haptic devices using device index, there is a new fun
704704
SDL_Log("Haptic %" SDL_PRIu32 ": %s\n",
705705
instance_id, name ? name : "Unknown");
706706
}
707-
SDL_free(haptics);
708707
}
709708
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
710709
}

Diff for: include/SDL3/SDL_haptic.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
* SDL_HapticID *haptics = SDL_GetHaptics(NULL);
4646
* if (haptics) {
4747
* haptic = SDL_OpenHaptic(haptics[0]);
48-
* SDL_free(haptics);
4948
* }
5049
* if (haptic == NULL)
5150
* return -1;
@@ -932,17 +931,18 @@ typedef Uint32 SDL_HapticID;
932931
/**
933932
* Get a list of currently connected haptic devices.
934933
*
934+
* The returned array follows the SDL_GetStringRule, and will be automatically freed later.
935+
*
935936
* \param count a pointer filled in with the number of haptic devices
936-
* returned.
937-
* \returns a 0 terminated array of haptic device instance IDs which should be
938-
* freed with SDL_free(), or NULL on failure; call SDL_GetError() for
937+
* returned, may be NULL.
938+
* \returns a 0 terminated array of haptic device instance IDs or NULL on failure; call SDL_GetError() for
939939
* more information.
940940
*
941941
* \since This function is available since SDL 3.0.0.
942942
*
943943
* \sa SDL_OpenHaptic
944944
*/
945-
extern SDL_DECLSPEC SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);
945+
extern SDL_DECLSPEC const SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);
946946

947947
/**
948948
* Get the implementation dependent name of a haptic device.

Diff for: src/dynapi/SDL_dynapi_procs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ SDL_DYNAPI_PROC(SDL_Haptic*,SDL_GetHapticFromID,(SDL_HapticID a),(a),return)
327327
SDL_DYNAPI_PROC(SDL_HapticID,SDL_GetHapticID,(SDL_Haptic *a),(a),return)
328328
SDL_DYNAPI_PROC(const char*,SDL_GetHapticName,(SDL_Haptic *a),(a),return)
329329
SDL_DYNAPI_PROC(const char*,SDL_GetHapticNameForID,(SDL_HapticID a),(a),return)
330-
SDL_DYNAPI_PROC(SDL_HapticID*,SDL_GetHaptics,(int *a),(a),return)
330+
SDL_DYNAPI_PROC(const SDL_HapticID*,SDL_GetHaptics,(int *a),(a),return)
331331
SDL_DYNAPI_PROC(const char*,SDL_GetHint,(const char *a),(a),return)
332332
SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),return)
333333
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetIOProperties,(SDL_IOStream *a),(a),return)

Diff for: src/haptic/SDL_haptic.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static SDL_bool SDL_GetHapticIndex(SDL_HapticID instance_id, int *driver_index)
6363
return SDL_FALSE;
6464
}
6565

66-
SDL_HapticID *SDL_GetHaptics(int *count)
66+
const SDL_HapticID *SDL_GetHaptics(int *count)
6767
{
6868
int device_index;
6969
int haptic_index = 0, num_haptics = 0;
@@ -89,7 +89,7 @@ SDL_HapticID *SDL_GetHaptics(int *count)
8989
}
9090
}
9191

92-
return haptics;
92+
return SDL_FreeLater(haptics);
9393
}
9494

9595
const char *SDL_GetHapticNameForID(SDL_HapticID instance_id)

Diff for: test/testhaptic.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main(int argc, char **argv)
4040
int id[9];
4141
int nefx;
4242
unsigned int supported;
43-
SDL_HapticID *haptics;
43+
const SDL_HapticID *haptics;
4444
int num_haptics;
4545

4646
/* Initialize test framework */
@@ -91,7 +91,6 @@ int main(int argc, char **argv)
9191
if (haptics) {
9292
if (num_haptics == 0) {
9393
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
94-
SDL_free(haptics);
9594
return 1;
9695
}
9796

@@ -101,7 +100,6 @@ int main(int argc, char **argv)
101100

102101
if (i >= num_haptics) {
103102
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n");
104-
SDL_free(haptics);
105103
return 1;
106104
}
107105
}
@@ -115,20 +113,17 @@ int main(int argc, char **argv)
115113

116114
if (i >= num_haptics) {
117115
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name);
118-
SDL_free(haptics);
119116
return 1;
120117
}
121118
}
122119

123120
haptic = SDL_OpenHaptic(haptics[i]);
124121
if (!haptic) {
125122
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError());
126-
SDL_free(haptics);
127123
return 1;
128124
}
129125
SDL_Log("Device: %s\n", SDL_GetHapticName(haptic));
130126
HapticPrintSupported(haptic);
131-
SDL_free(haptics);
132127
}
133128

134129
/* We only want force feedback errors. */

Diff for: test/testhotplug.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int main(int argc, char *argv[])
9191

9292
if (enable_haptic) {
9393
int num_haptics;
94-
SDL_free(SDL_GetHaptics(&num_haptics));
94+
SDL_GetHaptics(&num_haptics);
9595
SDL_Log("There are %d haptic devices at startup\n", num_haptics);
9696
}
9797

Diff for: test/testrumble.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(int argc, char **argv)
3939
char *name = NULL;
4040
int index;
4141
SDLTest_CommonState *state;
42-
SDL_HapticID *haptics;
42+
const SDL_HapticID *haptics;
4343
int num_haptics;
4444

4545
/* Initialize test framework */
@@ -92,7 +92,6 @@ int main(int argc, char **argv)
9292
if (haptics) {
9393
if (num_haptics == 0) {
9494
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
95-
SDL_free(haptics);
9695
return 1;
9796
}
9897

@@ -102,7 +101,6 @@ int main(int argc, char **argv)
102101

103102
if (i >= num_haptics) {
104103
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n");
105-
SDL_free(haptics);
106104
return 1;
107105
}
108106
}
@@ -116,19 +114,16 @@ int main(int argc, char **argv)
116114

117115
if (i >= num_haptics) {
118116
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name);
119-
SDL_free(haptics);
120117
return 1;
121118
}
122119
}
123120

124121
haptic = SDL_OpenHaptic(haptics[i]);
125122
if (!haptic) {
126123
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError());
127-
SDL_free(haptics);
128124
return 1;
129125
}
130126
SDL_Log("Device: %s\n", SDL_GetHapticName(haptic));
131-
SDL_free(haptics);
132127
}
133128

134129
/* We only want force feedback errors. */

0 commit comments

Comments
 (0)