[Spice-devel] [PATCH spice-xpi 4/5] build: deal with non-const return values of NPP_GetMIMEDescription()
Marc-André Lureau
marcandre.lureau at gmail.com
Fri Jan 27 06:45:13 PST 2012
Deal with const and non-const return value of NPP_GetMIMEDescription().
Although it is hard to find evidences of how this value is used, I
think the non-const value could return a static string. But I prefer
being on the safe side and return a strdup() to the risk of leaking
that string on older versions.
Fixes the build on RHEL6 with xulrunner-1.9.2.24-2.el6.
---
SpiceXPI/src/plugin/np_entry.cpp | 7 +++++++
SpiceXPI/src/plugin/plugin.cpp | 7 +++++++
configure.ac | 28 ++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/SpiceXPI/src/plugin/np_entry.cpp b/SpiceXPI/src/plugin/np_entry.cpp
index 021694c..4eba645 100644
--- a/SpiceXPI/src/plugin/np_entry.cpp
+++ b/SpiceXPI/src/plugin/np_entry.cpp
@@ -209,10 +209,17 @@ NPError NP_Initialize(NPNetscapeFuncs *aNPNFuncs, NPPluginFuncs *aNPPFuncs)
return NS_PluginInitialize();
}
+#ifdef NPAPI_USE_CONSTCHARS
const char *NP_GetMIMEDescription()
{
return NPP_GetMIMEDescription();
}
+#else
+char *NP_GetMIMEDescription()
+{
+ return NPP_GetMIMEDescription();
+}
+#endif
NPError NP_GetValue(void *future, NPPVariable aVariable, void *aValue)
{
diff --git a/SpiceXPI/src/plugin/plugin.cpp b/SpiceXPI/src/plugin/plugin.cpp
index 2dada12..816ac63 100644
--- a/SpiceXPI/src/plugin/plugin.cpp
+++ b/SpiceXPI/src/plugin/plugin.cpp
@@ -106,10 +106,17 @@ namespace {
}
}
+#ifdef NPAPI_USE_CONSTCHARS
const char *NPP_GetMIMEDescription(void)
{
return const_cast<char *>(MIME_TYPES_DESCRIPTION.c_str());
}
+#else
+char *NPP_GetMIMEDescription(void)
+{
+ return strdup(MIME_TYPES_DESCRIPTION.c_str());
+}
+#endif
//////////////////////////////////////
//
diff --git a/configure.ac b/configure.ac
index 061ea56..42e130b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,6 +46,34 @@ PKG_CHECK_MODULES(XUL, libxul-embedding >= 1.9 nspr >= 4.7.1)
AC_SUBST(XUL_CFLAGS)
AC_SUBST(XUL_LIBS)
+# test for const return value of NPP_GetMIMEDescription, based on gecko-mediaplayer
+AC_MSG_CHECKING([for const return value of NPP_GetMIMEDescription])
+oCFLAGS=$CFLAGS
+CFLAGS="$XUL_CFLAGS"
+AC_LANG_PUSH([C])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+#ifndef XP_UNIX
+#define XP_UNIX 1
+#endif
+#include <npapi.h>
+#if NP_VERSION_MAJOR == 0 && NP_VERSION_MINOR < 27
+#error
+#else
+const char*NPP_GetMIMEDescription(void) {
+ return "test";
+}
+#endif
+],[
+const char *f=NPP_GetMIMEDescription();
+])],[
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([NPAPI_USE_CONSTCHARS],[1],[Define if NPAPI declares NPP_GetMIMEDescription as a const char*])
+],[
+ AC_MSG_RESULT([no])
+])
+AC_LANG_POP([C])
+CFLAGS=$oCFLAGS
+
# Find xpidl
XPIDL=`pkg-config --variable=libdir libxul`/xpidl
AM_CONDITIONAL([HAVE_XPIDL], [test -x "$XPIDL"])
--
1.7.7.6
More information about the Spice-devel
mailing list