-
Notifications
You must be signed in to change notification settings - Fork 70
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
fix: method naming conflicts #215
Conversation
@@ -25,6 +28,7 @@ export default function () { | |||
} | |||
} | |||
for (let method of Object.keys(contractMethods)) { | |||
validateMethod(method, cFunctions) |
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.
This validating pattern is cool!
|
||
function getCFunctions(){ | ||
const builderRaw = readFileSync(path.resolve('../cli/builder/builder.c'), 'utf-8') | ||
const regex = new RegExp(/(?<=JS_SetPropertyStr\(ctx, env, ").+?(?=", JS_NewCFunction\(ctx,)/gm) |
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.
There are more functions to filter out, basically every C function that's included in builder.c, such as strncpy
, so this is quite challenging to figure out all C function names. I wonder whether one these directions can be easier:
- when confliction happens, can we collect the C compiler's error/warning and indicate the user to rename the contract method
- can we iterate contract method names like you did, then for any name confliction, use some C code-transformation / compiler tool to rename C functions to some random names. For example, a developer can write a contract method named
strncpy
(:joy:), and we let the tool to rename original Cstrncpy
(not user contract method name) to___strncpy
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.
Wooow, yes. Why not, I will update PR
The reason why you can not import these functions from utils is that Babel not allowing imports without .js file extension. You are importing it from |
@osalkanovic Looks like a |
…/method-naming-conflict
…ear-sdk-js into fix/method-naming-conflict
@ailisp can you re-run CI? |
@ailisp first step is resolved Now we have coordinates where function start in builder.c so we can easily include __ in function name :D I have to also found coordinates for regex match functions :D cc @volovyks can you assist with moving functions to utils? |
CI should fail because I have c function in smart contract |
@osalkanovic Seems that your collectCFunction/groupCFunction implemented a great algorithm that parsed all c function used in builder.c! However it doesn't collect the names in I suggest to look for some existing unix tool that recursively process C includes, for example |
We can move functions later. That is a separate issue. @osalkanovic Can we continue with this PR? We are happy to help you if you are stuck with something. |
Fixed in #346 . @osalkanovic Appreciate your contributions to near-sdk-js! We are now accepting proposals and give fundings to improve NEAR developer tools, including JS SDK. If you have an idea about near-sdk-js, create an The place to submit idea / solution: https://devgovgigs.near.social |
Issue: #121
Here is working example how to prevent same functions naming as c functions.
I tried to move functions to helper, but unsuccessfully to import helper inside babel transformer, if someone can assist it would be good :))