-
Notifications
You must be signed in to change notification settings - Fork 182
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
🐛 Bug Report
Description:
When trying to pass a string from Node.js to C, the string does not get passed correctly as an argument. Instead, a garbage value is received in C. Similarly, when returning a string from C to Node.js, the returned value is also a garbage value, not the expected string.
Note: When passing a single character from Node.js to C ( char
), it works correctly. Likewise, when a character is returned from C, Node.js receives the corresponding ASCII value.
Expected Behavior:
- Strings passed from Node.js to C should be properly received as arguments.
- Strings returned from C to Node.js should be properly returned and not as garbage values.
Current Behavior:
- Strings passed from Node.js to C result in garbage values instead of valid strings.
- Strings returned from C to Node.js also result in garbage values instead of valid strings.
Steps to Reproduce:
1. Testing the Return Value from C to Node.js
C file (textpro.c
):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char* process_text() {
char* input = "hello";
return input;
}
Node.js file (testing.js
):
const { metacall_load_from_file, metacall } = require('metacall');
metacall_load_from_file('c', ['textpro.c']);
console.log(metacall('process_text'));
Steps:
- Build and install Metacall, ensuring that the C loader is enabled.
- Write the C file
textpro.c
and Node.js filetesting.js
as shown above. - Export the necessary script and library environment path.
- Run the script with
metacallcli testing.js
. - Observe the garbage value returned instead of the expected string.
2. Testing Argument Passing from Node.js to C
C file (textpro.c
):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void process_text(char* input) {
printf("%s", input);
}
Node.js file (testing.js
):
const { metacall_load_from_file, metacall } = require('metacall');
metacall_load_from_file('c', ['textpro.c']);
console.log(metacall('process_text', 'test_test'));
Steps:
- Build and install Metacall, ensuring that the C loader is enabled.
- Write the C file
textpro.c
and Node.js filetesting.js
as shown above. - Export the necessary script and library environment path.
- Run the script with
metacallcli testing.js
. - Observe a segmentation fault (due to the invalid memory location being used by
printf
).
Conclusion:
- When passing a string from Node.js to C, the string is not properly passed, resulting in an invalid or garbage value.
- When returning a string from C to Node.js, the returned value is not a string, but a garbage value instead.
- These issues appear when passing strings, but single characters work as expected.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
viferga commentedon Jul 10, 2025
@RohanKrMahato thank you so much for reporting, I solved the issue already:
1d14941
2cf32ca
I used your tests as a base for making it.
RohanKrMahato commentedon Jul 11, 2025
@viferga I’m happy I could help you. I’ll be returning and contributing actively to Metacall starting in September.