mod_ty PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc, int start, const char *ps1, const char *ps2, PyCompilerFlags *flags, int *errcode, PyArena *arena) { mod_ty mod; PyCompilerFlags localflags; perrdetail err; int iflags = PARSER_FLAGS(flags); node *n = PyParser_ParseFileObject(fp, filename, enc, &_PyParser_Grammar, start, ps1, ps2, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; flags = &localflags; } if (n) { flags->cf_flags |= iflags & PyCF_MASK; mod = PyAST_FromNodeObject(n, flags, filename, arena); PyNode_Free(n); } else { err_input(&err); if (errcode) *errcode = err.error; mod = NULL; } err_free(&err); return mod; }
/* Preferred access to parser is through AST. */ static mod_ty string_object_to_c_ast(const char *s, PyObject *filename, int start, PyCompilerFlags *flags, PyArena *arena) { mod_ty mod; PyCompilerFlags localflags; perrdetail err; int iflags = PARSER_FLAGS(flags); node *n = Ta27Parser_ParseStringObject(s, filename, &_Ta27Parser_Grammar, start, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; flags = &localflags; } if (n) { flags->cf_flags |= iflags & PyCF_MASK; mod = Ta27AST_FromNode(n, flags, PyUnicode_AsUTF8(filename), arena); Ta27Node_Free(n); } else { err_input(&err); mod = NULL; } err_free(&err); return mod; }
/* Preferred access to parser is through AST. */ mod_ty PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start, PyCompilerFlags *flags, PyArena *arena) { mod_ty mod; PyCompilerFlags localflags; perrdetail err; int iflags = PARSER_FLAGS(flags); node *n = PyParser_ParseStringObject(s, filename, &_PyParser_Grammar, start, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; flags = &localflags; } if (n) { flags->cf_flags |= iflags & PyCF_MASK; mod = PyAST_FromNodeObject(n, flags, filename, arena); PyNode_Free(n); } else { err_input(&err); mod = NULL; } err_free(&err); return mod; }
/* * Logs the error and then frees it. This function is equivalent to * err_log(err); * err_free(err); * * Arguments: * err The error. * level The logging level. */ void err_log_and_free( ErrorObj* const err, const enum err_level level) { err_log(err, level); err_free(err); }
node * PyParser_SimpleParseStringFlags(const char *str, int start, int flags) { perrdetail err; node *n = PyParser_ParseStringFlags(str, &_PyParser_Grammar, start, &err, flags); if (n == NULL) err_input(&err); err_free(&err); return n; }
void err_free( ErrorObj* const err) { if (err != NULL) { if (err->cause != NULL) err_free(err->cause); free((void*)err); } }
node * PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags) { perrdetail err; node *n = PyParser_ParseFileFlags(fp, filename, NULL, &_PyParser_Grammar, start, NULL, NULL, &err, flags); if (n == NULL) err_input(&err); err_free(&err); return n; }
int herc_main(int argc, char **argv) { err_t err; struct herc *h; err = herc_make(&h, argc, argv); if (err) { err_print(err); err_free(err); return 1; } return herc_run(h, argc, argv); }
void PyParser_ClearError(perrdetail *err) { err_free(err); }
/* * Returns a new instance of an LDM proxy. Can take a while because it * establishes a connection to the LDM. * * Arguments: * host Identifier of the host on which an LDM server is * running. * instance Pointer to a pointer to the new instance. "*instance" * is set upon successful return. * Returns: * 0 Success. "*instance" is set. * LP_SYSTEM System error. "log_start()" called. * LP_TIMEDOUT Connection attempt timed-out. "log_start()" called. * LP_HOSTUNREACH Host is unreachable. "log_start()" called. * LP_RPC_ERROR RPC error. "log_start()" called. * LP_LDM_ERROR LDM error. "log_start()" called. */ LdmProxyStatus lp_new( const char* const host, LdmProxy** const instance) { LdmProxyStatus status = 0; /* success */ size_t nbytes = sizeof(LdmProxy); LdmProxy* proxy = (LdmProxy*)malloc(nbytes); if (NULL == proxy) { log_serror("Couldn't allocate %lu bytes for new LdmProxy", nbytes); status = LP_SYSTEM; } else { proxy->host = strdup(host); if (NULL == proxy->host) { LOG_SERROR1("Couldn't duplicate string \"%s\"", host); status = LP_SYSTEM; } else { CLIENT* clnt = NULL; ErrorObj* error = ldm_clnttcp_create_vers(host, LDM_PORT, 6, &clnt, NULL, NULL); if (!error) { proxy->version = 6; proxy->hiya = my_hiya_6; proxy->send = my_send_6; proxy->flush = my_flush_6; } else if (LDM_CLNT_BAD_VERSION == err_code(error)) { /* Couldn't connect due to protocol version. */ err_free(error); error = ldm_clnttcp_create_vers(host, LDM_PORT, 5, &clnt, NULL, NULL); if (!error) { proxy->version = 5; proxy->hiya = my_hiya_5; proxy->send = my_send_5; proxy->flush = my_flush_5; } } if (error) { LOG_START1("%s", err_message(error)); err_free(error); free(proxy->host); status = convertStatus(error); } else { proxy->clnt = clnt; proxy->rpcTimeout = rpcTimeout; } } /* "proxy->host" allocated */ if (LP_OK == status) { *instance = proxy; } else { free(proxy); } } /* "proxy" allocated */ return status; }
int main(int ac, char *av[]) { char myname[HOSTNAMESIZE]; char *progname = av[0]; char *logfname; unsigned version; prod_class_t clss; prod_spec spec; int seq_start = 0; int status; ErrorObj* error; unsigned remotePort = LDM_PORT; logfname = "-"; remote = "localhost"; (void)set_timestamp(&clss.from); clss.to = TS_ENDT; clss.psa.psa_len = 1; clss.psa.psa_val = &spec; spec.feedtype = DEFAULT_FEEDTYPE; spec.pattern = ".*"; { extern int optind; extern char *optarg; int ch; int logmask = (LOG_MASK(LOG_ERR) | LOG_MASK(LOG_WARNING) | LOG_MASK(LOG_NOTICE)); while ((ch = getopt(ac, av, "vxl:h:f:P:s:")) != EOF) switch (ch) { case 'v': logmask |= LOG_MASK(LOG_INFO); break; case 'x': logmask |= LOG_MASK(LOG_DEBUG); break; case 'l': logfname = optarg; break; case 'h': remote = optarg; break; case 'f': spec.feedtype = atofeedtypet(optarg); if(spec.feedtype == NONE) { fprintf(stderr, "Unknown feedtype \"%s\"\n", optarg); usage(progname); } break; case 'P': { char* suffix = ""; long port; errno = 0; port = strtol(optarg, &suffix, 0); if (0 != errno || 0 != *suffix || 0 >= port || 0xffff < port) { (void)fprintf(stderr, "%s: invalid port %s\n", av[0], optarg); usage(av[0]); } remotePort = (unsigned)port; break; } case 's': seq_start = atoi(optarg); break; case '?': usage(progname); break; } ac -= optind; av += optind; if(ac < 1) usage(progname); (void) setulogmask(logmask); } /* * Set up error logging */ (void) openulog(ubasename(progname), LOG_NOTIME, LOG_LDM, logfname); /* * register exit handler */ if(atexit(cleanup) != 0) { serror("atexit"); exit(1); } /* * set up signal handlers */ set_sigactions(); (void) strcpy(myname, ghostname()); /* * Contact the server. */ error = ldm_clnttcp_create_vers(remote, remotePort, SIX, &clnt, NULL, NULL); (void)exitIfDone(1); if (!error) { version = SIX; hiya = my_hiya_6; send_product = send_product_6; nullproc = nullproc_6; } else if (LDM_CLNT_BAD_VERSION == err_code(error)) { err_free(error); error = ldm_clnttcp_create_vers(remote, remotePort, FIVE, &clnt, NULL, NULL); (void)exitIfDone(1); if (!error) { version = FIVE; hiya = my_hiya_5; send_product = send_product_5; nullproc = NULL; } } if (error) { err_log(error, ERR_FAILURE); err_free(error); status = 1; } else { udebug("version %u", version); status = ldmsend(clnt, &clss, myname, seq_start, ac, av); } return status != 0; }