Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Jul 7, 2024
1 parent 942942a commit ea1dedc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
1 change: 1 addition & 0 deletions mypyc/lib-rt/bytes_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <Python.h>
#include "CPy.h"
#include "pythonsupport.h"

// Returns -1 on error, 0 on inequality, 1 on equality.
//
Expand Down
16 changes: 7 additions & 9 deletions mypyc/lib-rt/dict_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <Python.h>
#include "CPy.h"
#include "pythonsupport.h"

#ifndef Py_TPFLAGS_MAPPING
#define Py_TPFLAGS_MAPPING (1 << 6)
Expand Down Expand Up @@ -230,12 +231,11 @@ PyObject *CPyDict_Keys(PyObject *dict) {
if (view == NULL) {
return NULL;
}
PyObject *res = _PyList_Extend((PyListObject *)list, view);
int res = PyList_Extend(list, view);
Py_DECREF(view);
if (res == NULL) {
if (res == -1) {
return NULL;
}
Py_DECREF(res);
return list;
}

Expand All @@ -250,12 +250,11 @@ PyObject *CPyDict_Values(PyObject *dict) {
if (view == NULL) {
return NULL;
}
PyObject *res = _PyList_Extend((PyListObject *)list, view);
int res = PyList_Extend(list, view);
Py_DECREF(view);
if (res == NULL) {
if (res == -1) {
return NULL;
}
Py_DECREF(res);
return list;
}

Expand All @@ -270,12 +269,11 @@ PyObject *CPyDict_Items(PyObject *dict) {
if (view == NULL) {
return NULL;
}
PyObject *res = _PyList_Extend((PyListObject *)list, view);
int res = PyList_Extend(list, view);
Py_DECREF(view);
if (res == NULL) {
if (res == -1) {
return NULL;
}
Py_DECREF(res);
return list;
}

Expand Down
1 change: 1 addition & 0 deletions mypyc/lib-rt/getargsfast.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <Python.h>
#include "CPy.h"
#include "pythonsupport.h"

#define PARSER_INITED(parser) ((parser)->kwtuple != NULL)

Expand Down
1 change: 1 addition & 0 deletions mypyc/lib-rt/init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Python.h>
#include "CPy.h"
#include "pythonsupport.h"

struct ExcDummyStruct _CPy_ExcDummyStruct = { PyObject_HEAD_INIT(NULL) };
PyObject *_CPy_ExcDummy = (PyObject *)&_CPy_ExcDummyStruct;
Expand Down
6 changes: 5 additions & 1 deletion mypyc/lib-rt/list_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ int CPyList_Insert(PyObject *list, CPyTagged index, PyObject *value)
}

PyObject *CPyList_Extend(PyObject *o1, PyObject *o2) {
return _PyList_Extend((PyListObject *)o1, o2);
int res = PyList_Extend(o1, o2);
if (res == -1) {
return NULL;
}
return Py_None;
}

// Return -2 or error, -1 if not found, or index of first match otherwise.
Expand Down
8 changes: 8 additions & 0 deletions mypyc/lib-rt/mypyc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,12 @@ static inline void CPyLong_SetUnsignedSize(PyLongObject *o, Py_ssize_t n) {
// Are we targeting Python 3.13 or newer?
#define CPY_3_13_FEATURES (PY_VERSION_HEX >= 0x030d0000)

#if CPY_3_13_FEATURES

#define CPY_GET_OPTIONAL_ATTR

#else

#endif

#endif
28 changes: 22 additions & 6 deletions mypyc/lib-rt/pythonsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@
#include "mypyc_util.h"

#if CPY_3_12_FEATURES
#ifndef Py_BUILD_CORE
#define Py_BUILD_CORE
#endif
#include "internal/pycore_frame.h"
#undef Py_BUILD_CORE
#endif

#if CPY_3_13_FEATURES
#ifndef Py_BUILD_CORE
#define Py_BUILD_CORE
#endif
#include "internal/pycore_bytesobject.h"
#include "internal/pycore_call.h"
#include "internal/pycore_frame.h"
#include "internal/pycore_object.h"
#include "internal/pycore_unicodeobject.h"
#undef Py_BUILD_CORE
#endif

#ifdef __cplusplus
Expand Down Expand Up @@ -48,7 +64,7 @@ update_bases(PyObject *bases)
}
continue;
}
if (_PyObject_LookupAttrId(base, &PyId___mro_entries__, &meth) < 0) {
if (PyObject_GetOptionalAttrString(base, PyId___mro_entries__.string, &meth) < 0) {
goto error;
}
if (!meth) {
Expand All @@ -59,7 +75,7 @@ update_bases(PyObject *bases)
}
continue;
}
new_base = _PyObject_FastCall(meth, stack, 1);
new_base = PyObject_Vectorcall(meth, stack, 1, NULL);
Py_DECREF(meth);
if (!new_base) {
goto error;
Expand Down Expand Up @@ -108,7 +124,7 @@ init_subclass(PyTypeObject *type, PyObject *kwds)
PyObject *super, *func, *result;
PyObject *args[2] = {(PyObject *)type, (PyObject *)type};

super = _PyObject_FastCall((PyObject *)&PySuper_Type, args, 2);
super = PyObject_Vectorcall((PyObject *)&PySuper_Type, args, 2, NULL);
if (super == NULL) {
return -1;
}
Expand All @@ -119,7 +135,7 @@ init_subclass(PyTypeObject *type, PyObject *kwds)
return -1;
}

result = _PyObject_FastCallDict(func, NULL, 0, kwds);
result = PyObject_VectorcallDict(func, NULL, 0, kwds);
Py_DECREF(func);
if (result == NULL) {
return -1;
Expand Down Expand Up @@ -307,7 +323,7 @@ list_count(PyListObject *self, PyObject *value)
return CPyTagged_ShortFromSsize_t(count);
}

#define CPyUnicode_EqualToASCIIString(x, y) _PyUnicode_EqualToASCIIString(x, y)
#define CPyUnicode_EqualToASCIIString(x, y) PyUnicode_EqualToUTF8(x, y)

// Adapted from genobject.c in Python 3.7.2
// Copied because it wasn't in 3.5.2 and it is undocumented anyways.
Expand Down Expand Up @@ -374,7 +390,7 @@ _CPyDictView_New(PyObject *dict, PyTypeObject *type)
static int
_CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) {
PyObject *tmp = NULL;
int result = _PyObject_LookupAttrId(v, name, &tmp);
int result = PyObject_GetOptionalAttrString(v, name->string, &tmp);
if (tmp) {
Py_DECREF(tmp);
}
Expand Down
1 change: 1 addition & 0 deletions mypyc/lib-rt/str_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ PyObject *CPyStr_Build(Py_ssize_t len, ...) {
PyObject *item = va_arg(args, PyObject *);
Py_ssize_t itemlen = PyUnicode_GET_LENGTH(item);
if (itemlen != 0) {
// PyUnicode_CopyCharacters
_PyUnicode_FastCopyCharacters(res, res_offset, item, 0, itemlen);
res_offset += itemlen;
}
Expand Down

0 comments on commit ea1dedc

Please sign in to comment.