Jed Brown <[email protected]> writes: > Barry Smith <[email protected]> writes: >> PetscNew() is PetscCalloc1(1,&beasty); the original analogy with C++ >> was that it creates a struct and initializes it to zero entries. :-) > > But C++ new does not initialize structs. It does calls constructors for > non-POD types. > >> I’d like to keep it. > > Okay, it becomes > > PetscNew(&beasty);
'jed/malloc-array' is now pushed to 'next'. Other people merging to 'next' may encounter compilation errors if they have been using the original macros. The commit message contains a shell script that can be used to convert almost all normal use cases. Running ./malloc-convert.sh src should be idempotent. There are two places in include/ that the script would update, but where I'd rather stick with the original. Since this change is somewhat disruptive, I would like to merge it to 'master' as soon as possible. If you are significantly affected by this change, go ahead and merge 'jed/malloc-array' into your branch, then run the attached script. commit 38506d2d16b2b06013b0dc5205b1648e494db573 Merge: 335e720 b00a911 Author: Jed Brown <[email protected]> Date: Tue Dec 3 13:35:29 2013 -0600 Merge branch 'jed/malloc-array' into next * jed/malloc-array: Sys: drop explicit type arguments from PetscNew() and PetscNewLog() Sys: add PetscCalloc[1-7] Sys: add PetscMalloc1 macro, array allocation without redundant types PetscMalloc[2-7]: remove type arguments, infer from pointer type SNESComputeJacobianDefaultColor: fix uninitialized variable Conflicts: src/sys/objects/mpinit.c cat > malloc-convert.sh <<EOF git grep -l PetscMalloc[2-7] $1 | xargs perl -pi \ -e ' s@PetscMalloc2\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc2($1,$3,$4,$6)@; s@PetscMalloc3\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc3($1,$3,$4,$6,$7,$9)@; s@PetscMalloc4\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc4($1,$3,$4,$6,$7,$9,$10,$12)@; s@PetscMalloc5\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc5($1,$3,$4,$6,$7,$9,$10,$12,$13,$15)@; s@PetscMalloc6\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc6($1,$3,$4,$6,$7,$9,$10,$12,$13,$15,$16,$18)@; s@PetscMalloc7\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc7($1,$3,$4,$6,$7,$9,$10,$12,$13,$15,$16,$18,$19,$21)@; ' git grep -l 'PetscMalloc(.*sizeof' -- $1 | xargs perl -pi -e 's@PetscMalloc\(([^,;]*[^,; ]) *\* *sizeof\([^,;()]+\),@PetscMalloc1($1,@' git grep -l 'PetscNew\(Log\)\?(' -- $1 | xargs perl -pi -e ' s@PetscNew\([^,;()]+ *, *@PetscNew(@; s@PetscNewLog\(([^,;()]+) *,[^,;()]+, *@PetscNewLog($1,@' EOF malloc-convert.sh src I have also attached the script.
#!/bin/sh
git grep -l PetscMalloc[2-7] $1 | xargs perl -pi \
-e '
s@PetscMalloc2\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc2($1,$3,$4,$6)@;
s@PetscMalloc3\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc3($1,$3,$4,$6,$7,$9)@;
s@PetscMalloc4\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc4($1,$3,$4,$6,$7,$9,$10,$12)@;
s@PetscMalloc5\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc5($1,$3,$4,$6,$7,$9,$10,$12,$13,$15)@;
s@PetscMalloc6\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc6($1,$3,$4,$6,$7,$9,$10,$12,$13,$15,$16,$18)@;
s@PetscMalloc7\(([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+),([^,;()]+)\)@PetscMalloc7($1,$3,$4,$6,$7,$9,$10,$12,$13,$15,$16,$18,$19,$21)@;
'
git grep -l 'PetscMalloc(.*sizeof' -- $1 | xargs perl -pi -e 's@PetscMalloc\(([^,;]*[^,; ]) *\* *sizeof\([^,;()]+\),@PetscMalloc1($1,@'
git grep -l 'PetscNew\(Log\)\?(' -- $1 | xargs perl -pi -e '
s@PetscNew\([^,;()]+ *, *@PetscNew(@;
s@PetscNewLog\(([^,;()]+) *,[^,;()]+, *@PetscNewLog($1,@'
pgpz86wNLRd1z.pgp
Description: PGP signature
