[bug #63219] Introduce a close function for loadable plugins.

2023-05-14 Thread Paul D. Smith
Update of bug #63219 (project make):

  Status:None => Fixed  
 Open/Closed:Open => Closed 
   Fixed Release:None => SCM
   Triage Status:None => Medium Effort  

___

Follow-up Comment #4:

I added an implementation but I changed the name to "unload" and reworked
parts of the implementation.

I also created a API/ABI version value but couldn't find a backward-compatible
way to implement it, that I liked.  So, it's a change in the API.  If anyone
has a good idea of a better way to do it please let me know.

It is possible, via preprocessor statements, to implement a loadable module
that will work with both old and new APIs.  But unfortunately modules written
for the old API won't work with the new one.


___

Reply to this item at:

  

___
Message sent via Savannah
https://savannah.gnu.org/




[bug #63219] Introduce a close function for loadable plugins.

2022-10-15 Thread Eli Zaretskii
Follow-up Comment #3, bug #63219 (project make):

If we are going to extend the API of the loadable modules, I think we will
have to introduce API versions, because the new API will be
binary-incompatible with the old one, and Make should refuse to load modules
that are incompatible with the API for which it was built.



___

Reply to this item at:

  

___
Message sent via Savannah
https://savannah.gnu.org/




[bug #63219] Introduce a close function for loadable plugins.

2022-10-15 Thread Dmitry Goncharov
Follow-up Comment #2, bug #63219 (project make):

This is the example from the manual extended with a close function




#include 
#include 
#include 
#include 
#include 

#include 

int plugin_is_GPL_compatible;

struct file {
  struct file *next;
  char *name;
};
static struct file *files = NULL;

static char *
gen_tmpfile (const char *nm, int argc, char **argv)
{
  int fd;

  /* Compute the size of the filename and allocate space for it.  */
  int len = strlen (argv[0]) + 6 + 1;
  char *buf = gmk_alloc (len);

  strcpy (buf, argv[0]);
  strcat (buf, "XX");

  fd = mkstemp(buf);
  if (fd >= 0)
{
  struct file *new = (struct file *) malloc (sizeof *new);
  new->name = strdup (buf);
  new->next = files;
  files = new;
  /* Don't leak the file descriptor.  */
  close (fd);
  return buf;
}

  /* Failure.  */
  fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno));
  gmk_free (buf);
  return NULL;
}

int
mk_temp_gmk_setup (const gmk_floc *floc)
{
  printf ("mk_temp plugin loaded from %s:%lu\n", floc->filenm, floc->lineno);
  /* Register the function with make name "mk-temp".  */
  gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1);
  return 1;
}

void
mk_temp_gmk_close ()
{
  while (files)
{
  struct file *f = files;
  printf ("unlinking %s\n", f->name);
  unlink (f->name);
  free (f->name);
  files = f->next;
  free (f);
}
  files = NULL;
  printf ("mk_temp plugin unloaded\n");
}


Now when you run make you’ll see something like:


$ make
mk_temp plugin loaded from makefile:1
Temporary file tmpfile.O7vuwn
unlinking tmpfile.O7vuwn
mk_temp plugin unloaded
cc -shared -fPIC -o mk_temp.so mk_temp.c
mk_temp plugin loaded from makefile:1
Temporary file tmpfile.lpgecm
Temporary file tmpfile.sIdBvo
unlinking tmpfile.sIdBvo
unlinking tmpfile.lpgecm
mk_temp plugin unloaded



___

Reply to this item at:

  

___
Message sent via Savannah
https://savannah.gnu.org/




[bug #63219] Introduce a close function for loadable plugins.

2022-10-15 Thread Dmitry Goncharov
Follow-up Comment #1, bug #63219 (project make):

Make allows a loadable plugin to implement a setup function.
This patch adds the ability for a loadable plugin to optionally specify a
close function.

Make calls this close function before unloading the plugin. This close
function can be used for cleanup purposes.

The impl in this patch calls the close function of each loaded plugin before
unloading and at exit, whether successful or not.
This impl does not call the close function when make is killed by a signal. It
is possible to call the close function even when make is killed.
However
1. This would introduce restrictions on call that the close function can do. 
2. Make is going to be modified to have the signal handler set a flag and
handle the flag outside the signal handler.


___

Reply to this item at:

  

___
Message sent via Savannah
https://savannah.gnu.org/




[bug #63219] Introduce a close function for loadable plugins.

2022-10-15 Thread Dmitry Goncharov
Additional Item Attachment, bug #63219 (project make):

File name: sv63219.diff   Size:6 KB


File name: sv63219_test.diff  Size:4 KB


File name: sv63219_doc.diff   Size:4 KB




___

Reply to this item at:

  

___
Message sent via Savannah
https://savannah.gnu.org/




[bug #63219] Introduce a close function for loadable plugins.

2022-10-15 Thread Dmitry Goncharov
URL:
  

 Summary: Introduce a close function for loadable plugins.
 Project: make
   Submitter: dgoncharov
   Submitted: Sun 16 Oct 2022 12:17:42 AM UTC
Severity: 3 - Normal
  Item Group: Enhancement
  Status: None
 Privacy: Public
 Assigned to: None
 Open/Closed: Open
 Discussion Lock: Any
   Component Version: SCM
Operating System: None
   Fixed Release: None
   Triage Status: None


___

Follow-up Comments:


---
Date: Sun 16 Oct 2022 12:17:42 AM UTC By: Dmitry Goncharov 
.







___

Reply to this item at:

  

___
Message sent via Savannah
https://savannah.gnu.org/