2 * "The Road goes ever on and on, down from the door where it began."
21 /* Register any extra external extensions */
22 char *staticlinkmodules[] = {
27 EXTERN_C void boot_DynaLoader (pTHXo_ CV* cv);
32 char *file = __FILE__;
34 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
40 PerlMemMalloc(struct IPerlMem*, size_t size)
42 return win32_malloc(size);
45 PerlMemRealloc(struct IPerlMem*, void* ptr, size_t size)
47 return win32_realloc(ptr, size);
50 PerlMemFree(struct IPerlMem*, void* ptr)
55 struct IPerlMem perlMem =
64 extern char * g_win32_get_privlib(char *pl);
65 extern char * g_win32_get_sitelib(char *pl);
69 PerlEnvGetenv(struct IPerlEnv*, const char *varname)
71 return win32_getenv(varname);
74 PerlEnvPutenv(struct IPerlEnv*, const char *envstring)
76 return win32_putenv(envstring);
80 PerlEnvGetenv_len(struct IPerlEnv*, const char* varname, unsigned long* len)
82 char *e = win32_getenv(varname);
89 PerlEnvUname(struct IPerlEnv*, struct utsname *name)
91 return win32_uname(name);
95 PerlEnvOsId(struct IPerlEnv*)
101 PerlEnvLibPath(struct IPerlEnv*, char *pl)
103 return g_win32_get_privlib(pl);
107 PerlEnvSiteLibPath(struct IPerlEnv*, char *pl)
109 return g_win32_get_sitelib(pl);
112 struct IPerlEnv perlEnv =
127 PerlStdIOStdin(struct IPerlStdIO*)
129 return (PerlIO*)win32_stdin();
133 PerlStdIOStdout(struct IPerlStdIO*)
135 return (PerlIO*)win32_stdout();
139 PerlStdIOStderr(struct IPerlStdIO*)
141 return (PerlIO*)win32_stderr();
145 PerlStdIOOpen(struct IPerlStdIO*, const char *path, const char *mode)
147 return (PerlIO*)win32_fopen(path, mode);
151 PerlStdIOClose(struct IPerlStdIO*, PerlIO* pf)
153 return win32_fclose(((FILE*)pf));
157 PerlStdIOEof(struct IPerlStdIO*, PerlIO* pf)
159 return win32_feof((FILE*)pf);
163 PerlStdIOError(struct IPerlStdIO*, PerlIO* pf)
165 return win32_ferror((FILE*)pf);
169 PerlStdIOClearerr(struct IPerlStdIO*, PerlIO* pf)
171 win32_clearerr((FILE*)pf);
175 PerlStdIOGetc(struct IPerlStdIO*, PerlIO* pf)
177 return win32_getc((FILE*)pf);
181 PerlStdIOGetBase(struct IPerlStdIO*, PerlIO* pf)
192 PerlStdIOGetBufsiz(struct IPerlStdIO*, PerlIO* pf)
196 return FILE_bufsiz(f);
203 PerlStdIOGetCnt(struct IPerlStdIO*, PerlIO* pf)
214 PerlStdIOGetPtr(struct IPerlStdIO*, PerlIO* pf)
225 PerlStdIOGets(struct IPerlStdIO*, PerlIO* pf, char* s, int n)
227 return win32_fgets(s, n, (FILE*)pf);
231 PerlStdIOPutc(struct IPerlStdIO*, PerlIO* pf, int c)
233 return win32_fputc(c, (FILE*)pf);
237 PerlStdIOPuts(struct IPerlStdIO*, PerlIO* pf, const char *s)
239 return win32_fputs(s, (FILE*)pf);
243 PerlStdIOFlush(struct IPerlStdIO*, PerlIO* pf)
245 return win32_fflush((FILE*)pf);
249 PerlStdIOUngetc(struct IPerlStdIO*, PerlIO* pf,int c)
251 return win32_ungetc(c, (FILE*)pf);
255 PerlStdIOFileno(struct IPerlStdIO*, PerlIO* pf)
257 return win32_fileno((FILE*)pf);
261 PerlStdIOFdopen(struct IPerlStdIO*, int fd, const char *mode)
263 return (PerlIO*)win32_fdopen(fd, mode);
267 PerlStdIOReopen(struct IPerlStdIO*, const char*path, const char*mode, PerlIO* pf)
269 return (PerlIO*)win32_freopen(path, mode, (FILE*)pf);
273 PerlStdIORead(struct IPerlStdIO*, PerlIO* pf, void *buffer, Size_t size)
275 return win32_fread(buffer, 1, size, (FILE*)pf);
279 PerlStdIOWrite(struct IPerlStdIO*, PerlIO* pf, const void *buffer, Size_t size)
281 return win32_fwrite(buffer, 1, size, (FILE*)pf);
285 PerlStdIOSetBuf(struct IPerlStdIO*, PerlIO* pf, char* buffer)
287 win32_setbuf((FILE*)pf, buffer);
291 PerlStdIOSetVBuf(struct IPerlStdIO*, PerlIO* pf, char* buffer, int type, Size_t size)
293 return win32_setvbuf((FILE*)pf, buffer, type, size);
297 PerlStdIOSetCnt(struct IPerlStdIO*, PerlIO* pf, int n)
299 #ifdef STDIO_CNT_LVALUE
306 PerlStdIOSetPtrCnt(struct IPerlStdIO*, PerlIO* pf, char * ptr, int n)
308 #ifdef STDIO_PTR_LVALUE
316 PerlStdIOSetlinebuf(struct IPerlStdIO*, PerlIO* pf)
318 win32_setvbuf((FILE*)pf, NULL, _IOLBF, 0);
322 PerlStdIOPrintf(struct IPerlStdIO*, PerlIO* pf, const char *format,...)
325 va_start(arglist, format);
326 return win32_vfprintf((FILE*)pf, format, arglist);
330 PerlStdIOVprintf(struct IPerlStdIO*, PerlIO* pf, const char *format, va_list arglist)
332 return win32_vfprintf((FILE*)pf, format, arglist);
336 PerlStdIOTell(struct IPerlStdIO*, PerlIO* pf)
338 return win32_ftell((FILE*)pf);
342 PerlStdIOSeek(struct IPerlStdIO*, PerlIO* pf, off_t offset, int origin)
344 return win32_fseek((FILE*)pf, offset, origin);
348 PerlStdIORewind(struct IPerlStdIO*, PerlIO* pf)
350 win32_rewind((FILE*)pf);
354 PerlStdIOTmpfile(struct IPerlStdIO*)
356 return (PerlIO*)win32_tmpfile();
360 PerlStdIOGetpos(struct IPerlStdIO*, PerlIO* pf, Fpos_t *p)
362 return win32_fgetpos((FILE*)pf, p);
366 PerlStdIOSetpos(struct IPerlStdIO*, PerlIO* pf, const Fpos_t *p)
368 return win32_fsetpos((FILE*)pf, p);
371 PerlStdIOInit(struct IPerlStdIO*)
376 PerlStdIOInitOSExtras(struct IPerlStdIO*)
378 Perl_init_os_extras();
382 PerlStdIOOpenOSfhandle(struct IPerlStdIO*, long osfhandle, int flags)
384 return win32_open_osfhandle(osfhandle, flags);
388 PerlStdIOGetOSfhandle(struct IPerlStdIO*, int filenum)
390 return win32_get_osfhandle(filenum);
394 struct IPerlStdIO perlStdIO =
433 PerlStdIOInitOSExtras,
439 PerlLIOAccess(struct IPerlLIO*, const char *path, int mode)
441 return access(path, mode);
445 PerlLIOChmod(struct IPerlLIO*, const char *filename, int pmode)
447 return chmod(filename, pmode);
451 PerlLIOChown(struct IPerlLIO*, const char *filename, uid_t owner, gid_t group)
453 return chown(filename, owner, group);
457 PerlLIOChsize(struct IPerlLIO*, int handle, long size)
459 return chsize(handle, size);
463 PerlLIOClose(struct IPerlLIO*, int handle)
465 return win32_close(handle);
469 PerlLIODup(struct IPerlLIO*, int handle)
471 return win32_dup(handle);
475 PerlLIODup2(struct IPerlLIO*, int handle1, int handle2)
477 return win32_dup2(handle1, handle2);
481 PerlLIOFlock(struct IPerlLIO*, int fd, int oper)
483 return win32_flock(fd, oper);
487 PerlLIOFileStat(struct IPerlLIO*, int handle, struct stat *buffer)
489 return fstat(handle, buffer);
493 PerlLIOIOCtl(struct IPerlLIO*, int i, unsigned int u, char *data)
495 return win32_ioctlsocket((SOCKET)i, (long)u, (u_long*)data);
499 PerlLIOIsatty(struct IPerlLIO*, int fd)
505 PerlLIOLseek(struct IPerlLIO*, int handle, long offset, int origin)
507 return win32_lseek(handle, offset, origin);
511 PerlLIOLstat(struct IPerlLIO* p, const char *path, struct stat *buffer)
513 return win32_stat(path, buffer);
517 PerlLIOMktemp(struct IPerlLIO*, char *Template)
519 return mktemp(Template);
523 PerlLIOOpen(struct IPerlLIO*, const char *filename, int oflag)
525 return win32_open(filename, oflag);
529 PerlLIOOpen3(struct IPerlLIO*, const char *filename, int oflag, int pmode)
532 if(stricmp(filename, "/dev/null") == 0)
533 ret = open("NUL", oflag, pmode);
535 ret = open(filename, oflag, pmode);
541 PerlLIORead(struct IPerlLIO*, int handle, void *buffer, unsigned int count)
543 return win32_read(handle, buffer, count);
547 PerlLIORename(struct IPerlLIO*, const char *OldFileName, const char *newname)
549 return win32_rename(OldFileName, newname);
553 PerlLIOSetmode(struct IPerlLIO*, int handle, int mode)
555 return win32_setmode(handle, mode);
559 PerlLIONameStat(struct IPerlLIO*, const char *path, struct stat *buffer)
561 return win32_stat(path, buffer);
565 PerlLIOTmpnam(struct IPerlLIO*, char *string)
567 return tmpnam(string);
571 PerlLIOUmask(struct IPerlLIO*, int pmode)
577 PerlLIOUnlink(struct IPerlLIO*, const char *filename)
579 chmod(filename, S_IREAD | S_IWRITE);
580 return unlink(filename);
584 PerlLIOUtime(struct IPerlLIO*, char *filename, struct utimbuf *times)
586 return win32_utime(filename, times);
590 PerlLIOWrite(struct IPerlLIO*, int handle, const void *buffer, unsigned int count)
592 return win32_write(handle, buffer, count);
595 struct IPerlLIO perlLIO =
626 PerlDirMakedir(struct IPerlDir*, const char *dirname, int mode)
628 return win32_mkdir(dirname, mode);
632 PerlDirChdir(struct IPerlDir*, const char *dirname)
634 return win32_chdir(dirname);
638 PerlDirRmdir(struct IPerlDir*, const char *dirname)
640 return win32_rmdir(dirname);
644 PerlDirClose(struct IPerlDir*, DIR *dirp)
646 return win32_closedir(dirp);
650 PerlDirOpen(struct IPerlDir*, char *filename)
652 return win32_opendir(filename);
656 PerlDirRead(struct IPerlDir*, DIR *dirp)
658 return win32_readdir(dirp);
662 PerlDirRewind(struct IPerlDir*, DIR *dirp)
664 win32_rewinddir(dirp);
668 PerlDirSeek(struct IPerlDir*, DIR *dirp, long loc)
670 win32_seekdir(dirp, loc);
674 PerlDirTell(struct IPerlDir*, DIR *dirp)
676 return win32_telldir(dirp);
679 struct IPerlDir perlDir =
695 PerlSockHtonl(struct IPerlSock*, u_long hostlong)
697 return win32_htonl(hostlong);
701 PerlSockHtons(struct IPerlSock*, u_short hostshort)
703 return win32_htons(hostshort);
707 PerlSockNtohl(struct IPerlSock*, u_long netlong)
709 return win32_ntohl(netlong);
713 PerlSockNtohs(struct IPerlSock*, u_short netshort)
715 return win32_ntohs(netshort);
718 SOCKET PerlSockAccept(struct IPerlSock*, SOCKET s, struct sockaddr* addr, int* addrlen)
720 return win32_accept(s, addr, addrlen);
724 PerlSockBind(struct IPerlSock*, SOCKET s, const struct sockaddr* name, int namelen)
726 return win32_bind(s, name, namelen);
730 PerlSockConnect(struct IPerlSock*, SOCKET s, const struct sockaddr* name, int namelen)
732 return win32_connect(s, name, namelen);
736 PerlSockEndhostent(struct IPerlSock*)
742 PerlSockEndnetent(struct IPerlSock*)
748 PerlSockEndprotoent(struct IPerlSock*)
754 PerlSockEndservent(struct IPerlSock*)
760 PerlSockGethostbyaddr(struct IPerlSock*, const char* addr, int len, int type)
762 return win32_gethostbyaddr(addr, len, type);
766 PerlSockGethostbyname(struct IPerlSock*, const char* name)
768 return win32_gethostbyname(name);
772 PerlSockGethostent(struct IPerlSock*)
775 croak("gethostent not implemented!\n");
780 PerlSockGethostname(struct IPerlSock*, char* name, int namelen)
782 return win32_gethostname(name, namelen);
786 PerlSockGetnetbyaddr(struct IPerlSock*, long net, int type)
788 return win32_getnetbyaddr(net, type);
792 PerlSockGetnetbyname(struct IPerlSock*, const char *name)
794 return win32_getnetbyname((char*)name);
798 PerlSockGetnetent(struct IPerlSock*)
800 return win32_getnetent();
803 int PerlSockGetpeername(struct IPerlSock*, SOCKET s, struct sockaddr* name, int* namelen)
805 return win32_getpeername(s, name, namelen);
809 PerlSockGetprotobyname(struct IPerlSock*, const char* name)
811 return win32_getprotobyname(name);
815 PerlSockGetprotobynumber(struct IPerlSock*, int number)
817 return win32_getprotobynumber(number);
821 PerlSockGetprotoent(struct IPerlSock*)
823 return win32_getprotoent();
827 PerlSockGetservbyname(struct IPerlSock*, const char* name, const char* proto)
829 return win32_getservbyname(name, proto);
833 PerlSockGetservbyport(struct IPerlSock*, int port, const char* proto)
835 return win32_getservbyport(port, proto);
839 PerlSockGetservent(struct IPerlSock*)
841 return win32_getservent();
845 PerlSockGetsockname(struct IPerlSock*, SOCKET s, struct sockaddr* name, int* namelen)
847 return win32_getsockname(s, name, namelen);
851 PerlSockGetsockopt(struct IPerlSock*, SOCKET s, int level, int optname, char* optval, int* optlen)
853 return win32_getsockopt(s, level, optname, optval, optlen);
857 PerlSockInetAddr(struct IPerlSock*, const char* cp)
859 return win32_inet_addr(cp);
863 PerlSockInetNtoa(struct IPerlSock*, struct in_addr in)
865 return win32_inet_ntoa(in);
869 PerlSockListen(struct IPerlSock*, SOCKET s, int backlog)
871 return win32_listen(s, backlog);
875 PerlSockRecv(struct IPerlSock*, SOCKET s, char* buffer, int len, int flags)
877 return win32_recv(s, buffer, len, flags);
881 PerlSockRecvfrom(struct IPerlSock*, SOCKET s, char* buffer, int len, int flags, struct sockaddr* from, int* fromlen)
883 return win32_recvfrom(s, buffer, len, flags, from, fromlen);
887 PerlSockSelect(struct IPerlSock*, int nfds, char* readfds, char* writefds, char* exceptfds, const struct timeval* timeout)
889 return win32_select(nfds, (Perl_fd_set*)readfds, (Perl_fd_set*)writefds, (Perl_fd_set*)exceptfds, timeout);
893 PerlSockSend(struct IPerlSock*, SOCKET s, const char* buffer, int len, int flags)
895 return win32_send(s, buffer, len, flags);
899 PerlSockSendto(struct IPerlSock*, SOCKET s, const char* buffer, int len, int flags, const struct sockaddr* to, int tolen)
901 return win32_sendto(s, buffer, len, flags, to, tolen);
905 PerlSockSethostent(struct IPerlSock*, int stayopen)
907 win32_sethostent(stayopen);
911 PerlSockSetnetent(struct IPerlSock*, int stayopen)
913 win32_setnetent(stayopen);
917 PerlSockSetprotoent(struct IPerlSock*, int stayopen)
919 win32_setprotoent(stayopen);
923 PerlSockSetservent(struct IPerlSock*, int stayopen)
925 win32_setservent(stayopen);
929 PerlSockSetsockopt(struct IPerlSock*, SOCKET s, int level, int optname, const char* optval, int optlen)
931 return win32_setsockopt(s, level, optname, optval, optlen);
935 PerlSockShutdown(struct IPerlSock*, SOCKET s, int how)
937 return win32_shutdown(s, how);
941 PerlSockSocket(struct IPerlSock*, int af, int type, int protocol)
943 return win32_socket(af, type, protocol);
947 PerlSockSocketpair(struct IPerlSock*, int domain, int type, int protocol, int* fds)
950 croak("socketpair not implemented!\n");
955 PerlSockClosesocket(struct IPerlSock*, SOCKET s)
957 return win32_closesocket(s);
961 PerlSockIoctlsocket(struct IPerlSock*, SOCKET s, long cmd, u_long *argp)
963 return win32_ioctlsocket(s, cmd, argp);
966 struct IPerlSock perlSock =
981 PerlSockGethostbyaddr,
982 PerlSockGethostbyname,
984 PerlSockGetnetbyaddr,
985 PerlSockGetnetbyname,
987 PerlSockGetprotobyname,
988 PerlSockGetprotobynumber,
990 PerlSockGetservbyname,
991 PerlSockGetservbyport,
1005 PerlSockSetprotoent,
1011 PerlSockClosesocket,
1017 #define EXECF_EXEC 1
1018 #define EXECF_SPAWN 2
1020 extern char * g_getlogin(void);
1021 extern int do_spawn2(char *cmd, int exectype);
1022 extern int g_do_aspawn(void *vreally, void **vmark, void **vsp);
1025 PerlProcAbort(struct IPerlProc*)
1031 PerlProcCrypt(struct IPerlProc*, const char* clear, const char* salt)
1033 return win32_crypt(clear, salt);
1037 PerlProcExit(struct IPerlProc*, int status)
1043 PerlProc_Exit(struct IPerlProc*, int status)
1049 PerlProcExecl(struct IPerlProc*, const char *cmdname, const char *arg0, const char *arg1, const char *arg2, const char *arg3)
1051 return execl(cmdname, arg0, arg1, arg2, arg3);
1055 PerlProcExecv(struct IPerlProc*, const char *cmdname, const char *const *argv)
1057 return win32_execvp(cmdname, argv);
1061 PerlProcExecvp(struct IPerlProc*, const char *cmdname, const char *const *argv)
1063 return win32_execvp(cmdname, argv);
1067 PerlProcGetuid(struct IPerlProc*)
1073 PerlProcGeteuid(struct IPerlProc*)
1079 PerlProcGetgid(struct IPerlProc*)
1085 PerlProcGetegid(struct IPerlProc*)
1091 PerlProcGetlogin(struct IPerlProc*)
1093 return g_getlogin();
1097 PerlProcKill(struct IPerlProc*, int pid, int sig)
1099 return win32_kill(pid, sig);
1103 PerlProcKillpg(struct IPerlProc*, int pid, int sig)
1106 croak("killpg not implemented!\n");
1111 PerlProcPauseProc(struct IPerlProc*)
1113 return win32_sleep((32767L << 16) + 32767);
1117 PerlProcPopen(struct IPerlProc*, const char *command, const char *mode)
1119 win32_fflush(stdout);
1120 win32_fflush(stderr);
1121 return (PerlIO*)win32_popen(command, mode);
1125 PerlProcPclose(struct IPerlProc*, PerlIO *stream)
1127 return win32_pclose((FILE*)stream);
1131 PerlProcPipe(struct IPerlProc*, int *phandles)
1133 return win32_pipe(phandles, 512, O_BINARY);
1137 PerlProcSetuid(struct IPerlProc*, uid_t u)
1143 PerlProcSetgid(struct IPerlProc*, gid_t g)
1149 PerlProcSleep(struct IPerlProc*, unsigned int s)
1151 return win32_sleep(s);
1155 PerlProcTimes(struct IPerlProc*, struct tms *timebuf)
1157 return win32_times(timebuf);
1161 PerlProcWait(struct IPerlProc*, int *status)
1163 return win32_wait(status);
1167 PerlProcWaitpid(struct IPerlProc*, int pid, int *status, int flags)
1169 return win32_waitpid(pid, status, flags);
1173 PerlProcSignal(struct IPerlProc*, int sig, Sighandler_t subcode)
1179 PerlProcDynaLoader(struct IPerlProc*, const char* filename)
1181 return win32_dynaload(filename);
1185 PerlProcGetOSError(struct IPerlProc*, SV* sv, DWORD dwErr)
1187 win32_str_os_error(aTHX_ sv, dwErr);
1191 PerlProcDoCmd(struct IPerlProc*, char *cmd)
1193 do_spawn2(cmd, EXECF_EXEC);
1198 PerlProcSpawn(struct IPerlProc*, char* cmds)
1200 return do_spawn2(cmds, EXECF_SPAWN);
1204 PerlProcSpawnvp(struct IPerlProc*, int mode, const char *cmdname, const char *const *argv)
1206 return win32_spawnvp(mode, cmdname, argv);
1210 PerlProcASpawn(struct IPerlProc*, void *vreally, void **vmark, void **vsp)
1212 return g_do_aspawn(vreally, vmark, vsp);
1215 struct IPerlProc perlProc =
1250 //#include "perlhost.h"
1252 static DWORD g_TlsAllocIndex;
1253 BOOL SetPerlInterpreter(CPerlObj* pPerl)
1255 return TlsSetValue(g_TlsAllocIndex, pPerl);
1258 EXTERN_C CPerlObj* GetPerlInterpreter(PerlInterpreter* sv_interp)
1260 if(GetCurrentThreadId() == (DWORD)sv_interp)
1261 return (CPerlObj*)TlsGetValue(g_TlsAllocIndex);
1265 CPerlObj* GetPerlInter(void)
1267 return (CPerlObj*)TlsGetValue(g_TlsAllocIndex);
1271 EXTERN_C void perl_get_host_info(IPerlMemInfo* perlMemInfo,
1272 IPerlEnvInfo* perlEnvInfo, IPerlStdIOInfo* perlStdIOInfo,
1273 IPerlLIOInfo* perlLIOInfo, IPerlDirInfo* perlDirInfo,
1274 IPerlSockInfo* perlSockInfo, IPerlProcInfo* perlProcInfo)
1277 Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
1278 perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
1281 Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
1282 perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
1285 Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
1286 perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
1289 Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
1290 perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
1293 Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
1294 perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
1297 Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
1298 perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
1301 Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
1302 perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
1306 EXTERN_C PerlInterpreter* perl_alloc_using(IPerlMem* pMem,
1307 IPerlEnv* pEnv, IPerlStdIO* pStdIO,
1308 IPerlLIO* pLIO, IPerlDir* pDir,
1309 IPerlSock* pSock, IPerlProc* pProc)
1311 CPerlObj* pPerl = NULL;
1314 pPerl = Perl_alloc(pMem, pEnv, pStdIO, pLIO, pDir, pSock, pProc);
1318 win32_fprintf(stderr, "%s\n", "Error: Unable to allocate memory");
1323 SetPerlInterpreter(pPerl);
1324 return (PerlInterpreter*)GetCurrentThreadId();
1326 SetPerlInterpreter(NULL);
1331 #undef perl_construct
1332 #undef perl_destruct
1336 EXTERN_C PerlInterpreter* perl_alloc(void)
1338 CPerlObj* pPerl = NULL;
1341 pPerl = Perl_alloc(&perlMem, &perlEnv, &perlStdIO, &perlLIO,
1342 &perlDir, &perlSock, &perlProc);
1346 win32_fprintf(stderr, "%s\n", "Error: Unable to allocate memory");
1351 SetPerlInterpreter(pPerl);
1352 return (PerlInterpreter*)GetCurrentThreadId();
1354 SetPerlInterpreter(NULL);
1358 EXTERN_C void perl_construct(PerlInterpreter* sv_interp)
1360 CPerlObj* pPerl = GetPerlInterpreter(sv_interp);
1363 pPerl->perl_construct();
1367 win32_fprintf(stderr, "%s\n",
1368 "Error: Unable to construct data structures");
1370 SetPerlInterpreter(NULL);
1374 EXTERN_C void perl_destruct(PerlInterpreter* sv_interp)
1376 CPerlObj* pPerl = GetPerlInterpreter(sv_interp);
1379 pPerl->perl_destruct();
1386 EXTERN_C void perl_free(PerlInterpreter* sv_interp)
1388 CPerlObj* pPerl = GetPerlInterpreter(sv_interp);
1396 SetPerlInterpreter(NULL);
1399 EXTERN_C int perl_run(PerlInterpreter* sv_interp)
1401 CPerlObj* pPerl = GetPerlInterpreter(sv_interp);
1405 retVal = pPerl->perl_run();
1410 // this is where exit() should arrive
1416 win32_fprintf(stderr, "Error: Runtime exception\n");
1422 EXTERN_C int perl_parse(PerlInterpreter* sv_interp, void (*xsinit)(CPerlObj*), int argc, char** argv, char** env)
1425 CPerlObj* pPerl = GetPerlInterpreter(sv_interp);
1428 retVal = pPerl->perl_parse(xs_init, argc, argv, env);
1433 // this is where exit() should arrive
1439 win32_fprintf(stderr, "Error: Parse exception\n");
1446 #undef PL_perl_destruct_level
1447 #define PL_perl_destruct_level int dummy
1448 #undef w32_perldll_handle
1449 #define w32_perldll_handle g_w32_perldll_handle
1450 HANDLE g_w32_perldll_handle;
1452 extern HANDLE w32_perldll_handle;
1453 #endif /* PERL_OBJECT */
1456 RunPerl(int argc, char **argv, char **env)
1459 PerlInterpreter *my_perl;
1460 struct perl_thread *thr;
1462 #ifndef __BORLANDC__
1463 /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
1464 * want to free() argv after main() returns. As luck would have it,
1465 * Borland's CRT does the right thing to argv[0] already. */
1466 char szModuleName[MAX_PATH];
1469 GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
1470 (void)win32_longpath(szModuleName);
1471 argv[0] = szModuleName;
1474 #ifdef PERL_GLOBAL_STRUCT
1475 #define PERLVAR(var,type) /**/
1476 #define PERLVARI(var,type,init) PL_Vars.var = init;
1477 #define PERLVARIC(var,type,init) PL_Vars.var = init;
1478 #include "perlvars.h"
1484 PERL_SYS_INIT(&argc,&argv);
1486 if (!(my_perl = perl_alloc()))
1488 perl_construct( my_perl );
1489 PL_perl_destruct_level = 0;
1491 exitstatus = perl_parse(my_perl, xs_init, argc, argv, env);
1493 exitstatus = perl_run( my_perl );
1496 perl_destruct( my_perl );
1497 perl_free( my_perl );
1501 return (exitstatus);
1505 DllMain(HANDLE hModule, /* DLL module handle */
1506 DWORD fdwReason, /* reason called */
1507 LPVOID lpvReserved) /* reserved */
1509 switch (fdwReason) {
1510 /* The DLL is attaching to a process due to process
1511 * initialization or a call to LoadLibrary.
1513 case DLL_PROCESS_ATTACH:
1514 /* #define DEFAULT_BINMODE */
1515 #ifdef DEFAULT_BINMODE
1516 setmode( fileno( stdin ), O_BINARY );
1517 setmode( fileno( stdout ), O_BINARY );
1518 setmode( fileno( stderr ), O_BINARY );
1522 g_TlsAllocIndex = TlsAlloc();
1523 DisableThreadLibraryCalls(hModule);
1525 w32_perldll_handle = hModule;
1529 /* The DLL is detaching from a process due to
1530 * process termination or call to FreeLibrary.
1532 case DLL_PROCESS_DETACH:
1534 TlsFree(g_TlsAllocIndex);
1538 /* The attached process creates a new thread. */
1539 case DLL_THREAD_ATTACH:
1542 /* The thread of the attached process terminates. */
1543 case DLL_THREAD_DETACH: