static int stdcall_closure (lua_State *L) { lua_stdcallCFunction function = (lua_stdcallCFunction)lua_touserdata (L, lua_upvalueindex (1)); return function (L); }

llvm::CallInst* call(const char* name, llvm::Value** start, int size, const char* inst_name, llvm::IRBuilder<>& builder) { return builder.CreateCall(function(name), llvm::ArrayRef<llvm::Value*>(start, size), inst_name); }

struct pthreadpool* pthreadpool_create(size_t threads_count) { if (threads_count == 0) { threads_count = (size_t) sysconf(_SC_NPROCESSORS_ONLN); } #if !defined(__ANDROID__) struct pthreadpool* threadpool = NULL; if (posix_memalign((void**) &threadpool, 64, sizeof(struct pthreadpool) + threads_count * sizeof(struct thread_info)) != 0) { #else /* * Android didn't get posix_memalign until API level 17 (Android 4.2). * Use (otherwise obsolete) memalign function on Android platform. */ struct pthreadpool* threadpool = memalign(64, sizeof(struct pthreadpool) + threads_count * sizeof(struct thread_info)); if (threadpool == NULL) { #endif return NULL; } memset(threadpool, 0, sizeof(struct pthreadpool) + threads_count * sizeof(struct thread_info)); threadpool->threads_count = threads_count; pthread_mutex_init(&threadpool->execution_mutex, NULL); pthread_mutex_init(&threadpool->barrier_mutex, NULL); pthread_cond_init(&threadpool->barrier_condvar, NULL); pthread_mutex_init(&threadpool->state_mutex, NULL); pthread_cond_init(&threadpool->state_condvar, NULL); for (size_t tid = 0; tid < threads_count; tid++) { threadpool->threads[tid].thread_number = tid; pthread_create(&threadpool->threads[tid].thread_object, NULL, &thread_main, &threadpool->threads[tid]); } /* Wait until all threads initialize */ wait_worker_threads(threadpool); return threadpool; } size_t pthreadpool_get_threads_count(struct pthreadpool* threadpool) { return threadpool->threads_count; } void pthreadpool_compute_1d( struct pthreadpool* threadpool, pthreadpool_function_1d_t function, void* argument, size_t range) { if (threadpool == NULL) { /* No thread pool provided: execute function sequentially on the calling thread */ for (size_t i = 0; i < range; i++) { function(argument, i); } } else { /* Protect the global threadpool structures */ pthread_mutex_lock(&threadpool->execution_mutex); /* Lock the state variables to ensure that threads don't start processing before they observe complete state */ pthread_mutex_lock(&threadpool->state_mutex); /* Setup global arguments */ threadpool->function = function; threadpool->argument = argument; /* Spread the work between threads */ for (size_t tid = 0; tid < threadpool->threads_count; tid++) { struct thread_info* thread = &threadpool->threads[tid]; thread->range_start = multiply_divide(range, tid, threadpool->threads_count); thread->range_end = multiply_divide(range, tid + 1, threadpool->threads_count); thread->range_length = thread->range_end - thread->range_start; thread->state = thread_state_compute_1d; } /* Unlock the state variables before waking up the threads for better performance */ pthread_mutex_unlock(&threadpool->state_mutex); /* Wake up the threads */ wakeup_worker_threads(threadpool); /* Wait until the threads finish computation */ wait_worker_threads(threadpool); /* Unprotect the global threadpool structures */ pthread_mutex_unlock(&threadpool->execution_mutex); } } struct compute_1d_tiled_context { pthreadpool_function_1d_tiled_t function; void* argument; size_t range; size_t tile; }; static void compute_1d_tiled(const struct compute_1d_tiled_context* context, size_t linear_index) { const size_t tile_index = linear_index; const size_t index = tile_index * context->tile; const size_t tile = min(context->tile, context->range - index); context->function(context->argument, index, tile); } void pthreadpool_compute_1d_tiled( pthreadpool_t threadpool, pthreadpool_function_1d_tiled_t function, void* argument, size_t range, size_t tile) { if (threadpool == NULL) { /* No thread pool provided: execute function sequentially on the calling thread */ for (size_t i = 0; i < range; i += tile) { function(argument, i, min(range - i, tile)); } } else { /* Execute in parallel on the thread pool using linearized index */ const size_t tile_range = divide_round_up(range, tile); struct compute_1d_tiled_context context = { .function = function, .argument = argument, .range = range, .tile = tile }; pthreadpool_compute_1d(threadpool, (pthreadpool_function_1d_t) compute_1d_tiled, &context, tile_range); } } struct compute_2d_context { pthreadpool_function_2d_t function; void* argument; struct fxdiv_divisor_size_t range_j; }; static void compute_2d(const struct compute_2d_context* context, size_t linear_index) { const struct fxdiv_divisor_size_t range_j = context->range_j; const struct fxdiv_result_size_t index = fxdiv_divide_size_t(linear_index, range_j); context->function(context->argument, index.quotient, index.remainder); } void pthreadpool_compute_2d( struct pthreadpool* threadpool, pthreadpool_function_2d_t function, void* argument, size_t range_i, size_t range_j) { if (threadpool == NULL) { /* No thread pool provided: execute function sequentially on the calling thread */ for (size_t i = 0; i < range_i; i++) { for (size_t j = 0; j < range_j; j++) { function(argument, i, j); } } } else { /* Execute in parallel on the thread pool using linearized index */ struct compute_2d_context context = { .function = function, .argument = argument, .range_j = fxdiv_init_size_t(range_j) }; pthreadpool_compute_1d(threadpool, (pthreadpool_function_1d_t) compute_2d, &context, range_i * range_j); } } struct compute_2d_tiled_context { pthreadpool_function_2d_tiled_t function; void* argument; struct fxdiv_divisor_size_t tile_range_j; size_t range_i; size_t range_j; size_t tile_i; size_t tile_j; }; static void compute_2d_tiled(const struct compute_2d_tiled_context* context, size_t linear_index) { const struct fxdiv_divisor_size_t tile_range_j = context->tile_range_j; const struct fxdiv_result_size_t tile_index = fxdiv_divide_size_t(linear_index, tile_range_j); const size_t max_tile_i = context->tile_i; const size_t max_tile_j = context->tile_j; const size_t index_i = tile_index.quotient * max_tile_i; const size_t index_j = tile_index.remainder * max_tile_j; const size_t tile_i = min(max_tile_i, context->range_i - index_i); const size_t tile_j = min(max_tile_j, context->range_j - index_j); context->function(context->argument, index_i, index_j, tile_i, tile_j); } void pthreadpool_compute_2d_tiled( pthreadpool_t threadpool, pthreadpool_function_2d_tiled_t function, void* argument, size_t range_i, size_t range_j, size_t tile_i, size_t tile_j) { if (threadpool == NULL) { /* No thread pool provided: execute function sequentially on the calling thread */ for (size_t i = 0; i < range_i; i += tile_i) { for (size_t j = 0; j < range_j; j += tile_j) { function(argument, i, j, min(range_i - i, tile_i), min(range_j - j, tile_j)); } } } else { /* Execute in parallel on the thread pool using linearized index */ const size_t tile_range_i = divide_round_up(range_i, tile_i); const size_t tile_range_j = divide_round_up(range_j, tile_j); struct compute_2d_tiled_context context = { .function = function, .argument = argument, .tile_range_j = fxdiv_init_size_t(tile_range_j), .range_i = range_i, .range_j = range_j, .tile_i = tile_i, .tile_j = tile_j }; pthreadpool_compute_1d(threadpool, (pthreadpool_function_1d_t) compute_2d_tiled, &context, tile_range_i * tile_range_j); } } void pthreadpool_destroy(struct pthreadpool* threadpool) { /* Update threads' states */ for (size_t tid = 0; tid < threadpool->threads_count; tid++) { threadpool->threads[tid].state = thread_state_shutdown; } /* Wake up the threads */ wakeup_worker_threads(threadpool); /* Wait until all threads return */ for (size_t tid = 0; tid < threadpool->threads_count; tid++) { pthread_join(threadpool->threads[tid].thread_object, NULL); } /* Release resources */ pthread_mutex_destroy(&threadpool->execution_mutex); pthread_mutex_destroy(&threadpool->barrier_mutex); pthread_cond_destroy(&threadpool->barrier_condvar); pthread_mutex_destroy(&threadpool->state_mutex); pthread_cond_destroy(&threadpool->state_condvar); free(threadpool); }

static fru_errno_t frt_for_each_packet(fru_seghdl_t node, int (*function)(fru_tag_t *tag, uint8_t *payload, size_t length, void *args), void *args) { int rc_num; int status; char *rc_tags; char *rc_data; int i; packet_t *packets = NULL; segment_list_t *tmp_list; fru_segdesc_t *descriptor; tmp_list = g_raw->segs; /* num of packet */ rc_num = fru_get_num_packets(node, NULL); if (rc_num == -1) { return (map_errno(errno)); } else if (rc_num == 0) { return (FRU_SUCCESS); } while (tmp_list) { if (node == tmp_list->segment->handle) { break; } tmp_list = tmp_list->next; } if (tmp_list) { descriptor = (fru_segdesc_t *)&tmp_list->segment->descriptor; if (descriptor->field.opaque) { return (FRU_SUCCESS); } if (descriptor->field.encrypted && (encrypt_func == NULL)) { return (FRU_SUCCESS); } } packets = malloc(sizeof (*packets) * (rc_num)); if (packets == NULL) { return (FRU_FAILURE); } /* get all packets */ if (fru_get_packets(node, packets, rc_num, NULL) == -1) { free(packets); return (map_errno(errno)); } rc_tags = malloc(sizeof (*rc_tags) * (rc_num)); if (rc_tags == NULL) { free(packets); return (FRU_FAILURE); } /* number of tags */ for (i = 0; i < rc_num; i++) { size_t rc_len = get_payload_length((fru_tag_t *)&packets[i].tag); rc_data = malloc(sizeof (*rc_data) * (rc_len)); if (rc_data == NULL) { free(packets); return (FRU_FAILURE); } /* get the payload data */ (void) fru_get_payload(packets[i].handle, (void *)rc_data, rc_len, NULL); if (tmp_list) { descriptor = (fru_segdesc_t *)&tmp_list->segment->descriptor; if ((descriptor->field.encrypted) && ((status = encrypt_func(FRU_DECRYPT, (void *)rc_data, rc_len)) != FRU_SUCCESS)) { return (status); } } /* print packet */ if ((status = function((fru_tag_t *)&packets[i].tag, (uint8_t *)rc_data, rc_len, args)) != FRU_SUCCESS) { free(rc_data); free(packets); return (status); } free(rc_data); } return (FRU_SUCCESS); }

void setDoesNotCapture(const char* name, int which) { function(name)->setDoesNotCapture(which, true); }

void PCCommand::execute(vector<string> &mIns) { function(mIns); }

// // Transport schedule // SQInteger Transportschedule(HSQUIRRELVM vm) { SQInteger numargs = sq_gettop(vm); // check parameter count if(numargs > 5) { return sq_throwerror(vm, "too many parameters, expected at most 4"); } if(numargs < 3) { return sq_throwerror(vm, "insufficient parameters, expected at least 2"); } // get parameter 1 "function" as function HSQOBJECT functionObj; if (SQ_FAILED(sq_getstackobj(vm, 2, &functionObj))) { return sq_throwerror(vm, "argument 1 \"function\" is not of type function"); } if (sq_gettype(vm, 2) != OT_CLOSURE) { return sq_throwerror(vm, "argument 1 \"function\" is not of type function"); } SQUnsignedInteger nparams, nfreevars; sq_getclosureinfo(vm, 2, &nparams, &nfreevars); sq_addref(vm, &functionObj); ScriptFunction function(vm, functionObj, nparams); // get parameter 2 "bar" as integer SQInteger bar; if (SQ_FAILED(sq_getinteger(vm, 3, &bar))){ return sq_throwerror(vm, "argument 2 \"bar\" is not of type integer"); } // 3 parameters passed in if(numargs == 4) { // get parameter 3 "position" as integer SQInteger position; if (SQ_FAILED(sq_getinteger(vm, 4, &position))){ return sq_throwerror(vm, "argument 3 \"position\" is not of type integer"); } // call the implementation try { Transport::instance().schedule(function, bar, position); } catch(std::exception const& e) { return sq_throwerror(vm, e.what()); } } // 4 parameters passed in else if(numargs == 5) { // get parameter 3 "position" as integer SQInteger position; if (SQ_FAILED(sq_getinteger(vm, 4, &position))){ return sq_throwerror(vm, "argument 3 \"position\" is not of type integer"); } // get parameter 4 "division" as integer SQInteger division; if (SQ_FAILED(sq_getinteger(vm, 5, &division))){ return sq_throwerror(vm, "argument 4 \"division\" is not of type integer"); } // call the implementation try { Transport::instance().schedule(function, bar, position, division); } catch(std::exception const& e) { return sq_throwerror(vm, e.what()); } } else { // call the implementation try { Transport::instance().schedule(function, bar); } catch(std::exception const& e) { return sq_throwerror(vm, e.what()); } } // void method, returns no value return 0; }

xdm::RefPtr< xdmGrid::UniformGrid > build2DGrid() { xdm::RefPtr< xdmGrid::UniformGrid > grid( new xdmGrid::UniformGrid ); grid->setName( "FunctionEvaluationGrid" ); // Time { grid->setTime( xdm::makeRefPtr( new xdmGrid::Time( 0.0 ) ) ); } // Topology { xdm::RefPtr< xdmGrid::RectilinearMesh > topology( new xdmGrid::RectilinearMesh ); topology->setShape( xdm::makeShape( kMeshSize[0]-1, kMeshSize[1]-1 ) ); grid->setTopology( topology ); } // Geometry xdm::RefPtr< xdm::VectorStructuredArray< float > > meshValues[2]; { xdm::RefPtr< xdmGrid::TensorProductGeometry > geometry( new xdmGrid::TensorProductGeometry( 2 ) ); for ( int i = 0; i < 2; i++ ) { // Build the Geometry data as single precision to force an up conversion // upon read. xdm::RefPtr< xdm::UniformDataItem > dataItem( new xdm::UniformDataItem ); dataItem->setDataType( xdm::primitiveType::kFloat ); dataItem->setDataspace( xdm::makeShape( kMeshSize[i] ) ); meshValues[i] = xdm::makeRefPtr( new xdm::VectorStructuredArray< float >( kMeshSize[i] ) ); for ( int j = 0; j < kMeshSize[i]; j++ ) { (*meshValues[i])[j] = kRange[i][0] + j * ( (kRange[i][1] - kRange[i][0]) / kMeshSize[i] ); } dataItem->setData( xdm::makeRefPtr( new xdm::ArrayAdapter( meshValues[i] ) ) ); geometry->setCoordinateValues( i, dataItem ); } grid->setGeometry( geometry ); } // Give it an attribute. { xdm::RefPtr< xdmGrid::Attribute > attribute( new xdmGrid::Attribute( xdmGrid::Attribute::kScalar, xdmGrid::Attribute::kNode ) ); attribute->setName( "attr" ); xdm::RefPtr< xdm::VectorStructuredArray< double > > attrValues( new xdm::VectorStructuredArray< double >( kMeshSize[1] * kMeshSize[0] ) ); for ( int j = 0; j < kMeshSize[1]; j++ ) { for ( int i = 0; i < kMeshSize[0]; i++ ) { double xpoint = (*meshValues[0])[i]; double ypoint = (*meshValues[1])[j]; (*attrValues)[j*kMeshSize[0] + i] = function( xpoint, ypoint ); } } xdm::RefPtr< xdm::UniformDataItem > dataItem( new xdm::UniformDataItem( xdm::primitiveType::kDouble, xdm::makeShape( kMeshSize[1], kMeshSize[0] ) ) ); dataItem->setData( xdm::makeRefPtr( new xdm::ArrayAdapter( attrValues, true ) ) ); attribute->setDataItem( dataItem ); grid->addAttribute( attribute ); } return grid; }

/* MAIN PROGRAM */ int main() { /*------------------------------------------------------------------------*/ /* variables */ const int tag = 1; // tape tag const int size = 5; // system size const int indep = size*size+size; // # of indeps const int depen = size; // # of deps double A[size][size], a1[size], a2[size], // passive variables b[size], x[size]; adouble **AA, *AAp, *Abx; // active variables double *args = myalloc1(indep); // arguments double **jac = myalloc2(depen,indep); // the Jacobian double *laghessvec = myalloc1(indep); // Hessian-vector product int i,j; /*------------------------------------------------------------------------*/ /* Info */ fprintf(stdout,"LINEAR SYSTEM SOLVING by " "LU-DECOMPOSITION (ADOL-C Example)\n\n"); /*------------------------------------------------------------------------*/ /* Allocation und initialization of the system matrix */ AA = new adouble*[size]; AAp = new adouble[size*size]; for (i=0; i<size; i++) { AA[i] = AAp; AAp += size; } Abx = new adouble[size]; for(i=0; i<size; i++) { a1[i] = i*0.25; a2[i] = i*0.33; } for(i=0; i<size; i++) { for(j=0; j<size; j++) A[i][j] = a1[i]*a2[j]; A[i][i] += i+1; b[i] = -i-1; } /*------------------------------------------------------------------------*/ /* Taping the computation of the determinant */ trace_on(tag); /* marking indeps */ for(i=0; i<size; i++) for(j=0; j<size; j++) AA[i][j] <<= (args[i*size+j] = A[i][j]); for(i=0; i<size; i++) Abx[i] <<= (args[size*size+i] = b[i]); /* LU-factorization and computation of solution */ LUfact(size,AA); LUsolve(size,AA,Abx); /* marking deps */ for (i=0; i<size; i++) Abx[i] >>= x[i]; trace_off(); fprintf(stdout," x[0] (original): %16.4le\n",x[0]); /*------------------------------------------------------------------------*/ /* Recomputation */ function(tag,depen,indep,args,x); fprintf(stdout," x[0] (from tape): %16.4le\n",x[0]); /*------------------------------------------------------------------------*/ /* Computation of Jacobian */ jacobian(tag,depen,indep,args,jac); fprintf(stdout," Jacobian:\n"); for (i=0; i<depen; i++) { for (j=0; j<indep; j++) fprintf(stdout," %14.6le",jac[i][j]); fprintf(stdout,"\n"); } /*------------------------------------------------------------------------*/ /* Computation of Lagrange-Hessian-vector product */ lagra_hess_vec(tag,depen,indep,args,args,x,laghessvec); fprintf(stdout," Part of Lagrange-Hessian-vector product:\n"); for (i=0; i<size; i++) { for (j=0; j<size; j++) fprintf(stdout," %14.6le",laghessvec[i*size+j]); fprintf(stdout,"\n"); } /*------------------------------------------------------------------------*/ /* Tape-documentation */ tape_doc(tag,depen,indep,args,x); /*------------------------------------------------------------------------*/ /* Tape statistics */ int tape_stats[STAT_SIZE]; tapestats(tag,tape_stats); fprintf(stdout,"\n independents %d\n",tape_stats[NUM_INDEPENDENTS]); fprintf(stdout," dependents %d\n",tape_stats[NUM_DEPENDENTS]); fprintf(stdout," operations %d\n",tape_stats[NUM_OPERATIONS]); fprintf(stdout," operations buffer size %d\n",tape_stats[OP_BUFFER_SIZE]); fprintf(stdout," locations buffer size %d\n",tape_stats[LOC_BUFFER_SIZE]); fprintf(stdout," constants buffer size %d\n",tape_stats[VAL_BUFFER_SIZE]); fprintf(stdout," maxlive %d\n",tape_stats[NUM_MAX_LIVES]); fprintf(stdout," valstack size %d\n\n",tape_stats[TAY_STACK_SIZE]); /*------------------------------------------------------------------------*/ /* That's it */ return 1; }

function compose(actor_list const& elements) const { return function(Function(elements.front())); }

QList<Number> NelderMead::findMinimum(const QList<QList<Number> > &initialSimplex, Number reflectionCoefficient, Number contractionCoefficient, Number expansionCoefficient, Number accuracy) { QList<QList<Number> > simplex = initialSimplex; forever { // Find best, worst and second worst values QList<Number> functions; foreach (const QList<Number> point, simplex) { functions << function(point); } int best = indexOfMinimal(functions); int worst = indexOfMaximal(functions); int secondWorst = indexOfSecondMaximal(functions); // Find center value QList<Number> center = findCenter(simplex, worst); // Check for exit if (found(simplex, center, accuracy)) { return simplex[best]; } // Get reflected value QList<Number> reflected = MathUtils::addVectorToVector( center, MathUtils::multiplyVectorByNumber( MathUtils::subtractVectorFromVector( center, simplex[worst]), reflectionCoefficient)); // reflected <= best if (function(reflected) <= function(simplex[best])) { QList<Number> expanded = MathUtils::addVectorToVector( center, MathUtils::multiplyVectorByNumber( MathUtils::subtractVectorFromVector( reflected, center), expansionCoefficient) ); if (function(expanded) < function(simplex[best])) { simplex[worst] = expanded; } else { simplex[worst] = reflected; } } // second-worst < reflected <= worst else if (MathUtils::isBetween(function(reflected), function(simplex[secondWorst]), function(simplex[worst]), true)) { QList<Number> contracted = MathUtils::addVectorToVector( center, MathUtils::multiplyVectorByNumber( MathUtils::subtractVectorFromVector( simplex[worst], center), contractionCoefficient) ); simplex[worst] = contracted; } // best < reflected <= worst else if (MathUtils::isBetween(function(reflected), function(simplex[best]), function(simplex[worst]), true)) { simplex[worst] = reflected; } // reflected > worst else { QList<Number> bestValue = simplex[best]; for (int i = 0; i < simplex.size(); ++i) { simplex[i] = MathUtils::addVectorToVector( bestValue, MathUtils::multiplyVectorByNumber( MathUtils::subtractVectorFromVector( simplex[i], bestValue), 0.5) ); } } }

function operator()(std::size_t n, std::size_t level = 0) const { return function(vararg_function<scoped>(n, level)); }

function operator()(utree const& val) const { return function(value_function(val)); }

static int zbx_execute_script_on_terminal(DC_HOST *host, zbx_script_t *script, char **result, char *error, size_t max_error_len) { const char *__function_name = "zbx_execute_script_on_terminal"; int ret; AGENT_RESULT agent_result; DC_ITEM item; int (*function)(); #ifdef HAVE_SSH2 assert(ZBX_SCRIPT_TYPE_SSH == script->type || ZBX_SCRIPT_TYPE_TELNET == script->type); #else assert(ZBX_SCRIPT_TYPE_TELNET == script->type); #endif zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); *error = '\0'; memset(&item, 0, sizeof(item)); memcpy(&item.host, host, sizeof(item.host)); if (SUCCEED != (ret = DCconfig_get_interface_by_type(&item.interface, host->hostid, INTERFACE_TYPE_AGENT))) { zbx_snprintf(error, max_error_len, "Zabbix agent interface is not defined for host [%s]", host->host); goto fail; } switch (script->type) { case ZBX_SCRIPT_TYPE_SSH: item.authtype = script->authtype; item.publickey = script->publickey; item.privatekey = script->privatekey; /* break; is not missing here */ case ZBX_SCRIPT_TYPE_TELNET: item.username = script->username; item.password = script->password; break; } substitute_simple_macros(NULL, NULL, NULL, NULL, &host->hostid, NULL, NULL, &script->port, MACRO_TYPE_COMMON, NULL, 0); if ('\0' != *script->port && SUCCEED != (ret = is_ushort(script->port, NULL))) { zbx_snprintf(error, max_error_len, "Invalid port number [%s]", script->port); goto fail; } #ifdef HAVE_SSH2 if (ZBX_SCRIPT_TYPE_SSH == script->type) { item.key = zbx_dsprintf(item.key, "ssh.run[,,%s]", script->port); function = get_value_ssh; } else { #endif item.key = zbx_dsprintf(item.key, "telnet.run[,,%s]", script->port); function = get_value_telnet; #ifdef HAVE_SSH2 } #endif item.value_type = ITEM_VALUE_TYPE_TEXT; item.params = zbx_strdup(item.params, script->command); init_result(&agent_result); alarm(CONFIG_TIMEOUT); if (SUCCEED != (ret = function(&item, &agent_result))) { if (ISSET_MSG(&agent_result)) zbx_strlcpy(error, agent_result.msg, max_error_len); ret = FAIL; } else if (NULL != result && ISSET_TEXT(&agent_result)) *result = zbx_strdup(*result, agent_result.text); alarm(0); free_result(&agent_result); zbx_free(item.params); zbx_free(item.key); fail: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }

/* DESCRIPTION: ED_ParseEdict // LOCATION: pr_edict.c // PATH: ED_LoadFromFile // // To quote the text block that came with it: // Parses an edict out of the given string, returning the new position // ed should be a properly initialized empty edict. // Used for initial level load and for savegames. */ const char * ED_ParseEdict(const char *data, edict_t *ent) { KeyValueData_t var_120_KeyValue; int init; char keyname[256]; unsigned int var_108_keylen; double var_32c_angle; char * var_110_string; void (*function)(entvars_t *); // clear it if(ent != global_sv.edicts) { //listed as a hack, dunno why. memset(&(ent->v), 0, sizeof(entvars_t)); } init = 0; InitEntityDLLFields(ent); SuckOutClassname(data, ent); var_110_string = global_pr_strings + ent->v.classname; function = (void (*)(entvars_t *))GetEntityInit(var_110_string); if(function == NULL) { var_110_string = "custom"; function = (void (*)(entvars_t *))GetEntityInit(var_110_string); if(function == NULL) { Con_Printf("%s: Couldn't find an init function for some edict.\n", __FUNCTION__); } else { function(&(ent->v)); var_120_KeyValue.szClassName = var_110_string; var_120_KeyValue.szKeyName = "customclass"; var_120_KeyValue.szValue = global_pr_strings + ent->v.classname; var_120_KeyValue.fHandled = 0; gEntityInterface.pfnKeyValue(ent, &var_120_KeyValue); init = 1; } } else { function(&(ent->v)); init = 1; } // go through all the dictionary pairs while(1) { // parse key data = COM_Parse(data); if(global_com_token[0] == '}') { break; } if(data == NULL) { Sys_Error("%s: EOF without closing brace.", __FUNCTION__); } //Q_strncpy(keyname, global_com_token, sizeof(keyname)-1); //keyname[sizeof(keyname)-1] = '\0'; //var_108_keylen = strlen(keyname); var_108_keylen = Q_snprintf(keyname, sizeof(keyname), "%s", global_com_token); if(var_108_keylen >= sizeof(keyname)) { keyname[sizeof(keyname)-1] = '\0'; var_108_keylen = sizeof(keyname)-1; Con_Printf("%s: truncating oversized keyname.", __FUNCTION__); } while(var_108_keylen > 0 && keyname[var_108_keylen-1] == ' ') { keyname[var_108_keylen-1] = '\0'; var_108_keylen--; } // parse value data = COM_Parse(data); if(data == NULL) { Sys_Error("%s: EOF without closing brace.", __FUNCTION__); } if(global_com_token[0] == '}') { Sys_Error("%s: closing brace without data.", __FUNCTION__); } //Ignoring some Steam stuff that was here... if((global_pr_strings + ent->v.classname != NULL) && (Q_strcmp(global_pr_strings + ent->v.classname, global_com_token) == 0)) { continue; } if(Q_strcmp(keyname, "angle") == 0) { var_32c_angle = atof(global_com_token); if(var_32c_angle >= 0) { Q_snprintf(global_com_token, 0x400, "%f %f %f", ent->v.angles[0], var_32c_angle, ent->v.angles[2]); } else if(var_32c_angle == -1) { Q_sprintf(global_com_token, "-90 0 0"); } else { Q_sprintf(global_com_token, "90 0 0"); } Q_strcpy(keyname, "angles"); } var_120_KeyValue.szClassName = global_pr_strings + ent->v.classname; var_120_KeyValue.szKeyName = keyname; var_120_KeyValue.szValue = global_com_token; var_120_KeyValue.fHandled = 0; gEntityInterface.pfnKeyValue(ent, &var_120_KeyValue); //There are additional checks here, but none lead anywhere. //No doubt defined out in the dedicated server. } if(init == 0) { ent->free = 1; ent->serialnumber++; } return(data); }

void MD4::Transform() { #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) #define H(x, y, z) ((x) ^ (y) ^ (z)) word32 A, B, C, D; A = digest_[0]; B = digest_[1]; C = digest_[2]; D = digest_[3]; #define function(a,b,c,d,k,s) a=rotlFixed(a+F(b,c,d)+buffer_[k],s); function(A,B,C,D, 0, 3); function(D,A,B,C, 1, 7); function(C,D,A,B, 2,11); function(B,C,D,A, 3,19); function(A,B,C,D, 4, 3); function(D,A,B,C, 5, 7); function(C,D,A,B, 6,11); function(B,C,D,A, 7,19); function(A,B,C,D, 8, 3); function(D,A,B,C, 9, 7); function(C,D,A,B,10,11); function(B,C,D,A,11,19); function(A,B,C,D,12, 3); function(D,A,B,C,13, 7); function(C,D,A,B,14,11); function(B,C,D,A,15,19); #undef function #define function(a,b,c,d,k,s) a=rotlFixed(a+G(b,c,d)+buffer_[k]+0x5a827999,s); function(A,B,C,D, 0, 3); function(D,A,B,C, 4, 5); function(C,D,A,B, 8, 9); function(B,C,D,A,12,13); function(A,B,C,D, 1, 3); function(D,A,B,C, 5, 5); function(C,D,A,B, 9, 9); function(B,C,D,A,13,13); function(A,B,C,D, 2, 3); function(D,A,B,C, 6, 5); function(C,D,A,B,10, 9); function(B,C,D,A,14,13); function(A,B,C,D, 3, 3); function(D,A,B,C, 7, 5); function(C,D,A,B,11, 9); function(B,C,D,A,15,13); #undef function #define function(a,b,c,d,k,s) a=rotlFixed(a+H(b,c,d)+buffer_[k]+0x6ed9eba1,s); function(A,B,C,D, 0, 3); function(D,A,B,C, 8, 9); function(C,D,A,B, 4,11); function(B,C,D,A,12,15); function(A,B,C,D, 2, 3); function(D,A,B,C,10, 9); function(C,D,A,B, 6,11); function(B,C,D,A,14,15); function(A,B,C,D, 1, 3); function(D,A,B,C, 9, 9); function(C,D,A,B, 5,11); function(B,C,D,A,13,15); function(A,B,C,D, 3, 3); function(D,A,B,C,11, 9); function(C,D,A,B, 7,11); function(B,C,D,A,15,15); digest_[0] += A; digest_[1] += B; digest_[2] += C; digest_[3] += D; }

int main (int argc, char const * argv []) { extern struct channel channel; static char const * optv [] = { "b:d:e:hi:p:t:v", "", "Ethernet Frame Blast Utility", "b n\tbinary byte value is (n) [" LITERAL (EFBU_BINARY) "]", "d x\treplace destination address with (x)", "e x\tethertype is (x) [" LITERAL (EFBU_ETHERTYPE) "]", "h\treplace source address with host address", #if defined (WINPCAP) || defined (LIBPCAP) "i n\thost interface is (n) [" LITERAL (CHANNEL_ETHNUMBER) "]", #else "i s\thost interface is (s) [" LITERAL (CHANNEL_ETHDEVICE) "]", #endif "t n\ttransmit for (n) milliseconds [" LITERAL (EFBU_TIMER) "]", "p n\tpause (n) milliseconds between frames [" LITERAL (EFBU_PAUSE) "]", "v\tverbose messages", (char const *) (0) }; byte buffer [ETHER_MAX_LEN]; byte binary = EFBU_BINARY; unsigned timer = EFBU_TIMER; unsigned pause = EFBU_PAUSE; signed c; if (getenv (EFBU_INTERFACE)) { #if defined (WINPCAP) || defined (LIBPCAP) channel.ifindex = atoi (getenv (EFBU_INTERFACE)); #else channel.ifname = strdup (getenv (EFBU_INTERFACE)); #endif } optind = 1; memset (channel.peer, 0xFF, sizeof (channel.peer)); memset (channel.host, 0xFF, sizeof (channel.host)); channel.type = EFBU_ETHERTYPE; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case 'b': binary = (uint8_t)(uintspec (optarg, 0, 255)); break; case 'd': _setbits (channel.flags, CHANNEL_UPDATE_TARGET); if (!hexencode (channel.peer, sizeof (channel.peer), optarg)) { error (1, errno, "%s", optarg); } break; case 'e': channel.type = (uint16_t)(basespec (optarg, 16, sizeof (channel.type))); break; case 'h': _setbits (channel.flags, CHANNEL_UPDATE_SOURCE); break; case 'i': #if defined (WINPCAP) || defined (LIBPCAP) channel.ifindex = atoi (optarg); #else channel.ifname = optarg; #endif break; case 'p': pause = (unsigned)(uintspec (optarg, 0, UINT_MAX)); break; case 'q': _setbits (channel.flags, CHANNEL_SILENCE); break; case 't': timer = (unsigned)(uintspec (optarg, 0, UINT_MAX)); break; case 'v': _setbits (channel.flags, CHANNEL_VERBOSE); break; default: break; } } argc -= optind; argv += optind; if (argc) { error (1, ECANCELED, ERROR_TOOMANY); } openchannel (&channel); function (&channel, buffer, sizeof (buffer), binary, timer, pause); closechannel (&channel); return (0); }

int main() { return function("asdf", "asdf"); }

void use() { function(); // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:3-[[@LINE-1]]:3}:"if (__builtin_available(macOS 10.12, *)) {\n " // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:14-[[@LINE-2]]:14}:"\n } else {\n // Fallback on earlier versions\n }" }

VALUE rb_protect(VALUE (*function)(VALUE), VALUE data, int *status) { // TODO CS 23-Jul-16 return function(data); }

/* ARGSUSED */ static fru_errno_t frt_for_each_segment(fru_nodehdl_t node, int (*function)(fru_seghdl_t hdl, void *args), void *args) { int num_segment; int cnt; int num_sect; int each_seg; section_t *sects; segment_t *segs; segment_list_t *tmp_list; int acc_err; int status; container_hdl_t cont; cont = g_raw->cont; num_sect = fru_get_num_sections(cont, NULL); if (num_sect == -1) { return (map_errno(errno)); } sects = malloc((num_sect + 1) * sizeof (section_t)); if (sects == NULL) { return (FRU_FAILURE); } num_sect = fru_get_sections(cont, sects, num_sect, NULL); if (num_sect == -1) { free(sects); return (map_errno(errno)); } for (cnt = 0; cnt < num_sect; cnt++) { num_segment = fru_get_num_segments(sects[cnt].handle, NULL); if (num_segment == -1) { return (map_errno(errno)); } else if (num_segment == 0) { continue; } segs = malloc((num_segment + 1) * sizeof (segment_t)); if (segs == NULL) { free(sects); return (FRU_FAILURE); } acc_err = fru_get_segments(sects[cnt].handle, segs, num_segment, NULL); if (acc_err == -1) { free(sects); free(segs); return (map_errno(errno)); } for (each_seg = 0; each_seg < num_segment; each_seg++) { tmp_list = malloc(sizeof (segment_list_t)); tmp_list->segment = &segs[each_seg]; tmp_list->next = NULL; if (g_raw->segs == NULL) { g_raw->segs = tmp_list; } else { tmp_list->next = g_raw->segs; g_raw->segs = tmp_list; } if ((status = function(segs[each_seg].handle, args)) != FRU_SUCCESS) { free(segs); free(sects); return (status); } } free(segs); free(sects); } return (FRU_SUCCESS); }

void *rb_thread_call_with_gvl(gvl_call function, void *data1) { return function(data1); }

// // loads the Link control dll // int LinkLoad(char *dllname) { char fullname[MBUFFER]; int error; char * (*function)(); char *prefix; if(osCheckLibraryHandle(LinkLibrary)!=0) { // // Return immediately if the library is already loaded. // if(Smatch(LinkLibraryName,dllname)) { return 0; } // // otherwise, unload previous library // else { LinkUnload(); } } // // Load DLL file // error = osDllLoad(dllname,fullname,LinkLibrary); if(error!=0) { ErrorPrint(LinkNoLoad,dllname); return -1; } fullname[MBUFFER-1]=0; // // Clear all function pointers // LinkFunctionReset(); // // see if the dll defines a prefix for all function names // prefix=dllname; function=LinkFunctionFind(dllname,"LinkPrefix"); if(function!=0) { prefix=(char *)function(); if(prefix==0) { prefix=dllname; } } // // Get function pointers for this Link // function=LinkFunctionFind(prefix,"LinkSelect"); if(function==0) { ErrorPrint(LinkLoadBad,prefix,fullname); LinkUnload(); return -1; } error=(int)function(); if(error!=0) { ErrorPrint(LinkLoadBad,prefix,fullname); LinkUnload(); return -1; } ErrorPrint(LinkLoadGood,prefix,fullname); SformatOutput(LinkLibraryName,MBUFFER-1,"%s",dllname); LinkLibraryName[MBUFFER-1]=0; return 0; }

void *rb_thread_call_without_gvl2(gvl_call function, void *data1, rb_unblock_function_t *unblock_function, void *data2) { // TODO do we need to do anyhting with the unblock_function? return function(data1); }

llvm::CallInst* call(const char* name, llvm::Value** start, int size, const char* inst_name, llvm::BasicBlock* block) { return llvm::CallInst::Create(function(name), llvm::ArrayRef<llvm::Value*>(start, size), inst_name, block); }

void run() { function(); }

llvm::CallInst* call(const char* name, std::vector<llvm::Value*> args, const char* inst_name, llvm::IRBuilder<>& builder) { return builder.CreateCall(function(name), args, inst_name); }

void Functions::retranslateText() { // ANALYSIS function( "abs" )->setDescription( tr( "Absolute Value" ) ); function( "average" )->setDescription( tr( "Average (Arithmetic Mean)" ) ); function( "bin" )->setDescription( tr( "Binary Representation" ) ); function( "cbrt" )->setDescription( tr( "Cube Root" ) ); function( "ceil" )->setDescription( tr( "Ceiling" ) ); function( "dec" )->setDescription( tr( "Decimal Representation" ) ); function( "floor" )->setDescription( tr( "Floor" ) ); function( "frac" )->setDescription( tr( "Fractional Part" ) ); function( "gamma" )->setDescription( tr( "Extension of Factorials [= (x-1)!]" ) ); function( "geomean" )->setDescription( tr( "Geometric Mean" ) ); function( "hex" )->setDescription( tr( "Hexadecimal Representation" ) ); function( "int" )->setDescription( tr( "Integer Part" ) ); function( "lngamma" )->setDescription( tr( "ln(abs(Gamma))" ) ); function( "max" )->setDescription( tr( "Maximum" ) ); function( "min" )->setDescription( tr( "Minimum" ) ); function( "oct" )->setDescription( tr( "Octal Representation" ) ); function( "product" )->setDescription( tr( "Product" ) ); function( "round" )->setDescription( tr( "Rounding" ) ); function( "sign" )->setDescription( tr( "Signum" ) ); function( "sqrt" )->setDescription( tr( "Square Root" ) ); function( "sum" )->setDescription( tr( "Sum" ) ); function( "trunc" )->setDescription( tr( "Truncation" ) ); //// LOGARITHM function( "arcosh" )->setDescription( tr( "Area Hyperbolic Cosine" ) ); function( "arsinh" )->setDescription( tr( "Area Hyperbolic Sine" ) ); function( "artanh" )->setDescription( tr( "Area Hyperbolic Tangent" ) ); function( "cosh" )->setDescription( tr( "Hyperbolic Cosine" ) ); function( "exp" )->setDescription( tr( "Exponential" ) ); function( "lg" )->setDescription( tr( "Base-2 Logarithm" ) ); function( "ln" )->setDescription( tr( "Natural Logarithm" ) ); function( "log" )->setDescription( tr( "Base-10 Logarithm" ) ); function( "sinh" )->setDescription( tr( "Hyperbolic Sine" ) ); function( "tanh" )->setDescription( tr( "Hyperbolic Tangent" ) ); //// DISCRETE function( "gcd" )->setDescription( tr( "Greatest Common Divisor" ) ); function( "ncr" )->setDescription( tr( "Combination (Binomial Coefficient)" ) ); function( "npr" )->setDescription( tr( "Permutation (Arrangement)" ) ); //// PROBABILITY function( "binomcdf" )->setDescription( tr( "Binomial Cumulative Distribution Function" ) ); function( "binommean" )->setDescription( tr( "Binomial Distribution Mean" ) ); function( "binompmf" )->setDescription( tr( "Binomial Probability Mass Function" ) ); function( "binomvar" )->setDescription( tr( "Binomial Distribution Variance" ) ); function( "erf" )->setDescription( tr( "Error Function" ) ); function( "erfc" )->setDescription( tr( "Complementary Error Function" ) ); function( "hypercdf" )->setDescription( tr( "Hypergeometric Cumulative Distribution Function" ) ); function( "hypermean" )->setDescription( tr( "Hypergeometric Distribution Mean" ) ); function( "hyperpmf" )->setDescription( tr( "Hypergeometric Probability Mass Function" ) ); function( "hypervar" )->setDescription( tr( "Hypergeometric Distribution Variance" ) ); function( "poicdf" )->setDescription( tr( "Poissonian Cumulative Distribution Function" ) ); function( "poimean" )->setDescription( tr( "Poissonian Distribution Mean" ) ); function( "poipmf" )->setDescription( tr( "Poissonian Probability Mass Function" ) ); function( "poivar" )->setDescription( tr( "Poissonian Distribution Variance" ) ); //// TRIGONOMETRY function( "acos" )->setDescription( tr( "Arc Cosine" ) ); function( "asin" )->setDescription( tr( "Arc Sine" ) ); function( "atan" )->setDescription( tr( "Arc Tangent" ) ); function( "cos" )->setDescription( tr( "Cosine" ) ); function( "cot" )->setDescription( tr( "Cotangent" ) ); function( "csc" )->setDescription( tr( "Cosecant" ) ); function( "degrees" )->setDescription( tr( "Degrees of Arc" ) ); function( "radians" )->setDescription( tr( "Radians" ) ); function( "sec" )->setDescription( tr( "Secant" ) ); function( "sin" )->setDescription( tr( "Sine" ) ); function( "tan" )->setDescription( tr( "Tangent" ) ); //// LOGIC function( "mask" )->setDescription( tr( "Mask to a bit size" ) ); function( "unmask" )->setDescription( tr( "Sign-extent a value" ) ); function( "not" )->setDescription( tr( "Logical NOT" ) ); function( "and" )->setDescription( tr( "Logical AND" ) ); function( "or" )->setDescription( tr( "Logical OR" ) ); function( "xor" )->setDescription( tr( "Logical XOR" ) ); function( "shl" )->setDescription( tr( "Arithmetic Shift Left" ) ); function( "shr" )->setDescription( tr( "Arithmetic Shift Right" ) ); function( "idiv" )->setDescription( tr( "Integer Quotient" ) ); function( "mod" )->setDescription( tr( "Modulo" ) ); }

void Thread::run(){ if(function != NULL) function(); }

void test_thread_function_one_argument() { boost::thread function(normal_function_one_arg,42); function.join(); BOOST_CHECK_EQUAL(42,nfoa_res); }