本文整理汇总了C++中PyMem_RawFree函数的典型用法代码示例。如果您正苦于以下问题:C++ PyMem_RawFree函数的具体用法?C++ PyMem_RawFree怎么用?C++ PyMem_RawFree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyMem_RawFree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: _cleanup_editlineobject
static void
_cleanup_editlineobject(EditLineObject *self)
{
/* mop up libedit */
if (self->el)
el_end(self->el);
if (self->tok)
tok_end(self->tok);
if (self->hist)
history_end(self->hist);
/* tidy up the allocated bits */
if (self->name)
PyMem_RawFree(self->name);
if (self->prompt)
PyMem_RawFree(self->prompt);
if (self->rprompt)
PyMem_RawFree(self->rprompt);
if (self->buffer)
PyMem_RawFree(self->buffer);
/* manage file-handles? */
if (self->fin)
fclose(self->fin);
if (self->fout)
fclose(self->fout);
if (self->ferr)
fclose(self->ferr);
/* release my ownership of the I/O refs */
Py_DECREF(self->pyin);
Py_DECREF(self->pyout);
Py_DECREF(self->pyerr);
}
开发者ID:mark-nicholson,项目名称:python-editline,代码行数:34,代码来源:_editline.c
示例2: nacl_main
int nacl_main(int argc, char **argv) {
if (nacl_startup_untar(argv[0], DATA_FILE, "/"))
return -1;
wchar_t **argv_copy;
/* We need a second copy, as Python might modify the first one. */
wchar_t **argv_copy2;
int i, res;
char *oldloc;
#ifdef __FreeBSD__
fp_except_t m;
#endif
argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
if (!argv_copy || !argv_copy2) {
fprintf(stderr, "out of memory\n");
return 1;
}
/* 754 requires that FP exceptions run in "no stop" mode by default,
* and until C vendors implement C99's ways to control FP exceptions,
* Python requires non-stop mode. Alas, some platforms enable FP
* exceptions by default. Here we disable them.
*/
#ifdef __FreeBSD__
m = fpgetmask();
fpsetmask(m & ~FP_X_OFL);
#endif
oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
if (!oldloc) {
fprintf(stderr, "out of memory\n");
return 1;
}
setlocale(LC_ALL, "");
for (i = 0; i < argc; i++) {
argv_copy[i] = _Py_char2wchar(argv[i], NULL);
if (!argv_copy[i]) {
PyMem_RawFree(oldloc);
fprintf(stderr, "Fatal Python error: "
"unable to decode the command line argument #%i\n",
i + 1);
return 1;
}
argv_copy2[i] = argv_copy[i];
}
argv_copy2[argc] = argv_copy[argc] = NULL;
setlocale(LC_ALL, oldloc);
PyMem_RawFree(oldloc);
res = Py_Main(argc, argv_copy);
for (i = 0; i < argc; i++) {
PyMem_RawFree(argv_copy2[i]);
}
PyMem_RawFree(argv_copy);
PyMem_RawFree(argv_copy2);
return res;
}
开发者ID:KnoooW,项目名称:naclports,代码行数:60,代码来源:python.c
示例3: _Py_wrealpath
wchar_t*
_Py_wrealpath(const wchar_t *path,
wchar_t *resolved_path, size_t resolved_path_size)
{
char *cpath;
char cresolved_path[MAXPATHLEN];
wchar_t *wresolved_path;
char *res;
size_t r;
cpath = _Py_wchar2char(path, NULL);
if (cpath == NULL) {
errno = EINVAL;
return NULL;
}
res = realpath(cpath, cresolved_path);
PyMem_Free(cpath);
if (res == NULL)
return NULL;
wresolved_path = _Py_char2wchar(cresolved_path, &r);
if (wresolved_path == NULL) {
errno = EINVAL;
return NULL;
}
if (resolved_path_size <= r) {
PyMem_RawFree(wresolved_path);
errno = EINVAL;
return NULL;
}
wcsncpy(resolved_path, wresolved_path, resolved_path_size);
PyMem_RawFree(wresolved_path);
return resolved_path;
}
开发者ID:CIBC-Internal,项目名称:python,代码行数:33,代码来源:fileutils.c
示例4: _Py_wgetcwd
wchar_t*
_Py_wgetcwd(wchar_t *buf, size_t size)
{
#ifdef MS_WINDOWS
int isize = (int)Py_MIN(size, INT_MAX);
return _wgetcwd(buf, isize);
#else
char fname[MAXPATHLEN];
wchar_t *wname;
size_t len;
if (getcwd(fname, Py_ARRAY_LENGTH(fname)) == NULL)
return NULL;
wname = _Py_char2wchar(fname, &len);
if (wname == NULL)
return NULL;
if (size <= len) {
PyMem_RawFree(wname);
return NULL;
}
wcsncpy(buf, wname, size);
PyMem_RawFree(wname);
return buf;
#endif
}
开发者ID:CIBC-Internal,项目名称:python,代码行数:25,代码来源:fileutils.c
示例5: calculate_free
static void
calculate_free(PyCalculatePath *calculate)
{
PyMem_RawFree(calculate->pythonpath);
PyMem_RawFree(calculate->prefix);
PyMem_RawFree(calculate->exec_prefix);
PyMem_RawFree(calculate->lib_python);
PyMem_RawFree(calculate->path_env);
}
开发者ID:DinoV,项目名称:cpython,代码行数:9,代码来源:getpath.c
示例6: getFileData
PyObject* getFileData(int argc, char *argv[])
{
PyObject *BioModule = PyImport_ImportModule("Bio");
const char *filename, *filetype, *pycmdToRun;
filename = (const char *)PyUnicode_DecodeFSDefault(argv[1]);
filetype = (const char *)PyUnicode_DecodeFSDefault(argv[2]);
std::string cmdToRun = "import Bio\nBio.SeqIO.parse(";
cmdToRun = cmdToRun + filename + std::string(",") + filetype;
pycmdToRun = cmdToRun.c_str();
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize();
PyObject* filedata;
filedata = PyRun_String(pycmdToRun, 0, NULL, NULL);
Py_DECREF(filename);
Py_DECREF(filetype);
Py_Finalize();
PyMem_RawFree(program);
return filedata;
}
开发者ID:BMJHayward,项目名称:navtome,代码行数:27,代码来源:biopythonParser.cpp
示例7: _PyThreadState_DeleteExcept
/*
* Delete all thread states except the one passed as argument.
* Note that, if there is a current thread state, it *must* be the one
* passed as argument. Also, this won't touch any other interpreters
* than the current one, since we don't know which thread state should
* be kept in those other interpreteres.
*/
void
_PyThreadState_DeleteExcept(PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
PyThreadState *p, *next, *garbage;
HEAD_LOCK();
/* Remove all thread states, except tstate, from the linked list of
thread states. This will allow calling PyThreadState_Clear()
without holding the lock. */
garbage = interp->tstate_head;
if (garbage == tstate)
garbage = tstate->next;
if (tstate->prev)
tstate->prev->next = tstate->next;
if (tstate->next)
tstate->next->prev = tstate->prev;
tstate->prev = tstate->next = NULL;
interp->tstate_head = tstate;
HEAD_UNLOCK();
/* Clear and deallocate all stale thread states. Even if this
executes Python code, we should be safe since it executes
in the current thread, not one of the stale threads. */
for (p = garbage; p; p = next) {
next = p->next;
PyThreadState_Clear(p);
PyMem_RawFree(p);
}
}
开发者ID:Alkalit,项目名称:cpython,代码行数:35,代码来源:pystate.c
示例8: PyThread_ReInitTLS
/* Forget everything not associated with the current thread id.
* This function is called from PyOS_AfterFork(). It is necessary
* because other thread ids which were in use at the time of the fork
* may be reused for new threads created in the forked process.
*/
void
PyThread_ReInitTLS(void)
{
long id = PyThread_get_thread_ident();
struct key *p, **q;
if (!keymutex)
return;
/* As with interpreter_lock in PyEval_ReInitThreads()
we just create a new lock without freeing the old one */
keymutex = PyThread_allocate_lock();
/* Delete all keys which do not match the current thread id */
q = &keyhead;
while ((p = *q) != NULL) {
if (p->id != id) {
*q = p->next;
PyMem_RawFree((void *)p);
/* NB This does *not* free p->value! */
}
else
q = &p->next;
}
}
开发者ID:dougmassay,项目名称:cpython3.4.4,代码行数:30,代码来源:thread.c
示例9: overlapped_RegisterWaitWithQueue
static PyObject *
overlapped_RegisterWaitWithQueue(PyObject *self, PyObject *args)
{
HANDLE NewWaitObject;
HANDLE Object;
ULONG Milliseconds;
struct PostCallbackData data, *pdata;
if (!PyArg_ParseTuple(args, F_HANDLE F_HANDLE F_POINTER F_DWORD,
&Object,
&data.CompletionPort,
&data.Overlapped,
&Milliseconds))
return NULL;
/* Use PyMem_RawMalloc() rather than PyMem_Malloc(), since
PostToQueueCallback() will call PyMem_Free() from a new C thread
which doesn't hold the GIL. */
pdata = PyMem_RawMalloc(sizeof(struct PostCallbackData));
if (pdata == NULL)
return SetFromWindowsErr(0);
*pdata = data;
if (!RegisterWaitForSingleObject(
&NewWaitObject, Object, (WAITORTIMERCALLBACK)PostToQueueCallback,
pdata, Milliseconds,
WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE))
{
PyMem_RawFree(pdata);
return SetFromWindowsErr(0);
}
return Py_BuildValue(F_HANDLE, NewWaitObject);
}
开发者ID:ARK4579,项目名称:cpython,代码行数:35,代码来源:overlapped.c
示例10: PyInterpreterState_Delete
void
PyInterpreterState_Delete(PyInterpreterState *interp)
{
PyInterpreterState **p;
zapthreads(interp);
HEAD_LOCK();
for (p = &_PyRuntime.interpreters.head; ; p = &(*p)->next) {
if (*p == NULL)
Py_FatalError(
"PyInterpreterState_Delete: invalid interp");
if (*p == interp)
break;
}
if (interp->tstate_head != NULL)
Py_FatalError("PyInterpreterState_Delete: remaining threads");
*p = interp->next;
if (_PyRuntime.interpreters.main == interp) {
_PyRuntime.interpreters.main = NULL;
if (_PyRuntime.interpreters.head != NULL)
Py_FatalError("PyInterpreterState_Delete: remaining subinterpreters");
}
HEAD_UNLOCK();
if (interp->id_mutex != NULL) {
PyThread_free_lock(interp->id_mutex);
}
if (interp->ceval.pending.lock != NULL) {
PyThread_free_lock(interp->ceval.pending.lock);
}
PyMem_RawFree(interp);
}
开发者ID:tiran,项目名称:cpython,代码行数:30,代码来源:pystate.c
示例11: Py_SetStandardStreamEncoding
int
Py_SetStandardStreamEncoding(const char *encoding, const char *errors)
{
if (Py_IsInitialized()) {
/* This is too late to have any effect */
return -1;
}
/* Can't call PyErr_NoMemory() on errors, as Python hasn't been
* initialised yet.
*
* However, the raw memory allocators are initialised appropriately
* as C static variables, so _PyMem_RawStrdup is OK even though
* Py_Initialize hasn't been called yet.
*/
if (encoding) {
_Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding);
if (!_Py_StandardStreamEncoding) {
return -2;
}
}
if (errors) {
_Py_StandardStreamErrors = _PyMem_RawStrdup(errors);
if (!_Py_StandardStreamErrors) {
if (_Py_StandardStreamEncoding) {
PyMem_RawFree(_Py_StandardStreamEncoding);
}
return -3;
}
}
return 0;
}
开发者ID:yoongkang,项目名称:cpython,代码行数:31,代码来源:pylifecycle.c
示例12: _PyInterpreterState_DeleteExceptMain
/*
* Delete all interpreter states except the main interpreter. If there
* is a current interpreter state, it *must* be the main interpreter.
*/
void
_PyInterpreterState_DeleteExceptMain()
{
PyThreadState *tstate = PyThreadState_Swap(NULL);
if (tstate != NULL && tstate->interp != _PyRuntime.interpreters.main) {
Py_FatalError("PyInterpreterState_DeleteExceptMain: not main interpreter");
}
HEAD_LOCK();
PyInterpreterState *interp = _PyRuntime.interpreters.head;
_PyRuntime.interpreters.head = NULL;
while (interp != NULL) {
if (interp == _PyRuntime.interpreters.main) {
_PyRuntime.interpreters.main->next = NULL;
_PyRuntime.interpreters.head = interp;
interp = interp->next;
continue;
}
PyInterpreterState_Clear(interp); // XXX must activate?
zapthreads(interp);
if (interp->id_mutex != NULL) {
PyThread_free_lock(interp->id_mutex);
}
PyInterpreterState *prev_interp = interp;
interp = interp->next;
PyMem_RawFree(prev_interp);
}
HEAD_UNLOCK();
if (_PyRuntime.interpreters.head == NULL) {
Py_FatalError("PyInterpreterState_DeleteExceptMain: missing main");
}
PyThreadState_Swap(tstate);
}
开发者ID:tiran,项目名称:cpython,代码行数:39,代码来源:pystate.c
示例13: PyInterpreterState_Delete
void
PyInterpreterState_Delete(PyInterpreterState *interp)
{
PyInterpreterState **p;
zapthreads(interp);
HEAD_LOCK();
for (p = &interp_head; ; p = &(*p)->next) {
if (*p == NULL)
Py_FatalError(
"PyInterpreterState_Delete: invalid interp");
if (*p == interp)
break;
}
if (interp->tstate_head != NULL)
Py_FatalError("PyInterpreterState_Delete: remaining threads");
*p = interp->next;
HEAD_UNLOCK();
PyMem_RawFree(interp);
#ifdef WITH_THREAD
if (interp_head == NULL && head_mutex != NULL) {
PyThread_free_lock(head_mutex);
head_mutex = NULL;
}
#endif
}
开发者ID:Alkalit,项目名称:cpython,代码行数:25,代码来源:pystate.c
示例14: Py_DecodeLocale
static wchar_t* Py_DecodeLocale(const char* arg, size_t*) {
size_t argsize = mbstowcs(NULL, arg, 0);
if (argsize == (size_t)-1) {
return NULL;
}
if (argsize == PY_SSIZE_T_MAX) {
return NULL;
}
if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t)) {
return NULL;
}
wchar_t *res = (wchar_t *)PyMem_RawMalloc(argsize*sizeof(wchar_t));
if (!res) {
return NULL;
}
size_t count = mbstowcs(res, arg, argsize);
if (count != (size_t)-1) {
wchar_t *tmp;
for (tmp = res; *tmp != 0 && !Py_UNICODE_IS_SURROGATE(*tmp); tmp++) {
}
if (*tmp == 0) {
return res;
}
}
PyMem_RawFree(res);
return NULL;
}
开发者ID:P4N74,项目名称:demangler,代码行数:27,代码来源:demangle.cpp
示例15: elObj_rprompt_setter
static int
elObj_rprompt_setter(EditLineObject *self, PyObject *value, void *closure)
{
int rv = 0;
int n;
char *new_rprompt;
const char *encoded_c;
PyObject *encoded;
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "Cannot delete the rprompt attribute");
return -1;
}
if (! PyUnicode_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"The rprompt attribute value must be a string");
return -1;
}
/* it is stored as a C string */
encoded = encode(value);
if (encoded == NULL) {
PyErr_SetString(PyExc_ValueError,
"The rprompt attribute could not be encoded");
return -1;
}
/* get it as a c-string */
encoded_c = PyBytes_AS_STRING(encoded);
n = strlen(encoded_c);
/* create a RawMalloc'd buffer */
new_rprompt = PyMem_RawMalloc(n+1);
if (new_rprompt == NULL) {
Py_DECREF(encoded);
PyErr_NoMemory();
return -1;
}
/* Copy the malloc'ed buffer into a PyMem_Malloc'ed one. */
strncpy(new_rprompt, encoded_c, n);
new_rprompt[n] = '\0';
/* release the previous one if it was assigned */
if (self->rprompt)
PyMem_RawFree(self->rprompt);
/* make this the active one */
self->rprompt = new_rprompt;
/*
* REFs: only manage 'enc' to ensure it gets removed. We don't 'own'
* any of the others, so we just borrow the ref.
*/
Py_DECREF(encoded);
/* done */
return rv;
}
开发者ID:mark-nicholson,项目名称:python-editline,代码行数:60,代码来源:_editline.c
示例16: _Py_FindEnvConfigValue
/* Search for a prefix value in an environment file (pyvenv.cfg).
If found, copy it into the provided buffer. */
int
_Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key,
wchar_t *value, size_t value_size)
{
int result = 0; /* meaning not found */
char buffer[MAXPATHLEN*2+1]; /* allow extra for key, '=', etc. */
fseek(env_file, 0, SEEK_SET);
while (!feof(env_file)) {
char * p = fgets(buffer, MAXPATHLEN*2, env_file);
if (p == NULL) {
break;
}
size_t n = strlen(p);
if (p[n - 1] != '\n') {
/* line has overflowed - bail */
break;
}
if (p[0] == '#') {
/* Comment - skip */
continue;
}
wchar_t *tmpbuffer = _Py_DecodeUTF8_surrogateescape(buffer, n);
if (tmpbuffer) {
wchar_t * state;
wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n", &state);
if ((tok != NULL) && !wcscmp(tok, key)) {
tok = wcstok(NULL, L" \t", &state);
if ((tok != NULL) && !wcscmp(tok, L"=")) {
tok = wcstok(NULL, L"\r\n", &state);
if (tok != NULL) {
wcsncpy(value, tok, MAXPATHLEN);
result = 1;
PyMem_RawFree(tmpbuffer);
break;
}
}
}
PyMem_RawFree(tmpbuffer);
}
}
return result;
}
开发者ID:tzickel,项目名称:cpython,代码行数:48,代码来源:pathconfig.c
示例17: PostToQueueCallback
static VOID CALLBACK
PostToQueueCallback(PVOID lpParameter, BOOL TimerOrWaitFired)
{
struct PostCallbackData *p = (struct PostCallbackData*) lpParameter;
PostQueuedCompletionStatus(p->CompletionPort, TimerOrWaitFired,
0, p->Overlapped);
/* ignore possible error! */
PyMem_RawFree(p);
}
开发者ID:ARK4579,项目名称:cpython,代码行数:10,代码来源:overlapped.c
示例18: encode_ascii
static int
encode_ascii(const wchar_t *text, char **str,
size_t *error_pos, const char **reason,
int raw_malloc, int surrogateescape)
{
char *result = NULL, *out;
size_t len, i;
wchar_t ch;
len = wcslen(text);
/* +1 for NULL byte */
if (raw_malloc) {
result = PyMem_RawMalloc(len + 1);
}
else {
result = PyMem_Malloc(len + 1);
}
if (result == NULL) {
return -1;
}
out = result;
for (i=0; i<len; i++) {
ch = text[i];
if (ch <= 0x7f) {
/* ASCII character */
*out++ = (char)ch;
}
else if (surrogateescape && 0xdc80 <= ch && ch <= 0xdcff) {
/* UTF-8b surrogate */
*out++ = (char)(ch - 0xdc00);
}
else {
if (raw_malloc) {
PyMem_RawFree(result);
}
else {
PyMem_Free(result);
}
if (error_pos != NULL) {
*error_pos = i;
}
if (reason) {
*reason = "encoding error";
}
return -2;
}
}
*out = '\0';
*str = result;
return 0;
}
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:54,代码来源:fileutils.c
示例19: _Py_wstat
/* Get file status. Encode the path to the locale encoding. */
static int
_Py_wstat(const wchar_t* path, struct stat *buf)
{
int err;
char *fname;
fname = _Py_EncodeLocaleRaw(path, NULL);
if (fname == NULL) {
errno = EINVAL;
return -1;
}
err = stat(fname, buf);
PyMem_RawFree(fname);
return err;
}
开发者ID:DinoV,项目名称:cpython,代码行数:15,代码来源:getpath.c
示例20: _Py_wreadlink
int
_Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz)
{
char *cpath;
char cbuf[MAXPATHLEN];
wchar_t *wbuf;
int res;
size_t r1;
cpath = _Py_wchar2char(path, NULL);
if (cpath == NULL) {
errno = EINVAL;
return -1;
}
res = (int)readlink(cpath, cbuf, Py_ARRAY_LENGTH(cbuf));
PyMem_Free(cpath);
if (res == -1)
return -1;
if (res == Py_ARRAY_LENGTH(cbuf)) {
errno = EINVAL;
return -1;
}
cbuf[res] = '\0'; /* buf will be null terminated */
wbuf = _Py_char2wchar(cbuf, &r1);
if (wbuf == NULL) {
errno = EINVAL;
return -1;
}
if (bufsiz <= r1) {
PyMem_RawFree(wbuf);
errno = EINVAL;
return -1;
}
wcsncpy(buf, wbuf, bufsiz);
PyMem_RawFree(wbuf);
return (int)r1;
}
开发者ID:CIBC-Internal,项目名称:python,代码行数:37,代码来源:fileutils.c
注:本文中的PyMem_RawFree函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论