Skip to content

Conversation

jcoffland
Copy link
Contributor

ChakraCore.h appears to desire compatibility with C99 however this is currently broken due to the use of nullptr, bool and C++11 style enums. Fortunately these problems are easily remedied.

@msftclas
Copy link

Hi @jcoffland, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

@msftclas
Copy link

@jcoffland, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, MSBOT;

@obastemur
Copy link
Collaborator

@jcoffland could you please squash the commits ? That should also trigger CI

@@ -71,6 +71,10 @@ typedef BYTE* ChakraBytePtr;
#define CHAKRA_API extern "C" SET_API_VISIBILITY JsErrorCode
#else
#define CHAKRA_API extern SET_API_VISIBILITY JsErrorCode
#include <stdbool.h>
#endif
#if !defined(__cplusplus) || (__cplusplus <= 199711L)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick: Could you please insert a blank line before this #if for readability?

@jcoffland
Copy link
Contributor Author

Ok, I've added the whitespace and squashed the commits.

@jcoffland
Copy link
Contributor Author

Any chance this will get merged? It's a very basic fix and I followed all the guidelines. Will someone please take responsibility for merging this PR?

@jianchun
Copy link

@jcoffland CI has been failing on this PR weirdly. Could you please try squash (still seeing 3 commits) and rebase onto latest master and force push your PR? Thanks!

@jcoffland jcoffland force-pushed the master branch 2 times, most recently from 8a87583 to 348bf15 Compare November 29, 2016 01:15
@jcoffland
Copy link
Contributor Author

Ok, I believe I've sorted it out. I had already squashed my commits but then updated my fork by doing a merge which added extra commits to this PR. I fixed this by redoing the fork update as a rebase.

@obastemur
Copy link
Collaborator

@dotnet-bot test this please

@jianchun
Copy link

Did a search and found

JsTTDMoveMode moveMode = (JsTTDMoveMode)(JsTTDMoveMode::JsTTDMoveKthEvent | ((int64) startEventCount) << 32);

Looks current JsTTDMoveMode needs 64 bits.

@mrkmarron

@jcoffland
Copy link
Contributor Author

@jianchun good catch. I found the line you quoted above https://github.com/Microsoft/ChakraCore/blob/master/bin/ch/ch.cpp#L275. I did a little investigating and found that JsTTDMoveMode was hijacked to also pass in an event count. You can see it being used at https://github.com/Microsoft/ChakraCore/blob/master/lib/Jsrt/Jsrt.cpp#L3781. It appears that JsTTDGetSnapTimeTopLevelEventMove() is the only place JsTTDMoveMode is used in this way and https://github.com/Microsoft/ChakraCore/blob/master/bin/ch/ch.cpp#L275 is the only place it's ever called like this. In fact, this is the only place JsTTDGetSnapTimeTopLevelEventMove() is called.

Abusing JsTTDMoveMode like this seems like a bad idea since it is very likely to cause confusion. It's not at all obvious from looking at the definition of JsTTDMoveMode that it is going to be used in this way. The easiest solution is to add a kthEvent parameter to JsTTDGetSnapTimeTopLevelEventMove(). I've implemented this change.

@jcoffland jcoffland changed the title Fixes Jsrt API C99 compatability Fixes Jsrt API C99/C++98 compatability Nov 29, 2016
@mrkmarron
Copy link
Contributor

Hi @jcoffland, you are 100% correct that I was doing some parameter hijacking. I agree with you that this is suboptimal and converting the API to use a second parameter instead is more appropriate (thanks for your help cleaning this up).

One comment I have is that kthEvent is an optional parameter so we should probably make that clear in the SAL annotation/name.

@jianchun we will need to update the use of this API in the node/xplat branch when we merge later as well.

@jcoffland
Copy link
Contributor Author

@mrkmarron right. I've now changed the parameter annotation from _In_ to _In_opt.

@dilijev
Copy link
Contributor

dilijev commented Nov 29, 2016

Question for ChakraCore maintainers:

Is it possible to add a sort of test suite which exercises the use of our API when embedding ChakraCore in C99 and C++98 projects (using legacy build compatibility modes in vc and/or clang)?

On that note, @liminzhu, I remember someone mentioning that one or more samples had broken when we updated the API. Should we think about including a set of tests that include the samples to ensure we don't unexpectedly break anything? (I guess we could clone the repo https://github.com/Microsoft/Chakra-Samples as a step in the tests, or include it as a submodule of ChakraCore for this purpose.)

@dilijev
Copy link
Contributor

dilijev commented Nov 29, 2016

On another note:

Should this fix be back-ported to release/1.4, release/1.3, and/or release/1.2 because we still support 1.2 and 1.3, and we had intended this to work?

