use size_t instead of unsigned in a bunch of appropriate places

This would theoretically break compatibility with apps using embedded
classpaths, on big-endian architectures - because of the size type
extension.  However, we don't currently support any big-endian
architectures, so it shouldn't be a problem.
This commit is contained in:
Joshua Warner 2015-03-16 15:32:50 -06:00
parent d9650be570
commit 1fcc097344
15 changed files with 71 additions and 71 deletions

View File

@ -454,7 +454,7 @@ setting the boot classpath to "[bootJar]".
extern const uint8_t SYMBOL(end)[];
EXPORT const uint8_t*
bootJar(unsigned* size)
bootJar(size_t* size)
{
*size = SYMBOL(end) - SYMBOL(start);
return SYMBOL(start);
@ -682,7 +682,7 @@ containing them. See the previous example for instructions.
extern const uint8_t BOOTIMAGE_BIN(end)[];
EXPORT const uint8_t*
bootimageBin(unsigned* size)
bootimageBin(size_t* size)
{
*size = BOOTIMAGE_BIN(end) - BOOTIMAGE_BIN(start);
return BOOTIMAGE_BIN(start);
@ -692,7 +692,7 @@ containing them. See the previous example for instructions.
extern const uint8_t CODEIMAGE_BIN(end)[];
EXPORT const uint8_t*
codeimageBin(unsigned* size)
codeimageBin(size_t* size)
{
*size = CODEIMAGE_BIN(end) - CODEIMAGE_BIN(start);
return CODEIMAGE_BIN(start);

View File

@ -111,7 +111,7 @@ class System : public avian::util::Aborter {
};
virtual bool success(Status) = 0;
virtual void* tryAllocate(unsigned sizeInBytes) = 0;
virtual void* tryAllocate(size_t sizeInBytes) = 0;
virtual void free(const void* p) = 0;
virtual Status attach(Runnable*) = 0;
virtual Status start(Runnable*) = 0;
@ -123,7 +123,7 @@ class System : public avian::util::Aborter {
= 0;
virtual Status map(Region**, const char* name) = 0;
virtual FileType stat(const char* name, unsigned* length) = 0;
virtual FileType stat(const char* name, size_t* length) = 0;
virtual Status open(Directory**, const char* name) = 0;
virtual const char* libraryPrefix() = 0;
virtual const char* librarySuffix() = 0;
@ -138,7 +138,7 @@ class System : public avian::util::Aborter {
virtual void dispose() = 0;
};
inline void* allocate(System* s, unsigned size)
inline void* allocate(System* s, size_t size)
{
void* p = s->tryAllocate(size);
if (p == 0)

View File

@ -648,7 +648,7 @@ void intercept(Thread* t,
}
}
Finder* getFinder(Thread* t, const char* name, unsigned nameLength)
Finder* getFinder(Thread* t, const char* name, size_t nameLength)
{
ACQUIRE(t, t->m->referenceLock);
@ -668,10 +668,10 @@ Finder* getFinder(Thread* t, const char* name, unsigned nameLength)
reinterpret_cast<const char*>(n->body().begin()));
if (p) {
uint8_t* (*function)(unsigned*);
uint8_t* (*function)(size_t*);
memcpy(&function, &p, BytesPerWord);
unsigned size;
size_t size = 0;
uint8_t* data = function(&size);
if (data) {
Finder* f = makeFinder(t->m->system, t->m->heap, data, size);

View File

@ -126,8 +126,8 @@ inline const uint8_t* endOfEntry(const uint8_t* p)
inline bool readLine(const uint8_t* base,
unsigned total,
unsigned* start,
unsigned* length)
size_t* start,
size_t* length)
{
const uint8_t* p = base + *start;
const uint8_t* end = base + total;
@ -147,7 +147,7 @@ class Finder {
public:
class IteratorImp {
public:
virtual const char* next(unsigned* size) = 0;
virtual const char* next(size_t* size) = 0;
virtual void dispose() = 0;
};
@ -171,7 +171,7 @@ class Finder {
return current != 0;
}
const char* next(unsigned* size)
const char* next(size_t* size)
{
if (hasMore()) {
*size = currentSize;
@ -185,13 +185,13 @@ class Finder {
IteratorImp* it;
const char* current;
unsigned currentSize;
size_t currentSize;
};
virtual IteratorImp* iterator() = 0;
virtual System::Region* find(const char* name) = 0;
virtual System::FileType stat(const char* name,
unsigned* length,
size_t* length,
bool tryDirectory = false) = 0;
virtual const char* urlPrefix(const char* name) = 0;
virtual const char* nextUrlPrefix(const char* name, void*& finderElementPtr)
@ -209,7 +209,7 @@ AVIAN_EXPORT Finder* makeFinder(System* s,
Finder* makeFinder(System* s,
avian::util::Alloc* a,
const uint8_t* jarData,
unsigned jarLength);
size_t jarLength);
} // namespace vm

View File

@ -24,14 +24,14 @@ namespace vm {
uint8_t* decodeLZMA(System* s,
avian::util::Alloc* a,
uint8_t* in,
unsigned inSize,
unsigned* outSize);
size_t inSize,
size_t* outSize);
uint8_t* encodeLZMA(System* s,
avian::util::Alloc* a,
uint8_t* in,
unsigned inSize,
unsigned* outSize);
size_t inSize,
size_t* outSize);
} // namespace vm

View File

@ -1062,7 +1062,7 @@ class Machine {
JNIEnvVTable jniEnvVTable;
uintptr_t* heapPool[ThreadHeapPoolSize];
unsigned heapPoolIndex;
unsigned bootimageSize;
size_t bootimageSize;
};
void printTrace(Thread* t, GcThrowable* exception);

View File

@ -22,7 +22,7 @@ extern "C" {
extern const uint8_t SYMBOL(start)[];
extern const uint8_t SYMBOL(end)[];
AVIAN_EXPORT const uint8_t* javahomeJar(unsigned* size)
AVIAN_EXPORT const uint8_t* javahomeJar(size_t* size)
{
*size = SYMBOL(end) - SYMBOL(start);
return SYMBOL(start);

View File

@ -33,7 +33,7 @@ extern "C" {
extern const uint8_t BOOTIMAGE_SYMBOL(start)[];
extern const uint8_t BOOTIMAGE_SYMBOL(end)[];
AVIAN_EXPORT const uint8_t* bootimageBin(unsigned* size)
AVIAN_EXPORT const uint8_t* bootimageBin(size_t* size)
{
*size = BOOTIMAGE_SYMBOL(end) - BOOTIMAGE_SYMBOL(start);
return BOOTIMAGE_SYMBOL(start);
@ -42,7 +42,7 @@ AVIAN_EXPORT const uint8_t* bootimageBin(unsigned* size)
extern const uint8_t CODEIMAGE_SYMBOL(start)[];
extern const uint8_t CODEIMAGE_SYMBOL(end)[];
AVIAN_EXPORT const uint8_t* codeimageBin(unsigned* size)
AVIAN_EXPORT const uint8_t* codeimageBin(size_t* size)
{
*size = CODEIMAGE_SYMBOL(end) - CODEIMAGE_SYMBOL(start);
return CODEIMAGE_SYMBOL(start);
@ -65,7 +65,7 @@ extern "C" {
extern const uint8_t SYMBOL(start)[];
extern const uint8_t SYMBOL(end)[];
AVIAN_EXPORT const uint8_t* classpathJar(unsigned* size)
AVIAN_EXPORT const uint8_t* classpathJar(size_t* size)
{
*size = SYMBOL(end) - SYMBOL(start);
return SYMBOL(start);

View File

@ -32,7 +32,7 @@ class Element {
public:
class Iterator {
public:
virtual const char* next(unsigned* size) = 0;
virtual const char* next(size_t* size) = 0;
virtual void dispose() = 0;
};
@ -43,7 +43,7 @@ class Element {
virtual Iterator* iterator() = 0;
virtual System::Region* find(const char* name) = 0;
virtual System::FileType stat(const char* name,
unsigned* length,
size_t* length,
bool tryDirectory) = 0;
virtual const char* urlPrefix() = 0;
virtual const char* sourceUrl() = 0;
@ -70,7 +70,7 @@ class DirectoryElement : public Element {
}
}
virtual const char* next(unsigned* size)
virtual const char* next(size_t* size)
{
if (it) {
const char* v = it->next(size);
@ -90,7 +90,7 @@ class DirectoryElement : public Element {
for (const char* v = directory->next(); v; v = directory->next()) {
if (v[0] != '.') {
last = append(allocator, name, "/", v);
unsigned length;
size_t length;
if (s->stat(last, &length) == System::TypeDirectory) {
it = new (allocator->allocate(sizeof(Iterator)))
Iterator(s, allocator, last, skip);
@ -157,7 +157,7 @@ class DirectoryElement : public Element {
}
}
virtual System::FileType stat(const char* name, unsigned* length, bool)
virtual System::FileType stat(const char* name, size_t* length, bool)
{
const char* file = append(allocator, this->name, "/", name);
System::FileType type = s->stat(file, length);
@ -344,7 +344,7 @@ class JarIndex {
List<Entry>* findNode(const char* name)
{
unsigned length = strlen(name);
size_t length = strlen(name);
unsigned i = hash(name) & (capacity - 1);
for (List<Entry>* n = table[i]; n; n = n->next) {
const uint8_t* p = n->item.entry;
@ -403,7 +403,7 @@ class JarIndex {
return 0;
}
System::FileType stat(const char* name, unsigned* length, bool tryDirectory)
System::FileType stat(const char* name, size_t* length, bool tryDirectory)
{
List<Entry>* node = findNode(name);
if (node) {
@ -413,7 +413,7 @@ class JarIndex {
*length = 0;
// try again with '/' appended
unsigned length = strlen(name);
size_t length = strlen(name);
RUNTIME_ARRAY(char, n, length + 2);
memcpy(RUNTIME_ARRAY_BODY(n), name, length);
RUNTIME_ARRAY_BODY(n)[length] = '/';
@ -455,7 +455,7 @@ class JarElement : public Element {
{
}
virtual const char* next(unsigned* size)
virtual const char* next(size_t* size)
{
if (position < index->position) {
List<JarIndex::Entry>* n = index->nodes + (position++);
@ -548,7 +548,7 @@ class JarElement : public Element {
}
virtual System::FileType stat(const char* name,
unsigned* length,
size_t* length,
bool tryDirectory)
{
init();
@ -629,16 +629,16 @@ class BuiltinElement : public JarElement {
void* p = library->resolve(symbolName);
if (p) {
uint8_t* (*function)(unsigned*);
uint8_t* (*function)(size_t*);
memcpy(&function, &p, BytesPerWord);
unsigned size;
size_t size = 0;
uint8_t* data = function(&size);
if (data) {
bool freePointer;
if (lzma) {
#ifdef AVIAN_USE_LZMA
unsigned outSize;
size_t outSize;
data = decodeLZMA(s, allocator, data, size, &outSize);
size = outSize;
freePointer = true;
@ -751,8 +751,8 @@ void addTokens(System* s,
bool continuationLine(const uint8_t* base,
unsigned total,
unsigned* start,
unsigned* length)
size_t* start,
size_t* length)
{
return readLine(base, total, start, length) and *length > 0
and base[*start] == ' ';
@ -778,8 +778,8 @@ void addJar(System* s,
System::Region* region = e->find("META-INF/MANIFEST.MF");
if (region) {
unsigned start = 0;
unsigned length;
size_t start = 0;
size_t length;
while (readLine(region->start(), region->length(), &start, &length)) {
unsigned multilineTotal = 0;
@ -789,8 +789,8 @@ void addJar(System* s,
reinterpret_cast<const char*>(region->start() + start),
PrefixLength) == 0) {
{
unsigned nextStart = start + length;
unsigned nextLength;
size_t nextStart = start + length;
size_t nextLength;
while (continuationLine(
region->start(), region->length(), &nextStart, &nextLength)) {
multilineTotal += nextLength;
@ -810,8 +810,8 @@ void addJar(System* s,
unsigned offset = lineLength;
{
unsigned nextStart = start + length;
unsigned nextLength;
size_t nextStart = start + length;
size_t nextLength;
while (continuationLine(
region->start(), region->length(), &nextStart, &nextLength)) {
unsigned continuationLength = nextLength - 1;
@ -880,7 +880,7 @@ void add(System* s,
memcpy(name, token, tokenLength);
name[tokenLength] = 0;
unsigned length;
size_t length;
switch (s->stat(name, &length)) {
case System::TypeFile: {
addJar(s, first, last, allocator, name, bootLibrary);
@ -934,7 +934,7 @@ class MyIterator : public Finder::IteratorImp {
{
}
virtual const char* next(unsigned* size)
virtual const char* next(size_t* size)
{
while (it) {
const char* v = it->next(size);
@ -1010,7 +1010,7 @@ class MyFinder : public Finder {
}
virtual System::FileType stat(const char* name,
unsigned* length,
size_t* length,
bool tryDirectory)
{
for (Element* e = path_; e; e = e->next) {
@ -1034,7 +1034,7 @@ class MyFinder : public Finder {
Element*& e = reinterpret_cast<Element*&>(finderElementPtr);
e = e ? e->next : path_;
for (; e; e = e->next) {
unsigned length;
size_t length;
System::FileType type = e->stat(name, &length, true);
if (type != System::TypeDoesNotExist) {
return e->urlPrefix();
@ -1047,7 +1047,7 @@ class MyFinder : public Finder {
virtual const char* sourceUrl(const char* name)
{
for (Element* e = path_; e; e = e->next) {
unsigned length;
size_t length;
System::FileType type = e->stat(name, &length, true);
if (type != System::TypeDoesNotExist) {
return e->sourceUrl();
@ -1096,7 +1096,7 @@ AVIAN_EXPORT Finder* makeFinder(System* s,
Finder* makeFinder(System* s,
Alloc* a,
const uint8_t* jarData,
unsigned jarLength)
size_t jarLength)
{
return new (a->allocate(sizeof(MyFinder))) MyFinder(s, a, jarData, jarLength);
}

View File

@ -29,11 +29,11 @@ namespace vm {
uint8_t* decodeLZMA(System* s,
avian::util::Alloc* a,
uint8_t* in,
unsigned inSize,
unsigned* outSize)
size_t inSize,
size_t* outSize)
{
const unsigned PropHeaderSize = 5;
const unsigned HeaderSize = 13;
const size_t PropHeaderSize = 5;
const size_t HeaderSize = 13;
int32_t outSize32 = read4(in + PropHeaderSize);
expect(s, outSize32 >= 0);

View File

@ -3810,10 +3810,10 @@ void Thread::init()
void* imagep = m->libraries->resolve(symbolName);
if (imagep) {
uint8_t* (*imageFunction)(unsigned*);
uint8_t* (*imageFunction)(size_t*);
memcpy(&imageFunction, &imagep, BytesPerWord);
unsigned size;
size_t size = 0;
uint8_t* imageBytes = imageFunction(&size);
if (lzma) {
#ifdef AVIAN_USE_LZMA
@ -3830,7 +3830,7 @@ void Thread::init()
if (codeFunctionName) {
void* codep = m->libraries->resolve(codeFunctionName);
if (codep) {
uint8_t* (*codeFunction)(unsigned*);
uint8_t* (*codeFunction)(size_t*);
memcpy(&codeFunction, &codep, BytesPerWord);
code = codeFunction(&size);

View File

@ -91,8 +91,8 @@ const char* mainClass(const char* jar)
System::Region* region = finder->find("META-INF/MANIFEST.MF");
if (region) {
unsigned start = 0;
unsigned length;
size_t start = 0;
size_t length;
while (readLine(region->start(), region->length(), &start, &length)) {
const unsigned PrefixLength = 12;
if (strncasecmp("Main-Class: ",
@ -226,8 +226,8 @@ int main(int ac, const char** av)
#define CLASSPATH_PROPERTY "-Djava.class.path="
unsigned classpathSize = strlen(classpath);
unsigned classpathPropertyBufferSize = sizeof(CLASSPATH_PROPERTY)
size_t classpathSize = strlen(classpath);
size_t classpathPropertyBufferSize = sizeof(CLASSPATH_PROPERTY)
+ classpathSize;
RUNTIME_ARRAY(char, classpathPropertyBuffer, classpathPropertyBufferSize);

View File

@ -654,7 +654,7 @@ class MySystem : public System {
return sigaction(signals[index], &sa, oldHandlers + index) == 0;
}
virtual void* tryAllocate(unsigned sizeInBytes)
virtual void* tryAllocate(size_t sizeInBytes)
{
return malloc(sizeInBytes);
}
@ -808,7 +808,7 @@ class MySystem : public System {
return status;
}
virtual FileType stat(const char* name, unsigned* length)
virtual FileType stat(const char* name, size_t* length)
{
#ifdef __FreeBSD__
// Now the hack below causes the error "Dereferencing type-punned

View File

@ -664,7 +664,7 @@ class MySystem : public System {
assertT(this, mutex);
}
virtual void* tryAllocate(unsigned sizeInBytes)
virtual void* tryAllocate(size_t sizeInBytes)
{
return malloc(sizeInBytes);
}
@ -862,7 +862,7 @@ class MySystem : public System {
return status;
}
virtual FileType stat(const char* name, unsigned* length)
virtual FileType stat(const char* name, size_t* length)
{
size_t nameLen = strlen(name) * 2;
RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1);

View File

@ -348,13 +348,13 @@ GcTriple* makeCodeImage(Thread* t,
roots(t)->bootLoader()->as<GcSystemClassLoader>(t)->finder());
for (Finder::Iterator it(finder); it.hasMore();) {
unsigned nameSize = 0;
size_t nameSize = 0;
const char* name = it.next(&nameSize);
if (endsWith(".class", name, nameSize)
and (className == 0 or strncmp(name, className, nameSize - 6) == 0)) {
if (false) {
fprintf(stderr, "pass 1 %.*s\n", nameSize - 6, name);
fprintf(stderr, "pass 1 %.*s\n", (int)nameSize - 6, name);
}
GcClass* c
= resolveSystemClass(t,
@ -686,13 +686,13 @@ GcTriple* makeCodeImage(Thread* t,
}
for (Finder::Iterator it(finder); it.hasMore();) {
unsigned nameSize = 0;
size_t nameSize = 0;
const char* name = it.next(&nameSize);
if (endsWith(".class", name, nameSize)
and (className == 0 or strncmp(name, className, nameSize - 6) == 0)) {
if (false) {
fprintf(stderr, "pass 2 %.*s\n", nameSize - 6, name);
fprintf(stderr, "pass 2 %.*s\n", (int)nameSize - 6, name);
}
GcClass* c = 0;
PROTECT(t, c);