[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r12146: Use NPPAI functions for memo
From: |
Rob Savoye |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r12146: Use NPPAI functions for memory allocation and destruction. |
Date: |
Tue, 13 Apr 2010 16:11:42 -0600 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 12146
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Tue 2010-04-13 16:11:42 -0600
message:
Use NPPAI functions for memory allocation and destruction.
Hack PercentLoaded() to return something ofor now.
Always return a value NPVariant, and don't forget to delete the temporary
ones.
Be less verbose.
modified:
plugin/npapi/plugin.cpp
plugin/npapi/pluginScriptObject.cpp
plugin/npapi/pluginScriptObject.h
=== modified file 'plugin/npapi/plugin.cpp'
--- a/plugin/npapi/plugin.cpp 2010-04-10 20:52:15 +0000
+++ b/plugin/npapi/plugin.cpp 2010-04-13 22:11:42 +0000
@@ -31,7 +31,6 @@
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
-# include <sys/socket.h> // shutdown
#endif
#define MIME_TYPES_HANDLED "application/x-shockwave-flash"
@@ -67,7 +66,7 @@
// 1: fatal errors (errors preventing the plugin from working as it should)
// 2: informational messages
//
-#define GNASH_PLUGIN_DEBUG 1
+#define GNASH_PLUGIN_DEBUG 2
//#define WRITE_FILE
// Defining this flag disables the pipe to the standalone player, as well
@@ -82,6 +81,7 @@
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/join.hpp>
+#include <boost/format.hpp>
#include <sys/param.h>
#include <csignal>
#include <cstdio>
@@ -144,7 +144,7 @@
return NPERR_NO_ERROR;
}
- GnashLogDebug("NS_PluginInitialize call
---------------------------------------------------");
+ GnashLogDebug("NS_PluginInitialize call ---------------------------");
/* Browser Functionality Checks */
@@ -505,10 +505,6 @@
}
if (_controlfd != -1) {
- if (shutdown(_controlfd, SHUT_RDWR) !=0) {
- GnashLogError("Gnash plugin failed to shutdown the control
socket!");
- }
-
if (close(_controlfd) != 0) {
GnashLogError("Gnash plugin failed to close the control socket!");
}
@@ -618,13 +614,12 @@
}
_swf_url = stream->url;
-#if 1
+#if 0
// FIXME: debugging crap for now call javascript
NPN_PluginThreadAsyncCall(_instance, myfunc, NULL);
// printf("FIXME: %s", getEmbedURL());
#endif
-
#if GNASH_PLUGIN_DEBUG > 1
std::cout << __FUNCTION__ << ": The full URL is " << _swf_url << std::endl;
#endif
=== modified file 'plugin/npapi/pluginScriptObject.cpp'
--- a/plugin/npapi/pluginScriptObject.cpp 2010-04-12 15:02:55 +0000
+++ b/plugin/npapi/pluginScriptObject.cpp 2010-04-13 22:11:42 +0000
@@ -170,14 +170,14 @@
GnashLogDebug(__PRETTY_FUNCTION__);
GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;
-
+ NPVariant *value = 0;
std::string varname;
// This method only takes one argument
if (argCount == 1) {
varname = NPVARIANT_TO_STRING(args[0]).UTF8Characters;
- NPVariant *value = gpso->GetVariable(varname);
+ value = gpso->GetVariable(varname);
if (value == 0) {
- NPVARIANT_IS_VOID(*value);
+ NPVARIANT_IS_NULL(*result);
} else {
if (NPVARIANT_IS_DOUBLE(*value)) {
double num = NPVARIANT_TO_DOUBLE(*value);
@@ -193,14 +193,16 @@
} else if (NPVARIANT_IS_NULL(*value)) {
NULL_TO_NPVARIANT(*result);
} else if (NPVARIANT_IS_VOID(*value)) {
- VOID_TO_NPVARIANT(*result);
+ VOID_TO_NPVARIANT(*result);
} else if (NPVARIANT_IS_OBJECT(*value)) {
OBJECT_TO_NPVARIANT(NPVARIANT_TO_OBJECT(*value), *result);
}
+ NPN_MemFree(value);
return true;
}
}
+ NPVARIANT_IS_NULL(*result);
return false;
}
@@ -389,10 +391,21 @@
PercentLoaded (NPObject *npobj, NPIdentifier /* name */, const NPVariant
*/*args */,
uint32_t argCount, NPVariant *result)
{
- GnashLogDebug(__PRETTY_FUNCTION__);
+// GnashLogDebug(__PRETTY_FUNCTION__);
GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;
+#if 1
+ static int counter = 0;
+// log_error("%s: %d ; %d\n", __FUNCTION__, gpso->getControlFD(), counter);
+ INT32_TO_NPVARIANT(counter, *result);
+ if (counter >= 100) {
+ counter = 0;
+ } else {
+ counter += 20;
+ }
+ return true;
+#else
if (argCount == 0) {
std::stringstream ss;
ss << "PercentLoaded" << std::endl;
@@ -433,6 +446,7 @@
BOOLEAN_TO_NPVARIANT(false, *result);
return false;
+#endif
}
// Play();
@@ -675,11 +689,14 @@
const std::string &str)
{
NPIdentifier id = NPN_GetStringIdentifier(name.c_str());
- NPVariant *value = new NPVariant;
+ NPVariant *value = (NPVariant *)NPN_MemAlloc(sizeof(NPVariant));
int length = str.size();;
- char *bar = new char[length+1];
+ char *bar = (char *)NPN_MemAlloc(length+1);
std::copy(str.begin(), str.end(), bar);
bar[length] = 0; // terminate the new string or bad things happen
+
+ // When an NPVariant becomes a string object, it *does not* make a copy.
+ // Instead it stores the pointer (and length) we just allocated.
STRINGN_TO_NPVARIANT(bar, length, *value);
SetProperty(id, value);
}
@@ -688,7 +705,7 @@
GnashPluginScriptObject::AddProperty(const std::string &name, double num)
{
NPIdentifier id = NPN_GetStringIdentifier(name.c_str());
- NPVariant *value = new NPVariant;
+ NPVariant *value = (NPVariant *)NPN_MemAlloc(sizeof(NPVariant));
DOUBLE_TO_NPVARIANT(num, *value);
SetProperty(id, value);
}
@@ -697,7 +714,7 @@
GnashPluginScriptObject::AddProperty(const std::string &name, int num)
{
NPIdentifier id = NPN_GetStringIdentifier(name.c_str());
- NPVariant *value = new NPVariant;
+ NPVariant *value = (NPVariant *)NPN_MemAlloc(sizeof(NPVariant));
INT32_TO_NPVARIANT(num, *value);
SetProperty(id, value);
}
@@ -707,16 +724,19 @@
void
GnashPluginScriptObject::initializeIdentifiers()
{
- GnashLogDebug("initializeIdentifiers");
+// GnashLogDebug("initializeIdentifiers");
+// NPN_Status(_nppinstance, __FUNCTION__);
+
//
http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_04.html
// We maintain an internal property for our version number, rather
// than asking the player.
-
- AddProperty("$version", "456.789");
+ AddProperty("$version", "10,1,r999");
+ // id and name appear to be the same tag, but differeing browsers access
+ // one or the other, or both.
AddProperty("name", "Hello World");
- AddProperty("id", 1);
+ AddProperty("id", "Hello World");
AddProperty("src", "example");
AddProperty("align", "middle");
@@ -869,7 +889,14 @@
GnashPluginScriptObject::marshalAllocate (NPP npp, NPClass */* aClass */)
{
GnashLogDebug(__PRETTY_FUNCTION__);
+#if 0
+ GnashPluginScriptObject *npobj = reinterpret_cast<GnashPluginScriptObject
*>
+ (NPN_MemAlloc(sizeof(GnashPluginScriptObject)));
+ npobj->setInstance(npp);
+ return npobj;
+#else
return new GnashPluginScriptObject(npp);
+#endif
}
@@ -877,9 +904,11 @@
GnashPluginScriptObject::marshalDeallocate (NPObject *npobj)
{
GnashLogDebug(__PRETTY_FUNCTION__);
-// GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;
-// gpso->Deallocate();
+#if 0
+ NPN_MemFree(reinterpret_cast<void *>(npobj));
+#else
delete (GnashPluginScriptObject *)npobj;
+#endif
}
void
@@ -1145,22 +1174,22 @@
GnashPluginScriptObject::Invoke(NPIdentifier name, const NPVariant *args,
uint32_t argCount, NPVariant *result)
{
// GnashLogDebug(__PRETTY_FUNCTION__);
-#if 1
+#if 0
printf("Invoking Method \"");
if (NPN_IdentifierIsString(name)) {
- printf("%s\"...", NPN_UTF8FromIdentifier(name));
+ printf("%s\"...\n", NPN_UTF8FromIdentifier(name));
} else {
- printf("%d\"...", NPN_IntFromIdentifier(name));
+ printf("%d\"...\n", NPN_IntFromIdentifier(name));
}
#endif
std::map<NPIdentifier, NPInvokeFunctionPtr>::iterator it;
it = _methods.find(name);
if (it != _methods.end()) {
- printf(" FOUND\n");
+ // printf(" FOUND\n");
NPInvokeFunctionPtr func = it->second;
return func(NULL, name, args, argCount, result);
- }
+ }
return false;
}
@@ -1255,7 +1284,7 @@
GnashLogDebug(__PRETTY_FUNCTION__);
printf("Get Variable \"%s\" is ", name.c_str());
- NPVariant *value = new NPVariant;
+ NPVariant *value = (NPVariant *)NPN_MemAlloc(sizeof(NPVariant));
NULL_TO_NPVARIANT(*value);
std::stringstream ss;
@@ -1275,9 +1304,8 @@
if (ret == 0) {
return value;
}
-
+ // We need a non const pointer to walk through the data.
ptr = const_cast<char *>(data);
- value = new NPVariant;
// Make sure this mesasge is our response, whnich it should be,
// but you never know...
@@ -1336,7 +1364,7 @@
ss << std::endl;
// free the memory used for the data, as it was allocated in readPlayer().
- delete[](data);
+ NPN_MemFree(reinterpret_cast<void *>(const_cast<char *>(data)));
return value;
}
@@ -1351,7 +1379,7 @@
int
GnashPluginScriptObject::getControlFD()
{
- GnashLogDebug(__PRETTY_FUNCTION__);
+// GnashLogDebug(__PRETTY_FUNCTION__);
return controlfd;
};
@@ -1425,7 +1453,7 @@
if (*data == 0) {
// Since we know how bytes are in the network buffer, allocate
// some memory to read the data.
- buf = new char[bytes+1];
+ buf = (char *)NPN_MemAlloc(bytes+1);
// terminate incase we want to treat the data like a string.
buf[bytes] = 0;
length = bytes;
=== modified file 'plugin/npapi/pluginScriptObject.h'
--- a/plugin/npapi/pluginScriptObject.h 2010-04-10 16:43:47 +0000
+++ b/plugin/npapi/pluginScriptObject.h 2010-04-13 22:11:42 +0000
@@ -119,8 +119,10 @@
bool RemoveProperty(NPIdentifier name);
bool Enumerate(NPIdentifier **identifier, uint32_t *count);
bool Construct(const NPVariant *data, uint32_t argCount, NPVariant
*result);
+
private:
void initializeIdentifiers();
+ void setInstance(NPP inst) { _nppinstance = inst; };
// _nppinstance->pdata should be the nsPluginInstance once NPP_New() is
finished.
NPP _nppinstance;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r12146: Use NPPAI functions for memory allocation and destruction.,
Rob Savoye <=