On 13 Mar 2001, David N. Welton wrote:
> Looks good!
>
> A couple of things I have noticed, after a (quick) look at the code:
>
> mmap
>
> How portable is it? Does it work on Windows? I don't know, as I
> don't use Windows myself, but there are a fair amount of people who
> seem to be interested in Apache+Tcl+Windows.
I have heard that mmap is portable to Windows. It would be trivial to
write an #ifdef for it though so that a malloc(),read(),free() could be
used instead if mmap does not exist on a system... (actually I've already
done this).
>
> blocks like
>
> {
> ....
> }
>
> I'm not sure this is ok with all compilers. A friend says the best
> way to do that, portably and efficiently, is
>
> do {
> .......
> } while (0);
well the do while is how I see preprocessor macros defined so that people
can use a ; as a statement. The { } is really just a complex statement
not at all different from a complex statement following an
if,else,while,for etc... If this convention doesn't work on a compiler
I'd be really interested in seeing it.
>
> I see
>
> if ((fd = open(r->filename, O_RDONLY, 0)) == -1) {
> ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0,
> r->server, "open(%s, ...): %s", r->filename, strerror(errno));
>
> return HTTP_NOT_FOUND;
> }
>
> mptr = mmap((caddr_t) 0, r->finfo.size, PROT_READ, MAP_SHARED,
> fd, 0);
> bptr = (char*) malloc(r->finfo.size + flen + 21);
>
> memcpy(bptr, "namespace eval ", 15); pos += 15;
> memcpy(bptr + pos, r->filename, flen); pos += flen;
> memcpy(bptr + pos, " {\n", 3); pos +=
> 3;
> memcpy(bptr + pos, mptr, r->finfo.size); pos +=
> r->finfo.size;
> memcpy(bptr + pos, "\n}\0", 3);
>
> munmap((char*) mptr, r->finfo.size);
> close(fd);
>
> in several places. Is it worth making a function out of it?
naw, it can just remain inline. It is only 3 segments, 1 for loading, 1
for reloading if the file was updated, and 1 for the raw TCL that can be
input in the config file.
>
> Tcl_CreateObjCommand(interp, "r", cmd_r, NULL, NULL);
>
> 'request_rec' might be more descriptive. Is there a problem with
> putting all these commands in a namespace of their own, like
> 'Apache::' (to borrow something from the perl folks)?
>
hmm, I suppose I could do this, I thought mod_perl also used a convention
like `r'? The reason I used r is because it is customary for the
request_rec variable passed to handlers to be called r. So if your
writing modules you always see statements like this `r->server_name'. I
thought it would be an easier transfer of knowledge if someone knew how to
deal with C modules. This is the same thought applied to the command
names for the functions, they are all synonomous with the apache function
name ap_*. Let me know what you think. As far as putting them in a
namespace, I don't see why this can't be done.
> Thanks for all the work! Soon I'll try 'porting' dtcl to it to see how
> it runs, and how fast it runs.
>
> BTW, you don't have access to tcl.apache.org yet, do you? Let me know
> when you are ready to post some stuff to the web, and I can set you up
> with that, to
Ok, cool beans :)
--
Mike