Fix Java and C lesson code execution (partial fix) - #65
Open
umarjaved204 wants to merge 3 commits into
Open
umarjaved204 wants to merge 3 commits into
umarjaved204 wants to merge 3 commits into
Conversation
- Detect the learner's public/main class instead of forcing the class to be named Solution, so lessons using `public class Main` compile and run. Package declarations are supported too. - Accept stdin and close the child's stdin, so Scanner-based lessons get their input instead of blocking until the 8s timeout. - Report timeouts with a clear message instead of "exited with code null". - Handle spawn errors on javac/java. Previously a missing JDK emitted an unhandled 'error' event and terminated the Node process; it now returns a "Java (JDK) is not installed" message like the C++ runner does. - Use getWritableRuntimeDir() so serverless hosts reach the JDK check instead of failing on a read-only filesystem.
C submissions were written to a .cpp file and compiled with g++, so valid C was judged by C++ rules: `int *p = malloc(n)` failed with "invalid conversion from void*", and C identifiers such as `new` or `class` were syntax errors. C now has its own runner using gcc (linked with -lm so math.h works). The C and C++ runners share one compile-and-run implementation, which also: - deletes the binary when compilation fails (a failed link could leave a partial executable behind) - reports timeouts with a clear message instead of "exited with code null" - retries spawning a freshly linked binary on EPERM/EBUSY, which Windows antivirus causes intermittently (~2 in 15 runs locally) - uses getWritableRuntimeDir() like the Ruby runner
Remove twelve leftover run_*.cpp files (learner code from earlier runs) from src/runtime/tmp and ignore the directory, keeping it in the repo with a .gitkeep. app.log is left tracked as before.
|
@umarjaved204 is attempting to deploy a commit to the seno-quantum-coder's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes errors in Java and C lesson code ("Try and Learn"). This is a partial fix: see "Not included" below.
What is fixed
Main,HelloWorld, etc.), not onlySolution.packagelines also work.Scannernow get the learner's input instead of hanging for 8 seconds.gccinstead ofg++, so normal C code (int *p = malloc(n), a variable namednew) compiles.math.his linked.spawn EPERM, about 2 in 15 runs before).run_*.cppfiles removed from the repo, andsrc/runtime/tmpis now in.gitignore.getWritableRuntimeDir()(/tmpon Vercel), like the Ruby runner.Not included
src/routes/challenge.js) still skip Java and C++ on purpose. The Java/C++ test drivers there also add the learner's code twice, so they need their own fix after the hosting decision.Testing
No automated tests exist in the repo, so I tested by running code through
playgroundService.executeCode():package, Scanner input, timeout, compile errors, and JDK missing from PATH (server stays up).malloc, a variable namednew,sqrt,scanf, compile errors and timeout.Please test before merging: one C++ lesson that uses
<iostream>. C++ was only tested with<cstdio>programs.