@@ -158,33 +158,41 @@ PyObject *pocky_bufpair_copy_from_device(pocky_bufpair_object *self, PyObject *a
158
158
cl_int err ;
159
159
cl_uint idx ;
160
160
char buf [BUFSIZ ];
161
- PyObject * device , * cap ;
161
+ PyObject * device = NULL ;
162
162
cl_device_id dev = NULL ;
163
163
164
- if (!PyArg_ParseTuple (args , "O!" , pocky_device_type , & device )) return NULL ;
164
+ if (!PyArg_ParseTuple (args , "| O!" , pocky_device_type , & device )) return NULL ;
165
165
166
- cap = PyStructSequence_GetItem (device , 0 );
167
- if (!PyCapsule_CheckExact (cap ))
166
+ if (device )
168
167
{
169
- PyErr_SetString (PyExc_TypeError , pocky_ocl_msg_not_a_capsule );
170
- return NULL ;
171
- }
168
+ PyObject * cap ;
169
+
170
+ cap = PyStructSequence_GetItem (device , 0 );
171
+ if (!PyCapsule_CheckExact (cap ))
172
+ {
173
+ PyErr_SetString (PyExc_TypeError , pocky_ocl_msg_not_a_capsule );
174
+ return NULL ;
175
+ }
172
176
173
- dev = PyCapsule_GetPointer (cap , "DeviceID" );
177
+ dev = PyCapsule_GetPointer (cap , "DeviceID" );
178
+ }
174
179
175
180
for (idx = 0 ; idx < self -> context -> num_queues ; ++ idx )
176
181
{
177
182
cl_device_id qdev = NULL ;
178
183
cl_command_queue queue = self -> context -> queues [idx ];
179
184
180
- err = clGetCommandQueueInfo (queue ,
181
- CL_QUEUE_DEVICE , sizeof (cl_device_id ), & qdev , NULL );
182
- if (err != CL_SUCCESS )
185
+ if (device )
183
186
{
184
- snprintf (buf , BUFSIZ , pocky_ocl_fmt_internal ,
185
- pocky_opencl_error_to_string (err ), err );
186
- PyErr_SetString (pocky_ocl_error , buf );
187
- return NULL ;
187
+ err = clGetCommandQueueInfo (queue ,
188
+ CL_QUEUE_DEVICE , sizeof (cl_device_id ), & qdev , NULL );
189
+ if (err != CL_SUCCESS )
190
+ {
191
+ snprintf (buf , BUFSIZ , pocky_ocl_fmt_internal ,
192
+ pocky_opencl_error_to_string (err ), err );
193
+ PyErr_SetString (pocky_ocl_error , buf );
194
+ return NULL ;
195
+ }
188
196
}
189
197
190
198
if (qdev == dev )
0 commit comments