@jcoffland
Copy link
Contributor Author

It wasn't an issue in 1.3 when I tried it.

@dilijev
Copy link
Contributor

dilijev commented Nov 29, 2016

@jcoffland Thanks for confirming that. In any case, I think this PR should probably be re-targeted to 1.4 (because I'm pretty sure this issue would affect that release). But, hold off on that until we confirm. Worst-case we can just merge to master and then back-port the change to 1.4.

@obastemur
Copy link
Collaborator

I remember someone mentioning that one or more samples had broken when we updated the API. Should we think about including a set of tests that include the samples to ensure we don't unexpectedly break anything?

@dilijev We already test that for some time. See https://github.com/Microsoft/ChakraCore/tree/master/test/native-tests

@jcoffland
Copy link
Contributor Author

@obastemur Do those tests check that the samples in https://github.com/Microsoft/Chakra-Samples work?

@obastemur
Copy link
Collaborator

@jcoffland AFAIK we do check a bit more here. However, we should add more tests there indeed.

@jcoffland
Copy link
Contributor Author

It would make sense to trigger CI builds on https://github.com/Microsoft/Chakra-Samples to make sure they build. It would be best to have CI build badges on that project's README.md. The reason being that the samples are one of the first places new users start with ChakraCore. If it doesn't work they are likely to go elsewhere.

@obastemur
Copy link
Collaborator

obastemur commented Dec 1, 2016

It would make sense to trigger CI builds on https://github.com/Microsoft/Chakra-Samples to make sure they build.

I am not sure if I was being clear. We already build and test the Jsrt usage (with the same xplat compile scripts and same code) on ChakraCore CI for each PR.

If CI here is not failing, it is unlikely that we break Chakra-Samples. That is what https://github.com/Microsoft/ChakraCore/tree/master/test/native-tests for.

@jcoffland
Copy link
Contributor Author

@obastemur What keeps native-tests in sync with Chakra-Samples? My experience when I tried building Chakra-Samples was that they would not compile against ChakraCore master. This makes for a disheartening introduction.

Anyway, I've gone off topic. Can this PR be merged now?

@obastemur
Copy link
Collaborator

What keeps native-tests in sync with Chakra-Samples?

We do. Anything is failing on native tests, should alert devs to update Chakra Samples. IMHO it is similar to updating documentation.

@obastemur
Copy link
Collaborator

Can this PR be merged now?

Sorry for keeping this PR open for longer than it should. @dilijev any update?

In the mean time #2136 to make sure we don't break it again.

Fixed abuse of JsTTDMoveMode enum in call to JsTTDGetSnapTimeTopLevelEventMove() so that JsTTDMoveMode does not need to be 64-bit and thus incompatible with C99/C++98

Don't use nullptr at all, it's incompatible with C++98
@dilijev
Copy link
Contributor

dilijev commented Dec 5, 2016

This issue will affect release/1.4 so we should probably backport from master to release/1.4 it at a minimum.

Other than that, LGTM and good to merge.

@dilijev
Copy link
Contributor

dilijev commented Dec 7, 2016

should alert devs to update Chakra Samples

@obastemur while this seems true in principle, I think it is easy to miss, and since, unlike documentation (which, except for JSRT APIs where we look closely at public documentation, is basically best-effort), Samples are something which we expect to work and which we can actually break. People new to the project would expect it to work right out of the box without having to work through any issues.

I think we should seriously think about adding some automated test mechanism to ensure they all continue to work.

/cc @liminzhu

@dilijev
Copy link
Contributor

dilijev commented Dec 7, 2016

Assigning myself. I'll test and merge.

@chakrabot chakrabot merged commit 979a9f3 into chakra-core:master Dec 7, 2016
chakrabot pushed a commit that referenced this pull request Dec 7, 2016
Merge pull request #2001 from CauldronDevelopmentLLC:master
@jcoffland
Copy link
Contributor Author

It should be noted that there are additional compile problems using the Jsrt API with the MSVC compiler in C mode that are not addressed by this PR.

Thanks for the merge!

@dilijev
Copy link
Contributor

dilijev commented Dec 9, 2016

@jcoffland Thanks for the heads-up. Could you open an issue so we can track those issues?

chakrabot pushed a commit that referenced this pull request Dec 13, 2016
…ak again

Merge pull request #2136 from obastemur:add_c99_test

#2001 fixes Jsrt C99/C++98 compatibility issue. @dilijev brought the idea of adding a test to make sure we don't break it again.

This native test should take care of that.

p.s.: This PR will break until #2001 is merged.

/cc @dilijev @jcoffland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants