Re: Extramake loadable module library - sum, multiply and comparison functions
Kaz Kylheku <[email protected]> Sun, 29 Jun 2025 08:39:32 +0900
| Newsgroups | gmane.comp.gnu.make.general |
|---|---|
| Message-ID | <[email protected]> |
In my opinion, this should be done by improving the interface between Guile= and Make=2E=20 I mean why would you be making a reverse function as a C extension when yo= u already have a Lisp dialect bolted on? On June 28, 2025 7:09:35 AM GMT+09:00, Tim Murphy <tnmurphy@gmail=2Ecom> w= rote: >Hi, > >https://github=2Ecom/tnmurphy/extramake > >extramake is a C function library for GNU Make=2E It has quite a lot of >functions already but most recently I've added a function to reverse >tokens in a list: > >New Features and Corrections >----------------------------------------- >$(reverse ab cd ef) =3D ef cd ab > >This is something the GNU Make Standard Library already does but=2E=2E=2E= =2Ewell >this one might end up being a bit faster possibly=2E > >I've also partially taken a hint from David Boyce a while ago and added a >$(hash) function as an alternate name for $(siphash24)=2E This means we c= ould >later decide to change the underlying hashing method without breaking >anything=2E > > >Unit Tests >-------------- >The main change has been the addition of a way to create unit tests for t= he >functions=2E This is somewhat limited now but still very useful=2E It req= uires >that valgrind is installed=2E > >For each c file containing a function or group of functions there is a >test_NAME=2Emk file where NAME would be the name of the C file without th= e >extension=2E Example for reverse here is test_reverse=2Emk: > >include xtra=2Emk >-load $(XTRA_OUTPUTDIR)/reverse$(XTRA_EXT) >include simple_test=2Emk > ># tests >$(eval $(call simpletest,reverse_letters,d c b a,$(reverse a b c d))) >$(eval $(call simpletest,reverse_tokens_longer_than_one,ef cd ab,$(revers= e >ab cd ef))) > >There's a macro (simpletest) that generates the test as a rule=2E The ac= tual >execution of the function happens while parsing test_reverse=2Emk but th= e >checking of the result happens in a shell statement when the rule is >executed=2E This allows failures to be treated like > >As a direct result I've fixed a number of things that I perceive as bugs: > > > - $(equals ,) returned the empty string which suggests that an empty > string is not equal to an empty string=2E That's bad! :-) > - The numeric comparison functions gt lt lte gte all returned false if > there was any whitespace wrapping either argument=2E Now they tolerate= it and > gte and lte properly return the empty string if you try to compare an = empty > string with anything else=2E > - > > >The test mechanism isn't good with side effects yet - no setup/teardown f= or >tests=2E The test for mkdir is weak because it really needs a random >temporary directory name and for that directory to be deleted afterwards= =2E > > >To test an individual function you can do this: > > make -f reverse=2Emk test > >This will compile the code and run the tests as well=2E It'll use valgrin= d to >check that no memory errors have occurred=2E > >to run all the tests just > make test > >Regards, > >Tim > >On Thu, 19 Jun 2025 at 16:49, Tim Murphy <tnmurphy@gmail=2Ecom> wrote: > >> Hi, >> >> I've added a couple more functions to this library of loadable C functi= ons >> for GNU make: >> >> https://github=2Ecom/tnmurphy/extramake >> >> Regards, >> >> Tim Murphy >> >> >> REGEX - Regular Expression Matching >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> -load regex=2Emk >> HANDLE:=3D$(regcomp, String(=2E*)) >> MATCH1:=3D$(regexec $(HANDLE),String123) >> MATCH2:=3D$(regexec $(HANDLE),String) >> >> $(info MATCH1=3D$(MATCH1)) >> $(info MATCH2=3D$(MATCH2)) >> >> >> The result would be >> >> MATCH1=3DString123 123 >> MATCH2=3DString >> These functions use the glibc regcomp and regexec functions to do regex= p >> matching so they will build wherever you have glibc=2E I wondered abou= t >> finding some more generic library where I could include a copy like wit= h >> siphash24 but so far I haven't found one and I thought this wasn't such= a >> terrible compromise=2E >> >> PROBLEMS: >> There's no way to set compile flags or exec flags yet - that can be fix= ed >> with a bit of dull work=2E >> There's some debugging code but no good error messages for regex >> compilation at least=2E >> >> The big problem is that there's a limit to the number of regexps one ca= n >> create and I really don't want to implement some kind of "regexp free" >> function to release the resources used by the regexp=2E >> I could compile and execute the regexp in one function and deal with it >> that way =2E=2E=2E=2E=2E=2Ebut it does seem very inefficient=2E At the= moment I just >> have an array of regex_t structures and regcomp returns >> an index into it=2E That's pretty ugly but it seems relatively efficien= t=2E >> I'd love to hear thoughts on this whole issue=2E >> >> >> MKDIR - Directory Creation >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> $(mkdir /makes/all/paths/upto/and/includingthe/last) >> >> This is like mkdir -p at the commandline=2E The idea is for one to be a= ble >> to make directories before any rules get executed=2E WHY? Ha well=2E >> Directories are a nuisance because they get updated when you add a file= to >> them so they cannot be used to trigger a rule because they change a lot >> even when it doesn't matter to you=2E So you can use order-only rules e= tc but >> sometimes it's just neater to make the output directory as part of a ma= cro=2E >> >> >> The existing ones are all there too: >> >> * $(equals x,y) tests string equality=2E Returns empty if the 2 paramet= ers >> don't match or the value if they do=2E >> * e=2Eg=2E `FILENAME=3Dfile=2E$(if $(equals >> $(compression_level),0),tar,=2Etar=2Ebz3)` >> * $(siphash24 text[,key]) returns a 16 character hash of the input text= , >> an optional key can be used to make the whole thing cryptographic=2E >> * $(strlen <string>) returns the number of characters in <string> >> * $(sum <number> <number> =2E=2E=2E=2E <number> ) finds the sum of a l= ist of >> integers=2E Negative integers are allowed=2E Any non-numeric character= s will >> cause the empty string to be returned=2E >> * $(mul <n> <n> <n>) returns the result of multiplying a list of number= s=2E >> Overflow can occur=2E The platform's "long long" is used=2E >> * $(lt x,y) returns 1 if x < y for integers x and y, empty string >> otherwise=2E >> * $(lte x,y) returns 1 if x <=3D y for integers x and y, empty string >> otherwise=2E >> * $(gt x,y) returns 1 if x >=3D y for integers x and y, empty string >> otherwise=2E >> * $(gte x,y) returns 1 if x >=3D y for integers x and y, empty string >> otherwise=2E >> * $(mkdir /path/to/dir) makes all directories up to and including "dir= "=2E >> Returns as much of the path as could be made or empty if no path could = be >> made e=2Eg=2E if the root doesn't exist=2E >> >> On Mon, 9 Nov 2015 at 22:45, Tim Murphy <tnmurphy@gmail=2Ecom> wrote: >> >>> >>> >>> Hi, >>> >>> I'd just like to mention that the extramake module library that I >>> mentioned some days ago now has a few new useful functions=2E >>> >>> https://bitbucket=2Eorg/tnmurphy/extramake >>> >>> $(sum <number> <number> =2E=2E=2E=2E <number> ) >>> finds the sum of a list of integers=2E Negative integers are allowe= d=2E >>> Any non-numeric characters will cause the empty string to be returned= =2E >>> >>> $(mul <n> <n> <n>) >>> returns the result of multiplying a list of numbers=2E Overflow can >>> occur=2E The platform's "long long" is used=2E Negative numbers are ok= =2E >>> >>> $(lt x,y) >>> returns 1 if x < y for integers x and y, empty string otherwise=2E >>> >>> $(lte x,y) >>> returns 1 if x <=3D y for integers x and y, empty string otherwise= =2E >>> >>> $(gt x,y) >>> returns 1 if x >=3D y for integers x and y, empty string otherwise= =2E >>> >>> $(gte x,y) >>> returns 1 if x >=3D y for integers x and y, empty string otherwise= =2E >>> >>> I am sorry to offend by adding possibly undesired numerical comparison >>> functions etc but I needed them once (trying to make sure commandlines >>> would fit the restrictions of the shell) so here they are to be ignore= d or >>> not as you wish=2E >>> >>> I've been trying to add things that don't require a lot of fancy memor= y >>> allocation or any other complications but the things I'm thinking abou= t >>> next are: >>> >>> reduce - as in lisp >>> map - as in lisp >>> find - finding files under a path=2E >>> mkdir - make directories (like mkdir -p) which can be important as a >>> companion to the $(file) function if you want to write a file to a spe= cific >>> directory=2E >>> >>> >>> I'd love to know if there's anything else that might be wanted=2E >>> Criticism would be welcome too=2E >>> >>> Regards, >>> >>> Tim >>> >>> >>> >>>