mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-07-12 12:19:55 +00:00
Property query functions don't set an error if they return the default value
You can call SDL_HasProperty() if you want to check to see if a property exists. Fixes https://github.com/libsdl-org/SDL/issues/9067
This commit is contained in:
@@ -451,17 +451,20 @@ int SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool va
|
||||
return SDL_PrivateSetProperty(props, name, property);
|
||||
}
|
||||
|
||||
SDL_bool SDL_HasProperty(SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
return (SDL_GetPropertyType(props, name) != SDL_PROPERTY_TYPE_INVALID);
|
||||
}
|
||||
|
||||
SDL_PropertyType SDL_GetPropertyType(SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
SDL_Properties *properties = NULL;
|
||||
SDL_PropertyType type = SDL_PROPERTY_TYPE_INVALID;
|
||||
|
||||
if (!props) {
|
||||
SDL_InvalidParamError("props");
|
||||
return SDL_PROPERTY_TYPE_INVALID;
|
||||
}
|
||||
if (!name || !*name) {
|
||||
SDL_InvalidParamError("name");
|
||||
return SDL_PROPERTY_TYPE_INVALID;
|
||||
}
|
||||
|
||||
@@ -470,7 +473,6 @@ SDL_PropertyType SDL_GetPropertyType(SDL_PropertiesID props, const char *name)
|
||||
SDL_UnlockMutex(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return SDL_PROPERTY_TYPE_INVALID;
|
||||
}
|
||||
|
||||
@@ -479,8 +481,6 @@ SDL_PropertyType SDL_GetPropertyType(SDL_PropertiesID props, const char *name)
|
||||
SDL_Property *property = NULL;
|
||||
if (SDL_FindInHashTable(properties->props, name, (const void **)&property)) {
|
||||
type = property->type;
|
||||
} else {
|
||||
SDL_SetError("Couldn't find property named %s", name);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
@@ -494,11 +494,9 @@ void *SDL_GetProperty(SDL_PropertiesID props, const char *name, void *default_va
|
||||
void *value = default_value;
|
||||
|
||||
if (!props) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
if (!name || !*name) {
|
||||
SDL_InvalidParamError("name");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -507,7 +505,6 @@ void *SDL_GetProperty(SDL_PropertiesID props, const char *name, void *default_va
|
||||
SDL_UnlockMutex(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -521,11 +518,7 @@ void *SDL_GetProperty(SDL_PropertiesID props, const char *name, void *default_va
|
||||
if (SDL_FindInHashTable(properties->props, name, (const void **)&property)) {
|
||||
if (property->type == SDL_PROPERTY_TYPE_POINTER) {
|
||||
value = property->value.pointer_value;
|
||||
} else {
|
||||
SDL_SetError("Property %s isn't a pointer value", name);
|
||||
}
|
||||
} else {
|
||||
SDL_SetError("Couldn't find property named %s", name);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
@@ -539,11 +532,9 @@ const char *SDL_GetStringProperty(SDL_PropertiesID props, const char *name, cons
|
||||
const char *value = default_value;
|
||||
|
||||
if (!props) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
if (!name || !*name) {
|
||||
SDL_InvalidParamError("name");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -552,7 +543,6 @@ const char *SDL_GetStringProperty(SDL_PropertiesID props, const char *name, cons
|
||||
SDL_UnlockMutex(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -594,11 +584,8 @@ const char *SDL_GetStringProperty(SDL_PropertiesID props, const char *name, cons
|
||||
value = property->value.boolean_value ? "true" : "false";
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Property %s isn't a string value", name);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
SDL_SetError("Couldn't find property named %s", name);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
@@ -612,11 +599,9 @@ Sint64 SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 de
|
||||
Sint64 value = default_value;
|
||||
|
||||
if (!props) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
if (!name || !*name) {
|
||||
SDL_InvalidParamError("name");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -625,7 +610,6 @@ Sint64 SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 de
|
||||
SDL_UnlockMutex(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -647,11 +631,8 @@ Sint64 SDL_GetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 de
|
||||
value = property->value.boolean_value;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Property %s isn't a number value", name);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
SDL_SetError("Couldn't find property named %s", name);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
@@ -665,11 +646,9 @@ float SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float defau
|
||||
float value = default_value;
|
||||
|
||||
if (!props) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
if (!name || !*name) {
|
||||
SDL_InvalidParamError("name");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -678,7 +657,6 @@ float SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float defau
|
||||
SDL_UnlockMutex(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -700,11 +678,8 @@ float SDL_GetFloatProperty(SDL_PropertiesID props, const char *name, float defau
|
||||
value = (float)property->value.boolean_value;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Property %s isn't a float value", name);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
SDL_SetError("Couldn't find property named %s", name);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
@@ -718,11 +693,9 @@ SDL_bool SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bo
|
||||
SDL_bool value = default_value;
|
||||
|
||||
if (!props) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
if (!name || !*name) {
|
||||
SDL_InvalidParamError("name");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -731,7 +704,6 @@ SDL_bool SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bo
|
||||
SDL_UnlockMutex(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -753,11 +725,8 @@ SDL_bool SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bo
|
||||
value = property->value.boolean_value;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Property %s isn't a boolean value", name);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
SDL_SetError("Couldn't find property named %s", name);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
|
||||
@@ -972,6 +972,7 @@ SDL3_0.0.0 {
|
||||
SDL_RenderGeometryRawFloat;
|
||||
SDL_SetWindowShape;
|
||||
SDL_RenderViewportSet;
|
||||
SDL_HasProperty;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
||||
@@ -997,3 +997,4 @@
|
||||
#define SDL_RenderGeometryRawFloat SDL_RenderGeometryRawFloat_REAL
|
||||
#define SDL_SetWindowShape SDL_SetWindowShape_REAL
|
||||
#define SDL_RenderViewportSet SDL_RenderViewportSet_REAL
|
||||
#define SDL_HasProperty SDL_HasProperty_REAL
|
||||
|
||||
@@ -1022,3 +1022,4 @@ SDL_DYNAPI_PROC(int,SDL_GetRenderColorScale,(SDL_Renderer *a, float *b),(a,b),re
|
||||
SDL_DYNAPI_PROC(int,SDL_RenderGeometryRawFloat,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const SDL_FColor *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SetWindowShape,(SDL_Window *a, SDL_Surface *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_RenderViewportSet,(SDL_Renderer *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_HasProperty,(SDL_PropertiesID a, const char *b),(a,b),return)
|
||||
|
||||
Reference in New Issue
Block a user