Enum type safety in NPNGetValue

Stuart Morgan stuartmorgan at chromium.org
Thu Jun 3 14:16:58 PDT 2010


On Thu, Jun 3, 2010 at 1:19 PM, David Sehr <sehr at google.com> wrote:
> As NPN_GetValue/NPP_GetValue can sometimes write pointer values, I would
> argue that something like void** or intptr_t* as the argument type would be
> better.  Some platforms (e.g., 64-bit Windows) have sizeof(void*) >
> sizeof(long).

To clarify, I wasn't trying to suggest that the function declaration
should change, just that there be well-defined convention for the
cases where the "value" is pointing to one of the NPAPI enums.

To take a concrete example, here's what Gecko does with NPNVToolkit:
  *((NPNToolkitType*)result) = ...;
WebKit does:
  *static_cast<uint32_t*>(value) = ...;

This works out only if all the browsers and all the plugin all end up
with sizeof(NPNToolkitType) == 32. If all browsers did what WebKit
does here, and plugins passed in a reference to a stack-declared
int32_t instead of a stack-declared NPNToolkitType, there wouldn't be
a problem.

(Oddly enough NPNVpluginDrawingModel is reversed; Gecko casts to
PRInt32* and WebKit casts to NPDrawingModel*.)

-Stuart


More information about the plugin-futures mailing list