MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / get_annotations

Function get_annotations

libsigrokdecode4DSL/decoder.c:411–483  ·  view source on GitHub ↗

Convert annotation class attribute to GSList of char **. */

Source from the content-addressed store, hash-verified

409
410/* Convert annotation class attribute to GSList of char **. */
411static int get_annotations(struct srd_decoder *dec)
412{
413 PyObject *py_annlist, *py_ann;
414 GSList *annotations;
415 char **annpair;
416 ssize_t i;
417 int ann_type = 7;
418 unsigned int j;
419 PyGILState_STATE gstate;
420
421 assert(dec);
422
423 gstate = PyGILState_Ensure();
424
425 if (!PyObject_HasAttrString(dec->py_dec, "annotations")) {
426 PyGILState_Release(gstate);
427 return SRD_OK;
428 }
429
430 annotations = NULL;
431
432 py_annlist = PyObject_GetAttrString(dec->py_dec, "annotations");
433 if (!py_annlist)
434 goto except_out;
435
436 if (!PyTuple_Check(py_annlist)) {
437 srd_err("Protocol decoder %s annotations should "
438 "be a tuple.", dec->name);
439 goto err_out;
440 }
441
442 for (i = 0; i < PyTuple_Size(py_annlist); i++) {
443 py_ann = PyTuple_GetItem(py_annlist, i);
444 if (!py_ann)
445 goto except_out;
446
447 if (!PyTuple_Check(py_ann) || (PyTuple_Size(py_ann) != 3 && PyTuple_Size(py_ann) != 2)) {
448 srd_err("Protocol decoder %s annotation %zd should "
449 "be a tuple with two or three elements.",
450 dec->name, i + 1);
451 goto err_out;
452 }
453 if (py_strseq_to_char(py_ann, &annpair) != SRD_OK)
454 goto err_out;
455
456 annotations = g_slist_prepend(annotations, annpair);
457
458 if (PyTuple_Size(py_ann) == 3) {
459 ann_type = 0;
460 for (j = 0; j < strlen(annpair[0]); j++)
461 ann_type = ann_type * 10 + (annpair[0][j] - '0');
462 dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
463 } else if (PyTuple_Size(py_ann) == 2) {
464 dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
465 ann_type++;
466 }
467 }
468 dec->annotations = annotations;

Callers 1

srd_decoder_loadFunction · 0.85

Calls 2

py_strseq_to_charFunction · 0.85
srd_exception_catchFunction · 0.85

Tested by

no test coverage detected