From f14a7dade0b0e3e0db746524c217595c57c11da3 Mon Sep 17 00:00:00 2001 From: Stijn Van Campenhout Date: Wed, 1 Jul 2020 13:28:14 +0200 Subject: [PATCH] use a for..break because we can't depend on count as commented in http://aspell.net/sf-issue-files/11b76e92/632d/test.c ` aspell_dict_info_list_size(dlist)` will allways return `0` for some reason. execute `aspell_dict_info_enumeration_next(dels)` until it returns nil. --- aspell.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/aspell.go b/aspell.go index c675522..ffd4dd3 100644 --- a/aspell.go +++ b/aspell.go @@ -180,26 +180,24 @@ type Dict struct { // Dicts returns the list of available aspell dictionaries. func Dicts() []Dict { + var result []Dict config := C.new_aspell_config() dlist := C.get_aspell_dict_info_list(config) C.delete_aspell_config(config) - count := int(C.aspell_dict_info_list_size(dlist)) - result := make([]Dict, count) - dels := C.aspell_dict_info_list_elements(dlist) - for i := 0; i < count; i++ { + for { entry := C.aspell_dict_info_enumeration_next(dels) if entry == nil { break } - result[i] = Dict{ + result = append(result, Dict{ name: C.GoString(entry.name), code: C.GoString(entry.code), jargon: C.GoString(entry.jargon), size: C.GoString(entry.size_str), module: C.GoString(entry.module.name), - } + }) } C.delete_aspell_dict_info_enumeration(dels)