Define a function that is used to parse the values altered by LJM through the ffi library & save them to a return-object.
324541
function parseAndStoreSyncFunctionArgs(functionInfo, funcArgs, saveObj) {
    functionInfo.requiredArgTypes.forEach(function(type, i) {
        var buf = funcArgs[i];
        var parsedVal = ljTypeOps[type].parse(buf);
        var argName = functionInfo.requiredArgNames[i];
        saveObj[argName] = parsedVal;
    });
}
1177314
def prepare_return(x):
    '''
    
    '''
    ret = {}
    for a in list(x):
        if a.tag not in ret:
            ret[a.tag] = []
        ret[a.tag].append(prepare_return(a))
    for a in x.attrib:
        ret[a] = x.attrib[a]
    return ret
786526
def returner(ret):
    '''
    
    '''
    opts = _get_options(ret)
    try:
        with salt.utils.files.flopen(opts['filename'], 'a') as logfile:
            salt.utils.json.dump(ret, logfile)
            logfile.write(str('\n'))  # future lint: disable=blacklisted-function
    except Exception:
        log.error('Could not write to rawdata_json file %s', opts['filename'])
        raise
439214
function (originalObj, originalProp, targetObj, targetProp) {
                Object.defineProperty(
                    originalObj,
                    originalProp,
                    {
                        get: function () {
                            return targetObj[targetProp];
                        },
                        set: function (newValue) {
                            console.error(targetProp + ' is read-only.');
                            throw new Error('ReadOnly');
                        }
                    }
                );
            }
1065295
function functionWrapperFunction () {
        // call original function - catching errors for logging
        try {
            var res = functionObj.apply(this, arguments)
        }
        catch (error) {
            var err = error
        }
        // if log client then do logging
        if (options.logClient) {
            // get number of arguments
            var argsLength = arguments.length
            // copy of arguments
            var args = []
            // create copy of arguments
            for (var i=0; i < argsLength; i++) {
                args[i] = arguments[i]
            }
            // log call
            options.logClient.log('functionCall', {
                functionName: functionName,
                args: args,
                res: err || res,
                isError: (err ? true : false),
                moduleCallId: (this ? this.moduleCallId : undefined),
                requestId: (this ? this.requestId : undefined),
            })
        }
        // if result was an error then throw original error
        if (err) {
            throw err
        }
        // otherwise return original result
        else {
            return res
        }
    }
801028
function Library (libfile, funcs, lib) {
  debug('creating Library object for', libfile);

  if (libfile && libfile.indexOf(EXT) === -1) {
    debug('appending library extension to library name', EXT);
    libfile += EXT;
  }

  if (!lib) {
    lib = {};
  }
  const dl = new DynamicLibrary(libfile || null, RTLD_NOW);

  Object.keys(funcs || {}).forEach(function (func) {
    debug('defining function', func);

    const fptr = dl.get(func);
    const info = funcs[func];

    if (fptr.isNull()) {
      throw new Error('Library: "' + libfile
        + '" returned NULL function pointer for "' + func + '"');
    }

    const resultType = info[0];
    const paramTypes = info[1];
    const fopts = info[2];
    const abi = fopts && fopts.abi;
    const async = fopts && fopts.async;
    const varargs = fopts && fopts.varargs;

    if (varargs) {
      lib[func] = VariadicForeignFunction(fptr, resultType, paramTypes, abi);
    } else {
      const ff = ForeignFunction(fptr, resultType, paramTypes, abi);
      lib[func] = async ? ff.async : ff;
    }
  });

  return lib;
}
803543
protected <T> T invokeJavascriptReturnValue(String function, Class<T> returnType) {
        Object returnObject = invokeJavascript(function);
        if (returnObject instanceof JSObject) {
            try {
                Constructor<T> constructor = returnType.getConstructor(JSObject.class);
                return constructor.newInstance((JSObject) returnObject);
            } catch (Exception ex) {
                throw new IllegalStateException(ex);
            }
        } else {
            return (T) returnObject;
        }
    }
904376
function wrap(fn, isFocus, isDescription, isSpec) {
    if (!fn) return fn;
    return function(name, def) {
      if (isDescription && depth === 0) {
        // Reset isFaking on top-level descriptions
        isFaking = !shouldUseDescription(name, def);
      }

      hasOwnSpecs = hasOwnSpecs || (isSpec && !isFaking);
      hasOtherSpecs = hasOtherSpecs || (isSpec && isFaking);
      hasFocusedWhileFaking = hasFocusedWhileFaking || (isFocus && isFaking);
      hasFocusedWithoutFaking =
        hasFocusedWithoutFaking || (isFocus && !isFaking);

      if (isDescription) def = wrapDescription(def);

      if (!isFaking || forceDescribe) {
        // Call through to framework and return the result
        return fn.call(this, name, def);
      } else if (isDescription) {
        // If its a fake description, then we need to call through to eval inner its() looking for focuses
        // TODO, do we ever need parameters?
        def();
      }
    };
  }
