-
Notifications
You must be signed in to change notification settings - Fork 362
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
Migrated to calloc #2080
base: main
Are you sure you want to change the base?
Migrated to calloc #2080
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
int scalanative_convert_sockaddr_in(struct scalanative_sockaddr_in *in, | ||
struct sockaddr_in **out, socklen_t *size) { | ||
struct sockaddr_in *s = | ||
(struct sockaddr_in *)malloc(sizeof(struct sockaddr_in)); | ||
(struct sockaddr_in *)calloc(1, sizeof(struct sockaddr_in)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to previously expressed concerns: clearing memory which is not a |
||
*size = sizeof(struct sockaddr_in); | ||
s->sin_family = in->sin_family; | ||
s->sin_port = in->sin_port; | ||
|
@@ -20,7 +20,7 @@ int scalanative_convert_sockaddr_in6(struct scalanative_sockaddr_in6 *in, | |
struct sockaddr_in6 **out, | ||
socklen_t *size) { | ||
struct sockaddr_in6 *s = | ||
(struct sockaddr_in6 *)malloc(sizeof(struct sockaddr_in6)); | ||
(struct sockaddr_in6 *)calloc(1, sizeof(struct sockaddr_in6)); | ||
*size = sizeof(struct sockaddr_in6); | ||
s->sin6_family = in->sin6_family; | ||
s->sin6_port = in->sin6_port; | ||
|
@@ -35,7 +35,7 @@ int scalanative_convert_sockaddr_storage( | |
struct scalanative_sockaddr_storage *in, struct sockaddr_storage **out, | ||
socklen_t *size) { | ||
struct sockaddr_storage *s = | ||
(struct sockaddr_storage *)malloc(sizeof(struct sockaddr_storage)); | ||
(struct sockaddr_storage *)calloc(1, sizeof(struct sockaddr_storage)); | ||
*size = sizeof(struct sockaddr_storage); | ||
s->ss_family = in->ss_family; | ||
*out = s; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ object SocketHelpers { | |
var hints = alloc[addrinfo] | ||
var ret = alloc[Ptr[addrinfo]] | ||
|
||
libc.memset(hints.rawptr, 0, sizeof[addrinfo]) | ||
hints.ai_family = AF_UNSPEC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that removing the memset is a BUG before/until PR #2086 is merged. Both here and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LeeTibbert yes, this PR was created before #2086, and I'm still not sure that this one is required as #2086 required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks to refresh this, let me mark it is a draft to save time by anyone. |
||
hints.ai_protocol = 0 | ||
hints.ai_addr = null | ||
|
@@ -145,7 +144,6 @@ object SocketHelpers { | |
var hints = alloc[addrinfo] | ||
var ret = alloc[Ptr[addrinfo]] | ||
|
||
libc.memset(hints.rawptr, 0, sizeof[addrinfo]) | ||
hints.ai_family = AF_UNSPEC | ||
hints.ai_socktype = SOCK_STREAM | ||
hints.ai_protocol = 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,16 @@ import scalanative.junit.utils.AssertThrows._ | |
|
||
import scalanative.unsafe.Nat._ | ||
import scalanative.unsigned._ | ||
import scalanative.libc.stdlib.malloc | ||
import scalanative.libc.stdlib.calloc | ||
import java.lang.Long.toHexString | ||
|
||
class CArrayBoxingTest { | ||
var any: Any = null | ||
|
||
@noinline lazy val nullArr: CArray[Byte, _4] = null | ||
@noinline lazy val arr: CArray[Byte, _4] = !malloc(64.toULong) | ||
@noinline lazy val arr: CArray[Byte, _4] = !calloc(1.toUInt, 64.toUInt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the advantage of clearing the memory. On a quick read, arr & arr2 are used as addresses and the contents not considered before being set (if ever, I did not trace that). Have I missed something? |
||
.asInstanceOf[Ptr[CArray[Byte, _4]]] | ||
@noinline lazy val arr2: CArray[Byte, _4] = !malloc(64.toULong) | ||
@noinline lazy val arr2: CArray[Byte, _4] = !calloc(1.toUInt, 64.toUInt) | ||
.asInstanceOf[Ptr[CArray[Byte, _4]]] | ||
|
||
@noinline def f[T](x: T): T = x | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why clear memory that is just going to be overwritten?
Network code is particularly sensitive to speed of execution concerns and regressions.
I believe that all of the
calloc
in this file do not increase correctness and decreaseperformance and should not happen.