Skip to content

Commit 52f0506

Browse files
committed
claude part 1
1 parent 3914e50 commit 52f0506

File tree

8 files changed

+1415
-7
lines changed

8 files changed

+1415
-7
lines changed

coverage/core.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _debug(msg: str) -> None:
7070
_debug("in core.py")
7171

7272
# Check the conditions that preclude us from using sys.monitoring.
73+
# This applies to both sysmon and csysmon.
7374
reason_no_sysmon = ""
7475
if not env.PYBEHAVIOR.pep669:
7576
reason_no_sysmon = "sys.monitoring isn't available in this version"
@@ -89,9 +90,12 @@ def _debug(msg: str) -> None:
8990
core_name = config.core
9091
_debug(f"core.py: core from config is {core_name!r}")
9192

92-
if core_name == "sysmon" and reason_no_sysmon:
93-
_debug(f"core.py: defaulting because sysmon not usable: {reason_no_sysmon}")
94-
warn(f"Can't use core=sysmon: {reason_no_sysmon}, using default core", slug="no-sysmon")
93+
if core_name in ("sysmon", "csysmon") and reason_no_sysmon:
94+
_debug(f"core.py: defaulting because {core_name} not usable: {reason_no_sysmon}")
95+
warn(
96+
f"Can't use core={core_name}: {reason_no_sysmon}, using default core",
97+
slug="no-sysmon",
98+
)
9599
core_name = None
96100

97101
if core_name is None:
@@ -108,6 +112,12 @@ def _debug(msg: str) -> None:
108112
warn(f"Couldn't import C tracer: {IMPORT_ERROR}", slug="no-ctracer", once=True)
109113
core_name = "pytrace"
110114
_debug("core.py: Falling back to pytrace because C tracer not available")
115+
elif core_name == "csysmon":
116+
if not CTRACER_FILE:
117+
if IMPORT_ERROR and env.SHIPPING_WHEELS:
118+
warn(f"Couldn't import C tracer: {IMPORT_ERROR}", slug="no-csysmon", once=True)
119+
core_name = "sysmon"
120+
_debug("core.py: Falling back to sysmon because C tracer not available")
111121

112122
_debug(f"core.py: Using core={core_name}")
113123

@@ -120,6 +130,13 @@ def _debug(msg: str) -> None:
120130
self.supports_plugins = False
121131
self.packed_arcs = False
122132
self.systrace = False
133+
elif core_name == "csysmon":
134+
self.tracer_class = coverage.tracer.CSysMonitor
135+
self.tracer_kwargs["tool_id"] = 3 if metacov else 1
136+
self.file_disposition_class = FileDisposition
137+
self.supports_plugins = False
138+
self.packed_arcs = False
139+
self.systrace = False
123140
elif core_name == "ctrace":
124141
self.tracer_class = coverage.tracer.CTracer
125142
self.file_disposition_class = coverage.tracer.CFileDisposition

coverage/ctracer/module.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "util.h"
55
#include "tracer.h"
66
#include "filedisp.h"
7+
#include "sysmon.h"
78

89
/* Module definition */
910

@@ -22,6 +23,10 @@ tracer_exec(PyObject *mod)
2223
return -1;
2324
}
2425

26+
if (CSysMonitor_intern_strings() < 0) {
27+
return -1;
28+
}
29+
2530
/* Initialize CTracer */
2631
CTracerType.tp_new = PyType_GenericNew;
2732
if (PyType_Ready(&CTracerType) < 0) {
@@ -48,6 +53,22 @@ tracer_exec(PyObject *mod)
4853
return -1;
4954
}
5055

56+
/* Initialize CSysMonitor */
57+
CSysMonitorType.tp_new = PyType_GenericNew;
58+
if (PyType_Ready(&CSysMonitorType) < 0) {
59+
Py_DECREF(&CTracerType);
60+
Py_DECREF(&CFileDispositionType);
61+
return -1;
62+
}
63+
64+
Py_INCREF(&CSysMonitorType);
65+
if (PyModule_AddObject(mod, "CSysMonitor", (PyObject *)&CSysMonitorType) < 0) {
66+
Py_DECREF(&CTracerType);
67+
Py_DECREF(&CFileDispositionType);
68+
Py_DECREF(&CSysMonitorType);
69+
return -1;
70+
}
71+
5172
module_inited = TRUE;
5273
return 0;
5374
}

0 commit comments

Comments
 (0)