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

Add proc toOpenArray[byte] for strings #7820

Merged
merged 3 commits into from
Jul 7, 2018
Merged

Add proc toOpenArray[byte] for strings #7820

merged 3 commits into from
Jul 7, 2018

Conversation

data-man
Copy link
Contributor

No description provided.

@ghost
Copy link

ghost commented May 13, 2018

So user should use first argument as an uint instead of int because there's no result type overloading? It seems like not the best solution, but idk..

@data-man
Copy link
Contributor Author

because there's no result type overloading?

Yes.

It seems like not the best solution

Maybe toOpenArrayByte will be better.

@Araq
Copy link
Member

Araq commented May 14, 2018

Maybe toOpenArrayByte will be better.

Yeah...

@data-man
Copy link
Contributor Author

Renamed.

@Araq
Copy link
Member

Araq commented May 14, 2018

Ok, now the question is: Why do we need it?

@data-man
Copy link
Contributor Author

data-man commented May 14, 2018

E.g. for compressions/conversions.

proc compress/convert(bytes: openarray[byte]): seq[byte] =

Maybe can be used in the critbits module.

@mratsim
Copy link
Collaborator

mratsim commented May 17, 2018

For crypto

@data-man
Copy link
Contributor Author

data-man commented May 17, 2018

And would be great if proc toOpenArray*[T](x: T): openarray[byte] {.magic: "Slice".} will be implemented for any T with fixed size.
And proc toOpenArray*[T](x: seq[T]): openarray[T] {.magic: "Slice".}
And proc toOpenArrayByte*[T](x: seq[T]): openarray[byte] {.magic: "Slice".}
And proc toOpenArrayByte*(x: string): openarray[byte] {.magic: "Slice".}
:)

@data-man
Copy link
Contributor Author

Also many procs from strutils can be adapted for openarray[T].
It will be very useful.
Maybe within a new module, e.g. oautils.

@coffeepots
Copy link
Contributor

This fails for the cpp target for me with --cc:vcc (64 bit):

error C2664: 'void foo_2qb8oX71x3XZ4LiDnKOl6w(NU8 *,NI)': cannot convert argument 1 from 'NIM_CHAR *' to 'NU8 *'

note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

The line that raises the issue:

foo_2qb8oX71x3XZ4LiDnKOl6w(str_PePXyhboa11u24CvmKb3Vg->data+(((NU) 0)), ((str_PePXyhboa11u24CvmKb3Vg ? (str_PePXyhboa11u24CvmKb3Vg->len-1) : -1))-(((NU) 0))+1);

@data-man
Copy link
Contributor Author

Well, closed.

@data-man data-man closed this May 17, 2018
@ghost
Copy link

ghost commented May 17, 2018

@data-man why?

@ghost
Copy link

ghost commented May 17, 2018

Maybe it can be fixed

@data-man
Copy link
Contributor Author

@Yardanico Because @Araq are against it. :)

@coffeepots
Copy link
Contributor

@data-man we shouldn't be getting gen errors in Nim, so this is a valid bug that has been caught by your PR.

As others mention, it could well be useful for various low level processing.

@zah
Copy link
Member

zah commented Jul 6, 2018

It turned out that we need this in quite a lot of places. @Araq, any chance that we'll reconsider merging it?

@yglukhov
Copy link
Member

yglukhov commented Jul 6, 2018

This doesn't need to rely on magic, openarrays can be constructed from ptr/len and produce good codegen. We might add ptr/len to openarray conversion to stdlib though, as it is not obvious enough.

@Araq Araq reopened this Jul 6, 2018
@Araq
Copy link
Member

Araq commented Jul 6, 2018

any chance that we'll reconsider merging it?

Ok.

@Araq Araq merged commit a6c3bbf into nim-lang:devel Jul 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants