| Newsgroups |
perl.cvs.mod_parrot |
| Message-ID |
<[email protected]> |
cvsuser 02/04/10 20:39:19
Modified: . mod_parrot.c
Log:
* Now uses Parrot's embedding interface
* Attempts to cache bytecode until the file changes (not tested very
heavily)
* Still only prints to the console until I wrap modparrot_printf up in a
custom op
Revision Changes Path
1.4 +30 -26 mod_parrot/mod_parrot.c
Index: mod_parrot.c
===================================================================
RCS file: /cvs/public/mod_parrot/mod_parrot.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- mod_parrot.c 2 Dec 2001 05:32:40 -0000 1.3
+++ mod_parrot.c 11 Apr 2002 03:39:19 -0000 1.4
@@ -6,11 +6,12 @@
#include "http_protocol.h"
#include "util_script.h"
-#include "parrot/parrot.h"
-#include "parrot/oplib/core_ops.h"
-
+#include "parrot/embed.h"
#include <stdio.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <string.h>
/*
* Declare ourselves so the configuration routines can find and know us.
@@ -18,9 +19,13 @@
*/
module MODULE_VAR_EXPORT mod_parrot_module;
-struct Parrot_Interp *interpreter;
+Parrot interpreter;
request_rec *sharedr;
+/*
+ * This isn't used yet. It will be hooked into a custom op once I can
+ * make it build
+ */
int modparrot_printf(const char *format, ...) {
va_list ap;
char buf[2048];
@@ -35,37 +40,35 @@
return nbytes; /* return the same as printf */
}
-
static int parrot_handler(request_rec *r)
{
- struct PackFile * pf;
+ Parrot_PackFile pf;
void *program_code;
struct stat file_stat;
+ time_t ptime;
int fd;
sharedr = r;
+ if (r->filename == NULL) {
+ printf("null filename\n");
+ }
+
if (stat(r->filename, &file_stat)) {
- printf("can't stat %s, code %i\n", r->filename, errno);
+ printf("can't stat %s, code %s\n", r->filename, strerror(errno));
return DECLINED;
}
- fd = open(r->filename, O_RDONLY);
- if (!fd) {
- printf("Can't open, error %i\n", errno);
- return DECLINED;
+ if (!ptime) {
+ ptime = file_stat.st_mtime;
}
- program_code = mmap(0, file_stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
- if (!program_code) {
- printf("Can't mmap, code %i\n", errno);
- return 1;
+ if (!pf || file_stat.st_mtime != ptime) {
+ pf = Parrot_readbc(interpreter, r->filename);
}
- pf = PackFile_new();
- if( !PackFile_unpack(interpreter, pf, (char *)program_code,
- file_stat.st_size ) ) {
- printf( "Can't unpack.\n" );
+ if(!pf) {
+ printf( "Can't unpack file.\n" );
return 1;
}
@@ -79,7 +82,8 @@
}
// so here
- runops(interpreter, pf);
+ Parrot_loadbc(interpreter, pf);
+ Parrot_runcode(interpreter, 0, NULL);
ap_kill_timeout(r);
@@ -94,15 +98,15 @@
// init Parrot
init_world();
- interpreter = make_interpreter();
-
+ interpreter = Parrot_new();
+ Parrot_init(interpreter);
}
static void mod_parrot_child_exit(server_rec *s, pool *p)
{
//
-
+ Parrot_destroy(interpreter);
}