335189
def _ValidateReturnValue(return_value, type_check_dict):
  """"""
  return_check = type_check_dict.get("returns", None)
  if not return_check:
    return []

  messages = []
  if not _ValidateValue(return_value, return_check):
    message = ("Invalid return value '%s'. Expected %s" %
               (return_value, _FormatTypeCheck(return_check)))
    messages.append(message)
  return messages
469375
def validate_return_value(self, retval):
        '''
        
        '''

        if self.__return_annotation is None:
            return

        if not self.__is_valid(retval, self.__return_annotation):
            func_name = self.__function.__name__
            msg = self.RET_TYPE_ERROR_MESSAGE.format(
                func_name,
                self.__format_expectation(self.__return_annotation),
                retval.__class__.__name__
            )
            raise TypesafetyError(msg)
1338104
function ImmutableFunction (functionName, functionObj, options) {
    // require options to be an object
    options = requireValidOptionalObject(options)
    // get function definition - append assignment for uglify
    var functionBody = 'var x='+functionObj.toString()
    // throw error if function is native
    if (functionBody.substr(functionBody.length - 17) === '{ [native code] }') {
        throw new Error('function error: cannot wrap native function')
    }
    // use uglify to strip out whitespace and comments but do not modify code
    functionBody = uglifyEs.minify(functionBody, {
        compress: false,
        mangle: false,
    }).code
    // chop off var x= at beginning and ; at end
    functionBody = functionBody.substr(6, functionBody.length-7)
    // create function meta data
    var functionMeta = {
        functionBody: functionBody,
        functionName: functionName,
        functionId: stableId(functionBody),
        logClient: options.logClient,
    }
    // create wrapper function that will do logging and call original
    var functionWrapperFunction = function functionWrapperFunction () {
        // call original function - catching errors for logging
        try {
            var res = functionObj.apply(this, arguments)
        }
        catch (error) {
            var err = error
        }
        // if log client then do logging
        if (options.logClient) {
            // get number of arguments
            var argsLength = arguments.length
            // copy of arguments
            var args = []
            // create copy of arguments
            for (var i=0; i < argsLength; i++) {
                args[i] = arguments[i]
            }
            // log call
            options.logClient.log('functionCall', {
                functionName: functionName,
                args: args,
                res: err || res,
                isError: (err ? true : false),
                moduleCallId: (this ? this.moduleCallId : undefined),
                requestId: (this ? this.requestId : undefined),
            })
        }
        // if result was an error then throw original error
        if (err) {
            throw err
        }
        // otherwise return original result
        else {
            return res
        }
    }
    // attach meta data to function
    functionWrapperFunction.meta = functionMeta
    // return wrapper function
    return functionWrapperFunction
}
106792
function createAsyncFunction(functionName, functionInfo) {
    return function asyncLJMFunction() {
        var userCB;
        function cb(err, res) {
            if(err) {
                console.error('Error Reported by Async Function', functionName);
            }
            
            // Create an object to be returned.
            var ljmError = res;
            var retObj = {
                'ljmError': ljmError,
            };
            if(ljmError !== 0) {
                retObj.errorInfo = modbus_map.getErrorInfo(ljmError);
            }

            // Fill the object being returned with data.
            parseAndStoreSyncFunctionArgs(functionInfo, funcArgs, retObj);

            // Execute the user's callback function.
            userCB(retObj);

            return;
        }

        // Check arg-length + 1 for the callback.
        if(arguments.length != (functionInfo.args.length + 1)) {
            var errStr = 'Invalid number of arguments.  Should be: ';
            errStr += functionInfo.args.length.toString() + '.  ';
            errStr += getFunctionArgNames(functionInfo).join(', ');
            errStr += ', ' + 'callback.';
            throw new LJMFFIError(errStr);
        // } else if(typeof(arguments[arguments.length]) !== 'function') {
        //     var errStr
        } else {
            if(typeof(arguments[functionInfo.args.length]) !== 'function') {
                userCB = function() {};
            } else {
                userCB = arguments[functionInfo.args.length];

            }

            // Create an array that will be filled with values to call the
            // LJM function with.
            var funcArgs = [];

            // Parse and fill the function arguments array with data.
            allocateAndFillSyncFunctionArgs(functionInfo, funcArgs, arguments);

            // Over-write the function callback in the arguments list.
            funcArgs[funcArgs.length] = cb;

            // Execute the asynchronous LJM function.
            var ljmFunction = liblabjack[functionName].async;
            ljmFunction.apply(this, funcArgs);

            return;
        }
    };
}
1324112
def emit_function(self, return_type=None, argtypes=[], proxy=True):
        """"""

        if argtypes is not None:
            make_func = ctypes.CFUNCTYPE(return_type, *argtypes)
        else:
            make_func = ctypes.CFUNCTYPE(return_type)

        # NOTE: An optional way of binding the function is to use cffi.
        # It's a tad faster then emit_function_fast:
        #   import cffi
        #   ffi = cffi.FFI()
        #   ...
        #   code = jit.emit()
        #   func = ffi.cast("long (*fptr)(long, long)", code.value)
        #   func(123)

        code = self.emit()
        func = make_func(code.value)

        # Save this in case anyone wants to disassemble using external
        # libraries
        func.address = code

        # Because functions code are munmapped when we call _jit_destroy_state,
        # we need to return weakrefs to the functions. Otherwise, a user could
        # call a function that points to invalid memory.
        if proxy:
            self.functions.append(func)
            return weakref.proxy(func)
        else:
            return func
