Estranged nephew of more truncation fixes.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@5265 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2012-08-27 18:57:41 +00:00
parent a2a5b0f8b8
commit d7850617d5
27 changed files with 73 additions and 79 deletions

View File

@ -505,7 +505,7 @@ typedef struct
for (texEnum = [allTextures objectEnumerator]; (tex = [texEnum nextObject]); )
{
// We subtract one because allTextures retains the textures.
[textureRefCounts setObject:[NSNumber numberWithUnsignedInt:[tex retainCount] - 1] forKey:[NSValue valueWithNonretainedObject:tex]];
[textureRefCounts setObject:[NSNumber numberWithUnsignedInteger:[tex retainCount] - 1] forKey:[NSValue valueWithNonretainedObject:tex]];
}
size_t totalSize = 0;

View File

@ -242,8 +242,8 @@ OOINLINE BOOL StatusIsSendable(OOTCPClientConnectionStatus status)
if (emphasisRange.length != 0)
{
range = [NSArray arrayWithObjects:
[NSNumber numberWithUnsignedInt:emphasisRange.location],
[NSNumber numberWithUnsignedInt:emphasisRange.length],
[NSNumber numberWithUnsignedInteger:emphasisRange.location],
[NSNumber numberWithUnsignedInteger:emphasisRange.length],
nil];
[parameters setObject:range forKey:kOOTCPEmphasisRanges];
}
@ -338,14 +338,12 @@ noteChangedConfigrationValue:(in id)newValue
- (BOOL) sendBytes:(const void *)bytes count:(size_t)count
{
int written;
if (bytes == NULL || count == 0) return YES;
if (!StatusIsSendable(_status) || _outStream == nil) return NO;
do
{
written = [_outStream write:bytes maxLength:count];
OOInteger written = [_outStream write:bytes maxLength:count];
if (written < 1) return NO;
count -= written;
@ -471,24 +469,12 @@ noteChangedConfigrationValue:(in id)newValue
enum { kBufferSize = 16 << 10 };
uint8_t buffer[kBufferSize];
int length;
OOInteger length;
NSData *data;
length = [_inStream read:buffer maxLength:kBufferSize];
while (length > 0)
{
/* This test is superfluous after the rewrite to fix Bug#014643
* TODO: Put the BadStream test back into the code
if (length < 1)
{
// Under GNUstep, but not OS X (currently), -hasBytesAvailable will return YES when the buffer is in fact empty.
if ([_inStream streamStatus] == NSStreamStatusReading) break;
[self breakConnectionWithBadStream:_inStream];
return;
}
*/
data = [NSData dataWithBytesNoCopy:buffer length:length freeWhenDone:NO];
OOTCPStreamDecoderReceiveData(_decoder, data);
length = [_inStream read:buffer maxLength:kBufferSize];

View File

@ -315,7 +315,7 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsid propID
{
#ifndef NDEBUG
case kConsole_debugFlags:
*value = INT_TO_JSVAL(gDebugFlags);
*value = INT_TO_JSVAL((uint32_t)gDebugFlags);
break;
#endif
@ -372,11 +372,11 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsid propID
break;
case kConsole_glFixedFunctionTextureUnitCount:
*value = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureUnitCount]);
*value = INT_TO_JSVAL((uint32_t)[[OOOpenGLExtensionManager sharedManager] textureUnitCount]);
break;
case kConsole_glFragmentShaderTextureUnitCount:
*value = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureImageUnitCount]);
*value = INT_TO_JSVAL((uint32_t)[[OOOpenGLExtensionManager sharedManager] textureImageUnitCount]);
break;
#define DEBUG_FLAG_CASE(x) case kConsole_##x: *value = INT_TO_JSVAL(x); break;

View File

@ -298,8 +298,6 @@ static GLfloat sBaseMass = 0.0;
[shipCommodityData release];
shipCommodityData = manifest;
//[cargo removeAllObjects]; // empty the hold - not needed, done individually inside unloadAllCargoPodsForType
[self calculateCurrentCargo]; // work out the correct value for current_cargo
}

View File

@ -736,7 +736,7 @@ OOINLINE float Hermite(float q)
}
#if __BIG_ENDIAN_
#if __BIG_ENDIAN__
#define iman_ 1
#else
#define iman_ 0
@ -744,10 +744,10 @@ OOINLINE float Hermite(float q)
// (same behaviour as, but faster than, FLOAT->INT)
//Works OK for -32728 to 32727.99999236688
OOINLINE long fast_floor(double val)
OOINLINE int32_t fast_floor(double val)
{
val += 68719476736.0 * 1.5;
return (((long*)&val)[iman_] >> 16);
return (((int32_t*)&val)[iman_] >> 16);
}

