Skip to content

Commit 40c87e0

Browse files
committed
refactor: get rid of My* version shims we don't need anymore
1 parent e36b42e commit 40c87e0

File tree

3 files changed

+19
-39
lines changed

3 files changed

+19
-39
lines changed

coverage/ctracer/filedisp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CFileDisposition_members[] = {
4444

4545
PyTypeObject
4646
CFileDispositionType = {
47-
MyType_HEAD_INIT
47+
PyVarObject_HEAD_INIT(NULL, 0)
4848
"coverage.CFileDispositionType", /*tp_name*/
4949
sizeof(CFileDisposition), /*tp_basicsize*/
5050
0, /*tp_itemsize*/

coverage/ctracer/tracer.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
static int
1414
pyint_as_int(PyObject * pyint, int *pint)
1515
{
16-
int the_int = MyInt_AsInt(pyint);
16+
int the_int = (int)PyLong_AsLong(pyint);
1717
if (the_int == -1 && PyErr_Occurred()) {
1818
return RET_ERROR;
1919
}
@@ -39,7 +39,7 @@ CTracer_intern_strings(void)
3939
int ret = RET_ERROR;
4040

4141
#define INTERN_STRING(v, s) \
42-
v = MyText_InternFromString(s); \
42+
v = PyUnicode_InternFromString(s); \
4343
if (v == NULL) { \
4444
goto error; \
4545
}
@@ -149,7 +149,7 @@ showlog(int depth, int lineno, PyObject * filename, const char * msg)
149149
}
150150
if (filename) {
151151
PyObject *ascii = MyText_AS_BYTES(filename);
152-
printf(" %s", MyBytes_AS_STRING(ascii));
152+
printf(" %s", PyBytes_AS_STRING(ascii));
153153
Py_DECREF(ascii);
154154
}
155155
if (msg) {
@@ -232,7 +232,7 @@ CTracer_set_pdata_stack(CTracer *self)
232232

233233
/* A new concurrency object. Make a new data stack. */
234234
the_index = self->data_stacks_used;
235-
stack_index = MyInt_FromInt(the_index);
235+
stack_index = PyLong_FromLong((long)the_index);
236236
if (stack_index == NULL) {
237237
goto error;
238238
}
@@ -542,7 +542,7 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
542542

543543
/* Make the frame right in case settrace(gettrace()) happens. */
544544
Py_INCREF(self);
545-
My_XSETREF(frame->f_trace, (PyObject*)self);
545+
Py_XSETREF(frame->f_trace, (PyObject*)self);
546546

547547
/* A call event is really a "start frame" event, and can happen for
548548
* re-entering a generator also. f_lasti is -1 for a true call, and a
@@ -668,7 +668,7 @@ CTracer_handle_line(CTracer *self, PyFrameObject *frame)
668668
}
669669
else {
670670
/* Tracing lines: key is simply this_line. */
671-
PyObject * this_line = MyInt_FromInt(lineno_from);
671+
PyObject * this_line = PyLong_FromLong((long)lineno_from);
672672
if (this_line == NULL) {
673673
goto error;
674674
}
@@ -717,8 +717,8 @@ CTracer_handle_return(CTracer *self, PyFrameObject *frame)
717717
PyObject * pCode = frame->f_code->co_code;
718718
int lasti = MyFrame_lasti(frame);
719719

720-
if (lasti < MyBytes_GET_SIZE(pCode)) {
721-
bytecode = MyBytes_AS_STRING(pCode)[lasti];
720+
if (lasti < PyBytes_GET_SIZE(pCode)) {
721+
bytecode = PyBytes_AS_STRING(pCode)[lasti];
722722
}
723723
if (bytecode != YIELD_VALUE) {
724724
int first = frame->f_code->co_firstlineno;
@@ -806,15 +806,15 @@ CTracer_trace(CTracer *self, PyFrameObject *frame, int what, PyObject *arg_unuse
806806

807807
#if WHAT_LOG
808808
if (what <= (int)(sizeof(what_sym)/sizeof(const char *))) {
809-
ascii = MyText_AS_BYTES(frame->f_code->co_filename);
810-
printf("trace: %s @ %s %d\n", what_sym[what], MyBytes_AS_STRING(ascii), PyFrame_GetLineNumber(frame));
809+
ascii = PyUnicode_AsASCIIString(frame->f_code->co_filename);
810+
printf("trace: %s @ %s %d\n", what_sym[what], PyBytes_AS_STRING(ascii), PyFrame_GetLineNumber(frame));
811811
Py_DECREF(ascii);
812812
}
813813
#endif
814814

815815
#if TRACE_LOG
816-
ascii = MyText_AS_BYTES(frame->f_code->co_filename);
817-
if (strstr(MyBytes_AS_STRING(ascii), start_file) && PyFrame_GetLineNumber(frame) == start_line) {
816+
ascii = PyUnicode_AsASCIIString(frame->f_code->co_filename);
817+
if (strstr(PyBytes_AS_STRING(ascii), start_file) && PyFrame_GetLineNumber(frame) == start_line) {
818818
logging = TRUE;
819819
}
820820
Py_DECREF(ascii);
@@ -913,25 +913,25 @@ CTracer_call(CTracer *self, PyObject *args, PyObject *kwds)
913913
static char *kwlist[] = {"frame", "event", "arg", "lineno", NULL};
914914

915915
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O|i:Tracer_call", kwlist,
916-
&PyFrame_Type, &frame, &MyText_Type, &what_str, &arg, &lineno)) {
916+
&PyFrame_Type, &frame, &PyUnicode_Type, &what_str, &arg, &lineno)) {
917917
goto done;
918918
}
919919

920920
/* In Python, the what argument is a string, we need to find an int
921921
for the C function. */
922922
for (what = 0; what_names[what]; what++) {
923923
int should_break;
924-
ascii = MyText_AS_BYTES(what_str);
925-
should_break = !strcmp(MyBytes_AS_STRING(ascii), what_names[what]);
924+
ascii = PyUnicode_AsASCIIString(what_str);
925+
should_break = !strcmp(PyBytes_AS_STRING(ascii), what_names[what]);
926926
Py_DECREF(ascii);
927927
if (should_break) {
928928
break;
929929
}
930930
}
931931

932932
#if WHAT_LOG
933-
ascii = MyText_AS_BYTES(frame->f_code->co_filename);
934-
printf("pytrace: %s @ %s %d\n", what_sym[what], MyBytes_AS_STRING(ascii), PyFrame_GetLineNumber(frame));
933+
ascii = PyUnicode_AsASCIIString(frame->f_code->co_filename);
934+
printf("pytrace: %s @ %s %d\n", what_sym[what], PyBytes_AS_STRING(ascii), PyFrame_GetLineNumber(frame));
935935
Py_DECREF(ascii);
936936
#endif
937937

@@ -1108,7 +1108,7 @@ CTracer_methods[] = {
11081108

11091109
PyTypeObject
11101110
CTracerType = {
1111-
MyType_HEAD_INIT
1111+
PyVarObject_HEAD_INIT(NULL, 0)
11121112
"coverage.CTracer", /*tp_name*/
11131113
sizeof(CTracer), /*tp_basicsize*/
11141114
0, /*tp_itemsize*/

coverage/ctracer/util.h

-20
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212
#undef COLLECT_STATS /* Collect counters: stats are printed when tracer is stopped. */
1313
#undef DO_NOTHING /* Define this to make the tracer do nothing. */
1414

15-
#define MyText_Type PyUnicode_Type
16-
#define MyText_AS_BYTES(o) PyUnicode_AsASCIIString(o)
17-
#define MyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o)
18-
#define MyBytes_AS_STRING(o) PyBytes_AS_STRING(o)
19-
#define MyText_AsString(o) PyUnicode_AsUTF8(o)
20-
#define MyText_FromFormat PyUnicode_FromFormat
21-
#define MyInt_FromInt(i) PyLong_FromLong((long)i)
22-
#define MyInt_AsInt(o) (int)PyLong_AsLong(o)
23-
#define MyText_InternFromString(s) PyUnicode_InternFromString(s)
24-
25-
#define MyType_HEAD_INIT PyVarObject_HEAD_INIT(NULL, 0)
26-
2715
// The f_lasti field changed meaning in 3.10.0a7. It had been bytes, but
2816
// now is instructions, so we need to adjust it to use it as a byte index.
2917
#if PY_VERSION_HEX >= 0x030A00A7
@@ -32,14 +20,6 @@
3220
#define MyFrame_lasti(f) f->f_lasti
3321
#endif // 3.10.0a7
3422

35-
// Undocumented, and not in all 2.7.x, so our own copy of it.
36-
#define My_XSETREF(op, op2) \
37-
do { \
38-
PyObject *_py_tmp = (PyObject *)(op); \
39-
(op) = (op2); \
40-
Py_XDECREF(_py_tmp); \
41-
} while (0)
42-
4323
/* The values returned to indicate ok or error. */
4424
#define RET_OK 0
4525
#define RET_ERROR -1

0 commit comments

Comments
 (0)