[Gambas-user] [Git][gambas/gambas][master] 2 commits: When a task terminates, it now internally calls the QUIT instruction, so that…

Benoît Minisini gitlab at mg.gitlab.com
Sat Jan 20 16:52:59 CET 2018


Benoît Minisini pushed to branch master at Gambas / gambas


Commits:
dc9bdcfc by gambas at 2018-01-19T01:56:13+01:00
When a task terminates, it now internally calls the QUIT instruction, so that everything is cleaned up.

[INTERPRETER]
* BUG: When a task terminates, it now internally calls the QUIT instruction, so that everything is cleaned up.

- - - - -
47711694 by gambas at 2018-01-20T16:43:13+01:00
Tasks do not print memory and objects clean up warnings anymore, and their output serialization file is now automatically destroyed.

[INTERPRETER]
* BUG: Remove the task output serialization file when it is freed.
* BUG: Tasks do not print memory and objects clean up warnings anymore.

- - - - -


2 changed files:

- main/gbx/gbx.c
- main/gbx/gbx_c_task.c


Changes:

=====================================
main/gbx/gbx.c
=====================================
--- a/main/gbx/gbx.c
+++ b/main/gbx/gbx.c
@@ -116,6 +116,8 @@ static void init(const char *file, int argc, char **argv)
 
 static void main_exit(bool silent)
 {
+	silent |= EXEC_task;
+	
 	// If the stack has not been initialized because the project could not be started, do it now
 	if (!SP)
 		STACK_init();
@@ -466,7 +468,8 @@ int main(int argc, char *argv[])
 
 	main_exit(FALSE);
 
-	MEMORY_exit();
+	if (!EXEC_task)
+		MEMORY_exit();
 
 	fflush(NULL);
 


=====================================
main/gbx/gbx_c_task.c
=====================================
--- a/main/gbx/gbx_c_task.c
+++ b/main/gbx/gbx_c_task.c
@@ -250,6 +250,12 @@ static void prepare_task(CTASK *_object)
 	THIS->fd_err = -1;
 }
 
+static void exit_child(int ret)
+{
+	EXEC_quit_value = ret;
+	EXEC_quit();
+}
+
 static bool start_task(CTASK *_object)
 {
 	const char *err = NULL;
@@ -339,7 +345,7 @@ static bool start_task(CTASK *_object)
 			close(fd_out[0]);
 
 			if (dup2(fd_out[1], STDOUT_FILENO) == -1)
-				exit(CHILD_STDOUT);
+				exit_child(CHILD_STDOUT);
 			
 			setlinebuf(stdout);
 		}
@@ -351,7 +357,7 @@ static bool start_task(CTASK *_object)
 			close(fd_err[0]);
 
 			if (dup2(fd_err[1], STDERR_FILENO) == -1)
-				exit(CHILD_STDERR);
+				exit_child(CHILD_STDERR);
 			
 			setlinebuf(stderr);
 		}
@@ -377,7 +383,7 @@ static bool start_task(CTASK *_object)
 					#if DEBUG_ME
 					fprintf(stderr, "gb.task: serialization has failed\n");
 					#endif
-					exit(CHILD_RETURN);
+					exit_child(CHILD_RETURN);
 				}
 			}
 		}
@@ -393,12 +399,12 @@ static bool start_task(CTASK *_object)
 					fclose(f);
 				}
 				
-				exit(CHILD_ERROR);
+				exit_child(CHILD_ERROR);
 			}
 		}
 		END_TRY
 		
-		_exit(CHILD_OK);
+		exit_child(CHILD_OK);
 	}
 	
 	return FALSE;
@@ -426,6 +432,81 @@ static void close_fd(int *pfd)
 	}
 }
 
