~rsrchboy/+junk/ndn-perl

1 by Chris Weyl
perl v5.20.2, from upstream tag
1
/*
2
 * Copyright © 2001 Novell, Inc. All Rights Reserved.
3
 *
4
 * You may distribute under the terms of either the GNU General Public
5
 * License or the Artistic License, as specified in the README file.
6
 *
7
 */
8
9
/*
10
 * FILENAME		:	interface.c
11
 * DESCRIPTION	:	Perl parsing and running functions.
12
 * Author		:	SGP
13
 * Date			:	January 2001.
14
 *
15
 */
16
17
18
19
#include "interface.h"
20
21
#include "win32ish.h"		// For "BOOL", "TRUE" and "FALSE"
22
23
24
static void xs_init(pTHX);
25
//static void xs_init(pTHXo); //(J)
26
27
EXTERN_C int RunPerl(int argc, char **argv, char **env);
28
EXTERN_C void Perl_nw5_init(int *argcp, char ***argvp);
29
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);	// (J) pTHXo_
30
31
EXTERN_C BOOL Remove_Thread_Ctx(void);
32
33
34
ClsPerlHost::ClsPerlHost()
35
{
36
37
}
38
39
ClsPerlHost::~ClsPerlHost()
40
{
41
42
}
43
44
ClsPerlHost::VersionNumber()
45
{
46
	return 0;
47
}
48
49
int
50
ClsPerlHost::PerlCreate(PerlInterpreter *my_perl)
51
{
52
/*	if (!(my_perl = perl_alloc()))		// Allocate memory for Perl.
53
		return (1);*/
54
    perl_construct(my_perl);
55
56
	return 1;
57
}
58
59
int
60
ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env)
61
{
62
	return(perl_parse(my_perl, xs_init, argc, argv, env));		// Parse the command line.
63
}
64
65
int
66
ClsPerlHost::PerlRun(PerlInterpreter *my_perl)
67
{
68
	return(perl_run(my_perl));	// Run Perl.
69
}
70
71
void
72
ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl)
73
{
74
	perl_destruct(my_perl);		// Destructor for Perl.
75
////	perl_free(my_perl);			// Free the memory allocated for Perl.
76
}
77
78
void
79
ClsPerlHost::PerlFree(PerlInterpreter *my_perl)
80
{
81
	perl_free(my_perl);			// Free the memory allocated for Perl.
82
83
	// Remove the thread context set during Perl_set_context
84
	// This is added here since for web script there is no other place this gets executed
85
	// and it cannot be included into cgi2perl.xs unless this symbol is exported.
86
	Remove_Thread_Ctx();
87
}
88
89
/*============================================================================================
90
91
 Function		:	xs_init
92
93
 Description	:	
94
95
 Parameters 	:	pTHX	(IN)	-	
96
97
 Returns		:	Nothing.
98
99
==============================================================================================*/
100
101
static void xs_init(pTHX)
102
//static void xs_init(pTHXo) //J
103
{
104
	char *file = __FILE__;
105
106
	dXSUB_SYS;
107
	newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
108
}
109
110
111
EXTERN_C
112
int RunPerl(int argc, char **argv, char **env)
113
{
114
	int exitstatus = 0;
115
	ClsPerlHost nlm;
116
117
	PerlInterpreter *my_perl = NULL;		// defined in Perl.h
118
	PerlInterpreter *new_perl = NULL;		// defined in Perl.h
119
120
	//__asm{int 3};
121
	#ifdef PERL_GLOBAL_STRUCT
122
		#define PERLVAR(prefix,var,type)
123
		#define PERLVARA(prefix,var,type)
124
		#define PERLVARI(prefix,var,type,init) PL_Vars.prefix##var = init;
125
		#define PERLVARIC(prefix,var,type,init) PL_Vars.prefix##var = init;
126
127
		#include "perlvars.h"
128
129
		#undef PERLVAR
130
		#undef PERLVARA
131
		#undef PERLVARI
132
		#undef PERLVARIC
133
	#endif
134
135
	PERL_SYS_INIT(&argc, &argv);
136
137
	if (!(my_perl = perl_alloc()))		// Allocate memory for Perl.
138
		return (1);
139
140
	if(nlm.PerlCreate(my_perl))
141
	{
142
		PL_perl_destruct_level = 0;
143
144
		exitstatus = nlm.PerlParse(my_perl, argc, argv, env);
145
		if(exitstatus == 0)
146
		{
147
			#if defined(TOP_CLONE) && defined(USE_ITHREADS)		// XXXXXX testing
148
				#  ifdef PERL_OBJECT
149
					CPerlHost *h = new CPerlHost();
150
					new_perl = perl_clone_using(my_perl, 1,
151
										h->m_pHostperlMem,
152
										h->m_pHostperlMemShared,
153
										h->m_pHostperlMemParse,
154
										h->m_pHostperlEnv,
155
										h->m_pHostperlStdIO,
156
										h->m_pHostperlLIO,
157
										h->m_pHostperlDir,
158
										h->m_pHostperlSock,
159
										h->m_pHostperlProc
160
										);
161
					CPerlObj *pPerl = (CPerlObj*)new_perl;
162
				#  else
163
					new_perl = perl_clone(my_perl, 1);
164
				#  endif
165
166
				exitstatus = perl_run(new_perl);	// Run Perl.
167
				PERL_SET_THX(my_perl);
168
			#else
169
				exitstatus = nlm.PerlRun(my_perl);
170
			#endif
171
		}
172
		nlm.PerlDestroy(my_perl);
173
	}
174
	if(my_perl)
175
		nlm.PerlFree(my_perl);
176
177
	#ifdef USE_ITHREADS
178
		if (new_perl)
179
		{
180
			PERL_SET_THX(new_perl);
181
			nlm.PerlDestroy(new_perl);
182
			nlm.PerlFree(my_perl);
183
		}
184
	#endif
185
186
	PERL_SYS_TERM();
187
	return exitstatus;
188
}
189
190
191
// FUNCTION: AllocStdPerl
192
//
193
// DESCRIPTION:
194
//	Allocates a standard perl handler that other perl handlers
195
//	may delegate to. You should call FreeStdPerl to free this
196
//	instance when you are done with it.
197
//
198
IPerlHost* AllocStdPerl()
199
{
200
	return (IPerlHost*) new ClsPerlHost();
201
}
202
203
204
// FUNCTION: FreeStdPerl
205
//
206
// DESCRIPTION:
207
//	Frees an instance of a standard perl handler allocated by
208
//	AllocStdPerl.
209
//
210
void FreeStdPerl(IPerlHost* pPerlHost)
211
{
212
	if (pPerlHost)
213
		delete (ClsPerlHost*) pPerlHost;
214
////		delete pPerlHost;
215
}
216
217