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

Function srd_decoder_load_all_zip_path

libsigrokdecode4DSL/decoder.c:1019–1101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1017}
1018
1019static void srd_decoder_load_all_zip_path(char *zip_path)
1020{
1021 PyObject *zipimport_mod, *zipimporter_class, *zipimporter;
1022 PyObject *prefix_obj, *files, *key, *value, *set, *modname;
1023 Py_ssize_t pos = 0;
1024 char *prefix;
1025 size_t prefix_len;
1026 PyGILState_STATE gstate;
1027
1028 set = files = prefix_obj = zipimporter = zipimporter_class = NULL;
1029
1030 gstate = PyGILState_Ensure();
1031
1032 zipimport_mod = py_import_by_name("zipimport");
1033 if (zipimport_mod == NULL)
1034 goto err_out;
1035
1036 zipimporter_class = PyObject_GetAttrString(zipimport_mod, "zipimporter");
1037 if (zipimporter_class == NULL)
1038 goto err_out;
1039
1040 zipimporter = PyObject_CallFunction(zipimporter_class, "s", zip_path);
1041 if (zipimporter == NULL)
1042 goto err_out;
1043
1044 prefix_obj = PyObject_GetAttrString(zipimporter, "prefix");
1045 if (prefix_obj == NULL)
1046 goto err_out;
1047
1048 files = PyObject_GetAttrString(zipimporter, "_files");
1049 if (files == NULL || !PyDict_Check(files))
1050 goto err_out;
1051
1052 set = PySet_New(NULL);
1053 if (set == NULL)
1054 goto err_out;
1055
1056 if (py_str_as_str(prefix_obj, &prefix) != SRD_OK)
1057 goto err_out;
1058
1059 prefix_len = strlen(prefix);
1060
1061 while (PyDict_Next(files, &pos, &key, &value)) {
1062 char *path, *slash;
1063 if (py_str_as_str(key, &path) == SRD_OK) {
1064 if (strlen(path) > prefix_len
1065 && memcmp(path, prefix, prefix_len) == 0
1066 && (slash = strchr(path + prefix_len, '/'))) {
1067
1068 modname = PyUnicode_FromStringAndSize(path + prefix_len,
1069 slash - (path + prefix_len));
1070 if (modname == NULL) {
1071 PyErr_Clear();
1072 } else {
1073 PySet_Add(set, modname);
1074 Py_DECREF(modname);
1075 }
1076 }

Callers 1

Calls 3

py_import_by_nameFunction · 0.85
py_str_as_strFunction · 0.85
srd_decoder_loadFunction · 0.85

Tested by

no test coverage detected