-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make saving and loading the responsibility of Tox rather than Messenger #1213
Conversation
auto_tests/save_load_test.c
Outdated
const size_t save_size1 = tox_get_savedata_size(tox2); | ||
ck_assert_msg(save_size1 != 0, "save is invalid size %u", (unsigned)save_size1); | ||
printf("%u\n", (unsigned)save_size1); | ||
VLA(uint8_t, save1, save_size1); | ||
tox_get_savedata(tox2, save1); | ||
VLA(uint8_t, buffer, save_size1 + 2 * extra); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps while you're changing this code already, remove the vla and use malloc/free?
toxcore/group.h
Outdated
/* Save the conferences in data (must be allocated memory of size at least conferences_size()) */ | ||
uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data); | ||
|
||
/* Load a section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* Load a section.
*
* @...
f1c0e13
to
9038ec4
Compare
Codecov Report
@@ Coverage Diff @@
## master #1213 +/- ##
========================================
- Coverage 83.1% 83% -0.1%
========================================
Files 82 82
Lines 14694 14683 -11
========================================
- Hits 12218 12196 -22
- Misses 2476 2487 +11
Continue to review full report at Codecov.
|
b50824f
to
4d084e7
Compare
I factored the save invariance and associated tests out as a separate
PR, #1215.
|
toxcore/tox.c
Outdated
memcpy(data32, data, sizeof(uint32_t)); | ||
lendian_bytes_to_host32(data32 + 1, data + sizeof(uint32_t)); | ||
|
||
if (!data32[0] && (data32[1] == STATE_COOKIE_GLOBAL)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace !num
with num == 0
when num
is an integer, not a bool. Also, would it make sense to return -1 on the inverted condition, considering it an error return, and returning the success/failure of state_load at the end of the function?
toxcore/tox.c
Outdated
} | ||
|
||
void tox_get_savedata(const Tox *tox, uint8_t *savedata) | ||
void tox_get_savedata(const Tox *tox, uint8_t *data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you rename savedata to data? Now the .c and .h files are out of sync. If you want to use the name "data" in the function, you can assign savedata to data (which may not be such a bad idea anyway, since it avoids assigning to parameters).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to leave a comment, I can't just put comments on the code without also putting a comment in this box, so here is a comment. Thanks Github.
Can you rebase or merge upstream/master? |
* Tuesday, 2018-10-16 at 15:23 -0700 - iphydf <[email protected]>:
Can you rebase or merge upstream/master?
Done
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @zugz)
auto_tests/messenger_test.c, line 268 at r3 (raw file):
END_TEST /* This test is disabled, because saving is now handled by Tox rather than Messenger. */
Is there value in keeping this test around but commented out? Are you planning to delete or revive it in the future?
testing/Messenger_test.c, line 137 at r3 (raw file):
} /* Loading disabled, because loading is now handled by Tox rather than Messenger */
Should this also be deleted instead of commented out?
toxcore/group.h, line 457 at r1 (raw file):
Previously, iphydf wrote…
/** * Load a section. * * @...
Done. (comment on behalf of zugz)
toxcore/state.h, line 25 at r3 (raw file):
#define TOP_STATE_COOKIE_TYPE 0x01ce typedef enum Top_State_Type {
State_Type
, otherwise it's not in the module namespace of module "state", but instead in the namespace of module "top", which we don't have.
Separately, this is not a great place for this enum to live, but I don't have a better suggestion, so let's keep it here for now.
toxcore/state.c, line 109 at r1 (raw file):
Previously, zugz (zugz) wrote…
Hmm... I wouldn't know how best to do it, and I understand we intend to redo saving completely eventually. So I'd rather defer.
Ok, the way you do it is by serialising the integer instead of memcpying it into a byte array. I'm fine with deferring.
toxcore/tox.c, line 368 at r2 (raw file):
Previously, iphydf wrote…
Replace
!num
withnum == 0
whennum
is an integer, not a bool. Also, would it make sense to return -1 on the inverted condition, considering it an error return, and returning the success/failure of state_load at the end of the function?
Done (comment on behalf of zugz).
toxcore/tox.c, line 604 at r2 (raw file):
Previously, iphydf wrote…
Why did you rename savedata to data? Now the .c and .h files are out of sync. If you want to use the name "data" in the function, you can assign savedata to data (which may not be such a bad idea anyway, since it avoids assigning to parameters).
Done (comment on behalf of zugz).
auto_tests/save_load_test.c, line 100 at r1 (raw file):
Previously, iphydf wrote…
Perhaps while you're changing this code already, remove the vla and use malloc/free?
Done (in separate PR).
* Wednesday, 2018-10-17 at 05:17 -0700 - iphydf <[email protected]>:
*[testing/Messenger_test.c, line 137 at r3](https://reviewable.io/reviews/toktok/c-toxcore/1213#-LP0w4_o8qCfdpnPxHUy:-LP0w4_o8qCfdpnPxHUz:bqszos9) ([raw file](https://github.com/toktok/c-toxcore/blob/7f90dca13d91a2e47f859f31a29dc12056e7f40a/testing/Messenger_test.c#L137)):*
> ```C
> }
>
> /* Loading disabled, because loading is now handled by Tox rather than Messenger */
> ```
Should this also be deleted instead of commented out?
I'd rather leave it, in case someone one day wants to adapt it.
Done the rest. I can fire up reviewables to say so there if that would
really be helpful.
I looked again, and the loading code in Messenger_test is trivial enough that actually I don't think there's much point keeping it around. I've deleted it now.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 change requests, 0 of 1 approvals obtained
auto_tests/messenger_test.c, line 268 at r3 (raw file):
Previously, iphydf wrote…
Is there value in keeping this test around but commented out? Are you planning to delete or revive it in the future?
Done (comment on behalf of zugz).
testing/Messenger_test.c, line 137 at r3 (raw file):
Previously, zugz (zugz) wrote…
- Wednesday, 2018-10-17 at 05:17 -0700 - iphydf [email protected]:
testing/Messenger_test.c, line 137 at r3 (raw file): >
C > } > > /* Loading disabled, because loading is now handled by Tox rather than Messenger */ >
Should this also be deleted instead of commented out?
I'd rather leave it, in case someone one day wants to adapt it.
Done the rest. I can fire up reviewables to say so there if that would really be helpful. I looked again, and the loading code in Messenger_test is trivial enough that actually I don't think there's much point keeping it around. I've deleted it now.
Done (comment on behalf of zugz).
toxcore/state.h, line 25 at r3 (raw file):
Previously, iphydf wrote…
State_Type
, otherwise it's not in the module namespace of module "state", but instead in the namespace of module "top", which we don't have.Separately, this is not a great place for this enum to live, but I don't have a better suggestion, so let's keep it here for now.
Done (comment on behalf of zugz).
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)