You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Julian Foad <ju...@btopenworld.com> on 2015/03/05 13:16:52 UTC
Convenient array & hash iterators & accessors
In http://svn.apache.org/r1664127 (very similar to the attached patch),
I added some array & hash iterators & accessors to the 'move-tracking-2' branch
so that I could use more compact iteration code (http://svn.apache.org/r1664285)
and get an iteration pool 'for free' (http://svn.apache.org/r1664290).
Is there any interest in using some of this on trunk?
Here's a summary.
Array: apr_array_header_t of pointers to objects, with
- Simpler syntax for operations such as make, get, set, push, pop.
- no need to specify the element type in these operations
- The get and set and iteration functions avoid the need to use the
non-type-safe APR_ARRAY_IDX. (It does not assert that the sizeof(type)
matches, let alone (type) itself. Note: When I inserted
"assert(sizeof(type)==array->elt_size)" in APR's version, the Subversion
test suite still passed, so that's good.)
- Shallow and deep duplicators for an array of simple or compound elements.
Hash table: same as apr_hash_t but always with C-string keys.
Iteration over an array or a hash shares these features:
- Convenience prioritized over speed (but still good speed).
- Easy access to this key and this value as iterator member variables.
- for an array: it->i and it->val
- for a hash: it->key and it->val (and it->klen for good measure)
- Templated iterator with parameterized element type.
- in an iterator declared as "SVN_ITER_T(svn_branch_family_t) *it;",
it->val has type "svn_branch_family_t *"
- in an iterator declared as "svn_iter_t *it;",
it->val has type "void *"
- Built-in, managed iterpool as an iterator member variable.
- just use it->iterpool; it is automatically created/cleared/destroyed
- Iteration in sorted order (optional).
- just use "for (SVN_ARRAY_ITER_SORTED(it, array, comparator, pool))"
instead of "for (SVN_ARRAY_ITER(it, array, pool))"; same for a hash
Usage examples:
- outer_family->sub_families = apr_array_make(result_pool, 1, sizeof(void *));
+ outer_family->sub_families = svn_array_make(result_pool);
- APR_ARRAY_PUSH(outer_family->sub_families, void *) = family;
+ SVN_ARRAY_PUSH(outer_family->sub_families) = family;
{
- apr_array_header_t *sub_families
- = svn_branch_family_get_children(family, scratch_pool);
- int f;
+ SVN_ITER_T(svn_branch_family_t) *fi;
- for (f = 0; f < sub_families->nelts; f++)
+ for (SVN_ARRAY_ITER(fi, svn_branch_family_get_children(
+ family, scratch_pool), scratch_pool))
{
- svn_branch_family_t *sub_family
- = APR_ARRAY_IDX(sub_families, f, svn_branch_family_t *);
-
- SVN_ERR(family_list_branch_instances(rev_root, sub_family, recursive,
+ SVN_ERR(family_list_branch_instances(rev_root, fi->val, recursive,
- verbose, scratch_pool));
- verbose, fi->iterpool));
}
}
- Julian
Re: AW: Convenient array & hash iterators & accessors
Posted by Greg Stein <gs...@gmail.com>.
On Fri, Mar 13, 2015 at 4:31 AM, Branko Čibej <br...@wandisco.com> wrote:
>...
> >> Why not Groovy (soon to be incubating at the ASF). That way we keep
> >> things in the family, and we're likely to eventually move everything to
> >> a JVM-based implementation instead of this silly native-compiled, last
> >> century stuff.
>
Ha! … I'm taking this as a tongue-in-cheek joke.
Moving on …
>...
> The problem (or "problem") with C++ is that it's *extremely* hard to
> code things correctly in an exception-safe manner. Otherwise I'd be all
> for using it, these days (especially with C++11) you have a language
> that's in some ways horrible to use, but when used correctly can provide
> huge benefits. But it takes years of single-minded language-lawyerish
> hacking to get to the "used correctly" phase.
>
Agreed. Google had a very good approach to this. C++ was (is?) one of the
primary development languages, but the feature set allowed to developers
was extremely limited. Through the "style" guide, most features were
declared verboten.
I don't think we can expose C++ APIs. The ABI has never appeared to be
reliable. But in limited fashion, I *do* believe we can rely on a few
features of C++. Contrary to the state of C++ back in 2000, where we
totally threw it out as an option … today, the C++ compilers should be able
to provide a couple key features that could improve our code.
It might be an interesting consideration for 1.10 whether we can require
all our delivery platforms to provide a minimal set of C++
compilation/features.
>…
Cheers,
-g
Re: AW: Convenient array & hash iterators & accessors
Posted by Erik Huelsmann <eh...@gmail.com>.
> > Heh :-) I meant the branch-specific code -- not *all* of the client and
> > library! I have no idea what that means, because I didn't study the code
> > closely (yet). I'll need some directions on where to look for the
> > branch-specific code so I can try to figure out where to hook Lua in.
>
> Oh, so you you want to try it?
Well, my idea would be that if we're able to address the code
additions/changes in that branch with an integration design, then it
fulfills the requirement you were talking about at the beginning of this
thread. If it doesn't work, then it might not be the solution we're looking
for.
> OK, the new code is pretty well
> segrated from the existing code. Almost all of the relevant code is in
> these new files:
>
> subversion/svnmover/svnmover.c
> subversion/libsvn_delta/{element,branch,editor3e,compat3e}.c
>
Thanks! I'll have a look.
--
Bye,
Erik.
http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
Re: AW: Convenient array & hash iterators & accessors
Posted by Julian Foad <ju...@btopenworld.com>.
Erik Huelsmann wrote:
>> > Am I right that if we were to run this experiment with the
>> > move-tracking-2 branch code, that the entire client and library would
>> > be subject to conversion to the higher level language?
>>
>> No! That would be literally years of rewriting and debugging [...]
>
> Heh :-) I meant the branch-specific code -- not *all* of the client and
> library! I have no idea what that means, because I didn't study the code
> closely (yet). I'll need some directions on where to look for the
> branch-specific code so I can try to figure out where to hook Lua in.
Oh, so you you want to try it? OK, the new code is pretty well
segrated from the existing code. Almost all of the relevant code is in
these new files:
subversion/svnmover/svnmover.c
subversion/libsvn_delta/{element,branch,editor3e,compat3e}.c
- Julian
Re: AW: Convenient array & hash iterators & accessors
Posted by Erik Huelsmann <eh...@gmail.com>.
> > Am I right that if we were to run this experiment with the
> > move-tracking-2 branch code, that the entire client and library would
> > be subject to conversion to the higher level language?
>
> No! That would be literally years of rewriting and debugging and
> re-testing, not to mention interesting interfacing with the rest of the
> (pool-bound) code.
>
Heh :-) I meant the branch-specific code -- not *all* of the client and
library! I have no idea what that means, because I didn't study the code
closely (yet). I'll need some directions on where to look for the
branch-specific code so I can try to figure out where to hook Lua in.
--
Bye,
Erik.
http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
Re: AW: Convenient array & hash iterators & accessors
Posted by Julian Foad <ju...@btopenworld.com>.
>> Well, Lua supports calling both ways. A call isn't a straight C call,
>> though (in Lua, it's a straight Lua function invocation), but a call
>> that follows a certain calling protocol. Going from Lua to pure C or
>> pure C to Lua requires a bit of glue code much like sqlite does for
>> its parameter bindings.
>>
>> Am I right that if we were to run this experiment with the
>> move-tracking-2 branch code, that the entire client and library would
>> be subject to conversion to the higher level language?
>
> No! That would be literally years of rewriting and debugging and
> re-testing, not to mention interesting interfacing with the rest of the
> (pool-bound) code.
I assume we could start by writing one line of new code, getting it to
compile and run (that would involve a lot of configuration work and
learning, initially), and then extend bit by bit as desired. Probably
no point in ever rewriting the *whole* of anything, only new stuff and
anything that needs to be largely rewritten for another reason.
- Julian
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 13.03.2015 15:07, Erik Huelsmann wrote:
>
>
> > @Julian, do you have a specific area of our code that would most
> benefit
> > from "moving 'up' from C"? Preferably some part of code that's
> currently
> > very much in flux?
>
> 'svnmover' on the 'move-tracking-2' branch. It includes both 'client'
> and 'library' code, and I'm moving code freely between the two as I
> figure out what is the best layering. So it's important that a
> language would be good in both roles.
>
>
> Well, Lua supports calling both ways. A call isn't a straight C call,
> though (in Lua, it's a straight Lua function invocation), but a call
> that follows a certain calling protocol. Going from Lua to pure C or
> pure C to Lua requires a bit of glue code much like sqlite does for
> its parameter bindings.
>
> Am I right that if we were to run this experiment with the
> move-tracking-2 branch code, that the entire client and library would
> be subject to conversion to the higher level language?
No! That would be literally years of rewriting and debugging and
re-testing, not to mention interesting interfacing with the rest of the
(pool-bound) code.
-- Brane
Re: AW: Convenient array & hash iterators & accessors
Posted by Erik Huelsmann <eh...@gmail.com>.
> > @Julian, do you have a specific area of our code that would most benefit
> > from "moving 'up' from C"? Preferably some part of code that's currently
> > very much in flux?
>
> 'svnmover' on the 'move-tracking-2' branch. It includes both 'client'
> and 'library' code, and I'm moving code freely between the two as I
> figure out what is the best layering. So it's important that a
> language would be good in both roles.
>
Well, Lua supports calling both ways. A call isn't a straight C call,
though (in Lua, it's a straight Lua function invocation), but a call that
follows a certain calling protocol. Going from Lua to pure C or pure C to
Lua requires a bit of glue code much like sqlite does for its parameter
bindings.
Am I right that if we were to run this experiment with the move-tracking-2
branch code, that the entire client and library would be subject to
conversion to the higher level language?
--
Bye,
Erik.
http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
Re: AW: Convenient array & hash iterators & accessors
Posted by Julian Foad <ju...@btopenworld.com>.
Erik Huelsmann wrote:
>> I don't have direct experience with Lua, but have read/observed it for
>> many years. This is something that I could get behind as an embedded
>> *experimental* solution (to move "up" from lower-level C code), based on
>> what I've read.
>
> That would be the first step for any implementation, I take it -- we'd want
> to evaluate the benefits to be had. If we agree to start experimenting with
> Lua, the next step would be to create a high level design. Something I might
> be able to spend time on.
>
> @Julian, do you have a specific area of our code that would most benefit
> from "moving 'up' from C"? Preferably some part of code that's currently
> very much in flux?
'svnmover' on the 'move-tracking-2' branch. It includes both 'client'
and 'library' code, and I'm moving code freely between the two as I
figure out what is the best layering. So it's important that a
language would be good in both roles.
- Julian
Re: AW: Convenient array & hash iterators & accessors
Posted by Erik Huelsmann <eh...@gmail.com>.
> Hence my suggestion for Lua, which doesn't have a GIL, as far as I can
>> find. Nor does it need manual reference-keeping like is needed with Python
>> or Perl. With Lua you can have as many evaluation environments as you want.
>> Instantiating them when crossing a certain API boundary to be used by the
>> library internals.
>>
>
> I don't have direct experience with Lua, but have read/observed it for
> many years. This is something that I could get behind as an embedded
> *experimental* solution (to move "up" from lower-level C code), based on
> what I've read.
>
That would be the first step for any implementation, I take it -- we'd want
to evaluate the benefits to be had. If we agree to start experimenting with
Lua, the next step would be to create a high level design. Something I
might be able to spend time on.
@Julian, do you have a specific area of our code that would most benefit
from "moving 'up' from C"? Preferably some part of code that's currently
very much in flux?
--
Bye,
Erik.
http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
Re: AW: Convenient array & hash iterators & accessors
Posted by Greg Stein <gs...@gmail.com>.
On Fri, Mar 13, 2015 at 5:08 AM, Erik Huelsmann <eh...@gmail.com> wrote:
>
>
>> In the past I'd thought about embedding Python into our sources, but
>> Python still (after 20 years ...) depends on a global interpreter lock
>> which pretty much kills any chance of lockless thread-safe code.
>>
>
I've embedded Python in several production situations. Mostly, in
high-performance server-side code. That GIL was ever-present.
As part of some work back in the mid-90's, I created a set of patches to
*remove* the GIL. David Beazley has an excellent writeup/analysis/review of
those patches:
http://dabeaz.blogspot.com/2011/08/inside-look-at-gil-removal-patch-of.html
I love Python. I'd suggest (re)writing our client in Python. But I would
*not* suggest embedding it. It can be done, yes. It can help, yes. But it
is simply too tricky/brittle for me to truly recommend it.
Hence my suggestion for Lua, which doesn't have a GIL, as far as I can
> find. Nor does it need manual reference-keeping like is needed with Python
> or Perl. With Lua you can have as many evaluation environments as you want.
> Instantiating them when crossing a certain API boundary to be used by the
> library internals.
>
I don't have direct experience with Lua, but have read/observed it for many
years. This is something that I could get behind as an embedded
*experimental* solution (to move "up" from lower-level C code), based on
what I've read.
>...
Cheers,
-g
Re: AW: Convenient array & hash iterators & accessors
Posted by Erik Huelsmann <eh...@gmail.com>.
> In the past I'd thought about embedding Python into our sources, but
> Python still (after 20 years ...) depends on a global interpreter lock
> which pretty much kills any chance of lockless thread-safe code.
>
Hence my suggestion for Lua, which doesn't have a GIL, as far as I can
find. Nor does it need manual reference-keeping like is needed with Python
or Perl. With Lua you can have as many evaluation environments as you want.
Instantiating them when crossing a certain API boundary to be used by the
library internals.
These days, I suppose we'd be looking at something like Go, which can be
> linked with C/C++ and also natively export functions that can be called
> from C/C++.
>
Do you mean that the code one writes is exported as a C function? Or that
there's a C interface (the latter isn't better than e.g. Lua, Python and
Perl, so I assume you mean the former?)
Would it be an idea, if we really want this, to come up with a list of
requirements and nice-to-haves against which each of the languages brought
up should be measured? If we don't do that, we probably go on another 10
years with C only (and another 10... and anothor 10...)
--
Bye,
Erik.
http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 18.03.2015 10:36, Branko Čibej wrote:
> On 13.03.2015 13:23, Erik Huelsmann wrote:
>>
>>
>> > These days, I suppose we'd be looking at something like Go,
>> which can
>> > be linked with C/C++ and also natively export functions that can be
>> > called from C/C++.
>>
>> As far as I can see, Go always comes with Garbage Collection
>> instead of a deterministic memory management.
>>
>> Also, as far as I can see, Go does not go as far as Rust with
>> what the compiler can check at compiletime.
>>
>>
>> On the other hand, I see on rust-lang that the current state of Rust
>> is 1.0.0-alpha2 where Lua has 22 years of experience and development.
>
>
> Lua is not open source by any reasonable definition. The Lua devs
> intentionally do not give even read-only access to their source
> repository; they only post tarballs, if and when it suits them. That
> pretty much closes this topic in my opinion.
>
> http://lua-users.org/lists/lua-l/2008-06/msg00407.html
Also http://www.lua.org/faq.html#1.9
> -- Brane
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 13.03.2015 13:23, Erik Huelsmann wrote:
>
>
> > These days, I suppose we'd be looking at something like Go,
> which can
> > be linked with C/C++ and also natively export functions that can be
> > called from C/C++.
>
> As far as I can see, Go always comes with Garbage Collection
> instead of a deterministic memory management.
>
> Also, as far as I can see, Go does not go as far as Rust with what
> the compiler can check at compiletime.
>
>
> On the other hand, I see on rust-lang that the current state of Rust
> is 1.0.0-alpha2 where Lua has 22 years of experience and development.
Lua is not open source by any reasonable definition. The Lua devs
intentionally do not give even read-only access to their source
repository; they only post tarballs, if and when it suits them. That
pretty much closes this topic in my opinion.
http://lua-users.org/lists/lua-l/2008-06/msg00407.html
-- Brane
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 13.03.2015 13:23, Erik Huelsmann wrote:
>
>
> > These days, I suppose we'd be looking at something like Go,
> which can
> > be linked with C/C++ and also natively export functions that can be
> > called from C/C++.
>
> As far as I can see, Go always comes with Garbage Collection
> instead of a deterministic memory management.
>
> Also, as far as I can see, Go does not go as far as Rust with what
> the compiler can check at compiletime.
>
>
> On the other hand, I see on rust-lang that the current state of Rust
> is 1.0.0-alpha2 where Lua has 22 years of experience and development.
Yes, but cone written in a dynamically-typed, garbage-collected language
is the very devil to debug and test.
OTOH ... Rust's integration with C leaves quite a lot to be desired.
-- Brane
Re: AW: Convenient array & hash iterators & accessors
Posted by Erik Huelsmann <eh...@gmail.com>.
> > These days, I suppose we'd be looking at something like Go, which can
> > be linked with C/C++ and also natively export functions that can be
> > called from C/C++.
>
> As far as I can see, Go always comes with Garbage Collection instead of a
> deterministic memory management.
>
> Also, as far as I can see, Go does not go as far as Rust with what the
> compiler can check at compiletime.
>
On the other hand, I see on rust-lang that the current state of Rust is
1.0.0-alpha2 where Lua has 22 years of experience and development.
--
Bye,
Erik.
http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
AW: AW: Convenient array & hash iterators & accessors
Posted by Markus Schaber <m....@codesys.com>.
Hi,
Von: Branko Čibej [mailto:brane@wandisco.com]
> The problem (or "problem") with C++ is that it's *extremely* hard to
> code things correctly in an exception-safe manner. Otherwise I'd be
> all for using it, these days (especially with C++11) you have a
> language that's in some ways horrible to use, but when used correctly
> can provide huge benefits. But it takes years of single-minded
> language-lawyerish hacking to get to the "used correctly" phase.
Fully agreed.
> In the past I'd thought about embedding Python into our sources, but
> Python still (after 20 years ...) depends on a global interpreter
> lock which pretty much kills any chance of lockless thread-safe code.
One could use one interpreter instance per SVN client...
> These days, I suppose we'd be looking at something like Go, which can
> be linked with C/C++ and also natively export functions that can be
> called from C/C++.
As far as I can see, Go always comes with Garbage Collection instead of a deterministic memory management.
Also, as far as I can see, Go does not go as far as Rust with what the compiler can check at compiletime.
Best regards
Markus Schaber
CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50
E-Mail: m.schaber@codesys.com | Web: http://www.codesys.com | CODESYS store: http://store.codesys.com
CODESYS forum: http://forum.codesys.com
Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
> -----Ursprüngliche Nachricht-----
> Gesendet: Freitag, 13. März 2015 10:35
> An: dev@subversion.apache.org
> Betreff: Re: AW: Convenient array & hash iterators & accessors
>
> On 13.03.2015 10:05, Bert Huijben wrote:
> >
> >> -----Original Message-----
> >> From: Branko Čibej [mailto:brane@wandisco.com]
> >> Sent: vrijdag 13 maart 2015 08:53
> >> To: dev@subversion.apache.org
> >> Subject: Re: AW: Convenient array & hash iterators & accessors
> >>
> >> On 13.03.2015 08:43, Markus Schaber wrote:
> >>> Hi,
> >>>
> >>>
> >>>
> >>> I just wanted to throw „Rust“ into the discussion.
> >>>
> >>>
> >>>
> >>> Rust seems to have a very expressive type model, which allows to
> >>> handle most of the memory management automatically and compile-
> time-
> >> safe.
> >>>
> >>>
> >>> It also allows to go very “low level” / “lean” (they even wrote
> >>> bootloaders and POC Kernels with it).
> >>>
> >>>
> >>>
> >>> It is compiled to native code, and has rather good C interfacing
> >>> capabilities.
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On the other hand, I tend to oppose C++. While it feels “natural”
> to
> >>> “upgrade” from C to C++, the mere complexity of that language
> makes
> >>> it very difficult, at least if a project does not restrict itself
> to
> >>> a very well thought, strictly defined subset.
> >>>
> >>>
> >>>
> >>> Grüße,
> >>>
> >>> Markus
> >>>
> >>>
> >>>
> >>> *Von:*Erik Huelsmann [mailto:ehuels@gmail.com]
> >>> *Gesendet:* Freitag, 6. März 2015 22:37
> >>> *An:* Julian Foad
> >>> *Cc:* Branko Čibej; dev@subversion.apache.org
> >>> *Betreff:* Re: Convenient array & hash iterators & accessors
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> > It would make sense to design type-safe, light-weight
> container and
> >>> > iterator template wrappers around the APR structures if we
> >>> decided to
> >>> > write code in C++. Since we're not, "explicit is better
> than
> >>> > implicit".
> >>>
> >>> I understand the point. I note that "explicit" is not a
> binary
> >>> quality: there are degrees of it.
> >>>
> >>> I suppose I want to be writing in a higher level language.
> Maybe I
> >>> should just go ahead and really do so.
> >>>
> >>>
> >>>
> >>> Exactly. There's been talk about doing so for much too long
> without
> >>> action (other than attempts - including my own) to find a way to
> >>> "upgrade" C to something less verbose and more expressive.
> >>>
> >>>
> >>>
> >>> I've been long thinking that there are specific areas which are
> >>> more-or-less stand-alone, might be a good place to start this
> >>> strategy. One place like that might qualify is the piece of code
> >>> that deduces the eligeable revisions in merge tracking. That's
> the
> >>> code I'm thinking you're now working in?
> >>>
> >>>
> >>>
> >>> What kind of language were you thinking about? One of the
> languages
> >>> that came to mind is 'lua' which seems to have a pretty strong
> focus
> >>> on being integratable with C code. For lua there are also tools
> to
> >>> embed the compiled bytecode in a C library so the entire
> higherlevel
> >>> language can be fully encapsulated inside our libraries.
> >>>
> >> Why not Groovy (soon to be incubating at the ASF). That way we
> keep
> >> things in the family, and we're likely to eventually move
> everything
> >> to a JVM-based implementation instead of this silly native-
> compiled,
> >> last century stuff.
> > I wouldn't have a problem with requiring a small bytecode
> interpreter/stack machine inside libsvn_*, but a full JVM is
> certainly not something that can be embedded in every application.
> That changes the entire process requirements.
> >
> > I don't think multiple JVMs can run in the same process (especially
> different versions), and attaching to an existing VM introduces
> different problems. In AnkhSVN I run Subversion inside a process that
> potentially has multiple .Net runtimes loaded, and until Visual
> Studio is redesigned into a 64 bit process somewhere in the far
> future I certainly can't just load a JVM in the process.
> >
> > TortoiseSVN has similar (if not stricter) limitations, but it is
> > already multi process to avoid having to integrate everything into
> > every process. (Not sure how much of Subversion they still load in
> > every process that uses explorer infrastructure)
> >
> > I don't see a problem using something internally, and still
> providing a 100% C compatible api...
> >
> > A good subset of C++ to introduce more type safety would be a good
> option... But I can't think of a good way to define the subset and
> really limit us to such a subset...
> > And using more and more C++ will shrink the pool of developers that
> would be able to join.
> >
> > By developing our own macro world in C we would have the same
> problem though...
>
> The problem (or "problem") with C++ is that it's *extremely* hard to
> code things correctly in an exception-safe manner. Otherwise I'd be
> all for using it, these days (especially with C++11) you have a
> language that's in some ways horrible to use, but when used correctly
> can provide huge benefits. But it takes years of single-minded
> language-lawyerish hacking to get to the "used correctly" phase.
>
> In the past I'd thought about embedding Python into our sources, but
> Python still (after 20 years ...) depends on a global interpreter
> lock which pretty much kills any chance of lockless thread-safe code.
>
> These days, I suppose we'd be looking at something like Go, which can
> be linked with C/C++ and also natively export functions that can be
> called from C/C++.
>
> -- Brane
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 13.03.2015 14:18, Ivan Zhakov wrote:
> On 13 March 2015 at 13:43, Branko Čibej <br...@wandisco.com> wrote:
>> On 13.03.2015 11:13, Ivan Zhakov wrote:
>>> On 13 March 2015 at 12:31, Branko Čibej <br...@wandisco.com> wrote:
>>> [...]
>>>> These days, I suppose we'd be looking at something like Go, which can be
>>>> linked with C/C++ and also natively export functions that can be called
>>>> from C/C++.
>>>>
>>> After Google Code shutdown we have another reason to avoid monoculture
>>> technologies, especially from advertisement companies like Google.
>>> I'm -1 about using Go for Subversion project.
>> How about D then? They appear to be mostly interchangeable. :)
>>
> :)
>
> I don't think programming language is so important for project success
> or failure.
Exactly.
Re: AW: Convenient array & hash iterators & accessors
Posted by Ivan Zhakov <iv...@visualsvn.com>.
On 13 March 2015 at 13:43, Branko Čibej <br...@wandisco.com> wrote:
> On 13.03.2015 11:13, Ivan Zhakov wrote:
>> On 13 March 2015 at 12:31, Branko Čibej <br...@wandisco.com> wrote:
>> [...]
>>> These days, I suppose we'd be looking at something like Go, which can be
>>> linked with C/C++ and also natively export functions that can be called
>>> from C/C++.
>>>
>> After Google Code shutdown we have another reason to avoid monoculture
>> technologies, especially from advertisement companies like Google.
>> I'm -1 about using Go for Subversion project.
>
> How about D then? They appear to be mostly interchangeable. :)
>
:)
I don't think programming language is so important for project success
or failure.
--
Ivan Zhakov
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 13.03.2015 11:13, Ivan Zhakov wrote:
> On 13 March 2015 at 12:31, Branko Čibej <br...@wandisco.com> wrote:
> [...]
>> These days, I suppose we'd be looking at something like Go, which can be
>> linked with C/C++ and also natively export functions that can be called
>> from C/C++.
>>
> After Google Code shutdown we have another reason to avoid monoculture
> technologies, especially from advertisement companies like Google.
> I'm -1 about using Go for Subversion project.
How about D then? They appear to be mostly interchangeable. :)
-- Brane
Re: AW: Convenient array & hash iterators & accessors
Posted by Ivan Zhakov <iv...@visualsvn.com>.
On 13 March 2015 at 12:31, Branko Čibej <br...@wandisco.com> wrote:
[...]
> These days, I suppose we'd be looking at something like Go, which can be
> linked with C/C++ and also natively export functions that can be called
> from C/C++.
>
After Google Code shutdown we have another reason to avoid monoculture
technologies, especially from advertisement companies like Google.
I'm -1 about using Go for Subversion project.
--
Ivan Zhakov
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 13.03.2015 10:05, Bert Huijben wrote:
>
>> -----Original Message-----
>> From: Branko Čibej [mailto:brane@wandisco.com]
>> Sent: vrijdag 13 maart 2015 08:53
>> To: dev@subversion.apache.org
>> Subject: Re: AW: Convenient array & hash iterators & accessors
>>
>> On 13.03.2015 08:43, Markus Schaber wrote:
>>> Hi,
>>>
>>>
>>>
>>> I just wanted to throw „Rust“ into the discussion.
>>>
>>>
>>>
>>> Rust seems to have a very expressive type model, which allows to
>>> handle most of the memory management automatically and compile-time-
>> safe.
>>>
>>>
>>> It also allows to go very “low level” / “lean” (they even wrote
>>> bootloaders and POC Kernels with it).
>>>
>>>
>>>
>>> It is compiled to native code, and has rather good C interfacing
>>> capabilities.
>>>
>>>
>>>
>>>
>>>
>>> On the other hand, I tend to oppose C++. While it feels “natural” to
>>> “upgrade” from C to C++, the mere complexity of that language makes it
>>> very difficult, at least if a project does not restrict itself to a
>>> very well thought, strictly defined subset.
>>>
>>>
>>>
>>> Grüße,
>>>
>>> Markus
>>>
>>>
>>>
>>> *Von:*Erik Huelsmann [mailto:ehuels@gmail.com]
>>> *Gesendet:* Freitag, 6. März 2015 22:37
>>> *An:* Julian Foad
>>> *Cc:* Branko Čibej; dev@subversion.apache.org
>>> *Betreff:* Re: Convenient array & hash iterators & accessors
>>>
>>>
>>>
>>>
>>>
>>> > It would make sense to design type-safe, light-weight container and
>>> > iterator template wrappers around the APR structures if we
>>> decided to
>>> > write code in C++. Since we're not, "explicit is better than
>>> > implicit".
>>>
>>> I understand the point. I note that "explicit" is not a binary
>>> quality: there are degrees of it.
>>>
>>> I suppose I want to be writing in a higher level language. Maybe I
>>> should just go ahead and really do so.
>>>
>>>
>>>
>>> Exactly. There's been talk about doing so for much too long without
>>> action (other than attempts - including my own) to find a way to
>>> "upgrade" C to something less verbose and more expressive.
>>>
>>>
>>>
>>> I've been long thinking that there are specific areas which are
>>> more-or-less stand-alone, might be a good place to start this
>>> strategy. One place like that might qualify is the piece of code that
>>> deduces the eligeable revisions in merge tracking. That's the code I'm
>>> thinking you're now working in?
>>>
>>>
>>>
>>> What kind of language were you thinking about? One of the languages
>>> that came to mind is 'lua' which seems to have a pretty strong focus
>>> on being integratable with C code. For lua there are also tools to
>>> embed the compiled bytecode in a C library so the entire higherlevel
>>> language can be fully encapsulated inside our libraries.
>>>
>> Why not Groovy (soon to be incubating at the ASF). That way we keep
>> things in the family, and we're likely to eventually move everything to
>> a JVM-based implementation instead of this silly native-compiled, last
>> century stuff.
> I wouldn't have a problem with requiring a small bytecode interpreter/stack machine inside libsvn_*, but a full JVM is certainly not something that can be embedded in every application. That changes the entire process requirements.
>
> I don't think multiple JVMs can run in the same process (especially different versions), and attaching to an existing VM introduces different problems. In AnkhSVN I run Subversion inside a process that potentially has multiple .Net runtimes loaded, and until Visual Studio is redesigned into a 64 bit process somewhere in the far future I certainly can't just load a JVM in the process.
>
> TortoiseSVN has similar (if not stricter) limitations, but it is already multi process to avoid having to integrate everything into every process. (Not sure how much of Subversion they still load in every process that uses explorer infrastructure)
>
> I don't see a problem using something internally, and still providing a 100% C compatible api...
>
> A good subset of C++ to introduce more type safety would be a good option... But I can't think of a good way to define the subset and really limit us to such a subset...
> And using more and more C++ will shrink the pool of developers that would be able to join.
>
> By developing our own macro world in C we would have the same problem though...
The problem (or "problem") with C++ is that it's *extremely* hard to
code things correctly in an exception-safe manner. Otherwise I'd be all
for using it, these days (especially with C++11) you have a language
that's in some ways horrible to use, but when used correctly can provide
huge benefits. But it takes years of single-minded language-lawyerish
hacking to get to the "used correctly" phase.
In the past I'd thought about embedding Python into our sources, but
Python still (after 20 years ...) depends on a global interpreter lock
which pretty much kills any chance of lockless thread-safe code.
These days, I suppose we'd be looking at something like Go, which can be
linked with C/C++ and also natively export functions that can be called
from C/C++.
-- Brane
RE: AW: Convenient array & hash iterators & accessors
Posted by Bert Huijben <be...@qqmail.nl>.
> -----Original Message-----
> From: Branko Čibej [mailto:brane@wandisco.com]
> Sent: vrijdag 13 maart 2015 08:53
> To: dev@subversion.apache.org
> Subject: Re: AW: Convenient array & hash iterators & accessors
>
> On 13.03.2015 08:43, Markus Schaber wrote:
> >
> > Hi,
> >
> >
> >
> > I just wanted to throw „Rust“ into the discussion.
> >
> >
> >
> > Rust seems to have a very expressive type model, which allows to
> > handle most of the memory management automatically and compile-time-
> safe.
> >
> >
> >
> > It also allows to go very “low level” / “lean” (they even wrote
> > bootloaders and POC Kernels with it).
> >
> >
> >
> > It is compiled to native code, and has rather good C interfacing
> > capabilities.
> >
> >
> >
> >
> >
> > On the other hand, I tend to oppose C++. While it feels “natural” to
> > “upgrade” from C to C++, the mere complexity of that language makes it
> > very difficult, at least if a project does not restrict itself to a
> > very well thought, strictly defined subset.
> >
> >
> >
> > Grüße,
> >
> > Markus
> >
> >
> >
> > *Von:*Erik Huelsmann [mailto:ehuels@gmail.com]
> > *Gesendet:* Freitag, 6. März 2015 22:37
> > *An:* Julian Foad
> > *Cc:* Branko Čibej; dev@subversion.apache.org
> > *Betreff:* Re: Convenient array & hash iterators & accessors
> >
> >
> >
> >
> >
> > > It would make sense to design type-safe, light-weight container and
> > > iterator template wrappers around the APR structures if we
> > decided to
> > > write code in C++. Since we're not, "explicit is better than
> > > implicit".
> >
> > I understand the point. I note that "explicit" is not a binary
> > quality: there are degrees of it.
> >
> > I suppose I want to be writing in a higher level language. Maybe I
> > should just go ahead and really do so.
> >
> >
> >
> > Exactly. There's been talk about doing so for much too long without
> > action (other than attempts - including my own) to find a way to
> > "upgrade" C to something less verbose and more expressive.
> >
> >
> >
> > I've been long thinking that there are specific areas which are
> > more-or-less stand-alone, might be a good place to start this
> > strategy. One place like that might qualify is the piece of code that
> > deduces the eligeable revisions in merge tracking. That's the code I'm
> > thinking you're now working in?
> >
> >
> >
> > What kind of language were you thinking about? One of the languages
> > that came to mind is 'lua' which seems to have a pretty strong focus
> > on being integratable with C code. For lua there are also tools to
> > embed the compiled bytecode in a C library so the entire higherlevel
> > language can be fully encapsulated inside our libraries.
> >
>
> Why not Groovy (soon to be incubating at the ASF). That way we keep
> things in the family, and we're likely to eventually move everything to
> a JVM-based implementation instead of this silly native-compiled, last
> century stuff.
I wouldn't have a problem with requiring a small bytecode interpreter/stack machine inside libsvn_*, but a full JVM is certainly not something that can be embedded in every application. That changes the entire process requirements.
I don't think multiple JVMs can run in the same process (especially different versions), and attaching to an existing VM introduces different problems. In AnkhSVN I run Subversion inside a process that potentially has multiple .Net runtimes loaded, and until Visual Studio is redesigned into a 64 bit process somewhere in the far future I certainly can't just load a JVM in the process.
TortoiseSVN has similar (if not stricter) limitations, but it is already multi process to avoid having to integrate everything into every process. (Not sure how much of Subversion they still load in every process that uses explorer infrastructure)
I don't see a problem using something internally, and still providing a 100% C compatible api...
A good subset of C++ to introduce more type safety would be a good option... But I can't think of a good way to define the subset and really limit us to such a subset...
And using more and more C++ will shrink the pool of developers that would be able to join.
By developing our own macro world in C we would have the same problem though...
Bert
>
> -- Brane
Re: AW: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 13.03.2015 08:43, Markus Schaber wrote:
>
> Hi,
>
>
>
> I just wanted to throw „Rust“ into the discussion.
>
>
>
> Rust seems to have a very expressive type model, which allows to
> handle most of the memory management automatically and compile-time-safe.
>
>
>
> It also allows to go very “low level” / “lean” (they even wrote
> bootloaders and POC Kernels with it).
>
>
>
> It is compiled to native code, and has rather good C interfacing
> capabilities.
>
>
>
>
>
> On the other hand, I tend to oppose C++. While it feels “natural” to
> “upgrade” from C to C++, the mere complexity of that language makes it
> very difficult, at least if a project does not restrict itself to a
> very well thought, strictly defined subset.
>
>
>
> Grüße,
>
> Markus
>
>
>
> *Von:*Erik Huelsmann [mailto:ehuels@gmail.com]
> *Gesendet:* Freitag, 6. März 2015 22:37
> *An:* Julian Foad
> *Cc:* Branko Čibej; dev@subversion.apache.org
> *Betreff:* Re: Convenient array & hash iterators & accessors
>
>
>
>
>
> > It would make sense to design type-safe, light-weight container and
> > iterator template wrappers around the APR structures if we
> decided to
> > write code in C++. Since we're not, "explicit is better than
> > implicit".
>
> I understand the point. I note that "explicit" is not a binary
> quality: there are degrees of it.
>
> I suppose I want to be writing in a higher level language. Maybe I
> should just go ahead and really do so.
>
>
>
> Exactly. There's been talk about doing so for much too long without
> action (other than attempts - including my own) to find a way to
> "upgrade" C to something less verbose and more expressive.
>
>
>
> I've been long thinking that there are specific areas which are
> more-or-less stand-alone, might be a good place to start this
> strategy. One place like that might qualify is the piece of code that
> deduces the eligeable revisions in merge tracking. That's the code I'm
> thinking you're now working in?
>
>
>
> What kind of language were you thinking about? One of the languages
> that came to mind is 'lua' which seems to have a pretty strong focus
> on being integratable with C code. For lua there are also tools to
> embed the compiled bytecode in a C library so the entire higherlevel
> language can be fully encapsulated inside our libraries.
>
Why not Groovy (soon to be incubating at the ASF). That way we keep
things in the family, and we're likely to eventually move everything to
a JVM-based implementation instead of this silly native-compiled, last
century stuff.
-- Brane
AW: Convenient array & hash iterators & accessors
Posted by Markus Schaber <m....@codesys.com>.
Hi,
I just wanted to throw „Rust“ into the discussion.
Rust seems to have a very expressive type model, which allows to handle most of the memory management automatically and compile-time-safe.
It also allows to go very “low level” / “lean” (they even wrote bootloaders and POC Kernels with it).
It is compiled to native code, and has rather good C interfacing capabilities.
On the other hand, I tend to oppose C++. While it feels “natural” to “upgrade” from C to C++, the mere complexity of that language makes it very difficult, at least if a project does not restrict itself to a very well thought, strictly defined subset.
Grüße,
Markus
Von: Erik Huelsmann [mailto:ehuels@gmail.com]
Gesendet: Freitag, 6. März 2015 22:37
An: Julian Foad
Cc: Branko Čibej; dev@subversion.apache.org
Betreff: Re: Convenient array & hash iterators & accessors
> It would make sense to design type-safe, light-weight container and
> iterator template wrappers around the APR structures if we decided to
> write code in C++. Since we're not, "explicit is better than
> implicit".
I understand the point. I note that "explicit" is not a binary quality: there are degrees of it.
I suppose I want to be writing in a higher level language. Maybe I should just go ahead and really do so.
Exactly. There's been talk about doing so for much too long without action (other than attempts - including my own) to find a way to "upgrade" C to something less verbose and more expressive.
I've been long thinking that there are specific areas which are more-or-less stand-alone, might be a good place to start this strategy. One place like that might qualify is the piece of code that deduces the eligeable revisions in merge tracking. That's the code I'm thinking you're now working in?
What kind of language were you thinking about? One of the languages that came to mind is 'lua' which seems to have a pretty strong focus on being integratable with C code. For lua there are also tools to embed the compiled bytecode in a C library so the entire higherlevel language can be fully encapsulated inside our libraries.
--
Bye,
Erik.
http://efficito.com<http://efficito.com/> -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
AW: Convenient array & hash iterators & accessors
Posted by Markus Schaber <m....@codesys.com>.
Hi, Erik,
Von: Erik Huelsmann [mailto:ehuels@gmail.com]
>> It would make sense to design type-safe, light-weight container and
>> iterator template wrappers around the APR structures if we decided to
>> write code in C++. Since we're not, "explicit is better than
>> implicit".
> I understand the point. I note that "explicit" is not a binary quality: there are degrees of it.
> I suppose I want to be writing in a higher level language. Maybe I should just go ahead and really do so.
> Exactly. There's been talk about doing so for much too long without action (other than attempts - including my own) to find a way to "upgrade" C to something less verbose and more expressive.
> I've been long thinking that there are specific areas which are more-or-less stand-alone, might be a good place to start this strategy. One place like that might qualify is the piece of code that deduces the eligeable revisions in merge tracking. That's the code I'm thinking you're now working in?
> What kind of language were you thinking about? One of the languages that came to mind is 'lua' which seems to have a pretty strong focus on being integratable with C code. For lua there are also tools to embed the compiled bytecode in a C library so the entire higherlevel language can be fully encapsulated inside our libraries.
As far as I can see, Lua is dynamically typed, thus not buying us too much in way of compile time type-safety.
We just get exceptions instead of SegV - we can handle them, but we still have the problem of missing test coverage in not-so-common code pathes.
Thus, I tend to prefer _more_ compile time type safety instead of less compared to where we are now (C).
Best regards
Markus Schaber
--
CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions
________________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50
E-Mail: m.schaber@codesys.com | Web: codesys.com | CODESYS store: store.codesys.com
CODESYS forum: forum.codesys.com
Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
Re: Convenient array & hash iterators & accessors
Posted by Erik Huelsmann <eh...@gmail.com>.
> > It would make sense to design type-safe, light-weight container and
> > iterator template wrappers around the APR structures if we decided to
> > write code in C++. Since we're not, "explicit is better than
> > implicit".
>
> I understand the point. I note that "explicit" is not a binary quality:
> there are degrees of it.
>
> I suppose I want to be writing in a higher level language. Maybe I should
> just go ahead and really do so.
Exactly. There's been talk about doing so for much too long without action
(other than attempts - including my own) to find a way to "upgrade" C to
something less verbose and more expressive.
I've been long thinking that there are specific areas which are
more-or-less stand-alone, might be a good place to start this strategy. One
place like that might qualify is the piece of code that deduces the
eligeable revisions in merge tracking. That's the code I'm thinking you're
now working in?
What kind of language were you thinking about? One of the languages that
came to mind is 'lua' which seems to have a pretty strong focus on being
integratable with C code. For lua there are also tools to embed the
compiled bytecode in a C library so the entire higherlevel language can be
fully encapsulated inside our libraries.
--
Bye,
Erik.
http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
Re: Convenient array & hash iterators & accessors
Posted by Julian Foad <ju...@btopenworld.com>.
Branko Čibej wrote:
> On 06.03.2015 11:30, Julian Foad wrote:
>> Branko Čibej wrote:
>>> I'm also *very* scared of the implicit, hidden qsort in the sorted.
>>
>> It's invoked only if you write "..._SORTED()" or "..._sorted()". That's
>> explicit and visible. What's so scary about that?
>
> The term "sorted iteration" is ambiguous. In this case, it means "sort
> the container, then iterate", which means it has a side effect.
No, in this case it means the common meaning you suggest it should have.
See the doc strings:
+/** Like SVN_ARRAY_ITER but iterating over a copy of the array sorted by
+ * @a comparison_func. */
+#define SVN_ARRAY_ITER_SORTED(i, array, comparison_func, pool) \
+/** Start iterating over the array @a array, in sorted order according to
+ * @a comparison_func. Return a pointer to the first element, or NULL if
+ * there are no elements.
+ *
+ * It is permissible to change the original array @a array during the
+ * iteration. Doing so will not affect the sequence of elements returned
+ * by svn_array__next(), as svn_array__sorted_first() takes a snapshot of
+ * pointers to the original keys and values. The memory in which the
+ * original keys and values of HT are stored must remain available during
+ * the iteration.
+ */
+svn_iter_t *
+svn_array__sorted_first([...]
> A more
> common meaning is "iterate in sorted order, leaving the container
> unchanged". See, for example, Python's sorted() generator adaptor.
>
> It's much more visible and unambiguous to sort the container and then
> iterate on the result. Iterations should not have side effects on the
> container.
That's exactly the approach I took.
- Julian
Re: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 06.03.2015 11:30, Julian Foad wrote:
> Branko Čibej wrote:
>> I'm also *very* scared of the
>> implicit, hidden qsort in the sorted.
> It's invoked only if you write "..._SORTED()" or "..._sorted()". That's explicit and visible. What's so scary about that?
The term "sorted iteration" is ambiguous. In this case, it means "sort
the container, then iterate", which means it has a side effect. A more
common meaning is "iterate in sorted order, leaving the container
unchanged". See, for example, Python's sorted() generator adaptor.
It's much more visible and unambiguous to sort the container and then
iterate on the result. Iterations should not have side effects on the
container.
-- Brane
Re: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 06.03.2015 11:30, Julian Foad wrote:
> Hi, Greg and Brane. Thanks for your feedback.
>
> Branko Čibej wrote:
>> Greg Stein wrote:
>>> We've seen some of this kind of stuff in svn_iter.h, and it did not
>>> turn out to be useful. The additional concepts needed to
>>> learn/keep/use costed more than the incremental benefit.
> The new functions are aimed at making typical, shortish loops shorter and clearer to read. Those previous iterators were too cumbersome for most cases and rarely useful.
>
>>> I find the SVN_ITER_T() and SVN_ARRAY_ITER() macros in your example to
>>> be rather inscrutable.
> At first sight, yes, of course, but they could quickly become a familiar idiom.
>
>> Agreed. The new macros don't really add any type safety, since they rely
>> on implicit conversions from void*.
> That's right: they do not check that the declared element type of an array/hash matches the type requested for iteration, except that it is a pointer.
>
> The comment about 'parameterized element type' does not refer to type *safety* but rather means that the iterator's 'val' field has the requested type rather than 'void *', which enables using it directly as an element pointer like this:
>
> for (SVN_ARRAY_ITER(i, array_of_string_t, pool))
> foo(i->val->data, i->val->len);
>
> rather than having to first assign it to a variable of the correct type like this:
>
> for (SVN_ARRAY_ITER(i, array_of_string_t, pool))
> {
> svn_string_t *s = i->val;
>
> foo(s->data, s->len);
> }
>
>> I'm also *very* scared of the
>> implicit, hidden qsort in the sorted.
> It's invoked only if you write "..._SORTED()" or "..._sorted()". That's explicit and visible. What's so scary about that?
>
>> It would make sense to design type-safe, light-weight container and
>> iterator template wrappers around the APR structures if we decided to
>> write code in C++. Since we're not, "explicit is better than
>> implicit".
> I understand the point. I note that "explicit" is not a binary quality: there are degrees of it.
>
> I suppose I want to be writing in a higher level language. Maybe I should just go ahead and really do so.
Many of us do, I guess. :) But as long as we're stuck with C and APR,
it's worth considering the actual gain of any macro wrappers compared to
their apparent gain. This was very painfully demonstrated recently with
the fun we had with svn_hash_sets/gets.
-- Brane
Re: Convenient array & hash iterators & accessors
Posted by Julian Foad <ju...@btopenworld.com>.
Hi, Greg and Brane. Thanks for your feedback.
Branko Čibej wrote:
> Greg Stein wrote:
>> We've seen some of this kind of stuff in svn_iter.h, and it did not
>> turn out to be useful. The additional concepts needed to
>> learn/keep/use costed more than the incremental benefit.
The new functions are aimed at making typical, shortish loops shorter and clearer to read. Those previous iterators were too cumbersome for most cases and rarely useful.
>> I find the SVN_ITER_T() and SVN_ARRAY_ITER() macros in your example to
>> be rather inscrutable.
At first sight, yes, of course, but they could quickly become a familiar idiom.
> Agreed. The new macros don't really add any type safety, since they rely
> on implicit conversions from void*.
That's right: they do not check that the declared element type of an array/hash matches the type requested for iteration, except that it is a pointer.
The comment about 'parameterized element type' does not refer to type *safety* but rather means that the iterator's 'val' field has the requested type rather than 'void *', which enables using it directly as an element pointer like this:
for (SVN_ARRAY_ITER(i, array_of_string_t, pool))
foo(i->val->data, i->val->len);
rather than having to first assign it to a variable of the correct type like this:
for (SVN_ARRAY_ITER(i, array_of_string_t, pool))
{
svn_string_t *s = i->val;
foo(s->data, s->len);
}
> I'm also *very* scared of the
> implicit, hidden qsort in the sorted.
It's invoked only if you write "..._SORTED()" or "..._sorted()". That's explicit and visible. What's so scary about that?
> It would make sense to design type-safe, light-weight container and
> iterator template wrappers around the APR structures if we decided to
> write code in C++. Since we're not, "explicit is better than
> implicit".
I understand the point. I note that "explicit" is not a binary quality: there are degrees of it.
I suppose I want to be writing in a higher level language. Maybe I should just go ahead and really do so.
- Julian
Re: Convenient array & hash iterators & accessors
Posted by Branko Čibej <br...@wandisco.com>.
On 06.03.2015 09:08, Greg Stein wrote:
> We've seen some of this kind of stuff in svn_iter.h, and it did not
> turn out to be useful. The additional concepts needed to
> learn/keep/use costed more than the incremental benefit.
>
> I find the SVN_ITER_T() and SVN_ARRAY_ITER() macros in your example to
> be rather inscrutable.
Agreed. The new macros don't really add any type safety, since they rely
on implicit conversions from void*. I'm also *very* scared of the
implicit, hidden qsort in the sorted.
It would make sense to design type-safe, light-weight container and
iterator template wrappers around the APR structures if we decided to
write code in C++. Since we're not, "explicit is better than implicit".
-- Brane
Re: Convenient array & hash iterators & accessors
Posted by Greg Stein <gs...@gmail.com>.
We've seen some of this kind of stuff in svn_iter.h, and it did not turn
out to be useful. The additional concepts needed to learn/keep/use costed
more than the incremental benefit.
I find the SVN_ITER_T() and SVN_ARRAY_ITER() macros in your example to be
rather inscrutable.
Cheers,
-g
On Thu, Mar 5, 2015 at 6:16 AM, Julian Foad <ju...@btopenworld.com>
wrote:
> In http://svn.apache.org/r1664127 (very similar to the attached patch),
> I added some array & hash iterators & accessors to the 'move-tracking-2'
> branch
> so that I could use more compact iteration code (
> http://svn.apache.org/r1664285)
> and get an iteration pool 'for free' (http://svn.apache.org/r1664290).
>
> Is there any interest in using some of this on trunk?
>
> Here's a summary.
>
> Array: apr_array_header_t of pointers to objects, with
>
> - Simpler syntax for operations such as make, get, set, push, pop.
>
> - no need to specify the element type in these operations
>
> - The get and set and iteration functions avoid the need to use the
> non-type-safe APR_ARRAY_IDX. (It does not assert that the sizeof(type)
> matches, let alone (type) itself. Note: When I inserted
> "assert(sizeof(type)==array->elt_size)" in APR's version, the
> Subversion
> test suite still passed, so that's good.)
>
> - Shallow and deep duplicators for an array of simple or compound
> elements.
>
> Hash table: same as apr_hash_t but always with C-string keys.
>
> Iteration over an array or a hash shares these features:
>
> - Convenience prioritized over speed (but still good speed).
>
> - Easy access to this key and this value as iterator member variables.
>
> - for an array: it->i and it->val
> - for a hash: it->key and it->val (and it->klen for good measure)
>
> - Templated iterator with parameterized element type.
>
> - in an iterator declared as "SVN_ITER_T(svn_branch_family_t) *it;",
> it->val has type "svn_branch_family_t *"
>
> - in an iterator declared as "svn_iter_t *it;",
> it->val has type "void *"
>
> - Built-in, managed iterpool as an iterator member variable.
>
> - just use it->iterpool; it is automatically created/cleared/destroyed
>
> - Iteration in sorted order (optional).
>
> - just use "for (SVN_ARRAY_ITER_SORTED(it, array, comparator, pool))"
> instead of "for (SVN_ARRAY_ITER(it, array, pool))"; same for a hash
>
> Usage examples:
>
> - outer_family->sub_families = apr_array_make(result_pool, 1, sizeof(void
> *));
> + outer_family->sub_families = svn_array_make(result_pool);
>
> - APR_ARRAY_PUSH(outer_family->sub_families, void *) = family;
> + SVN_ARRAY_PUSH(outer_family->sub_families) = family;
>
> {
> - apr_array_header_t *sub_families
> - = svn_branch_family_get_children(family, scratch_pool);
> - int f;
> + SVN_ITER_T(svn_branch_family_t) *fi;
>
> - for (f = 0; f < sub_families->nelts; f++)
> + for (SVN_ARRAY_ITER(fi, svn_branch_family_get_children(
> + family, scratch_pool), scratch_pool))
> {
> - svn_branch_family_t *sub_family
> - = APR_ARRAY_IDX(sub_families, f, svn_branch_family_t *);
> -
> - SVN_ERR(family_list_branch_instances(rev_root, sub_family,
> recursive,
> + SVN_ERR(family_list_branch_instances(rev_root, fi->val, recursive,
> - verbose, scratch_pool));
> - verbose, fi->iterpool));
> }
> }
>
> - Julian
>