MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / __New

Method __New

source/script_object.cpp:2818–2859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2816
2817
2818ResultType ClipboardAll::__New(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount)
2819{
2820 void *data;
2821 size_t size;
2822 if (!aParamCount)
2823 {
2824 // Retrieve clipboard contents.
2825 if (!Var::GetClipboardAll(&data, &size))
2826 _o_return_FAIL;
2827 }
2828 else
2829 {
2830 // Use caller-supplied data.
2831 size_t caller_data;
2832 if (auto obj = ParamIndexToObject(0))
2833 {
2834 GetBufferObjectPtr(aResultToken, obj, caller_data, size);
2835 if (aResultToken.Exited())
2836 return aResultToken.Result();
2837 }
2838 else
2839 {
2840 // Caller supplied an address.
2841 caller_data = (size_t)ParamIndexToIntPtr(0);
2842 if (caller_data < 65536) // Basic check to catch incoming raw addresses that are zero or blank. On Win32, the first 64KB of address space is always invalid.
2843 _o_throw_param(0);
2844 size = -1;
2845 }
2846 if (!ParamIndexIsOmitted(1))
2847 size = (size_t)ParamIndexToIntPtr(1);
2848 else if (size == -1) // i.e. it can be omitted when size != -1 (a string was passed).
2849 _o_throw_value(ERR_PARAM2_MUST_NOT_BE_BLANK);
2850 if ( !(data = malloc(size)) ) // More likely to be due to invalid parameter than out of memory.
2851 _o_throw_oom;
2852 memcpy(data, (void *)caller_data, size);
2853 }
2854 if (mData != data)
2855 free(mData); // In case of explicit call to __New.
2856 mData = data;
2857 mSize = size;
2858 _o_return_empty;
2859}
2860
2861
2862Object *ClipboardAll::Create()

Callers

nothing calls this directly

Calls 3

GetBufferObjectPtrFunction · 0.85
ExitedMethod · 0.80
ResultMethod · 0.80

Tested by

no test coverage detected