summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2020-06-29 09:29:06 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2020-06-29 09:29:06 +0200
commit5193fd9d9945437fbc7663f1585ae5d96d2ba103 (patch)
treea8a634140a849b64e21675bb726bf01609fa38cd
parenta526eee1651ca643a3f3c88a0c852a43261a7ebb (diff)
downloadvdr-5193fd9d9945437fbc7663f1585ae5d96d2ba103.tar.gz
vdr-5193fd9d9945437fbc7663f1585ae5d96d2ba103.tar.bz2
Improved deleting plugins in case the plugin uses its own memory management
-rw-r--r--CONTRIBUTORS1
-rw-r--r--HISTORY6
-rw-r--r--plugin.c15
-rw-r--r--plugin.h8
4 files changed, 23 insertions, 7 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index ab656dc7..c15ced33 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -2761,6 +2761,7 @@ Winfried Köhler <w_koehl@gmx.de>
for fixing some copy&paste errors in PLUGINS.html
for fixing the size of cChannel::dtypes[]
for adding a device hook for detecting whether a device provides EIT data
+ for improving deleting plugins in case the plugin uses its own memory management
Hans-Werner Hilse <hilse@web.de>
for adding the command line option --userdump to enable core dumps in case VDR
diff --git a/HISTORY b/HISTORY
index d953a9db..266323ad 100644
--- a/HISTORY
+++ b/HISTORY
@@ -9498,3 +9498,9 @@ Video Disk Recorder Revision History
two bonded devices, which was "fixed" in version 1.7.29. Apparently this fix merely
rendered the whole code branch inactive. Now this branch is only executed for devices
that are not bonded.
+
+2020-06-29:
+
+- Improved deleting plugins in case the plugin uses its own memory management (thanks
+ to Winfried Köhler). Plugins that have been compiled with previous versions of VDR
+ do not need to be recompiled, they will silently be handled as before.
diff --git a/plugin.c b/plugin.c
index 223d709d..0e0f2d13 100644
--- a/plugin.c
+++ b/plugin.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: plugin.c 4.1 2015/04/18 14:51:20 kls Exp $
+ * $Id: plugin.c 4.2 2020/06/29 09:29:06 kls Exp $
*/
#include "plugin.h"
@@ -182,11 +182,15 @@ cDll::cDll(const char *FileName, const char *Args)
args = Args ? strdup(Args) : NULL;
handle = NULL;
plugin = NULL;
+ destroy = NULL;
}
cDll::~cDll()
{
- delete plugin;
+ if (destroy)
+ destroy(plugin);
+ else
+ delete plugin; // silently fall back for plugins compiled with VDR version <= 2.4.3
if (handle)
dlclose(handle);
free(args);
@@ -223,10 +227,11 @@ bool cDll::Load(bool Log)
handle = dlopen(fileName, RTLD_NOW);
const char *error = dlerror();
if (!error) {
- void *(*creator)(void);
- creator = (void *(*)(void))dlsym(handle, "VDRPluginCreator");
+ typedef cPlugin *create_t(void);
+ create_t *create = (create_t *)dlsym(handle, "VDRPluginCreator");
if (!(error = dlerror()))
- plugin = (cPlugin *)creator();
+ plugin = create();
+ destroy = (destroy_t *)dlsym(handle, "VDRPluginDestroyer");
}
if (!error) {
if (plugin && args) {
diff --git a/plugin.h b/plugin.h
index 3502741a..64632c55 100644
--- a/plugin.h
+++ b/plugin.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: plugin.h 2.2 2012/09/01 13:08:54 kls Exp $
+ * $Id: plugin.h 4.1 2020/06/29 09:29:06 kls Exp $
*/
#ifndef __PLUGIN_H
@@ -15,7 +15,9 @@
#include "osdbase.h"
#include "tools.h"
-#define VDRPLUGINCREATOR(PluginClass) extern "C" void *VDRPluginCreator(void) { return new PluginClass; }
+#define VDRPLUGINCREATOR(PluginClass) \
+ extern "C" void *VDRPluginCreator(void) { return new PluginClass; } \
+ extern "C" void VDRPluginDestroyer(PluginClass *p) { delete p; }
class cPlugin {
friend class cDll;
@@ -71,6 +73,8 @@ private:
char *args;
void *handle;
cPlugin *plugin;
+ typedef void destroy_t(cPlugin *);
+ destroy_t *destroy;
public:
cDll(const char *FileName, const char *Args);
virtual ~cDll();