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
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
./build
./meliae/_intset.c
./meliae/_loader.c
./meliae/_scanner.c
build/
__pycache__/
meliae/_intset.c
meliae/_loader.c
meliae/_scanner.c
./tags
15 changes: 13 additions & 2 deletions meliae/_scanner_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ _var_object_size(PyVarObject *c_obj)
PyErr_Clear();
}
return _basic_object_size((PyObject *)c_obj)
+ num_entries * c_obj->ob_type->tp_itemsize;
+ num_entries * Py_TYPE(c_obj)->tp_itemsize;
}

static Py_ssize_t
Expand Down Expand Up @@ -172,10 +172,17 @@ static Py_ssize_t
_size_of_dict(PyDictObject *c_obj)
{
Py_ssize_t size;
#if PY_MAJOR_VERSION >= 3
PyObject* long_size;

long_size = _PyDict_SizeOf(c_obj);
size = PyLong_AsSize_t(long_size);
#else
size = _basic_object_size((PyObject *)c_obj);
if (c_obj->ma_table != c_obj->ma_smalltable) {
size += sizeof(PyDictEntry) * (c_obj->ma_mask + 1);
}
#endif
return size;
}

Expand All @@ -185,7 +192,7 @@ _size_of_unicode(PyUnicodeObject *c_obj)
{
Py_ssize_t size;
size = _basic_object_size((PyObject *)c_obj);
size += Py_UNICODE_SIZE * c_obj->length;
size += Py_UNICODE_SIZE * PyUnicode_GetSize(c_obj);
return size;
}

Expand Down Expand Up @@ -515,7 +522,11 @@ _dump_object_to_ref_info(struct ref_info *info, PyObject *c_obj, int recurse)
} else if (PyClass_Check(c_obj)) {
/* Old style class */
_write_static_to_info(info, ", \"name\": ");
#if PY_MAJOR_VERSION >= 3
_dump_string(info, ((PyClassObject *)c_obj)->tp_name);
#else
_dump_string(info, ((PyClassObject *)c_obj)->cl_name);
#endif
}
if (PyString_Check(c_obj)) {
_write_to_ref_info(info, ", \"len\": " SSIZET_FMT, PyString_GET_SIZE(c_obj));
Expand Down
6 changes: 6 additions & 0 deletions meliae/_scanner_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
#include <Python.h>
#include <code.h>
#include <frameobject.h>
#include <dictobject.h>
#include <stdio.h>

#if PY_MAJOR_VERSION >= 3
#define PyClassObject PyTypeObject
#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type)
#endif

/**
* Compute the size of the data directly addressed by this object.
*
Expand Down
4 changes: 2 additions & 2 deletions meliae/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def open_file(filename):
process = subprocess.Popen(['gzip', '-d', '-c', filename],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=close_fds)
except OSError, e:
except OSError as e:
if e.errno == errno.ENOENT:
# failing that, use another python process
return _open_mprocess(filename)
Expand All @@ -71,7 +71,7 @@ def terminate_or_pass():
# no longer running.
try:
return terminate()
except OSError, e:
except OSError as e:
sys.stderr.write('Ignoring failure to terminate process:'
' %s\n' % (e,))
# We *could* check if process.poll() returns that the
Expand Down
11 changes: 6 additions & 5 deletions meliae/perf_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ def get_memory(self, process):
finally:
f.close()
m = re.search(r'(?i)vmpeak:\s*(?P<peak>\d+) kB', content)
peak = current = None

peak = current = None
if m is not None:
peak = int(m.group('peak')) * 1024
peak = int(m.group('peak')) * 1024
m = re.search(r'(?i)vmsize:\s*(?P<current>\d+) kB', content)
if m is not None:
current = int(m.group('current')) * 1024
return current, peak
current = int(m.group('current')) * 1024

return current, peak

class _Win32PerformanceCounter(PerformanceCounter):

class _Win32PerformanceCounter(PerformanceCounter):
def get_timer(self):
# This returns wall-clock time, but using a much higher precision than
# time.time() [which has a resolution of only 15ms]
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function


def config():
Expand Down Expand Up @@ -64,7 +65,7 @@ def config():
try:
from Cython.Distutils import build_ext
except ImportError:
print "We require Cython to be installed."
print("We require Cython to be installed.")
return

kwargs["cmdclass"] = {"build_ext": build_ext}
Expand Down