Skip to content

Bindings to overloaded functions aren't supported anymore #239

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

Closed
fitzgen opened this issue Nov 11, 2016 · 1 comment
Closed

Bindings to overloaded functions aren't supported anymore #239

fitzgen opened this issue Nov 11, 2016 · 1 comment

Comments

@fitzgen
Copy link
Member

fitzgen commented Nov 11, 2016

The old servo/rust-bindgen supported them by appending 1, 2, 3, ... to each overload, but the new one does not.

I'll make a fix.

Test case (this should generate bindings for each overload):

struct JSContext;
struct ReadOnlyCompileOptions;
struct SourceBufferHolder;
struct AutoObjectVector;
struct char16_t;

#define JS_PUBLIC_API(t) t

namespace JS {

struct MutableHandleValue {};

/**
 * Evaluate the given source buffer in the scope of the current global of cx.
 */
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, const ReadOnlyCompileOptions& options,
         SourceBufferHolder& srcBuf, JS::MutableHandleValue rval);

/**
 * As above, but providing an explicit scope chain.  envChain must not include
 * the global object on it; that's implicit.  It needs to contain the other
 * objects that should end up on the script's scope chain.
 */
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOptions& options,
         SourceBufferHolder& srcBuf, JS::MutableHandleValue rval);

/**
 * Evaluate the given character buffer in the scope of the current global of cx.
 */
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, const ReadOnlyCompileOptions& options,
         const char16_t* chars, int length, JS::MutableHandleValue rval);

/**
 * As above, but providing an explicit scope chain.  envChain must not include
 * the global object on it; that's implicit.  It needs to contain the other
 * objects that should end up on the script's scope chain.
 */
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, AutoObjectVector& envChain, const ReadOnlyCompileOptions& options,
         const char16_t* chars, int length, JS::MutableHandleValue rval);

/**
 * Evaluate the given byte buffer in the scope of the current global of cx.
 */
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, const ReadOnlyCompileOptions& options,
         const char* bytes, int length, JS::MutableHandleValue rval);

/**
 * Evaluate the given file in the scope of the current global of cx.
 */
extern JS_PUBLIC_API(bool)
Evaluate(JSContext* cx, const ReadOnlyCompileOptions& options,
         const char* filename, JS::MutableHandleValue rval);

} // namespace JS

But we only get bindings for the first:

/* automatically generated by rust-bindgen */

extern "C" {
    /**
 * Evaluate the given source buffer in the scope of the current global of cx.
 */
    #[link_name =
          "_ZN2JS8EvaluateEP9JSContextRK22ReadOnlyCompileOptionsR18SourceBufferHolderNS_18MutableHandleValueE"]
    pub fn Evaluate(cx: *mut JSContext,
                    options: *const ReadOnlyCompileOptions,
                    srcBuf: *mut SourceBufferHolder, rval: MutableHandleValue)
     -> bool;
}
@emilio
Copy link
Contributor

emilio commented Nov 11, 2016

Fix should be easy, we should store symbols instead of names in the functions seen we track in codegen.

bors-servo pushed a commit that referenced this issue Nov 12, 2016
Add support for bindings to overloaded functions

This commit (re)adds support for generating bindings to overloaded
functions. First, we use the symbol name instead of the canonical name
when checking if we have already generated bindings for a given
function. Second, we add a map from canonical names to number of times
we have generated a function with that canonical name. We increment this
number every time we generate a function. When the number is greater
than zero, we append it to the function name so that overloaded
functions get a unique Rust symbol.

Fixes #239

r? @emilio
luser pushed a commit to luser/rust-bindgen that referenced this issue Mar 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants