Make SDL_SetError and friends unconditionally return -1.

This lets us change things like this...

    if (Failed) {
        SDL_SetError("We failed");
        return -1;
    }

...into this...

    if (Failed) {
        return SDL_SetError("We failed");
    }


 Fixes Bugzilla #1778.
This commit is contained in:
Ryan C. Gordon 2013-03-31 12:48:50 -04:00
parent 8c6b9f4743
commit 4f438b70a2
106 changed files with 616 additions and 1189 deletions

View file

@ -160,15 +160,13 @@ SDL_SYS_HapticInit(void)
/* Get HID devices. */
match = IOServiceMatching(kIOHIDDeviceKey);
if (match == NULL) {
SDL_SetError("Haptic: Failed to get IOServiceMatching.");
return -1;
return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
}
/* Now search I/O Registry for matching devices. */
result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
if (result != kIOReturnSuccess) {
SDL_SetError("Haptic: Couldn't create a HID object iterator.");
return -1;
return SDL_SetError("Haptic: Couldn't create a HID object iterator.");
}
/* IOServiceGetMatchingServices consumes dictionary. */
@ -257,8 +255,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
ret = IORegistryEntryCreateCFProperties(dev, &hidProperties,
kCFAllocatorDefault, kNilOptions);
if ((ret != KERN_SUCCESS) || !hidProperties) {
SDL_SetError("Haptic: Unable to create CFProperties.");
return -1;
return SDL_SetError("Haptic: Unable to create CFProperties.");
}
/* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
@ -289,17 +286,15 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
if (refCF) {
if (!CFStringGetCString(refCF, name, 256,
CFStringGetSystemEncoding())) {
SDL_SetError
return SDL_SetError
("Haptic: CFStringGetCString error retrieving pDevice->product.");
return -1;
}
}
CFRelease(usbProperties);
} else {
SDL_SetError
return SDL_SetError
("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
return -1;
}
/* Release stuff. */
@ -310,8 +305,7 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
SDL_SetError("Haptic: IOObjectRelease error with parent1.");
}
} else {
SDL_SetError("Haptic: Error getting registry entries.");
return -1;
return SDL_SetError("Haptic: Error getting registry entries.");
}
return 0;
@ -336,8 +330,7 @@ GetSupportedFeatures(SDL_Haptic * haptic)
ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
if (ret != FF_OK) {
SDL_SetError("Haptic: Unable to get device's supported features.");
return -1;
return SDL_SetError("Haptic: Unable to get device's supported features.");
}
supported = 0;
@ -366,9 +359,8 @@ GetSupportedFeatures(SDL_Haptic * haptic)
if (ret == FF_OK)
supported |= SDL_HAPTIC_GAIN;
else if (ret != FFERR_UNSUPPORTED) {
SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
FFStrError(ret));
}
/* Checks if supports autocenter. */
@ -377,10 +369,9 @@ GetSupportedFeatures(SDL_Haptic * haptic)
if (ret == FF_OK)
supported |= SDL_HAPTIC_AUTOCENTER;
else if (ret != FFERR_UNSUPPORTED) {
SDL_SetError
return SDL_SetError
("Haptic: Unable to get if device supports autocenter: %s.",
FFStrError(ret));
return -1;
}
/* Check for axes, we have an artificial limit on axes */
@ -625,8 +616,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
/* Has axes. */
rglDir = SDL_malloc(sizeof(LONG) * naxes);
if (rglDir == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
effect->rglDirection = rglDir;
@ -654,8 +644,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
return 0;
default:
SDL_SetError("Haptic: Unknown direction type.");
return -1;
return SDL_SetError("Haptic: Unknown direction type.");
}
}
@ -695,8 +684,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
/* Envelope. */
envelope = SDL_malloc(sizeof(FFENVELOPE));
if (envelope == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
SDL_memset(envelope, 0, sizeof(FFENVELOPE));
dest->lpEnvelope = envelope;
@ -707,8 +695,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
if (dest->cAxes > 0) {
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
if (axes == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
if (dest->cAxes > 1) {
@ -727,8 +714,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
hap_constant = &src->constant;
constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
if (constant == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
@ -771,8 +757,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
hap_periodic = &src->periodic;
periodic = SDL_malloc(sizeof(FFPERIODIC));
if (periodic == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
SDL_memset(periodic, 0, sizeof(FFPERIODIC));
@ -817,8 +802,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
hap_condition = &src->condition;
condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
if (condition == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
SDL_memset(condition, 0, sizeof(FFCONDITION));
@ -860,8 +844,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
hap_ramp = &src->ramp;
ramp = SDL_malloc(sizeof(FFRAMPFORCE));
if (ramp == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
@ -899,8 +882,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
hap_custom = &src->custom;
custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
if (custom == NULL) {
SDL_OutOfMemory();
return -1;
return SDL_OutOfMemory();
}
SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
@ -944,8 +926,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
default:
SDL_SetError("Haptic: Unknown effect type.");
return -1;
return SDL_SetError("Haptic: Unknown effect type.");
}
return 0;
@ -1150,9 +1131,8 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
/* Run the effect. */
ret = FFEffectStart(effect->hweffect->ref, iter, 0);
if (ret != FF_OK) {
SDL_SetError("Haptic: Unable to run the effect: %s.",
FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Unable to run the effect: %s.",
FFStrError(ret));
}
return 0;
@ -1169,9 +1149,8 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
ret = FFEffectStop(effect->hweffect->ref);
if (ret != FF_OK) {
SDL_SetError("Haptic: Unable to stop the effect: %s.",
FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Unable to stop the effect: %s.",
FFStrError(ret));
}
return 0;
@ -1236,8 +1215,7 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
FFPROP_FFGAIN, &val);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
}
return 0;
@ -1262,9 +1240,8 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
FFPROP_AUTOCENTER, &val);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error setting autocenter: %s.",
FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Error setting autocenter: %s.",
FFStrError(ret));
}
return 0;
@ -1282,8 +1259,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic)
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
FFSFFC_PAUSE);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
}
return 0;
@ -1301,8 +1277,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
FFSFFC_CONTINUE);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
}
return 0;
@ -1320,8 +1295,7 @@ SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
FFSFFC_STOPALL);
if (ret != FF_OK) {
SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
return -1;
return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
}
return 0;