1024780
def add_returning_function(self, func_addr):
        

        self._returning_functions.add(func_addr)
        self._updated_functions.add(func_addr)
659924
function createSyncFunction(functionName, functionInfo) {
    return function syncLJMFunction() {
        if(arguments.length != functionInfo.args.length) {
            var errStr = 'Invalid number of arguments.  Should be: ';
            errStr += functionInfo.args.length.toString() + '.  ';
            errStr += 'Given: ' + arguments.length + '.  ';
            errStr += getFunctionArgNames(functionInfo).join(', ');
            errStr += '.';
            console.error('Error in ljm-ffi syncLJMFunction', errStr);
            throw new LJMFFIError(errStr);
        } else {
            // Create an array that will be filled with values to call the
            // LJM function with.
            var funcArgs = [];

            // Parse and fill the function arguments array with data.
            allocateAndFillSyncFunctionArgs(functionInfo, funcArgs, arguments);

            // Execute the synchronous LJM function.
            var ljmFunction = liblabjack[functionName];
            var ljmError = ljmFunction.apply(this, funcArgs);

            // Create an object to be returned.
            var retObj = {
                'ljmError': ljmError,
            };
            if(ljmError !== 0) {
                retObj.errorInfo = modbus_map.getErrorInfo(ljmError);
            }

            // Fill the object being returned with data.
            parseAndStoreSyncFunctionArgs(functionInfo, funcArgs, retObj);
            return retObj;
        }
    };
}
1214657
public final value_function_return value_function() throws RecognitionException {
        value_function_return retval = new value_function_return();
        retval.start = input.LT(1);


        CommonTree root_0 = null;

        equality_value_function_return equality_value_function85 =null;

        compariable_value_function_return compariable_value_function86 =null;



        try {
            // MessageFilter.g:169:2: ( equality_value_function | compariable_value_function )
            int alt12=2;
            int LA12_0 = input.LA(1);

            if ( (LA12_0==FALSE||LA12_0==NULL||LA12_0==STRING||LA12_0==TRUE||LA12_0==XPATH_FUN_NAME) ) {
                alt12=1;
            }
            else if ( (LA12_0==EOF||LA12_0==AND||LA12_0==NUMBER||LA12_0==OR||(LA12_0 >= TIME_MILLIS_FUN_NAME && LA12_0 <= TIME_STRING_FUN_NAME)||(LA12_0 >= 34 && LA12_0 <= 35)) ) {
                alt12=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 12, 0, input);

                throw nvae;

            }
            switch (alt12) {
                case 1 :
                    // MessageFilter.g:169:4: equality_value_function
                    {
                    root_0 = (CommonTree)adaptor.nil();


                    pushFollow(FOLLOW_equality_value_function_in_value_function1022);
                    equality_value_function85=equality_value_function();

                    state._fsp--;

                    adaptor.addChild(root_0, equality_value_function85.getTree());

                    }
                    break;
                case 2 :
                    // MessageFilter.g:169:30: compariable_value_function
                    {
                    root_0 = (CommonTree)adaptor.nil();


                    pushFollow(FOLLOW_compariable_value_function_in_value_function1026);
                    compariable_value_function86=compariable_value_function();

                    state._fsp--;

                    adaptor.addChild(root_0, compariable_value_function86.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);


            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
1276469
def parse_return_annotation(callback):
    ''''''
    # This has been implemented as a function as the parsing need to be
    # accessible from a decorator used on the function's class method
    responses = {}
    for data in callback.__annotations__['return']:
        tmp = dict(zip(('code', 'message', 'responseModel'), data))
        rm = tmp.get('responseModel', None)  # "None" can be omitted!
        tmp['responseModel'] = rm.name if rm else 'void'
        responses[tmp['code']] = tmp
    return responses