Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions prometheus_module/counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void Counter::set_wrapped(prometheus::Counter& wrapped) {

typedef struct {
PyObject_HEAD
std::unique_ptr<Counter> counter;
Counter* counter;
PyObject* family;
std::unordered_map<std::string, PyObject*>* cache;
} CounterPyObject;
Expand All @@ -123,7 +123,7 @@ static int Counter_init(CounterPyObject *self, PyObject *args, PyObject *kwds) {
return -1;

Counter* wrapped = (Counter*)PyCapsule_GetPointer(capsule, NULL);
self->counter.reset(wrapped);
self->counter = wrapped;

if (family != NULL) {
self->family = family;
Expand All @@ -139,14 +139,12 @@ static int Counter_init(CounterPyObject *self, PyObject *args, PyObject *kwds) {
}

static void Counter_dealloc(CounterPyObject* self) {
self->counter.reset(nullptr);
self->counter = nullptr;

if (self->family != reinterpret_cast<PyObject*>(self)) {
Py_DecRef(self->family);
}

delete self->family;

Py_TYPE(self)->tp_free((PyObject*)self);
}

Expand Down
8 changes: 3 additions & 5 deletions prometheus_module/gauge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void Gauge::set_wrapped(prometheus::Gauge& wrapped) {

typedef struct {
PyObject_HEAD
std::unique_ptr<Gauge> gauge;
Gauge* gauge;
PyObject* family;
std::unordered_map<std::string, PyObject*>* cache;
} GaugePyObject;
Expand All @@ -137,7 +137,7 @@ static int Gauge_init(GaugePyObject *self, PyObject *args, PyObject *kwds) {
return -1;

Gauge* wrapped = (Gauge*)PyCapsule_GetPointer(capsule, NULL);
self->gauge.reset(wrapped);
self->gauge = wrapped;

if (family != NULL) {
self->family = family;
Expand All @@ -153,14 +153,12 @@ static int Gauge_init(GaugePyObject *self, PyObject *args, PyObject *kwds) {
}

static void Gauge_dealloc(GaugePyObject* self) {
self->gauge.reset(nullptr);
self->gauge = nullptr;

if (self->family != reinterpret_cast<PyObject*>(self)) {
Py_DecRef(self->family);
}

delete self->family;

Py_TYPE(self)->tp_free((PyObject*)self);
}

Expand Down
8 changes: 3 additions & 5 deletions prometheus_module/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Histogram::set_wrapped(prometheus::Histogram& wrapped) {

typedef struct {
PyObject_HEAD
std::unique_ptr<Histogram> histogram;
Histogram* histogram;
PyObject* family;
std::unordered_map<std::string, PyObject*>* cache;
} HistogramPyObject;
Expand All @@ -120,7 +120,7 @@ static int Histogram_init(HistogramPyObject *self, PyObject *args, PyObject *kwd
return -1;

Histogram* wrapped = (Histogram*)PyCapsule_GetPointer(capsule, NULL);
self->histogram.reset(wrapped);
self->histogram = wrapped;

if (family != NULL) {
self->family = family;
Expand All @@ -136,14 +136,12 @@ static int Histogram_init(HistogramPyObject *self, PyObject *args, PyObject *kwd
}

static void Histogram_dealloc(HistogramPyObject* self) {
self->histogram.reset(nullptr);
self->histogram = nullptr;

if (self->family != reinterpret_cast<PyObject*>(self)) {
Py_DecRef(self->family);
}

delete self->family;

Py_TYPE(self)->tp_free((PyObject*)self);
}

Expand Down
8 changes: 3 additions & 5 deletions prometheus_module/summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void Summary::set_wrapped(prometheus::Summary& wrapped) {

typedef struct {
PyObject_HEAD
std::unique_ptr<Summary> summary;
Summary* summary;
PyObject* family;
std::unordered_map<std::string, PyObject*>* cache;
} SummaryPyObject;
Expand All @@ -126,7 +126,7 @@ static int Summary_init(SummaryPyObject *self, PyObject *args, PyObject *kwds) {
return -1;

Summary* wrapped = (Summary*)PyCapsule_GetPointer(capsule, NULL);
self->summary.reset(wrapped);
self->summary = wrapped;

if (family != NULL) {
self->family = family;
Expand All @@ -142,14 +142,12 @@ static int Summary_init(SummaryPyObject *self, PyObject *args, PyObject *kwds) {
}

static void Summary_dealloc(SummaryPyObject* self) {
self->summary.reset(nullptr);
self->summary = nullptr;

if (self->family != reinterpret_cast<PyObject*>(self)) {
Py_DecRef(self->family);
}

delete self->family;

Py_TYPE(self)->tp_free((PyObject*)self);
}

Expand Down