Calling same-named-function from abstruct object

2020-09-29 Thread slonik_az
I think Nim already has all the mechanisms needed to prevent this type of code injection. If I have a module `foo.nim` with templates containing late binding `mixin` code I, as a provider, can only expose my clients to a carefully restricted `foo_api.nim` that only exports safe and hygienic code

Calling same-named-function from abstruct object

2020-09-29 Thread chaemon
Thanks @Araq and @Stefan_Salewski. For now, heapqueue doesn't support custom comparison function. It only allows `<`. It is very inconvenient...

Calling same-named-function from abstruct object

2020-09-29 Thread Araq
The scope of your `<` must be the global scope. (And we should really have that in the spec...)

Calling same-named-function from abstruct object

2020-09-29 Thread Stefan_Salewski
`import heapqueue type Q = object d:int #mixin `<` proc `<`(a, b:Q):bool = a.d < b.d proc main() = var q = initHeapQueue[Q]() for d in [3, 1, 4, 1, 5, 9, 2, 6, 5]: q.push(Q(d:d)) while q.len > 0: var a = q.pop() echo a.d main() ` Run

Calling same-named-function from abstruct object

2020-09-29 Thread chaemon
Is this a similar issue? I can't define operator `<` even if I insert mixin statement. import heapqueue proc main() = type Q = object d:int mixin `<` proc `<`(a, b:Q):bool = a.d < b.d var q = initHeapQueue[Q]() for d in [3,

Calling same-named-function from abstruct object

2020-09-28 Thread Araq
> Does it pose a potential security risk by means of code injection? Depends on what you mean by "security". IMO not it doesn't, because you can always call the wrong function and produce a bug. But it depends on your definition of "security". For example, for my definition of security: An OS t

Calling same-named-function from abstruct object

2020-09-28 Thread chaemon
Thanks! I understand completely. I have some kind of similar trouble and I will ask them other threads!

Calling same-named-function from abstruct object

2020-09-28 Thread slonik_az
Very interesting. It means that mixins are violating lexical scoping rules, for one does not know at definition what procedure `pow` symbol will be bound to at instantiation. Does it pose a potential security risk by means of code injection?

Calling same-named-function from abstruct object

2020-09-27 Thread shirleyquirk
open means a symbol can refer to something that didn't exist at the time the symbol was defined in your case, `Modint` doesn't exist within formalpowerseries.nim, and `pow` can only refer to the `pow` in that file, that's the "context at definition" when we make `pow` an open symbol, it also ta

Calling same-named-function from abstruct object

2020-09-27 Thread chaemon
Thanks! I should learn mixin statement and open and closed symbol. Do you refer to the following? I read it several time but I couldn't understand what "open symbol" is.

Calling same-named-function from abstruct object

2020-09-27 Thread chaemon
Thanks! I didn't know mixin statement.

Calling same-named-function from abstruct object

2020-09-27 Thread shirleyquirk
If your intention is for `pow` to be overloaded, you can declare it an "open symbol" with the [mixin statement](https://nim-lang.org/docs/manual.html#generics-mixin-statement) like this: type FormalPowerSeries*[T] = object data*: seq[T] proc pow*[T](self: FormalPowe

Calling same-named-function from abstruct object

2020-09-27 Thread Araq
This should do the job: proc pow*[T](self:FormalPowerSeries[T], k:int):auto= mixin pow @[pow(T(), k)] Run

Calling same-named-function from abstruct object

2020-09-27 Thread chaemon
I am wrote the following three files. There are two objects ModInt and FormalPowerSeries. FormalPowerSeries has generics T and it takes ModInt. Both objects has proc named pow. Pow is called from FormalPowerSeries and in the proc, it also call pow of generics T. test.nim: import