This is an archive of the discontinued Mercurial Phabricator instance.

cdatapack: print path on error
ClosedPublic

Authored by quark on Oct 16 2017, 6:03 PM.
Tags
None
Subscribers

Details

Reviewers
durham
Group Reviewers
Restricted Project
Commits
rFBHGXbf081e811913: cdatapack: print path on error
Summary

This gives us more context about what pack file is problematic. It's useful
to detect issues like mmapping a 0-sized file.

Test Plan

Make sure the code compiles without warnings. Run related tests.

make local
rt test-cstore.t

Make sure setup.py specifies C99 so variable length array is available.

Diff Detail

Repository
rFBHGX Facebook Mercurial Extensions
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

quark created this revision.Oct 16 2017, 6:03 PM
Herald added a reviewer: Restricted Project. · View Herald TranscriptOct 16 2017, 6:03 PM
singhsrb added inline comments.
cstore/py-cdatapack.h
257

Wondering if something like this would be cleaner:

int ret_code = -1;
if (self->handle == NULL) {
  PyErr_NoMemory();
} else {
  switch (self->handle->status) {
    case DATAPACK_HANDLE_OK:
      ret_code = 0;
      break;
    case DATAPACK_HANDLE_VERSION_MISMATCH:
      PyErr_Format(PyExc_RuntimeError, "Unsupported version");
      break;
    default:
      PyErr_Format(
          PyExc_ValueError,
          "Error setting up datapack %s (status=%d)",
          data_path,
          self->handle->status);
  }
}

free(idx_path);
free(data_path);
free(self->handle);
self->handle = NULL;
return ret_code;
quark added inline comments.Oct 16 2017, 7:08 PM
cstore/py-cdatapack.h
257

Yes. I was just a bit lazy. I think we can use C99 variable length array here so it does not need to be freed explicitly.

quark edited the test plan for this revision. (Show Details)Oct 16 2017, 7:33 PM
quark updated this revision to Diff 2848.
quark updated this revision to Diff 2849.
singhsrb added inline comments.Oct 16 2017, 7:38 PM
cstore/py-cdatapack.h
245–246

That would really clean up a lot of this stuff. Great!

durham accepted this revision.Oct 31 2017, 12:25 PM
This revision is now accepted and ready to land.Oct 31 2017, 12:25 PM
This revision was automatically updated to reflect the committed changes.