Skip to content

Commit

Permalink
updated to python3.13.0a2 (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmckerns authored Dec 3, 2023
1 parent 30ad2d2 commit 212dfb2
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 113 deletions.
8 changes: 3 additions & 5 deletions py3.13/Modules/_multiprocess/clinic/multiprocessing.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
preserve
[clinic start generated code]*/

#include "pycore_modsupport.h" // _PyArg_CheckPositional()

#if defined(MS_WINDOWS)

PyDoc_STRVAR(_multiprocessing_closesocket__doc__,
Expand Down Expand Up @@ -102,10 +104,6 @@ _multiprocessing_send(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (PyObject_GetBuffer(args[1], &buf, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&buf, 'C')) {
_PyArg_BadArgument("send", "argument 2", "contiguous buffer", args[1]);
goto exit;
}
return_value = _multiprocessing_send_impl(module, handle, &buf);

exit:
Expand Down Expand Up @@ -166,4 +164,4 @@ _multiprocessing_sem_unlink(PyObject *module, PyObject *arg)
#ifndef _MULTIPROCESSING_SEND_METHODDEF
#define _MULTIPROCESSING_SEND_METHODDEF
#endif /* !defined(_MULTIPROCESSING_SEND_METHODDEF) */
/*[clinic end generated code: output=8b91c020d4353cc5 input=a9049054013a1b77]*/
/*[clinic end generated code: output=73b4cb8428d816da input=a9049054013a1b77]*/
102 changes: 11 additions & 91 deletions py3.13/Modules/_multiprocess/clinic/posixshmem.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
preserve
[clinic start generated code]*/

#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif

#if defined(HAVE_SHM_OPEN)

PyDoc_STRVAR(_posixshmem_shm_open__doc__,
Expand All @@ -16,69 +11,25 @@ PyDoc_STRVAR(_posixshmem_shm_open__doc__,
"Open a shared memory object. Returns a file descriptor (integer).");

#define _POSIXSHMEM_SHM_OPEN_METHODDEF \
{"shm_open", _PyCFunction_CAST(_posixshmem_shm_open), METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_open__doc__},
{"shm_open", (PyCFunction)(void(*)(void))_posixshmem_shm_open, METH_VARARGS|METH_KEYWORDS, _posixshmem_shm_open__doc__},

static int
_posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,
int mode);

static PyObject *
_posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
_posixshmem_shm_open(PyObject *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)

#define NUM_KEYWORDS 3
static struct {
PyGC_Head _this_is_not_used;
PyObject_VAR_HEAD
PyObject *ob_item[NUM_KEYWORDS];
} _kwtuple = {
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
.ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), },
};
#undef NUM_KEYWORDS
#define KWTUPLE (&_kwtuple.ob_base.ob_base)

#else // !Py_BUILD_CORE
# define KWTUPLE NULL
#endif // !Py_BUILD_CORE

static const char * const _keywords[] = {"path", "flags", "mode", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "shm_open",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[3];
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
static char *_keywords[] = {"path", "flags", "mode", NULL};
PyObject *path;
int flags;
int mode = 511;
int _return_value;

args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
if (!args) {
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]);
goto exit;
}
path = args[0];
flags = PyLong_AsInt(args[1]);
if (flags == -1 && PyErr_Occurred()) {
goto exit;
}
if (!noptargs) {
goto skip_optional_pos;
}
mode = PyLong_AsInt(args[2]);
if (mode == -1 && PyErr_Occurred()) {
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ui|i:shm_open", _keywords,
&path, &flags, &mode))
goto exit;
}
skip_optional_pos:
_return_value = _posixshmem_shm_open_impl(module, path, flags, mode);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
Expand All @@ -104,52 +55,21 @@ PyDoc_STRVAR(_posixshmem_shm_unlink__doc__,
"region.");

#define _POSIXSHMEM_SHM_UNLINK_METHODDEF \
{"shm_unlink", _PyCFunction_CAST(_posixshmem_shm_unlink), METH_FASTCALL|METH_KEYWORDS, _posixshmem_shm_unlink__doc__},
{"shm_unlink", (PyCFunction)(void(*)(void))_posixshmem_shm_unlink, METH_VARARGS|METH_KEYWORDS, _posixshmem_shm_unlink__doc__},

static PyObject *
_posixshmem_shm_unlink_impl(PyObject *module, PyObject *path);

static PyObject *
_posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
_posixshmem_shm_unlink(PyObject *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)

#define NUM_KEYWORDS 1
static struct {
PyGC_Head _this_is_not_used;
PyObject_VAR_HEAD
PyObject *ob_item[NUM_KEYWORDS];
} _kwtuple = {
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
.ob_item = { &_Py_ID(path), },
};
#undef NUM_KEYWORDS
#define KWTUPLE (&_kwtuple.ob_base.ob_base)

#else // !Py_BUILD_CORE
# define KWTUPLE NULL
#endif // !Py_BUILD_CORE

static const char * const _keywords[] = {"path", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "shm_unlink",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[1];
static char *_keywords[] = {"path", NULL};
PyObject *path;

args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
if (!args) {
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U:shm_unlink", _keywords,
&path))
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]);
goto exit;
}
path = args[0];
return_value = _posixshmem_shm_unlink_impl(module, path);

exit:
Expand All @@ -165,4 +85,4 @@ _posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs
#ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF
#define _POSIXSHMEM_SHM_UNLINK_METHODDEF
#endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */
/*[clinic end generated code: output=2f356903a281d857 input=a9049054013a1b77]*/
/*[clinic end generated code: output=be0661dbed83ea23 input=a9049054013a1b77]*/
3 changes: 2 additions & 1 deletion py3.13/Modules/_multiprocess/clinic/semaphore.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()

#if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS)

Expand Down Expand Up @@ -541,4 +542,4 @@ _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py
#ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
#define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
#endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */
/*[clinic end generated code: output=e8ea65f8cba8e173 input=a9049054013a1b77]*/
/*[clinic end generated code: output=d57992037e6770b6 input=a9049054013a1b77]*/
16 changes: 12 additions & 4 deletions py3.13/Modules/_multiprocess/posixshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
posixshmem - A Python extension that provides shm_open() and shm_unlink()
*/

#include "pyconfig.h" // Py_GIL_DISABLED

#ifndef Py_GIL_DISABLED
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
#define Py_LIMITED_API 0x030c0000
#endif

#include <Python.h>

// for shm_open() and shm_unlink()
#include <errno.h> // EINTR
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
# include <sys/mman.h> // shm_open(), shm_unlink()
#endif


/*[clinic input]
module _posixshmem
[clinic start generated code]*/
Expand Down Expand Up @@ -40,7 +48,7 @@ _posixshmem_shm_open_impl(PyObject *module, PyObject *path, int flags,
{
int fd;
int async_err = 0;
const char *name = PyUnicode_AsUTF8(path);
const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
if (name == NULL) {
return -1;
}
Expand Down Expand Up @@ -79,7 +87,7 @@ _posixshmem_shm_unlink_impl(PyObject *module, PyObject *path)
{
int rv;
int async_err = 0;
const char *name = PyUnicode_AsUTF8(path);
const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
if (name == NULL) {
return NULL;
}
Expand Down
Loading

0 comments on commit 212dfb2

Please sign in to comment.