From fd06aba05381055ab56e1ec81d56055b66462f0b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 26 Apr 2018 15:36:13 -0700 Subject: fixes #375 integer types are error prone This change converts the various integer types like nng_socket in the public API to opaque structures that are passed by value. Basically we just wrap the integer ID. This "hack" give us strong type checks by the compiler (yay!), at the expense of not being able to directly use these as numbers (so comparisions for example don't work, and neither does initialization to zero using the normal method. Comparison of disassembly output shows that at least with the optimizer enabled there is no difference in the compiler output between using a structure or an integral value. --- src/core/protocol.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/protocol.c b/src/core/protocol.c index e36bc31f..52b9b7fb 100644 --- a/src/core/protocol.c +++ b/src/core/protocol.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -62,7 +62,9 @@ nni_proto_open(nng_socket *sockidp, const nni_proto *proto) return (rv); } if ((rv = nni_sock_open(&sock, proto)) == 0) { - *sockidp = nni_sock_id(sock); // Keep socket held open. + nng_socket s; + s.id = nni_sock_id(sock); // Keep socket held open. + *sockidp = s; } return (rv); } -- cgit v1.2.3-70-g09d2