Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ follows.
unsigned total = sel_copyTypes_np("alloc", types, total);
if (total > 16)
{
types = calloc(sizeof(char*), total);
types = calloc(total, sizeof(char*));
sel_copyTypes_np("alloc", types, total);
}
// Do stuff with the types.
Expand Down
2 changes: 1 addition & 1 deletion Test/BoxedForeignException.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

int throw(void)
{
struct foreign_exception *foreign_exception = calloc(sizeof(struct foreign_exception), 1);
struct foreign_exception *foreign_exception = calloc(1, sizeof(struct foreign_exception));
foreign_exception->header.exception_class = 42;
foreign_exception->x = 12;
_Unwind_RaiseException(&foreign_exception->header);
Expand Down
69 changes: 33 additions & 36 deletions arc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ - (void)release;
template<typename T>
static inline T* new_zeroed()
{
return static_cast<T*>(calloc(sizeof(T), 1));
return static_cast<T*>(calloc(1, sizeof(T)));
}

static inline struct arc_tls* getARCThreadData(void)
Expand Down Expand Up @@ -737,7 +737,7 @@ void deallocate(T* p, std::size_t)
* exists.
*/
__attribute__((always_inline))
static BOOL loadWeakPointer(id *addr, id *obj, WeakRef **ref)
static inline BOOL loadWeakPointer(id *addr, id *obj, WeakRef **ref)
{
id oldObj = *addr;
if (oldObj == nil)
Expand Down Expand Up @@ -779,40 +779,37 @@ static BOOL setObjectHasWeakRefs(id obj)
if (obj && cls && objc_test_class_flag(cls, objc_class_flag_fast_arc))
{
uintptr_t *refCount = ((uintptr_t*)obj) - 1;
if (obj)
{
uintptr_t refCountVal = __sync_fetch_and_add(refCount, 0);
uintptr_t newVal = refCountVal;
do {
refCountVal = newVal;
size_t realCount = refCountVal & refcount_mask;
// If this object has already been deallocated (or is in the
// process of being deallocated) then don't bother storing it.
if (realCount == refcount_mask)
{
obj = nil;
cls = Nil;
break;
}
// The weak ref flag is monotonic (it is set, never cleared) so
// don't bother trying to re-set it.
if ((refCountVal & weak_mask) == weak_mask)
{
break;
}
// Set the flag in the reference count to indicate that a weak
// reference has been taken.
//
// We currently hold the weak ref lock, so another thread
// racing to deallocate this object will have to wait to do so
// if we manage to do the reference count update first. This
// shouldn't be possible, because `obj` should be a strong
// reference and so it shouldn't be possible to deallocate it
// while we're assigning it.
uintptr_t updated = ((uintptr_t)realCount | weak_mask);
newVal = __sync_val_compare_and_swap(refCount, refCountVal, updated);
} while (newVal != refCountVal);
}
uintptr_t refCountVal = __sync_fetch_and_add(refCount, 0);
uintptr_t newVal = refCountVal;
do {
refCountVal = newVal;
size_t realCount = refCountVal & refcount_mask;
// If this object has already been deallocated (or is in the
// process of being deallocated) then don't bother storing it.
if (realCount == refcount_mask)
{
obj = nil;
cls = Nil;
break;
}
// The weak ref flag is monotonic (it is set, never cleared) so
// don't bother trying to re-set it.
if ((refCountVal & weak_mask) == weak_mask)
{
break;
}
// Set the flag in the reference count to indicate that a weak
// reference has been taken.
//
// We currently hold the weak ref lock, so another thread
// racing to deallocate this object will have to wait to do so
// if we manage to do the reference count update first. This
// shouldn't be possible, because `obj` should be a strong
// reference and so it shouldn't be possible to deallocate it
// while we're assigning it.
uintptr_t updated = ((uintptr_t)realCount | weak_mask);
newVal = __sync_val_compare_and_swap(refCount, refCountVal, updated);
} while (newVal != refCountVal);
}
return isGlobalObject;
}
Expand Down
2 changes: 1 addition & 1 deletion class_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ int objc_getClassList(Class *buffer, int bufferLen)
Class *objc_copyClassList(unsigned int *outCount)
{
int count = class_table->table_used;
Class *buffer = calloc(sizeof(Class), count);
Class *buffer = calloc(count, sizeof(Class));
if (NULL != outCount)
{
*outCount = count;
Expand Down
5 changes: 0 additions & 5 deletions dtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,6 @@ PRIVATE void objc_resize_dtables(uint32_t newSize)
}
}

PRIVATE dtable_t objc_copy_dtable_for_class(dtable_t old, Class cls)
{
return SparseArrayCopy(old);
}

PRIVATE void free_dtable(dtable_t dtable)
{
SparseArrayDestroy(dtable);
Expand Down
4 changes: 2 additions & 2 deletions gc_none.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static id allocate_class(Class cls, size_t extraBytes)
_aligned_malloc(size, 32);
memset(addr, 0, size);
#else
calloc(size, 1);
calloc(1, size);
#endif
return (id)(addr + 1);
}
Expand All @@ -32,7 +32,7 @@ static void free_object(id obj)

static void *alloc(size_t size)
{
return calloc(size, 1);
return calloc(1, size);
}

void objc_registerThreadWithCollector(void) {}
Expand Down
4 changes: 2 additions & 2 deletions legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static struct objc_method_list *upgradeMethodList(struct objc_method_list_gcc *o
{
return NULL;
}
struct objc_method_list *l = calloc(sizeof(struct objc_method_list) + old->count * sizeof(struct objc_method), 1);
struct objc_method_list *l = calloc(1, sizeof(struct objc_method_list) + old->count * sizeof(struct objc_method));
l->count = old->count;
if (old->next)
{
Expand Down Expand Up @@ -343,7 +343,7 @@ PRIVATE struct objc_class_gsv1* objc_legacy_class_for_class(Class cls)

PRIVATE Class objc_upgrade_class(struct objc_class_gsv1 *oldClass)
{
Class cls = calloc(sizeof(struct objc_class), 1);
Class cls = calloc(1, sizeof(struct objc_class));
cls->isa = oldClass->isa;
// super_class is left nil and we upgrade it later.
cls->name = oldClass->name;
Expand Down
4 changes: 2 additions & 2 deletions properties.m
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ objc_property_t class_getProperty(Class cls, const char *name)
{
return NULL;
}
objc_property_t *list = calloc(sizeof(objc_property_t), count);
objc_property_t *list = calloc(count, sizeof(objc_property_t));
unsigned int out = 0;
for (struct objc_property_list *l=properties ; NULL!=l ; l=l->next)
{
Expand Down Expand Up @@ -423,7 +423,7 @@ objc_property_t class_getProperty(Class cls, const char *name)
}
count++;
}
objc_property_attribute_t *propAttrs = calloc(sizeof(objc_property_attribute_t), count);
objc_property_attribute_t *propAttrs = calloc(count, sizeof(objc_property_attribute_t));
memcpy(propAttrs, attrs, count * sizeof(objc_property_attribute_t));
if (NULL != outCount)
{
Expand Down
8 changes: 4 additions & 4 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ struct objc_method_description *protocol_copyMethodDescriptionList(Protocol *p,

*count = list->count;
struct objc_method_description *out =
calloc(sizeof(struct objc_method_description), list->count);
calloc(list->count, sizeof(struct objc_method_description));
for (int i=0 ; i < (list->count) ; i++)
{
out[i].name = protocol_method_at_index(list, i)->selector;
Expand All @@ -335,7 +335,7 @@ Protocol*__unsafe_unretained* protocol_copyProtocolList(Protocol *p, unsigned in
}

*count = p->protocol_list->count;
Protocol **out = calloc(sizeof(Protocol*), p->protocol_list->count);
Protocol **out = calloc(p->protocol_list->count, sizeof(Protocol*));
for (int i=0 ; i<p->protocol_list->count ; i++)
{
out[i] = (Protocol*)p->protocol_list->list[i];
Expand Down Expand Up @@ -370,7 +370,7 @@ objc_property_t *protocol_copyPropertyList2(Protocol *p, unsigned int *outCount,
{
return NULL;
}
objc_property_t *list = calloc(sizeof(objc_property_t), count);
objc_property_t *list = calloc(count, sizeof(objc_property_t));
unsigned int out = 0;
for (struct objc_property_list *l=properties ; l!=NULL ; l=l->next)
{
Expand Down Expand Up @@ -506,7 +506,7 @@ Protocol*__unsafe_unretained* objc_copyProtocolList(unsigned int *outCount)
{
LOCK_FOR_SCOPE(&protocol_table_lock);
unsigned int total = known_protocol_table->table_used;
Protocol **p = calloc(sizeof(Protocol*), known_protocol_table->table_used);
Protocol **p = calloc(known_protocol_table->table_used, sizeof(Protocol*));

struct protocol_table_enumerator *e = NULL;
Protocol *next;
Expand Down
2 changes: 1 addition & 1 deletion sarray2.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ PRIVATE void SparseArrayInsert(SparseArray * sarray, uint32_t index, void *value

PRIVATE SparseArray *SparseArrayCopy(SparseArray * sarray)
{
SparseArray *copy = calloc(sizeof(SparseArray), 1);
SparseArray *copy = calloc(1, sizeof(SparseArray));
memcpy(copy, sarray, sizeof(SparseArray));
copy->refCount = 1;
// If the sarray has children, increase their refcounts and link them
Expand Down