[comp.sys.amiga.tech] regex.library - regular expression library

ehoogerbeets@rose.waterloo.edu (Edwin Hoogerbeets) (07/16/89)

Hi, I just managed to shoehorn the Gnu regular expression package
into an Amiga sharable library. (with some assembler glue)

And it works. Almost. That is, it works only if you have one copy
running at a time. So I suspect there is something in there that isn't
re-entrant.

I've attached the global variables to the struct RegexBase, so they are
different for each OpenLibrary() call. That does not seem to be the
problem. I do have to use the Manx heapmem.o to access the realloc()
call.

My question is this: are the routines in heapmem.o re-entrant?  (ie.
free(), malloc(), realloc()) Are there any other Manx library routines
that I should avoid?

If I get this resolved, I shall send it to Bob soon. (no excuse for
not having regular expression searching anymore! Like in dme, hint,
hint... ;-)

Thanks for any suggestions.

Edwin

jimm@amiga.UUCP (Jim Mackraz) (07/17/89)

In article <15161@watdragon.waterloo.edu> ehoogerbeets@rose.waterloo.edu (Edwin Hoogerbeets) writes:
)
)Hi, I just managed to shoehorn the Gnu regular expression package
)into an Amiga sharable library. (with some assembler glue)

Great!

)And it works. Almost. That is, it works only if you have one copy
)running at a time. So I suspect there is something in there that isn't
)re-entrant.

Probably correct.

)I've attached the global variables to the struct RegexBase, so they are
)different for each OpenLibrary() call.

Stop.  This is dead wrong: the variables in your library base are
SHARED, not one-per.

If the source uses any globals at all, you'll probably have to package
them in a per-caller data structure.  Allocate one on specific request,
not OpenLibrary (since there really isn't any support for associating
the per-caller data structure with a caller), and call the pointer
you return to the requester a "handle," which must be passed to all
subsequent calls that have "state."

)That does not seem to be the problem. I do have to use the Manx
)heapmem.o to access the realloc() call.

Well, this might be ANOTHER problem.  You can VERY EASILY write malloc,
free, and realloc, in C, and never worry again.  What you *won't* have
(nor is it appropriate for you library) is automatic cleanup on 
exit that heapmem.o supports.

)My question is this: are the routines in heapmem.o re-entrant?  (ie.
)free(), malloc(), realloc()) Are there any other Manx library routines
)that I should avoid?

Watch it for any routines that do "per-process" stuff like cleaning
up.  All the fopen() calls are probably unusable.  Sprintf() OK, fprintf()
not OK.

)If I get this resolved, I shall send it to Bob soon. (no excuse for
)not having regular expression searching anymore! Like in dme, hint,
)hint... ;-)

I think it will be a great contribution if it is OK fast and not too huge.
(And doesn't use a GNU-bodacious amount of stack.)

)Thanks for any suggestions.
)Edwin

	jimm
-- 
Jim Mackraz, I and I Computing	   	"... the signs are very ominous,
{cbmvax,well,oliveb}!amiga!jimm          and a chill wind blows."
							- Justice Blackmun
Opinions are my own.  Comments are not to be taken as Commodore official policy.

kevin@uts.amdahl.com (Kevin Clague) (07/17/89)

In article <15161@watdragon.waterloo.edu> ehoogerbeets@rose.waterloo.edu (Edwin Hoogerbeets) writes:
>
>Hi, I just managed to shoehorn the Gnu regular expression package
>into an Amiga sharable library. (with some assembler glue)
>
>And it works. Almost. That is, it works only if you have one copy
>running at a time. So I suspect there is something in there that isn't
>re-entrant.
>
>I've attached the global variables to the struct RegexBase, so they are
>different for each OpenLibrary() call. That does not seem to be the
>problem. I do have to use the Manx heapmem.o to access the realloc()
>call.
>
>My question is this: are the routines in heapmem.o re-entrant?  (ie.
>free(), malloc(), realloc()) Are there any other Manx library routines
>that I should avoid?

None of the Manx library routines are guaranteed to be reentrant :-(
If you have the source to the libraries, you could look at all the
functions you use and check their source.  Another solution would
be to write your own version of all the lib functions you use.

You might want (need) to hack at the GNU code to make it use Amiga
functions whenever possible.  This is, of course, more work.

>
>If I get this resolved, I shall send it to Bob soon. (no excuse for
>not having regular expression searching anymore! Like in dme, hint,
>hint... ;-)
>
>Thanks for any suggestions.
>
>Edwin

Kevin
-- 
UUCP:  kevin@uts.amdahl.com
  or:  {sun,decwrl,hplabs,pyramid,seismo,oliveb}!amdahl!kevin
DDD:   408-737-5481
USPS:  Amdahl Corp.  M/S 249,  1250 E. Arques Av,  Sunnyvale, CA 94086

[  Any thoughts or opinions which may or may not have been expressed  ]
[  herein are my own.  They are not necessarily those of my employer. ]