Old 07-10-2018, 09:11 PM   #1
Human being with feelings
cfillion's Avatar
Join Date: May 2015
Location: Québec, Canada
Posts: 2,774
Default Extension API: Validation for custom pointer types

Currently, custom pointer types in extension-defined API functions are not validated by REAPER before being called nor with ValidatePtr.

For example: BR_EnvFree expects a BR_Envelope* but no explicit error is thrown if it receives anything else (unlike built-in REAPER types, which are checked).

reaper.BR_EnvFree(reaper.GetMasterTrack(), false)
--> 'reaper.BR_EnvFree' argument 1: expected BR_Envelope*

reaper.ValidatePtr(reaper.GetMasterTrack(), 'BR_Envelope*')
--> false
Possible implementation on the extension side:
typedef struct
  const char *name;
  bool (*Validate)(void *ptr); 
} custom_type_register_t;

custom_type_register_t br_env{"BR_Envelope*", &ValidateSWSPtr<BR_Envelope>};
plugin_register("custom_type", (void *)&br_env);
cfillion is online now   Reply With Quote
Old 07-13-2018, 06:38 AM   #2
Human being with feelings
mespotine's Avatar
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,558


It should also allow HWND and FastStrings as well, as they are used in SWS/Reaper.
mespotine is offline   Reply With Quote
Old 10-25-2018, 07:54 AM   #3
Justin's Avatar
Join Date: Jan 2005
Location: NYC
Posts: 12,435

Hmm, if an extension defines the type and all functions that implement that type, the extension should handle validation of any pointers of that type itself...

Though I guess we could add the ability to throw an error to Lua...
Justin is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 08:32 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.