Commit 92e2cadf36f7eb44fd9ffdacf374584fd1d94cbd

Authored by Perry Werneck
1 parent 81460183
Exists in master and in 1 other branch develop

Fixing segfaults in print settings.

src/dialogs/print/convenience.c
@@ -32,6 +32,8 @@ @@ -32,6 +32,8 @@
32 #include <v3270/dialogs.h> 32 #include <v3270/dialogs.h>
33 #include <terminal.h> 33 #include <terminal.h>
34 #include <lib3270/selection.h> 34 #include <lib3270/selection.h>
  35 + #include <lib3270/log.h>
  36 + #include <lib3270/trace.h>
35 37
36 /*--[ Implement ]------------------------------------------------------------------------------------*/ 38 /*--[ Implement ]------------------------------------------------------------------------------------*/
37 39
@@ -48,17 +50,14 @@ @@ -48,17 +50,14 @@
48 return errno = ENOTCONN; 50 return errno = ENOTCONN;
49 51
50 // Print operation. 52 // Print operation.
  53 + debug("************** %s",__FUNCTION__);
51 GtkPrintOperation * operation = v3270_print_operation_new(widget, mode); 54 GtkPrintOperation * operation = v3270_print_operation_new(widget, mode);
52 if(!operation) 55 if(!operation)
53 return errno = EPERM; 56 return errno = EPERM;
54 57
55 gtk_print_operation_set_show_progress(operation,TRUE); 58 gtk_print_operation_set_show_progress(operation,TRUE);
56 59
57 -#ifdef DEBUG  
58 gtk_print_operation_set_allow_async(operation,TRUE); 60 gtk_print_operation_set_allow_async(operation,TRUE);
59 -#else  
60 - gtk_print_operation_set_allow_async(operation,FALSE);  
61 -#endif // DEBUG  
62 61
63 GtkPrintOperationResult result = GTK_PRINT_OPERATION_RESULT_ERROR; 62 GtkPrintOperationResult result = GTK_PRINT_OPERATION_RESULT_ERROR;
64 63
@@ -105,22 +104,26 @@ @@ -105,22 +104,26 @@
105 switch(result) 104 switch(result)
106 { 105 {
107 case GTK_PRINT_OPERATION_RESULT_ERROR: 106 case GTK_PRINT_OPERATION_RESULT_ERROR:
108 - g_message("Error on print operation"); 107 + debug("%s: Error on print operation",__FUNCTION__);
  108 + lib3270_trace_event(v3270_get_session(widget),_("Error on print operation"));
109 rc = -1; 109 rc = -1;
110 break; 110 break;
111 111
112 case GTK_PRINT_OPERATION_RESULT_APPLY: 112 case GTK_PRINT_OPERATION_RESULT_APPLY:
113 - g_message("The print settings should be stored."); 113 + debug("%s: The print settings should be stored.",__FUNCTION__);
  114 + lib3270_trace_event(v3270_get_session(widget),_("The print settings should be stored."));
114 rc = 0; 115 rc = 0;
115 break; 116 break;
116 117
117 case GTK_PRINT_OPERATION_RESULT_CANCEL: 118 case GTK_PRINT_OPERATION_RESULT_CANCEL:
118 - g_message("The print operation has been canceled, the print settings should not be stored."); 119 + debug("%s: The print operation has been canceled, the print settings should not be stored.", __FUNCTION__);
  120 + lib3270_trace_event(v3270_get_session(widget),_("The print operation has been canceled, the print settings should not be stored."));
119 rc = 0; 121 rc = 0;
120 break; 122 break;
121 123
122 case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS: 124 case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS:
123 - g_message("The print operation is running"); 125 + debug("%s: The print operation is running",__FUNCTION__);
  126 + lib3270_trace_event(v3270_get_session(widget),_("The print operation is running"));
124 rc = 0; 127 rc = 0;
125 break; 128 break;
126 129
src/dialogs/print/print.c
@@ -63,7 +63,36 @@ @@ -63,7 +63,36 @@
63 63
64 if(operation->widget) 64 if(operation->widget)
65 { 65 {
66 - debug("%s: Emiting signal PRINT_DONE",__FUNCTION__); 66 + debug("%s: Emiting signal PRINT_DONE with result code %d",__FUNCTION__,result);
  67 +
  68 + switch(result)
  69 + {
  70 + case GTK_PRINT_OPERATION_RESULT_ERROR:
  71 + debug("%s: Error on print operation",__FUNCTION__);
  72 + lib3270_trace_event(operation->widget->host,_("Error on print operation"));
  73 + break;
  74 +
  75 + case GTK_PRINT_OPERATION_RESULT_APPLY:
  76 + debug("%s: The print settings should be stored.",__FUNCTION__);
  77 + lib3270_trace_event(operation->widget->host,_("The print settings should be stored."));
  78 + break;
  79 +
  80 + case GTK_PRINT_OPERATION_RESULT_CANCEL:
  81 + debug("%s: The print operation has been canceled, the print settings should not be stored.", __FUNCTION__);
  82 + lib3270_trace_event(operation->widget->host,_("The print operation has been canceled, the print settings should not be stored."));
  83 + break;
  84 +
  85 + case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS:
  86 + debug("%s: The print operation is running",__FUNCTION__);
  87 + lib3270_trace_event(operation->widget->host,_("The print operation is running"));
  88 + break;
  89 +
  90 + default:
  91 + debug("Unexpected status %d in print operation",(int) result);
  92 + lib3270_trace_event(operation->widget->host,_("Unexpected status %d in print operation"),(int) result);
  93 +
  94 + }
  95 +
67 g_signal_emit(GTK_WIDGET(operation->widget), v3270_widget_signal[V3270_SIGNAL_PRINT_DONE], 0, prt, (guint) result); 96 g_signal_emit(GTK_WIDGET(operation->widget), v3270_widget_signal[V3270_SIGNAL_PRINT_DONE], 0, prt, (guint) result);
68 } 97 }
69 98
@@ -77,6 +106,8 @@ @@ -77,6 +106,8 @@
77 106
78 V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object); 107 V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object);
79 108
  109 + operation->contents.selection = NULL;
  110 +
