--- OpenCL/OpenCL.xs 2012/05/05 02:30:27 1.69 +++ OpenCL/OpenCL.xs 2012/05/05 02:33:55 1.70 @@ -1422,35 +1422,32 @@ void program_with_binary (OpenCL::Context self, SV *devices, SV *binaries) PPCODE: - if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) - croak ("OpenCL::Context::program_with_binary: devices must be specified as reference to an array of device objects"); - - devices = SvRV (devices); + cl_uint device_count; + cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); if (!SvROK (binaries) || SvTYPE (SvRV (binaries)) != SVt_PVAV) croak ("OpenCL::Context::program_with_binary: binaries must be specified as reference to an array of strings"); binaries = SvRV (binaries); - if (av_len ((AV *)devices) != av_len ((AV *)binaries)) + if (device_count != av_len ((AV *)binaries) + 1) croak ("OpenCL::Context::program_with_binary: differing numbers of devices and binaries are not allowed"); - int count = av_len ((AV *)devices) + 1; - cl_device_id *device_list = tmpbuf (sizeof (*device_list) * count); - size_t *length_list = tmpbuf (sizeof (*length_list) * count); - const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * count); - cl_int *status_list = tmpbuf (sizeof (*status_list) * count); + size_t *length_list = tmpbuf (sizeof (*length_list) * device_count); + const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * device_count); + cl_int *status_list = tmpbuf (sizeof (*status_list) * device_count); int i; - for (i = 0; i < count; ++i) + for (i = 0; i < device_count; ++i) { - device_list [i] = SvCLOBJ ("OpenCL::Context::program_with_binary", "devices", *av_fetch ((AV *)devices, i, 0), "OpenCL::Device"); STRLEN len; binary_list [i] = (const unsigned char *)SvPVbyte (*av_fetch ((AV *)binaries, i, 0), len); length_list [i] = len; } - NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, count, device_list, length_list, binary_list, GIMME_V == G_ARRAY ? status_list : 0, &res)); + NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, device_count, device_list, + length_list, binary_list, + GIMME_V == G_ARRAY ? status_list : 0, &res)); EXTEND (SP, 2); PUSH_CLOBJ (stash_program, prog); @@ -1460,7 +1457,7 @@ AV *av = newAV (); PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); - for (i = count; i--; ) + for (i = device_count; i--; ) av_store (av, i, newSViv (status_list [i])); }