@@ 329,7 329,7 @@ static const char ulong_type[] = { _C_UL
/* Build FFI argumentlist description */
LOG("cif will have num args: %d\n", numargs);
- cl_arg_types = malloc(sizeof(ffi_type*) * (numargs));
+ cl_arg_types = calloc(sizeof(ffi_type*) * (numargs), 1);
if (cl_arg_types == NULL) {
free(cl_ret_type);
Pike_error("make_ffi_for_method: Unable to allocate memory.\n");
@@ 347,7 347,7 @@ printf("arg type %d is null\n", i);
}
/* Create the invocation description */
- cif = malloc(sizeof(*cif));
+ cif = calloc(sizeof(*cif), 1);
if (cif == NULL) {
free(cl_arg_types);
Pike_error("make_ffi_for_method: Unable to allocate memory.\n");
@@ 384,7 384,7 @@ void * make_create_stub(struct program *
if(init_cif == NULL)
{
- cl_arg_types = malloc(sizeof(ffi_type *) * 2);
+ cl_arg_types = calloc(sizeof(ffi_type *) * 2, 1);
if(cl_arg_types == NULL)
{
Pike_error("make_init_stub: out of memory\n");
@@ 393,7 393,7 @@ void * make_create_stub(struct program *
cl_arg_types[0] = &ffi_type_pointer;
cl_arg_types[1] = &ffi_type_pointer;
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(1, sizeof(ffi_cif));
rv = ffi_prep_cif(init_cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, cl_arg_types);
if(rv != FFI_OK)
@@ 405,7 405,7 @@ void * make_create_stub(struct program *
closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc);
- if(closure == ((void*)-1))
+ if(!closure)
{
Pike_error("quick_make_stub: out of memory\n");
}
@@ 446,7 446,7 @@ void * make_class_stub(struct program *
if(init_cif == NULL)
{
- cl_arg_types = malloc(sizeof(ffi_type *) * 2);
+ cl_arg_types = calloc(sizeof(ffi_type *) * 2, 1);
if(cl_arg_types == NULL)
{
Pike_error("make_init_stub: out of memory\n");
@@ 455,7 455,7 @@ void * make_class_stub(struct program *
cl_arg_types[0] = &ffi_type_pointer;
cl_arg_types[1] = &ffi_type_pointer;
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(sizeof(ffi_cif), 1);
rv = ffi_prep_cif(init_cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, cl_arg_types);
if(rv != FFI_OK)
@@ 467,7 467,7 @@ void * make_class_stub(struct program *
closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc);
- if(closure == ((void*)-1))
+ if(!closure)
{
Pike_error("quick_make_stub: out of memory\n");
}
@@ 528,7 528,7 @@ void * make_class_func_stub(struct progr
int numargs;
methodSig = [NSMethodSignature signatureWithObjCTypes: methodTypes];
numargs = [methodSig numberOfArguments];
- cl_arg_types = malloc(sizeof(ffi_type *) * numargs);
+ cl_arg_types = calloc(sizeof(ffi_type *) * numargs, 1);
if(cl_arg_types == NULL)
{
Pike_error("make_init_stub: out of memory\n");
@@ 593,7 593,7 @@ void * make_class_func_stub(struct progr
}
}
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(sizeof(ffi_cif), 1);
rv = ffi_prep_cif(init_cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, cl_arg_types);
if(rv != FFI_OK)
@@ 605,7 605,7 @@ void * make_class_func_stub(struct progr
closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc);
- if(closure == ((void*)-1))
+ if(!closure)
{
Pike_error("quick_make_stub: out of memory\n");
}
@@ 648,7 648,7 @@ void * make_dynamic_method_stub(char * f
if(init_cif == NULL)
{
- cl_arg_types = malloc(sizeof(ffi_type *));
+ cl_arg_types = calloc(sizeof(ffi_type *), 1);
if(cl_arg_types == NULL)
{
Pike_error("make_init_stub: out of memory\n");
@@ 656,7 656,7 @@ void * make_dynamic_method_stub(char * f
cl_arg_types[0] = &ffi_type_pointer;
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(sizeof(ffi_cif), 1);
rv = ffi_prep_cif(init_cif, FFI_DEFAULT_ABI, 1, &ffi_type_pointer, cl_arg_types);
if(rv != FFI_OK)
@@ 668,7 668,7 @@ void * make_dynamic_method_stub(char * f
closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc);
- if(closure == ((void*)-1))
+ if(!closure)
{
Pike_error("quick_make_stub: out of memory\n");
}
@@ 706,7 706,7 @@ void * quick_make_stub(void * dta, void
if(init_cif == NULL)
{
- cl_arg_types = malloc(sizeof(ffi_type *) * 2);
+ cl_arg_types = calloc(sizeof(ffi_type *) * 2, 1);
if(cl_arg_types == NULL)
{
Pike_error("quick_make_stub: out of memory\n");
@@ 715,7 715,7 @@ void * quick_make_stub(void * dta, void
cl_arg_types[0] = &ffi_type_pointer;
cl_arg_types[1] = &ffi_type_uint32;
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(sizeof(ffi_cif), 1);
rv = ffi_prep_cif(init_cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, cl_arg_types);
if(rv != FFI_OK)
@@ 765,7 765,7 @@ void * make_static_stub(void * dta, void
if(init_cif == NULL)
{
- cl_arg_types = malloc(sizeof(ffi_type *) * 2);
+ cl_arg_types = calloc(sizeof(ffi_type *) * 2, 1);
if(cl_arg_types == NULL)
{
Pike_error("quick_make_stub: out of memory\n");
@@ 774,7 774,7 @@ void * make_static_stub(void * dta, void
cl_arg_types[0] = &ffi_type_pointer;
cl_arg_types[1] = &ffi_type_uint32;
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(sizeof(ffi_cif), 1);
rv = ffi_prep_cif(init_cif, FFI_DEFAULT_ABI, 2, &ffi_type_void, cl_arg_types);
if(rv != FFI_OK)
@@ 786,7 786,7 @@ void * make_static_stub(void * dta, void
closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc);
- if(closure == ((void*)-1))
+ if(!closure)
{
Pike_error("quick_make_stub: out of memory\n");
}
@@ 826,7 826,7 @@ void * make_static_stub(void * dta, void
ffi_type* cl_ret_type;
const char* rettype;
- cl_arg_types = malloc(sizeof(ffi_type *)*2);
+ cl_arg_types = calloc(sizeof(ffi_type *)*2, 1);
if(cl_arg_types == NULL)
{
Pike_error("make_static_stub: out of memory\n");
@@ 835,7 835,7 @@ void * make_static_stub(void * dta, void
// cl_arg_types[0] = &ffi_type_pointer;
cl_arg_types[0] = &ffi_type_uint32;
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(sizeof(ffi_cif), 1);
if(init_cif == NULL) {
Pike_error("make_static_stub: out of memory\n");
@@ 849,13 849,11 @@ void * make_static_stub(void * dta, void
}
// Allocate a page to hold the closure with read and write permissions.
- if ((closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc))
- == (void*)-1)
+ if (!(closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc)))
{
LOG("error mmap%s\n", "");
// Check errno and handle the error.
}
-// closure = malloc(sizeof(ffi_closure));
if(closure == NULL)
{
@@ 892,7 890,7 @@ ffi_closure * make_static_stub3(void * d
ffi_type* cl_ret_type;
const char* rettype;
- cl_arg_types = malloc(sizeof(ffi_type *)*2);
+ cl_arg_types = calloc(sizeof(ffi_type *)*2, 1);
if(cl_arg_types == NULL)
{
Pike_error("quick_make_stub: out of memory\n");
@@ 901,7 899,7 @@ ffi_closure * make_static_stub3(void * d
// cl_arg_types[0] = &ffi_type_pointer;
cl_arg_types[0] = &ffi_type_uint32;
- init_cif = malloc(sizeof(ffi_cif));
+ init_cif = calloc(sizeof(ffi_cif), 1);
rv = ffi_prep_cif(init_cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, cl_arg_types);
if(rv != FFI_OK)
@@ 911,8 909,8 @@ ffi_closure * make_static_stub3(void * d
}
// Allocate a page to hold the closure with read and write permissions.
- if ((closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc)
- ) == (void*)-1)
+ if (!(closure = ffi_closure_alloc(sizeof(ffi_closure), &codeloc)
+ ) )
{
LOG("error mmap%s\n", "");
// Check errno and handle the error.
@@ 931,7 929,7 @@ ffi_closure * make_static_stub3(void * d
free(closure);
Pike_error("Cannot create FFI closure.\n");
}
-
+
#if 0
// Ensure that the closure will execute on all architectures.
if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1)