本文整理汇总了C++中free_and_null函数的典型用法代码示例。如果您正苦于以下问题:C++ free_and_null函数的具体用法?C++ free_and_null怎么用?C++ free_and_null使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了free_and_null函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mod_funcdef_clear
static void mod_funcdef_clear(struct py_function_def *def)
{
mod_objclear(&def->function);
mod_objclear(&def->module);
free_and_null(&def->function_name);
free_and_null(&def->module_name);
}
示例2: udf_dirent_free
/*!
free free resources associated with p_udf_dirent.
*/
bool
udf_dirent_free(udf_dirent_t *p_udf_dirent)
{
if (p_udf_dirent) {
p_udf_dirent->fid = NULL;
free_and_null(p_udf_dirent->psz_name);
free_and_null(p_udf_dirent->sector);
free_and_null(p_udf_dirent);
}
return true;
}
示例3: sharpel1pca
void sharpel1pca (double *points_XT, int *dataDim, int *q, double *PCs, double *objectives)
{
ENTITYINFO entityinfo;
SOLVERINFO solverinfo;
PROBLEMINFO probleminfo;
probleminfo.status = 0;
int status = probleminfo.status;
solverinfo.model = NULL;
probleminfo.obj = NULL;
probleminfo.lb = NULL;
probleminfo.ub = NULL;
probleminfo.rhs = NULL;
probleminfo.matbeg = NULL;
probleminfo.matind = NULL;
probleminfo.matval = NULL;
probleminfo.colname = NULL;
probleminfo.PCs = PCs;
/*probleminfo.getScores = *getScores;
probleminfo.scores = scores;*/
probleminfo.objectives = objectives;
entityinfo.numentities_n = dataDim[1];
entityinfo.numattributes_m = dataDim[0];
entityinfo.points_XT = points_XT; /* transpose of data matrix */
probleminfo.q = *q; /* desired number of PCs */
status = allocateMemoryL1Line(&entityinfo, &probleminfo);
if (status) {
REprintf ("Unable to allocate memory\n");
goto TERMINATE;
}
status = solveSharpeL1PCA( &entityinfo, &solverinfo, &probleminfo); /* in l1line.c*/
if (status) {
REprintf ("Unable to solve. Terminating...; or done\n");
goto TERMINATE;
}
TERMINATE:
free_and_null ((char **) &probleminfo.ratios);
free_and_null ((char **) &probleminfo.weights);
free_and_null ((char **) &probleminfo.v);
free_and_null ((char **) &probleminfo.tosort);
} /* end l1line */
示例4: destroy_separator
void destroy_separator(void *obj)
{
Separator *separator = (Separator *)obj;
remove_area(&separator->area);
free_area(&separator->area);
free_and_null(separator);
}
示例5: cleanup
/* This is run automatically before leaving the program.
Free allocated resources.
*/
static void
cleanup (void)
{
if (p) paranoia_free(p);
if (d) cdda_close(d);
free_and_null(force_cdrom_device);
free_and_null(span);
if(logfile_open) {
fclose(logfile);
logfile = NULL;
}
if(reportfile_open) {
fclose(reportfile);
reportfile = NULL;
}
}
示例6: free_user_cbhandle
static int
free_user_cbhandle (USER_CBHANDLE *user_cbhandle)
{
int status = 0;
if (user_cbhandle == NULL) goto TERMINATE;
free_and_null ((char **) &user_cbhandle->x);
free_and_null ((char **) &user_cbhandle->indices);
free_and_null ((char **) &user_cbhandle->ray);
free_and_null ((char **) &user_cbhandle->cutval);
free_and_null ((char **) &user_cbhandle->cutind);
if ( user_cbhandle->lp != NULL ) {
int local_status = CPXXfreeprob (user_cbhandle->env, &(user_cbhandle->lp) );
if ( local_status ) {
fprintf (stderr, "CPXXfreeprob failed, error code %d.\n", status);
status = local_status;
}
else
user_cbhandle->lp = NULL;
}
if ( user_cbhandle->env != NULL ) {
int local_status = CPXXcloseCPLEX ( &(user_cbhandle->env) );
if ( local_status ) {
fprintf (stderr, "CPXXcloseCPLEX failed, error code %d.\n", status);
status = local_status;
}
else
user_cbhandle->env = NULL;
}
TERMINATE:
return status;
} /* END free_user_cbhandle */
示例7: udf_close
/*!
Close UDF and free resources associated with p_udf.
*/
bool
udf_close (udf_t *p_udf)
{
if (!p_udf) return true;
if (p_udf->b_stream) {
cdio_stdio_destroy(p_udf->stream);
} else {
cdio_destroy(p_udf->cdio);
}
/* Get rid of root directory if allocated. */
free_and_null(p_udf);
return true;
}
示例8: populatebyrow
static int
populatebyrow (CPXENVptr env, CPXLPptr lp,
int nfoods, double *cost, double *lb, double *ub,
int nnutr, double *nutrmin, double *nutrmax,
double **nutrper)
{
int status = 0;
int zero = 0;
int *ind = NULL;
int i, j;
ind = (int*) malloc(nfoods * sizeof(int));
if ( ind == NULL ) {
status = CPXERR_NO_MEMORY;
goto TERMINATE;
}
for (j = 0; j < nfoods; j++) {
ind[j] = j;
}
status = CPXnewcols (env, lp, nfoods, cost, lb, ub, NULL, NULL);
if ( status ) goto TERMINATE;
for (i = 0; i < nnutr; i++) {
double rng = nutrmax[i] - nutrmin[i];
status = CPXaddrows (env, lp, 0, 1, nfoods, nutrmin+i, "R",
&zero, ind, nutrper[i], NULL, NULL);
if ( status ) goto TERMINATE;
status = CPXchgrngval (env, lp, 1, &i, &rng);
if ( status ) goto TERMINATE;
}
TERMINATE:
free_and_null ((char **)&ind);
return (status);
} /* END populatebyrow */
示例9: exec_instr_pipe
int exec_instr_pipe(s_instr *instr,
s_list_dup *list_dup,
int *error)
{
s_instr_pipe *instr_pipe = NULL;
int filedes[2];
int res = 0;
s_list_dup *dp = NULL;
s_list_dup *dp2 = NULL;
s_list_instr_item *list_instr = NULL;
int fd_in = STDIN_FILENO;
if (instr == NULL || instr->instr == NULL)
return (-1);
instr_pipe = instr->instr;
list_instr = instr_pipe->list_instr->first;
for (; list_instr != NULL; list_instr = list_instr->next)
{
if (list_instr->next != NULL)
mpipe(filedes);
if (list_instr->next != NULL)
dp = list_dup_insert(list_dup, filedes[1], STDOUT_FILENO);
if (list_instr != instr_pipe->list_instr->first)
dp2 = list_dup_insert(dp == NULL ? list_dup : dp, fd_in, STDIN_FILENO);
res = exec_instr(list_instr->elmt, dp2 == NULL ? dp : dp2, error);
close_fds(&fd_in, filedes, list_instr->next);
free_and_null(&dp, &dp2);
CHECK_ERROR()
}
return (res);
}
示例10: main
//.........这里部分代码省略.........
}
status = CPXgetbase (env, lp, cstat, rstat);
if ( status ) {
fprintf (stderr, "Failed to get basis; error %d.\n", status);
goto TERMINATE;
}
}
else {
printf ("No basis available\n");
}
/* Retrieve solution vector */
x = (double *) malloc (cur_numcols*sizeof(double));
if ( x == NULL ) {
fprintf (stderr, "No memory for solution.\n");
goto TERMINATE;
}
status = CPXgetx (env, lp, x, 0, cur_numcols-1);
if ( status ) {
fprintf (stderr, "Failed to obtain primal solution.\n");
goto TERMINATE;
}
/* Write out the solution */
for (j = 0; j < cur_numcols; j++) {
printf ( "Column %d: Value = %17.10g", j, x[j]);
if ( cstat != NULL ) {
switch (cstat[j]) {
case CPX_AT_LOWER:
basismsg = "Nonbasic at lower bound";
break;
case CPX_BASIC:
basismsg = "Basic";
break;
case CPX_AT_UPPER:
basismsg = "Nonbasic at upper bound";
break;
case CPX_FREE_SUPER:
basismsg = "Superbasic, or free variable at zero";
break;
default:
basismsg = "Bad basis status";
break;
}
printf (" %s",basismsg);
}
printf ("\n");
}
/* Display the maximum bound violation. */
status = CPXgetdblquality (env, lp, &maxviol, CPX_MAX_PRIMAL_INFEAS);
if ( status ) {
fprintf (stderr, "Failed to obtain bound violation.\n");
goto TERMINATE;
}
printf ("Maximum bound violation = %17.10g\n", maxviol);
TERMINATE:
/* Free up the basis and solution */
free_and_null ((char **) &cstat);
free_and_null ((char **) &rstat);
free_and_null ((char **) &x);
/* Free up the problem, if necessary */
if ( lp != NULL ) {
status = CPXfreeprob (env, &lp);
if ( status ) {
fprintf (stderr, "CPXfreeprob failed, error code %d.\n", status);
}
}
/* Free up the CPLEX environment, if necessary */
if ( env != NULL ) {
status = CPXcloseCPLEX (&env);
/* Note that CPXcloseCPLEX produces no output,
so the only way to see the cause of the error is to use
CPXgeterrorstring. For other CPLEX routines, the errors will
be seen if the CPXPARAM_ScreenOutput indicator is set to CPX_ON. */
if ( status ) {
char errmsg[CPXMESSAGEBUFSIZE];
fprintf (stderr, "Could not close CPLEX environment.\n");
CPXgeterrorstring (env, status, errmsg);
fprintf (stderr, "%s", errmsg);
}
}
return (status);
} /* END main */
示例11: main
//.........这里部分代码省略.........
totinv = 0;
for (j = 0; j < numcols; j++) {
if ( strncmp (nameptr[j], "inv", 3) ) {
values[j] = 0.0;
}
else {
values[j] = - 1.0;
}
}
status = CPXprechgobj (env, lp, numcols, indices, values);
if ( status ) {
fprintf (stderr,
"Failed to change to inventory objective. Status %d\n",
status);
goto TERMINATE;
}
status = CPXlpopt (env, lp);
if ( status ) {
fprintf (stderr, "Optimization on inventory level failed. Status %d.\n",
status);
goto TERMINATE;
}
solstat = CPXgetstat (env, lp);
status = CPXgetobjval (env, lp, &objval);
if ( status || solstat != CPX_STAT_OPTIMAL ) {
fprintf (stderr, "Solution failed. Status %d, solstat %d.\n",
status, solstat);
goto TERMINATE;
}
printf("Solution status %d.\n", solstat);
printf ("Inventory level after optimization is %g\n", -objval);
status = CPXgetx (env, lp, x, 0, numcols-1);
if ( status ) {
fprintf (stderr, "Failed to obtain primal solution.\n");
goto TERMINATE;
}
printf("Found solution");
/* Write out the solution */
printf ("\n");
for (j = 0; j < numcols; j++) {
printf ( "%s: Value = %17.10g\n", nameptr[j], x[j]);
}
TERMINATE:
/* Free the filename */
free_and_null ((char **) &prod);
/* Free up the basis and solution */
free_and_null ((char **) &indices);
free_and_null ((char **) &values);
free_and_null ((char **) &nameptr);
free_and_null ((char **) &namestore);
free_and_null ((char **) &x);
/* Free up the problem, if necessary */
if ( lp != NULL ) {
status = CPXfreeprob (env, &lp);
if ( status ) {
fprintf (stderr, "CPXfreeprob failed, error code %d.\n", status);
}
}
/* Free up the CPLEX environment, if necessary */
if ( env != NULL ) {
status = CPXcloseCPLEX (&env);
/* Note that CPXcloseCPLEX produces no output,
so the only way to see the cause of the error is to use
CPXgeterrorstring. For other CPLEX routines, the errors will
be seen if the CPXPARAM_ScreenOutput indicator is set to CPX_ON. */
if ( status ) {
char errmsg[CPXMESSAGEBUFSIZE];
fprintf (stderr, "Could not close CPLEX environment.\n");
CPXgeterrorstring (env, status, errmsg);
fprintf (stderr, "%s", errmsg);
}
}
return (status);
} /* END main */
示例12: rounddownheur
static int CPXPUBLIC
rounddownheur (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
double *objval_p,
double *x,
int *checkfeas_p,
int *useraction_p)
{
int status = 0;
int j, cols;
double roundobjval;
int *feas = NULL;
CPXCLPptr lp;
double *objcoefs = NULL;
*useraction_p = CPX_CALLBACK_DEFAULT;
/* Heuristic motivated by knapsack constrained problems.
Rounding down all fractional values will give an integer
solution that is feasible, since all constraints are <=
with positive coefficients */
status = CPXgetcallbacklp (env, cbdata, wherefrom, &lp);
if ( status ) {
fprintf (stdout, "Can't get lp pointer.");
goto TERMINATE;
}
cols = CPXgetnumcols (env, lp);
if ( cols <= 0 ) {
fprintf (stdout, "numcols = %d.", cols);
status = CPXERR_CALLBACK;
goto TERMINATE;
}
objcoefs = (double *) malloc (cols * sizeof (double));
feas = (int *) malloc (cols * sizeof (int));
if ( objcoefs == NULL || feas == NULL ) {
fprintf (stdout, "Out of memory.");
status = CPXERR_CALLBACK;
goto TERMINATE;
}
status = CPXgetobj (env, lp, objcoefs, 0, cols-1);
if ( status ) {
fprintf (stdout, "Can't get objective.");
goto TERMINATE;
}
status = CPXgetcallbacknodeintfeas (env, cbdata, wherefrom, feas,
0, cols-1);
if ( status ) {
fprintf (stdout,
"Can't get variable feasible status for node.");
goto TERMINATE;
}
roundobjval = *objval_p;
for (j = 0; j < cols; j++) {
/* Set the fractional variable to zero and update
the objective value */
if ( feas[j] == CPX_INTEGER_INFEASIBLE ) {
roundobjval -= x[j] * objcoefs[j];
x[j] = 0.0;
}
}
*objval_p = roundobjval;
/* Have CPLEX check the solution for integer feasibility */
*checkfeas_p = 1;
/* Tell CPLEX that a solution is being returned */
*useraction_p = CPX_CALLBACK_SET;
TERMINATE:
free_and_null ((char **) &objcoefs);
free_and_null ((char **) &feas);
return (status);
} /* END rounddown */
示例13: main
//.........这里部分代码省略.........
status = CPXsetdblparam (env, CPXPARAM_MIP_Tolerances_MIPGap,
(double) 1e-6);
if ( status ) goto TERMINATE;
/* Turn on traditional search for use with control callbacks */
status = CPXsetintparam (env, CPXPARAM_MIP_Strategy_Search,
CPX_MIPSEARCH_TRADITIONAL);
if ( status ) goto TERMINATE;
/* Set up to use MIP callback */
status = CPXsetheuristiccallbackfunc (env, rounddownheur, NULL);
if ( status ) goto TERMINATE;
/* Optimize the problem and obtain solution */
status = CPXmipopt (env, lp);
if ( status ) {
fprintf (stderr, "Failed to optimize MIP.\n");
goto TERMINATE;
}
solstat = CPXgetstat (env, lp);
printf ("Solution status %d.\n", solstat);
status = CPXgetobjval (env, lp, &objval);
if ( status ) {
fprintf (stderr, "Failed to obtain objective value.\n");
goto TERMINATE;
}
printf ("Objective value %.10g\n", objval);
cur_numcols = CPXgetnumcols (env, lp);
/* Allocate space for solution */
x = (double *) malloc (cur_numcols * sizeof (double));
if ( x == NULL ) {
fprintf (stderr, "No memory for solution values.\n");
goto TERMINATE;
}
status = CPXgetx (env, lp, x, 0, cur_numcols-1);
if ( status ) {
fprintf (stderr, "Failed to obtain solution.\n");
goto TERMINATE;
}
/* Write out the solution */
for (j = 0; j < cur_numcols; j++) {
if ( fabs (x[j]) > 1e-10 ) {
printf ( "Column %d: Value = %17.10g\n", j, x[j]);
}
}
TERMINATE:
/* Free the solution vector */
free_and_null ((char **) &x);
/* Free the problem as allocated by CPXcreateprob and
CPXreadcopyprob, if necessary */
if ( lp != NULL ) {
status = CPXfreeprob (env, &lp);
if ( status ) {
fprintf (stderr, "CPXfreeprob failed, error code %d.\n",
status);
}
}
/* Free the CPLEX environment, if necessary */
if ( env != NULL ) {
status = CPXcloseCPLEX (&env);
/* Note that CPXcloseCPLEX produces no output, so the only
way to see the cause of the error is to use
CPXgeterrorstring. For other CPLEX routines, the errors
will be seen if the CPXPARAM_ScreenOutput parameter is set to
CPX_ON */
if ( status ) {
char errmsg[CPXMESSAGEBUFSIZE];
fprintf (stderr, "Could not close CPLEX environment.\n");
CPXgeterrorstring (env, status, errmsg);
fprintf (stderr, "%s", errmsg);
}
}
return (status);
} /* END main */
示例14: main
//.........这里部分代码省略.........
solstat = CPXXgetstat (env, lp);
printf ("\nSolution status: %d\n", solstat);
/* Write out the objective value */
if ( CPXXgetobjval (env, lp, &objval) ) {
printf ("Failed to obtain objective value.\n");
}
else {
printf ("Objective value: %17.10e\n", objval);
}
if ( solstat == CPXMIP_OPTIMAL ) {
/* Write out the optimal tour */
num_x_cols = CPXXgetnumcols (env, lp);
x = malloc (num_x_cols * sizeof(*x));
if ( x == NULL ) {
fprintf (stderr, "No memory for x array.\n");
status = -1;
goto TERMINATE;
}
status = CPXXgetx (env, lp, x, 0, num_x_cols-1);
if ( status ) {
fprintf (stderr, "Failed to obtain solution, status = %d.\n", status);
goto TERMINATE;
}
succ = malloc (num_nodes * sizeof(*succ));
if ( succ == NULL ) {
fprintf (stderr, "No memory for succ array.\n");
status = -1;
goto TERMINATE;
}
for (j = 0; j < num_nodes; ++j)
succ[j] = -1;
for (i = 0; i < num_nodes; ++i) {
for (j = 0; j < num_nodes; ++j) {
if ( fabs (x[i * num_nodes + j]) > 1e-03 )
succ[i] = j;
}
}
printf ("Optimal tour:\n");
i = 0;
while ( succ[i] != 0 ) {
printf ("%d, ", i);
i = succ[i];
}
printf ("%d\n", i);
}
else {
printf ("Solution status is not CPX_STAT_OPTIMAL\n");
}
TERMINATE:
/* Free the allocated memory if necessary */
free_and_null ((char **) &x);
free_and_null ((char **) &succ);
if ( arc_cost != NULL ) {
for (i = 0; i < num_nodes; ++i) {
free_and_null ((char **) &(arc_cost[i]));
}
}
free_and_null ((char **) &arc_cost);
status = free_user_cbhandle (&user_cbhandle);
if ( status ) {
fprintf (stderr, "free_user_cbhandle failed, status = %d.\n",
status);
}
if ( lp != NULL ) {
int local_status = CPXXfreeprob (env, &lp);
if ( local_status ) {
fprintf (stderr, "CPXXfreeprob failed, error code %d.\n",
local_status);
status = local_status;
}
}
/* Free the CPLEX environment, if necessary */
if ( env != NULL ) {
int local_status = CPXXcloseCPLEX (&env);
if ( local_status ) {
fprintf (stderr,
"Could not close CPLEX environment, status = %d.\n",
local_status);
status = local_status;
}
}
return status;
} /* END main */
示例15: read_execp
gboolean read_execp(void *obj)
{
Execp *execp = (Execp *)obj;
if (execp->backend->child_pipe < 0)
return FALSE;
gboolean command_finished = FALSE;
while (1) {
// Make sure there is free space in the buffer
if (execp->backend->buf_capacity - execp->backend->buf_length < 1024) {
execp->backend->buf_capacity *= 2;
execp->backend->buf_output = realloc(execp->backend->buf_output, execp->backend->buf_capacity);
}
ssize_t count = read(execp->backend->child_pipe,
execp->backend->buf_output + execp->backend->buf_length,
execp->backend->buf_capacity - execp->backend->buf_length - 1);
if (count > 0) {
// Successful read
execp->backend->buf_length += count;
execp->backend->buf_output[execp->backend->buf_length] = '\0';
continue;
} else if (count == 0) {
// End of file
command_finished = TRUE;
break;
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
// No more data available at the moment
break;
} else if (errno == EINTR) {
// Harmless interruption by signal
continue;
} else {
// Error
command_finished = TRUE;
break;
}
break;
}
if (command_finished) {
execp->backend->child = 0;
close(execp->backend->child_pipe);
execp->backend->child_pipe = -1;
if (execp->backend->interval)
execp->backend->timer =
add_timeout(execp->backend->interval * 1000, 0, execp_timer_callback, execp, &execp->backend->timer);
}
if (!execp->backend->continuous && command_finished) {
free_and_null(execp->backend->text);
free_and_null(execp->backend->icon_path);
if (!execp->backend->has_icon) {
execp->backend->text = strdup(execp->backend->buf_output);
} else {
char *text = strchr(execp->backend->buf_output, '\n');
if (text) {
*text = '\0';
text++;
execp->backend->text = strdup(text);
} else {
execp->backend->text = strdup("");
}
execp->backend->icon_path = strdup(execp->backend->buf_output);
}
int len = strlen(execp->backend->text);
if (len > 0 && execp->backend->text[len - 1] == '\n')
execp->backend->text[len - 1] = '\0';
execp->backend->buf_length = 0;
execp->backend->buf_output[execp->backend->buf_length] = '\0';
execp->backend->last_update_finish_time = time(NULL);
execp->backend->last_update_duration =
execp->backend->last_update_finish_time - execp->backend->last_update_start_time;
return TRUE;
} else if (execp->backend->continuous > 0) {
// Count lines in buffer
int num_lines = 0;
char *last = execp->backend->buf_output;
char *end = NULL;
for (char *c = execp->backend->buf_output; *c; c++) {
if (*c == '\n') {
num_lines++;
if (num_lines == execp->backend->continuous)
end = c;
}
last = c;
}
if (*last && *last != '\n')
num_lines++;
if (num_lines >= execp->backend->continuous) {
if (end)
*end = '\0';
free_and_null(execp->backend->text);
free_and_null(execp->backend->icon_path);
if (!execp->backend->has_icon) {
execp->backend->text = strdup(execp->backend->buf_output);
} else {
char *text = strchr(execp->backend->buf_output, '\n');
if (text) {
*text = '\0';
//.........这里部分代码省略.........