View File

@ -321,7 +321,7 @@ OOINLINE BOOL ValidBindingType(OOShaderUniformType type)
{
BOOL OK = YES;
NSMethodSignature *signature = nil;
unsigned argCount;
OOUInteger argCount;
NSString *methodProblem = nil;
id<OOWeakReferenceSupport> superCandidate = nil;
@ -496,7 +496,7 @@ OOINLINE BOOL ValidBindingType(OOShaderUniformType type)
case kOOShaderUniformTypeUnsignedInt:
case kOOShaderUniformTypeLong:
case kOOShaderUniformTypeUnsignedLong:
iVal = OOCallIntegerMethod(object, value.binding.selector, value.binding.method, type);
iVal = (GLint)OOCallIntegerMethod(object, value.binding.selector, value.binding.method, type);
isInt = YES;
break;

View File

@ -34,7 +34,7 @@ void OOCPUInfoInit(void);
/* Number of processors (whether they be individual or cores), used to select
number of threads to use for things like texture loading.
*/
unsigned OOCPUCount(void);
OOUInteger OOCPUCount(void);
/* Set up OOLITE_BIG_ENDIAN and OOLITE_LITTLE_ENDIAN macros. Exactly one must

View File

@ -98,7 +98,7 @@ void OOCPUInfoInit(void)
}
unsigned OOCPUCount(void)
OOUInteger OOCPUCount(void)
{
if (!sInited) OOCPUInfoInit();
return (sNumberOfCPUs != 0) ? sNumberOfCPUs : 1;

View File

@ -186,7 +186,7 @@ NSArray *OOConvertSystemDescriptionsToArrayFormat(NSDictionary *descriptionsInDi
realResult = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++)
{
entry = [result objectForKey:[NSNumber numberWithUnsignedInt:i]];
entry = [result objectForKey:[NSNumber numberWithUnsignedInteger:i]];
if (entry == nil) entry = [NSArray array];
[realResult addObject:entry];
}
@ -323,7 +323,7 @@ static NSNumber *KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices,
// Search for free index
do
{
result = [NSNumber numberWithUnsignedInt:(*ioSlotCache)++];
result = [NSNumber numberWithUnsignedInteger:(*ioSlotCache)++];
}
while ([ioUsedIndicies containsObject:result]);

View File

@ -2235,7 +2235,7 @@ static void VFRAddFace(VertexFaceRef *vfr, OOUInteger index)
else
{
if (vfr->extra == nil) vfr->extra = [NSMutableArray array];
[vfr->extra addObject:[NSNumber numberWithInt:index]];
[vfr->extra addObject:[NSNumber numberWithInteger:index]];
}
}

View File

@ -261,8 +261,8 @@ static NSArray *ArrayOfExtensions(NSString *extensionString)
maximumShaderSetting = SHADERS_NOT_SUPPORTED;
}
GLint texImageUnitOverride = [gpuConfig oo_unsignedIntegerForKey:@"texture_image_units" defaultValue:textureImageUnitCount];
if (texImageUnitOverride < textureImageUnitCount) textureImageUnitCount = texImageUnitOverride;
GLint texImageUnitOverride = [gpuConfig oo_intForKey:@"texture_image_units" defaultValue:textureImageUnitCount];
if (texImageUnitOverride < textureImageUnitCount) textureImageUnitCount = MAX(texImageUnitOverride, 0);
#endif
#if OO_USE_VBO
@ -273,8 +273,8 @@ static NSArray *ArrayOfExtensions(NSString *extensionString)
#endif
#if OO_MULTITEXTURE
[self checkTextureCombinersSupported];
GLint texUnitOverride = [gpuConfig oo_unsignedIntegerForKey:@"texture_units" defaultValue:textureUnitCount];
if (texUnitOverride < textureUnitCount) textureUnitCount = texUnitOverride;
GLint texUnitOverride = [gpuConfig oo_intForKey:@"texture_units" defaultValue:textureUnitCount];
if (texUnitOverride < textureUnitCount) textureUnitCount = MAX(texUnitOverride, 0);
#endif
usePointSmoothing = [gpuConfig oo_boolForKey:@"smooth_points" defaultValue:YES];

View File

@ -54,7 +54,7 @@ SOFTWARE.
{
BOOL OK = YES;
NSArray *config = nil;
unsigned i, count;
OOUInteger i, count;
id entry = nil;
NSString *name = nil;
float probability;

View File

@ -316,7 +316,7 @@ NSDictionary *OOParseRolesFromString(NSString *string)
{
NSMutableDictionary *result = nil;
NSArray *tokens = nil;
unsigned i, count;
OOUInteger i, count;
NSString *role = nil;
float probability;
NSScanner *scanner = nil;

View File

@ -485,7 +485,7 @@ static NSString * const kVisualEffectDataCacheKey = @"visual effect data";
NSString *parentKey = nil;
NSDictionary *shipEntry = nil;
NSDictionary *parentEntry = nil;
unsigned count, lastCount;
OOUInteger count, lastCount;
NSMutableArray *reportedBadShips = nil;
// Build set of ships with like_ship references

View File

@ -96,7 +96,7 @@ static NSString * const kStageName = @"Checking equipment.plist";
NSEnumerator *entryEnum = nil;
NSArray *entry = nil;
unsigned entryIndex = 0;
unsigned elemCount;
OOUInteger elemCount;
NSString *name = nil;
NSString *entryDesc = nil;
@ -123,12 +123,12 @@ static NSString * const kStageName = @"Checking equipment.plist";
// Check that the entry has an acceptable number of elements.
if (elemCount < 5)
{
OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"***** ERROR: equipment.plist entry %@ has too few elements (%u, should be 5 or 6).", entryDesc, elemCount);
OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"***** ERROR: equipment.plist entry %@ has too few elements (%lu, should be 5 or 6).", entryDesc, elemCount);
continue;
}
if (6 < elemCount)
{
OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"----- WARNING: equipment.plist entry %@ has too many elements (%u, should be 5 or 6).", entryDesc, elemCount);
OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"----- WARNING: equipment.plist entry %@ has too many elements (%lu, should be 5 or 6).", entryDesc, elemCount);
}
/* Check element types. The numbers are required to be unsigned

View File

@ -326,7 +326,7 @@ static NSString * const kStageName = @"Checking shipdata.plist";
{
NSArray *parts = nil;
NSMutableSet *result = nil;
unsigned i, count;
OOUInteger i, count;
NSString *role = nil;
NSRange parenRange;

View File

@ -121,9 +121,9 @@ OOINLINE BackLinkChain BackLink(BackLinkChain *link, id element)
return result;
}
OOINLINE BackLinkChain BackLinkIndex(BackLinkChain *link, unsigned index)
OOINLINE BackLinkChain BackLinkIndex(BackLinkChain *link, OOUInteger index)
{
BackLinkChain result = { link, [NSNumber numberWithInt:index] };
BackLinkChain result = { link, [NSNumber numberWithInteger:index] };
return result;
}
@ -761,7 +761,7 @@ static NSString *ArrayForErrorReport(NSArray *array)
{
NSString *result = nil;
NSString *string = nil;
unsigned i, count;
OOUInteger i, count;
NSAutoreleasePool *pool = nil;
count = [array count];
@ -830,8 +830,8 @@ static NSError *Verify_String(OOPListSchemaVerifier *verifier, id value, NSDicti
{
NSString *filteredString = nil;
id testValue = nil;
unsigned length;
unsigned lengthConstraint;
OOUInteger length;
OOUInteger lengthConstraint;
NSError *error = nil;
REQUIRE_TYPE(NSString, @"string");
@ -875,13 +875,13 @@ static NSError *Verify_String(OOPListSchemaVerifier *verifier, id value, NSDicti
// Apply length bounds.
length = [filteredString length];
lengthConstraint = [params oo_unsignedIntForKey:@"minLength"];
lengthConstraint = [params oo_unsignedIntegerForKey:@"minLength"];
if (length < lengthConstraint)
{
return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"String \"%@\" is too short (%u bytes, minimum is %u).", StringForErrorReport(filteredString), length, lengthConstraint);
}
lengthConstraint = [params oo_unsignedIntForKey:@"maxLength" defaultValue:UINT_MAX];
lengthConstraint = [params oo_unsignedIntegerForKey:@"maxLength" defaultValue:NSUIntegerMax];
if (lengthConstraint < length)
{
return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"String \"%@\" is too long (%u bytes, maximum is %u).", StringForErrorReport(filteredString), length, lengthConstraint);
@ -896,9 +896,9 @@ static NSError *Verify_Array(OOPListSchemaVerifier *verifier, id value, NSDictio
{
id valueType = nil;
BOOL OK = YES, stop = NO;
unsigned i, count;
OOUInteger i, count;
id subProperty = nil;
unsigned constraint;
OOUInteger constraint;
REQUIRE_TYPE(NSArray, @"array");
@ -906,13 +906,13 @@ static NSError *Verify_Array(OOPListSchemaVerifier *verifier, id value, NSDictio
// Apply count bounds.
count = [value count];
constraint = [params oo_unsignedIntForKey:@"minCount" defaultValue:0];
constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0];
if (count < constraint)
{
return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Array has too few members (%u, minimum is %u).", count, constraint);
}
constraint = [params oo_unsignedIntForKey:@"maxCount" defaultValue:UINT_MAX];
constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax];
if (constraint < count)
{
return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Array has too many members (%u, maximum is %u).", count, constraint);
@ -961,7 +961,7 @@ static NSError *Verify_Dictionary(OOPListSchemaVerifier *verifier, id value, NSD
BOOL allowOthers;
NSMutableSet *requiredKeys = nil;
NSArray *requiredKeyList = nil;
unsigned count, constraint;
OOUInteger count, constraint;
REQUIRE_TYPE(NSDictionary, @"dictionary");
@ -969,12 +969,12 @@ static NSError *Verify_Dictionary(OOPListSchemaVerifier *verifier, id value, NSD
// Apply count bounds.
count = [value count];
constraint = [params oo_unsignedIntForKey:@"minCount" defaultValue:0];
constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0];
if (count < constraint)
{
return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Dictionary has too few pairs (%u, minimum is %u).", count, constraint);
}
constraint = [params oo_unsignedIntForKey:@"maxCount" defaultValue:UINT_MAX];
constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax];
if (constraint < count)
{
return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Dictionary has too manu pairs (%u, maximum is %u).", count, constraint);

View File

@ -164,8 +164,8 @@ static NSString * const kStageName = @"Testing textures and images";
if (success)
{
rWidth = OORoundUpToPowerOf2((2 * pixmap.width) / 3);
rHeight = OORoundUpToPowerOf2((2 * pixmap.height) / 3);
rWidth = (uint32_t)OORoundUpToPowerOf2((2 * pixmap.width) / 3);
rHeight = (uint32_t)OORoundUpToPowerOf2((2 * pixmap.height) / 3);
if (pixmap.width != rWidth || pixmap.height != rHeight)
{
OOLog(@"verifyOXP.texture.notPOT", @"----- WARNING: image %@ has non-power-of-two dimensions; it will have to be rescaled (from %ux%u pixels to %ux%u pixels) at runtime.", displayName, pixmap.width, pixmap.height, rWidth, rHeight);

View File

@ -35,7 +35,7 @@ static void AppendNewLineAndIndent(NSMutableString *ioString, unsigned indentDep
NSRange foundRange, searchRange;
NSString *foundString;
NSMutableString *newString;
unsigned length;
NSUInteger length;
length = [self length];
if (0 != length

View File

@ -263,16 +263,15 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsid
return JS_NewNumberValue(context, [eqType damageProbability], value);
case kEquipmentInfo_techLevel:
*value = INT_TO_JSVAL([eqType techLevel]);
*value = INT_TO_JSVAL((int32_t)[eqType techLevel]);
return YES;
case kEquipmentInfo_effectiveTechLevel:
*value = INT_TO_JSVAL([eqType effectiveTechLevel]);
*value = INT_TO_JSVAL((int32_t)[eqType effectiveTechLevel]);
return YES;
case kEquipmentInfo_price:
*value = INT_TO_JSVAL([eqType price]);
return YES;
return JS_NewNumberValue(context, [eqType price], value);
case kEquipmentInfo_isAvailableToAll:
*value = OOJSValueFromBOOL([eqType isAvailableToAll]);

View File

@ -92,9 +92,11 @@ MA 02110-1301, USA.
if (OK)
{
assert(argCount < UINT32_MAX);
[code getCharacters:buffer];
function = JS_CompileUCFunction(context, scope, [name UTF8String], argCount, argNames, buffer, length, [fileName UTF8String], lineNumber);
function = JS_CompileUCFunction(context, scope, [name UTF8String], (uint32_t)argCount, argNames, buffer, length, [fileName UTF8String], (uint32_t)lineNumber);
if (function == NULL) OK = NO;
free(buffer);
@ -196,6 +198,7 @@ MA 02110-1301, USA.
result:(jsval *)result
{
OOUInteger i, argc = [arguments count];
assert(argc < UINT32_MAX);
jsval argv[argc];
for (i = 0; i < argc; i++)
@ -209,7 +212,7 @@ MA 02110-1301, USA.
if (jsThis != nil) OK = JS_ValueToObject(context, [jsThis oo_jsValueInContext:context], &scopeObj);
if (OK) OK = [self evaluateWithContext:context
scope:scopeObj
argc:argc
argc:(uint32_t)argc
argv:argv
result:result];

View File

@ -175,7 +175,9 @@ static JSBool MissionVariablesEnumerate(JSContext *context, JSObject *object, JS
enumerator = [[mvars objectEnumerator] retain];
*state = PRIVATE_TO_JSVAL(enumerator);
if (idp != NULL) *idp = INT_TO_JSID([mvars count]);
OOUInteger count = [mvars count];
assert(count <= INT32_MAX);
if (idp != NULL) *idp = INT_TO_JSID((uint32_t)count);
return YES;
}

View File

@ -185,7 +185,7 @@ static JSBool OoliteCompareVersion(JSContext *context, uintN argc, jsval *vp)
if (components != nil)
{
OOJS_RETURN_INT(CompareVersions(components, VersionComponents()));
OOJS_RETURN_INT((int32_t)CompareVersions(components, VersionComponents()));
}
else
{

View File

@ -200,7 +200,7 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID,
return YES;
case kPlayer_legalStatus:
*value = OOJSValueFromNativeObject(context, OODisplayStringFromLegalStatus([player bounty]));
*value = OOJSValueFromNativeObject(context, OODisplayStringFromLegalStatus([player legalStatus]));
return YES;
case kPlayer_alertCondition:
@ -517,7 +517,7 @@ static JSBool PlayerSetEscapePodDestination(JSContext *context, uintN argc, jsva
rescueRange = [UNIVERSE strict] ? MAX_JUMP_RANGE / 3.0 : MAX_JUMP_RANGE / 2.0;
}
NSMutableArray *sDests = [UNIVERSE nearbyDestinationsWithinRange:rescueRange];
int i = 0, nDests = [sDests count];
OOUInteger i = 0, nDests = [sDests count];
if (nDests > 0) for (i = --nDests; i > 0; i--)
{

View File

@ -477,7 +477,7 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
return JS_NewNumberValue(context, [entity fuelChargeRate], value);
case kShip_bounty:
*value = INT_TO_JSVAL([entity bounty]);
return JS_NewNumberValue(context, [entity bounty], value);
return YES;
case kShip_subEntities:
@ -485,7 +485,7 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
break;
case kShip_subEntityCapacity:
*value = INT_TO_JSVAL([entity maxShipSubEntities]);
return JS_NewNumberValue(context, [entity maxShipSubEntities], value);
return YES;
case kShip_hasSuspendedAI:
@ -1996,8 +1996,12 @@ static JSBool ShipRestoreSubEntities(JSContext *context, uintN argc, jsval *vp)
if ([[thisEnt subEntitiesForScript] count] - subCount > 0) numSubEntitiesRestored = [[thisEnt subEntitiesForScript] count] - subCount;
// for each subentitiy restored, slightly increase the trade-in factor
if ([thisEnt isPlayer]) [(PlayerEntity *)thisEnt adjustTradeInFactorBy:(PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE * numSubEntitiesRestored)];
// for each subentity restored, slightly increase the trade-in factor
if ([thisEnt isPlayer])
{
int tradeInFactorChange = (int)MAX(PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE * numSubEntitiesRestored, 25U);
[(PlayerEntity *)thisEnt adjustTradeInFactorBy:tradeInFactorChange];
}
OOJS_RETURN_BOOL(numSubEntitiesRestored > 0);

View File

@ -225,7 +225,7 @@ static JSBool StationGetProperty(JSContext *context, JSObject *this, jsid propID
return YES;
case kStation_equivalentTechLevel:
*value = INT_TO_JSVAL([entity equivalentTechLevel]);
*value = INT_TO_JSVAL((int32_t)[entity equivalentTechLevel]);
return YES;
case kStation_equipmentPriceFactor:

View File

@ -350,7 +350,9 @@ static JSBool SystemInfoEnumerate(JSContext *context, JSObject *this, JSIterateO
enumerator = [[keys objectEnumerator] retain];
*state = PRIVATE_TO_JSVAL(enumerator);
if (idp != NULL) *idp = INT_TO_JSID([keys count]);
OOUInteger count = [keys count];
assert(count <= INT32_MAX);
if (idp != NULL) *idp = INT_TO_JSID((int32_t)count);
return YES;
}