80 debug("%s.operation->font.info.scaled=%p",__FUNCTION__,operation->font.info.scaled); 111 debug("%s.operation->font.info.scaled=%p",__FUNCTION__,operation->font.info.scaled);
81 g_message("%s.operation->font.info.scaled=%p",__FUNCTION__,operation->font.info.scaled); 112 g_message("%s.operation->font.info.scaled=%p",__FUNCTION__,operation->font.info.scaled);
82 if(operation->font.info.scaled) 113 if(operation->font.info.scaled)
@@ -103,13 +134,14 @@ @@ -103,13 +134,14 @@
103 #endif // _WIN32 134 #endif // _WIN32
104 135
105 g_list_free_full(operation->contents.dynamic,g_free); 136 g_list_free_full(operation->contents.dynamic,g_free);
  137 +
106 operation->contents.dynamic = NULL; 138 operation->contents.dynamic = NULL;
107 139
108 #pragma GCC diagnostic pop 140 #pragma GCC diagnostic pop
109 } 141 }
110 - operation->contents.selection = NULL;  
111 142
112 debug("%s: Calling parent dispose",__FUNCTION__); 143 debug("%s: Calling parent dispose",__FUNCTION__);
  144 +
113 g_message("%s: Calling parent dispose",__FUNCTION__); 145 g_message("%s: Calling parent dispose",__FUNCTION__);
114 G_OBJECT_CLASS(V3270PrintOperation_parent_class)->dispose(object); 146 G_OBJECT_CLASS(V3270PrintOperation_parent_class)->dispose(object);
115 debug("%s: Dispose is complete",__FUNCTION__); 147 debug("%s: Dispose is complete",__FUNCTION__);
@@ -203,14 +235,12 @@ @@ -203,14 +235,12 @@
203 } 235 }
204 236
205 237
206 -static GList * get_selection(H3270 *hSession, int all) 238 +static GList * get_selection(GList *list, H3270 *hSession, int all)
207 { 239 {
208 lib3270_selection * selection = lib3270_get_selection(hSession,0,all); 240 lib3270_selection * selection = lib3270_get_selection(hSession,0,all);
209 241
210 if(selection) 242 if(selection)
211 { 243 {
212 - GList * rc = g_new0(GList,1);  
213 -  
214 size_t sz = sizeof(lib3270_selection) + (sizeof(lib3270_selection_element) * ((selection->bounds.width * selection->bounds.height)+1)); 244 size_t sz = sizeof(lib3270_selection) + (sizeof(lib3270_selection_element) * ((selection->bounds.width * selection->bounds.height)+1));
215 245
216 debug( 246 debug(
@@ -223,12 +253,12 @@ static GList * get_selection(H3270 *hSession, int all) @@ -223,12 +253,12 @@ static GList * get_selection(H3270 *hSession, int all)
223 sizeof(lib3270_selection_element) 253 sizeof(lib3270_selection_element)
224 ); 254 );
225 255
226 - rc->data = g_malloc0(sz);  
227 - memcpy(rc->data,selection,sz); 256 + gpointer data = g_malloc0(sz);
  257 + memcpy(data,selection,sz);
228 258
229 lib3270_free(selection); 259 lib3270_free(selection);
230 260
231 - return rc; 261 + return g_list_append(list,data);
232 } 262 }
233 263
234 g_warning("Error getting selection"); 264 g_warning("Error getting selection");
@@ -261,7 +291,7 @@ GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT @@ -261,7 +291,7 @@ GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT
261 { 291 {
262 case LIB3270_CONTENT_ALL: 292 case LIB3270_CONTENT_ALL:
263 debug("%s","LIB3270_CONTENT_ALL"); 293 debug("%s","LIB3270_CONTENT_ALL");
264 - operation->contents.dynamic = get_selection(operation->session,1); 294 + operation->contents.dynamic = get_selection(operation->contents.dynamic, operation->session,1);
265 operation->contents.selection = operation->contents.dynamic; 295 operation->contents.selection = operation->contents.dynamic;
266 break; 296 break;
267 297
@@ -272,7 +302,7 @@ GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT @@ -272,7 +302,7 @@ GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT
272 302
273 case LIB3270_CONTENT_SELECTED: 303 case LIB3270_CONTENT_SELECTED:
274 debug("%s","LIB3270_CONTENT_SELECTED"); 304 debug("%s","LIB3270_CONTENT_SELECTED");
275 - operation->contents.dynamic = get_selection(operation->session,0); 305 + operation->contents.dynamic = get_selection(operation->contents.dynamic, operation->session,0);
276 operation->contents.selection = operation->contents.dynamic; 306 operation->contents.selection = operation->contents.dynamic;
277 break; 307 break;
278 } 308 }