Mercurial > hg > audiodb
comparison bindings/python/pyadbmodule.c @ 719:e3f1cf653c30
wooo! direct insert works! at least for the rather limited cases I've tests.
Bad news is that I seem to have found a rather nasty bug in the query code I wrote back in september.
(segfaults around line 471 if the query returns no results...)
author | map01bf |
---|---|
date | Fri, 25 Jun 2010 09:08:56 +0000 |
parents | 14568e432e73 |
children | 2fad8cfdb2d8 |
comparison
equal
deleted
inserted
replaced
718:14568e432e73 | 719:e3f1cf653c30 |
---|---|
209 current_db = (adb_t *)PyCObject_AsVoidPtr(incoming); | 209 current_db = (adb_t *)PyCObject_AsVoidPtr(incoming); |
210 status = (adb_status_t *)malloc(sizeof(adb_status_t)); | 210 status = (adb_status_t *)malloc(sizeof(adb_status_t)); |
211 //verify that the data to be inserted is the correct size for the database. | 211 //verify that the data to be inserted is the correct size for the database. |
212 | 212 |
213 ins = (adb_datum_t *)malloc(sizeof(adb_datum_t)); | 213 ins = (adb_datum_t *)malloc(sizeof(adb_datum_t)); |
214 if (!PyArray_AsCArray(&features, &(ins->data), dims, 1, descr)){ | 214 if (PyArray_AsCArray(&features, &(ins->data), dims, 1, descr)){ |
215 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array."); | 215 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array."); |
216 return NULL; | 216 return NULL; |
217 } | 217 } |
218 | 218 |
219 if (power){ | 219 if (power){ |
220 if (!PyArray_AsCArray(&power, &(ins->power), dims, 1, descr)){ | 220 if (PyArray_AsCArray(&power, &(ins->power), dims, 1, descr)){ |
221 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array."); | 221 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array."); |
222 return NULL; | 222 return NULL; |
223 } | 223 } |
224 }else{ | |
225 ins->power=NULL; | |
224 } | 226 } |
225 | 227 |
226 if (times){ | 228 if (times){ |
227 if (!PyArray_AsCArray(×, &(ins->times), dims, 1, descr)){ | 229 if (PyArray_AsCArray(×, &(ins->times), dims, 1, descr)){ |
228 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array."); | 230 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array."); |
229 return NULL; | 231 return NULL; |
230 } | 232 } |
233 }else{ | |
234 ins->times=NULL; | |
231 } | 235 } |
232 ins->key = key; | 236 ins->key = key; |
233 ins->nvectors = (uint32_t)nVect; | 237 ins->nvectors = (uint32_t)nVect; |
234 ins->dim = (uint32_t)nDims; | 238 ins->dim = (uint32_t)nDims; |
235 //printf("features::%s\npower::%s\nkey::%s\ntimes::%s\n", ins->features, ins->power, ins->key, ins->times); | 239 //printf("features::%s\npower::%s\nkey::%s\ntimes::%s\n", ins->features, ins->power, ins->key, ins->times); |
236 ok = audiodb_insert_datum(current_db, ins);//(current_db, ins); | 240 ok = audiodb_insert_datum(current_db, ins);//(current_db, ins); |
237 return PyBool_FromLong(ok-1); | 241 return PyInt_FromLong(ok); |
238 | 242 |
239 } | 243 } |
240 | 244 |
241 /* insert feature data stored in a file */ | 245 /* insert feature data stored in a file */ |
242 /* this is a bit gross, */ | 246 /* this is a bit gross, */ |