+static bool get_return_value(CTASK *_object, bool cleanup)
+{
+	char path[PATH_MAX];
+	GB_VALUE value;
+	bool fail = FALSE;
+	struct stat info;
+	char *err = NULL;
+	int fd;
+	int n;
+	
+	sprintf(path, RETURN_FILE_PATTERN, getuid(), getpid(), THIS->pid);
+	
+	if (!cleanup)
+	{
+		switch (THIS->status)
+		{
+			case CHILD_OK:
+				
+				#if DEBUG_ME
+				fprintf(stderr,"unserialize from: %s\n", path);
+				#endif
+				if (!THIS->got_value)
+				{
+					fail = GB_UnSerialize(path, &value);
+					if (!fail)
+						GB_StoreVariant(&value._variant, &THIS->ret);
+					THIS->got_value = TRUE;
+				}
+				break;
+				
+			case CHILD_ERROR:
+				
+				if (stat(path, &info))
+				{
+					fail = TRUE;
+				}
+				else
+				{
+					err = STRING_new_temp(NULL, info.st_size);
+					
+					fd = open(path, O_RDONLY);
+					if (fd < 0)
+					{
+						fail = TRUE;
+						break;
+					}
+					else
+					{
+						for(;;)
+						{
+							n = read(fd, err, info.st_size);
+							if (n == info.st_size || errno != EINTR)
+								break;
+						}
+						close(fd);
+						
+						if (n == info.st_size)
+							GB_Error("Task has failed: &1", err);
+						else
+							fail = TRUE;
+					}
+				}
+				
+				if (fail)
+					GB_Error("Unable to get task error");
+				
+				break;
+		}
+	}
+
+	unlink(path);
+	
+	return fail;
+}
+
 static void cleanup_task(CTASK *_object)
 {
 	//printf("cleanup task %p\n", THIS); fflush(stdout);
@@ -521,6 +602,7 @@ END_METHOD
 
 BEGIN_METHOD_VOID(Task_free)
 
+	get_return_value(THIS, TRUE);
 	GB_StoreVariant(NULL, &THIS->ret);
 
 END_METHOD
@@ -573,36 +655,16 @@ END_METHOD
 
 BEGIN_PROPERTY(Task_Value)
 
-	char path[PATH_MAX];
-	GB_VALUE ret;
-	FILE_STAT info;
-	char *err = NULL;
-	int fd;
-	int n;
-	
 	if (!THIS->child && THIS->stopped)
 	{
-		sprintf(path, RETURN_FILE_PATTERN, getuid(), getpid(), THIS->pid);
-		#if DEBUG_ME
-		fprintf(stderr,"unserialize from: %s\n", path);
-		#endif
-		
 		if (WIFEXITED(THIS->status))
 		{
 			switch (WEXITSTATUS(THIS->status))
 			{
 				case CHILD_OK:
 
-					if (!THIS->got_value)
-					{
-						bool fail = GB_UnSerialize(path, &ret);
-						if (!fail)
-							GB_StoreVariant(&ret._variant, &THIS->ret);
-						unlink(path);
-						THIS->got_value = TRUE;
-						if (fail)
-							break;
-					}
+					if (get_return_value(THIS, FALSE))
+						break;
 					GB_ReturnVariant(&THIS->ret);
 					return;
 					
@@ -623,23 +685,8 @@ BEGIN_PROPERTY(Task_Value)
 					
 				case CHILD_ERROR:
 					
-					FILE_stat(path, &info, FALSE);
-					
-					err = STRING_new_temp(NULL, info.size);
-					
-					fd = open(path, O_RDONLY);
-					if (fd < 0) goto __ERROR;
-					
-					for(;;)
-					{
-						n = read(fd, err, info.size);
-						if (n == info.size || errno != EINTR)
-							break;
-					}
-					close(fd);
-					
-					GB_Error("Task has failed: &1", err);
-					return;
+					get_return_value(THIS, FALSE);
+					break;
 			}
 		}
 		else if (WIFSIGNALED(THIS->status))
@@ -649,8 +696,6 @@ BEGIN_PROPERTY(Task_Value)
 		}
 	}
 	
-__ERROR:
-	
 	GB_ReturnNull();
 	GB_ReturnConvVariant();
 	



View it on GitLab: https://gitlab.com/gambas/gambas/compare/4ff9f7ddef726e3957c30bf31b794b894b88d914...477116942dec5d4a3e0da9956638a606c1fe0169

---
View it on GitLab: https://gitlab.com/gambas/gambas/compare/4ff9f7ddef726e3957c30bf31b794b894b88d914...477116942dec5d4a3e0da9956638a606c1fe0169
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180120/0e0bd390/attachment-0001.html>


More information about the User mailing list