Introduce formal policy for APIs that return strings.
This declares that any `const char *` returned from SDL is owned by SDL, and promises to be valid _at least_ until the next time the event queue runs, or SDL_Quit() is called, even if the thing that owns the string gets destroyed or changed before then. This is noted in the headers as "the SDL_GetStringRule", so this will both be greppable to find a detailed explaination in docs/README-strings.md and wikiheaders will automatically turn it into a link we can point at the appropriate documentation. Fixes #9902. (and several FIXMEs, both known and yet-undocumented.)
This commit is contained in:
parent
b1f3682216
commit
e23257307e
51 changed files with 262 additions and 123 deletions
|
@ -785,8 +785,7 @@ const char *SDL_GetJoystickInstanceName(SDL_JoystickID instance_id)
|
|||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
/* FIXME: Really we should reference count this name so it doesn't go away after unlock */
|
||||
return name;
|
||||
return name ? SDL_FreeLater(SDL_strdup(name)) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -804,11 +803,10 @@ const char *SDL_GetJoystickInstancePath(SDL_JoystickID instance_id)
|
|||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
/* FIXME: Really we should reference count this path so it doesn't go away after unlock */
|
||||
if (!path) {
|
||||
SDL_Unsupported();
|
||||
}
|
||||
return path;
|
||||
return path ? SDL_FreeLater(SDL_strdup(path)) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1663,7 +1661,6 @@ const char *SDL_GetJoystickName(SDL_Joystick *joystick)
|
|||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
/* FIXME: Really we should reference count this name so it doesn't go away after unlock */
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -1888,9 +1885,9 @@ void SDL_CloseJoystick(SDL_Joystick *joystick)
|
|||
}
|
||||
|
||||
/* Free the data associated with this joystick */
|
||||
SDL_free(joystick->name);
|
||||
SDL_free(joystick->path);
|
||||
SDL_free(joystick->serial);
|
||||
SDL_FreeLater(joystick->name); // SDL_GetJoystickName returns this pointer.
|
||||
SDL_FreeLater(joystick->path); // SDL_GetJoystickPath returns this pointer.
|
||||
SDL_FreeLater(joystick->serial); // SDL_GetJoystickSerial returns this pointer.
|
||||
SDL_free(joystick->axes);
|
||||
SDL_free(joystick->balls);
|
||||
SDL_free(joystick->hats);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue