Re: [Iup-users] IUP iupDlgListDestroyAll refactored
1) OK 2) No. During a IupDestroy, one of the other handles in the array could be destroyed, so the check must remain. Best, Scuri Em sáb., 11 de jul. de 2020 às 00:31, Ranier Vilela escreveu: > De: Antonio Scuri > Enviado: sexta-feira, 29 de maio de 2020 13:12 > Para: IUP discussion list. > Assunto: Re: [Iup-users] IUP iupDlgListDestroyAll refactored > > > Because IupDestroy will also remove the dialog from that list and > list->next will be invalid. > Like this, it worked without problems. > > void iupDlgListDestroyAll(void) > { > int i, count = 0; > Ihandle** ih_array = (Ihandle**)malloc(idlg_count * sizeof(Ihandle*)); > Idiallst *list; > for (list = idlglist; list; list = list->next) > { > if (iupObjectCheck(list->ih)) > { > ih_array[count] = list->ih; > ++count; > } > } > > for (i = 0; i < count; ++i) > { > IupDestroy(ih_array[i]); /* this will also destroy the list */ > } > > free(ih_array); > } > > Advantagens: > 1. Avoid assign variable count with i value; > 2. Avoid call iupObjectCheck for every ih_array[i], since they have all > been verified. > > regards, > Ranier Vilela > > ___ > Iup-users mailing list > Iup-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/iup-users > ___ Iup-users mailing list Iup-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iup-users
Re: [Iup-users] IUP iupDlgListDestroyAll refactored
De: Antonio Scuri Enviado: sexta-feira, 29 de maio de 2020 13:12 Para: IUP discussion list. Assunto: Re: [Iup-users] IUP iupDlgListDestroyAll refactored > Because IupDestroy will also remove the dialog from that list and list->next > will be invalid. Like this, it worked without problems. void iupDlgListDestroyAll(void) { int i, count = 0; Ihandle** ih_array = (Ihandle**)malloc(idlg_count * sizeof(Ihandle*)); Idiallst *list; for (list = idlglist; list; list = list->next) { if (iupObjectCheck(list->ih)) { ih_array[count] = list->ih; ++count; } } for (i = 0; i < count; ++i) { IupDestroy(ih_array[i]); /* this will also destroy the list */ } free(ih_array); } Advantagens: 1. Avoid assign variable count with i value; 2. Avoid call iupObjectCheck for every ih_array[i], since they have all been verified. regards, Ranier Vilela ___ Iup-users mailing list Iup-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iup-users
Re: [Iup-users] IUP iupDlgListDestroyAll refactored
Because IupDestroy will also remove the dialog from that list and list->next will be invalid. Best, Scuri Em qui., 28 de mai. de 2020 às 18:55, Ranier Vilela escreveu: > Hi Scuri, > > Is there a special condition, so that the function below is not written > like this? > > usr\iup_dlglist.c: > void iupDlgListDestroyAll(void) > { > Idiallst *list; > for (list = idlglist; list; list = list->next) > { > if (iupObjectCheck(list->ih)) > { > IupDestroy(list->ih); /* this will also destroy the list */ > list->ih = NULL; > } > } > } > > regards, > Ranier Vilela > > ___ > Iup-users mailing list > Iup-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/iup-users > ___ Iup-users mailing list Iup-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iup-users
[Iup-users] IUP iupDlgListDestroyAll refactored
Hi Scuri, Is there a special condition, so that the function below is not written like this? usr\iup_dlglist.c: void iupDlgListDestroyAll(void) { Idiallst *list; for (list = idlglist; list; list = list->next) { if (iupObjectCheck(list->ih)) { IupDestroy(list->ih); /* this will also destroy the list */ list->ih = NULL; } } } regards, Ranier Vilela ___ Iup-users mailing list Iup-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iup-users