Skip to content
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

wish: validation when retrieving public methods #3760

Closed
vicuna opened this Issue Aug 16, 2005 · 2 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

commented Aug 16, 2005

Original bug ID: 3760
Reporter: administrator
Status: closed (set by @garrigue on 2008-01-25T08:37:13Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 3.11+dev
Category: ~DO NOT USE (was: OCaml general)
Parent of: #3761

Bug description

Full_Name: Nathaniel Gray
Version: 3.08.3
OS: Mac OS X
Submission from: dhcp-133-195.caltech.edu (131.215.133.195)

The C interface to ocaml offers the caml_get_public_method function for
retrieving a closure by hash from an object's method table. Unfortunately, this
function always returns some method, even if the table doesn't contain the
requested method! It seems caml_get_public_method doesn't check that the hash
you supplied matches the hash it found. It would be nice if either: a)
caml_get_public_method verified that it found the correct method and returned
NULL if it didn't, or b) you provided a separate function
caml_get_valid_public_method that does so.

Why would this be useful? For one, it would make misspelling bugs that are
potentially very difficult to find much easier to find. For another, the
ability to query the method table of an object at runtime could prove handy when
interfacing with dynamic languages. For example, I am currently working on an
OCaml <-> Objective-C bridge. Objective-C method dispatch works by searching
the method tables of each class in the inheritance hierarchy up towards the
root. I would like to be able to create an OCamlProxy object that, when it is
asked to respond to a message, looks in the method table of its OCaml object.
If the method is found then it is used, otherwise the message is passed on to
the superclass. I cannot do this with the current implementation, because
there's no way to learn that an object doesn't implement a method.

At the very least, this should be considered a documentation bug. It's
important to know what the failure modes of a function are.

Thanks,
-Nathan Gray

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 26, 2005

Comment author: administrator

see #3761

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 25, 2008

Comment author: @garrigue

It looks like I completely forgot this good idea.
This is now done for 3.11: caml_get_public_method returns 0 when the tag was not found.
This does not necesseraly mean that the right method was found (hey, even if the name
was identical, there is no type information available anyway), but at least this is
more elegant than always returning an unrelated method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.