Coder Social home page Coder Social logo

Comments (11)

dgarske avatar dgarske commented on May 29, 2024

@joakim-strandberg can you please review this bug report?

from wolfssl.

joakim-strandberg avatar joakim-strandberg commented on May 29, 2024

@dalybrown good catch! The Ada code should be a direct translation of the C examples and that translation does not look correct. My bad, thanks for finding it!!

The best way to fix it? One idea is to rename the function 'function "&" (Left, Right : Mode_Type) return Mode_Type;' to 'function "|" (Left, Right : Mode_Type) return Mode_Type;' and instead of "and" in the implementation "or" should be used instead. It will make the Ada code look more like the C implementation when using the wolfSSL library. What do you think?

from wolfssl.

dalybrown avatar dalybrown commented on May 29, 2024

@dalybrown good catch! The Ada code should be a direct translation of the C examples and that translation does not look correct. My bad, thanks for finding it!!

The best way to fix it? One idea is to rename the function 'function "&" (Left, Right : Mode_Type) return Mode_Type;' to 'function "|" (Left, Right : Mode_Type) return Mode_Type;' and instead of "and" in the implementation "or" should be used instead. It will make the Ada code look more like the C implementation when using the wolfSSL library. What do you think?

My preference would be to use the existing Ada syntax for logical operators: and, or, and xor. So in this case, my preference would be to define the or operator for the Mode_Type.

In general, I like things to not look like C haha... but that's my opinion.

from wolfssl.

dalybrown avatar dalybrown commented on May 29, 2024

p.s., there is another issue too with examples: the user_settings.h needs to be updated to include #define HAVE_NETDB_H. This was introduced in a subsequent commit.

from wolfssl.

dalybrown avatar dalybrown commented on May 29, 2024

p.p.s, I'm happy to fix both issues here. Let me know.

from wolfssl.

dgarske avatar dgarske commented on May 29, 2024

Hi @dalybrown , yes feel free to put up a PR fixing both issues. You are right about needing HAVE_NETDB_H. That normally comes from configure in the config.h.

from wolfssl.

joakim-strandberg avatar joakim-strandberg commented on May 29, 2024

My preference would be to use the existing Ada syntax for logical operators: and, or, and xor. So in this case, my preference would be to define the or operator for the Mode_Type.

It's reasonable to use the "or" operator instead of the "|" operator. You can choose either way @dalybrown. I do note that we are in a gray zone. The Ada language uses both the keyword "or" and "|" to list alternatives. In if-statements the "or" keyword is used, for example "if A or B then" but in case-statement over an enumeration type the "|" is used for example "when Red | Green | Blue =>". In the C version of the wolfSSL library it is known that the Method_Type is an unsigned 32-bit number and one uses bit-wise operations to turn on specific flags. In the Ada version of the wolfSSL library the Method_Type is a private type indicating to the user that the exact type of a Method_Type instance is unknown. It's a fundamental idea in Ada to hide exact representations from users as much as possible to limit potential errors. Classical example is the Integer type where one does not have access to the representation. The major argument for that is the code should be cross-platform and negative numbers may be represented in different ways depending on the hardware. So, in an Ada binding the Method_Type should be private, so it is not known what Method_Type is, but then using the "or" operator to list alternatives implicates that the Method_Type is actually a modular type defined in the Interfaces package and the "or" operator defined there is used under the hood. Which is true, but then again I am thinking is it possible to hide this fact and still have an Ada binding that is easy to use and understand? Just something to keep in mind. I don't think we should spend time on this. It's good to be pragmatic, pushing things forward, everything doesn't have to be perfect.

from wolfssl.

dalybrown avatar dalybrown commented on May 29, 2024

That's a good point. WolfSSL happens to use a logical operator here. There is probably a more idiomatic Ada way of specifying this than having clients do any logical operations.

I'll think about it for a bit and circle back with a few options.

One way would be to track the state of the mode that is set, and have a subprogram that you continually set the flags. Under the hood it will perform the logical or operation but that's not exposed to the client.

type State is private;
procedure Set (This : Mode_Type; In_This : in out State);

private

type State is Unsigned_32;

and then in the body you could just the operator:

procedure Set (This : Mode_Type; In_This : in out State)
is
begin
   In_This := In_This or Unsigned_32 (This);
end Set;

You can then just call it for every flag you want to set and then call the regular procedure.

There are probably many other options. Thoughts?

from wolfssl.

dalybrown avatar dalybrown commented on May 29, 2024

Maybe better names would be:

procedure Include (This : Mode_Type; With_These : in out Flags);

Or something...

from wolfssl.

dgarske avatar dgarske commented on May 29, 2024

Hi @dalybrown , will you be able to put up a PR to fix this mask and the netdb_h?

from wolfssl.

dalybrown avatar dalybrown commented on May 29, 2024

Hi @dalybrown , will you be able to put up a PR to fix this mask and the netdb_h?

Definitely! I was hoping to hear back from @joakim-strandberg on my suggestions prior to pushing any changes.

from wolfssl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.