Skip to content

Commit

Permalink
Fix memory bug
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanSteinberg committed Aug 25, 2024
1 parent 8b43ec0 commit f1dbfb2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ docs/source/meds_reader.py
docs/source/README_copy.md
src/meds_reader/meds_reader_convert
*.swp
docs/source/html/
docs/source/latex/
docs/source/_build/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## meds_reader: A Pythonic interface for MEDS datasets

[![pypy](https://img.shields.io/pypi/v/meds_reader.svg)](https://pypi.org/project/meds_reader/) [![docs](https://readthedocs.org/projects/meds_reader/badge/?version=latest)](https://meds-reader.readthedocs.io/en/latest/) [![Build wheels](https://github.com/EthanSteinberg/meds_reader/actions/workflows/python-build.yml/badge.svg?branch=main)](https://github.com/EthanSteinberg/meds_reader/actions/workflows/python-build.yml?query=branch%3Amain) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![pypy](https://img.shields.io/pypi/v/meds_reader.svg)](https://pypi.org/project/meds_reader/) [![docs](https://readthedocs.org/projects/meds_reader/badge/?version=latest)](https://meds-reader.readthedocs.io/en/latest/) [![Build wheels](https://github.com/som-shahlab/meds_reader/actions/workflows/python-build.yml/badge.svg?branch=main)](https://github.com/som-shahlab/meds_reader/actions/workflows/python-build.yml?query=branch%3Amain) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

meds_reader is a fast and easy-to-use library for reading and processing subject data stored in [MEDS (Medical Event Data Standard)](https://github.com/Medical-Event-Data-Standard/) format using a Python-native API.

Expand Down
18 changes: 9 additions & 9 deletions native/meds_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,14 @@ inline PyObject* Subject::get_property(size_t index, Event* event_ptr) {
if (properties_initialized.test(index) == 0) {
num_allocated += subject_database->get_property_data(
index, subject_offset, subject_length,
saved_properties + capacity * index,
saved_properties + subject_length * index,
saved_properties +
capacity * subject_database->get_num_properties() +
subject_length * subject_database->get_num_properties() +
num_allocated);
properties_initialized.set(index);
}

PyObject* res = saved_properties[capacity * index + event_index];
PyObject* res = saved_properties[subject_length * index + event_index];

if (res == nullptr) {
Py_RETURN_NONE;
Expand Down Expand Up @@ -688,25 +688,25 @@ void Subject::dealloc() {
Py_DECREF(subject_id);
Py_DECREF(static_cast<PyObject*>(&events_obj));

decref();
}

void Subject::delete_self() {
for (size_t p_index = 0; p_index < subject_database->get_num_properties();
p_index++) {
if (!properties_initialized.test(p_index)) {
continue;
}
memset(saved_properties + p_index * capacity, 0,
memset(saved_properties + p_index * subject_length, 0,
subject_length * sizeof(PyObject*));
}

PyObject** to_remove =
saved_properties + subject_database->get_num_properties() * capacity;
saved_properties + subject_database->get_num_properties() * subject_length;
for (size_t i = 0; i < num_allocated; i++) {
Py_DECREF(to_remove[i]);
}

decref();
}

void Subject::delete_self() {
in_use = false;
subject_database->decref();
}
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ dependencies = [
[tool.setuptools_scm]

[project.urls]
Homepage = "https://github.com/EthanSteinberg/meds_reader"
Homepage = "https://github.com/som-shahlab/meds_reader"
Documentation = "https://meds-reader.readthedocs.io/en/latest/"
Repository = "https://github.com/EthanSteinberg/meds_reader"
Tracker = "https://github.com/EthanSteinberg/meds_reader/issues"
Repository = "https://github.com/som-shahlab/meds_reader"
Tracker = "https://github.com/som-shahlab/meds_reader/issues"

[project.scripts]
meds_reader_convert = "meds_reader:meds_reader_convert"
Expand Down

0 comments on commit f1dbfb2

Please sign in to comment.