Create a static method for ambiguous overloaded constructor#150
Merged
Naum-PDFTron merged 1 commit intonext_releasefrom Mar 25, 2025
Merged
Create a static method for ambiguous overloaded constructor#150Naum-PDFTron merged 1 commit intonext_releasefrom
Naum-PDFTron merged 1 commit intonext_releasefrom
Conversation
rchennafi
approved these changes
Mar 25, 2025
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.
Description
SWIG has issues with C++ overloaded methods (and constructors) to target scripting languages like Python, PHP and Ruby, like:
Both constructors take integral as input and, when called from scripting language (Python, PHP, Ruby), which knows just for one Integer type, SWIG has no way to unambiguosly distinguish which constructor to call. Therefor, SWIG offers several options to overcome that:
%renamethe second overloaded method and call it from the script by new name, sayFromDigestAlgorithm().It is fine for class method but not for constructor since one need an instance to call it and SWIG doesn't add a
staticprefix to call it asstatic. One need to create a dummy instance to call the instance method:This way to go is rejected.
%inlinethe second method by creating a global (non-class-related)staticmethod to do the above (1.) job. In script it would be called like:This works, but may confuse the developer. Say, in a similar case one should create instance as:
Developer doesn't need to know that it is a SWIG that dictates the API which may look confusing.
%extendtheObjectIdentifierclass (internally and locally to SWIG) with a static method that will call propper constructor:The developer could call:
This is acceptable solutuion. But there is one additional proposal...
Could we have a static method for the first case too and let it look like:
Or, generally, could we wrap all overloaded constructors (and methods) with this kind of extension?
Q: What to do with customers that already use current API?
A: They can continue as is is now, but with one note in the documentation: "Deprecated. Please use new notation ..."
During
Script/GenSwigWrappers.pyrun, there are several important products that are left in dark and that may be good to be uploaded somehow:PDFNetPython/PDFNetPython.cppPDFNetPython/PDFNetPython.hppPDFNetPython/PDFNetPython.pyPDFNetPHP/PDFNetPHP.cppPDFNetPHP/PDFNetPHP.phpPDFNetPHP/php_PDFNetPHP.hPDFNetRuby/PDFNetRuby.cppPDFNetRuby/PDFNetRuby.hppPDFNet*/swig.logPDFNet*/swig.err.logSWIG log files hides lot of overloading and missing defs info which would be good to look if some doesn;t work.
Changelog entry
N/A
Jenkins Builds
Wrappers ...
... Python3 Windows https://jenkins.apryse.com/job/Wrappers Python3 Windows/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... Windows32 https://jenkins.apryse.com/job/Wrappers Windows32/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... Python3 Linux https://jenkins.apryse.com/job/Wrappers Python3 Linux/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... Python3 Linux32 https://jenkins.apryse.com/job/Wrappers Python3 Linux32/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... Python Arm64 https://jenkins.apryse.com/job/Wrappers Python3 Linux ARM64/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... Python Alpine https://jenkins.apryse.com/job/Wrappers Python Alpine/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... Mac https://jenkins.apryse.com/job/Wrappers Mac/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... PHP Linux https://jenkins.apryse.com/job/Wrappers PHP Linux/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... PHP Alpine https://jenkins.apryse.com/job/Wrappers PHP Alpine/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
... Ruby Alpine https://jenkins.apryse.com/job/Wrappers%20Ruby%20Alpine/job/naum%252Fcap-747-SWIG-overloads-wrapper-3/1/
More details in: