ReactOS 0.4.17-dev-357-ga8f14ff
vbscript_main.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include "initguid.h"
20
21#include "vbscript.h"
22#include "objsafe.h"
23#include "mshtmhst.h"
24#include "rpcproxy.h"
25#include "vbscript_classes.h"
26#include "vbsglobal.h"
27#include "vbsregexp55.h"
28
29#include "wine/debug.h"
30
33
34DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
35
38
40{
41 WCHAR buf[512];
43 return SysAllocString(buf);
44}
45
46#define MIN_BLOCK_SIZE 128
47#define ARENA_FREE_FILLER 0xaa
48
50{
51 return MIN_BLOCK_SIZE << block;
52}
53
55{
56 memset(heap, 0, sizeof(*heap));
57 list_init(&heap->custom_blocks);
58}
59
61{
62 struct list *list;
63 void *tmp;
64
65 size = (size+3)&~3;
66
67 if(!heap->block_cnt) {
68 if(!heap->blocks) {
69 heap->blocks = malloc(sizeof(void*));
70 if(!heap->blocks)
71 return NULL;
72 }
73
74 tmp = malloc(block_size(0));
75 if(!tmp)
76 return NULL;
77
78 heap->blocks[0] = tmp;
79 heap->block_cnt = 1;
80 }
81
82 if(heap->offset + size <= block_size(heap->last_block)) {
83 tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset;
84 heap->offset += size;
85 return tmp;
86 }
87
88 if(size <= block_size(heap->last_block+1)) {
89 if(heap->last_block+1 == heap->block_cnt) {
90 tmp = realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*));
91 if(!tmp)
92 return NULL;
93
94 heap->blocks = tmp;
95 heap->blocks[heap->block_cnt] = malloc(block_size(heap->block_cnt));
96 if(!heap->blocks[heap->block_cnt])
97 return NULL;
98
99 heap->block_cnt++;
100 }
101
102 heap->last_block++;
103 heap->offset = size;
104 return heap->blocks[heap->last_block];
105 }
106
107 list = malloc(size + sizeof(struct list));
108 if(!list)
109 return NULL;
110
111 list_add_head(&heap->custom_blocks, list);
112 return list+1;
113}
114
116{
117 void *ret;
118
119 if(mem == (BYTE*)heap->blocks[heap->last_block] + heap->offset-size
120 && heap->offset+inc < block_size(heap->last_block)) {
121 heap->offset += inc;
122 return mem;
123 }
124
126 if(ret) /* FIXME: avoid copying for custom blocks */
127 memcpy(ret, mem, size);
128 return ret;
129}
130
132{
133 struct list *tmp;
134
135 if(!heap)
136 return;
137
138 while((tmp = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
139 list_remove(tmp);
140 free(tmp);
141 }
142
143 if(WARN_ON(heap)) {
144 DWORD i;
145
146 for(i=0; i < heap->block_cnt; i++)
148 }
149
150 heap->last_block = heap->offset = 0;
151 heap->mark = FALSE;
152}
153
155{
156 DWORD i;
157
159
160 for(i=0; i < heap->block_cnt; i++)
161 free(heap->blocks[i]);
162 free(heap->blocks);
163
165}
166
168{
169 if(heap->mark)
170 return NULL;
171
172 heap->mark = TRUE;
173 return heap;
174}
175
177{
180 HRESULT hr;
181
183 {
185 if (FAILED(hr)) return hr;
186
187 hr = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IDispatch, &typeinfo);
188 ITypeLib_Release(typelib);
189 if (FAILED(hr)) return hr;
190
192 ITypeInfo_Release(typeinfo);
193 }
194
196 return S_OK;
197}
198
200{
201 *ppv = NULL;
202
204 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
205 *ppv = iface;
206 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
207 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
208 *ppv = iface;
209 }
210
211 if(*ppv) {
212 IUnknown_AddRef((IUnknown*)*ppv);
213 return S_OK;
214 }
215
216 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
217 return E_NOINTERFACE;
218}
219
221{
222 TRACE("(%p)\n", iface);
223 return 2;
224}
225
227{
228 TRACE("(%p)\n", iface);
229 return 1;
230}
231
233{
234 TRACE("(%p)->(%x)\n", iface, fLock);
235 return S_OK;
236}
237
238static const IClassFactoryVtbl VBScriptFactoryVtbl = {
244};
245
247
248static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl = {
254};
255
257
258/******************************************************************
259 * DllMain (vbscript.@)
260 */
262{
263 TRACE("(%p %ld %p)\n", hInstDLL, fdwReason, lpv);
264
265 switch(fdwReason)
266 {
269 vbscript_hinstance = hInstDLL;
270 break;
272 if (lpv) break;
273 if (dispatch_typeinfo) ITypeInfo_Release(dispatch_typeinfo);
275 }
276
277 return TRUE;
278}
279
280/***********************************************************************
281 * DllGetClassObject (vbscript.@)
282 */
284{
285 if(IsEqualGUID(&CLSID_VBScript, rclsid)) {
286 TRACE("(CLSID_VBScript %s %p)\n", debugstr_guid(riid), ppv);
287 return IClassFactory_QueryInterface(&VBScriptFactory, riid, ppv);
288 }else if(IsEqualGUID(&CLSID_VBScriptRegExp, rclsid)) {
289 TRACE("(CLSID_VBScriptRegExp %s %p)\n", debugstr_guid(riid), ppv);
290 return IClassFactory_QueryInterface(&VBScriptRegExpFactory, riid, ppv);
291 }
292
293 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
295}
static DWORD const fdwReason
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
static void list_init(struct list_entry *head)
Definition: list.h:51
#define FIXME(fmt,...)
Definition: precomp.h:53
const GUID IID_IUnknown
const GUID IID_IClassFactory
Definition: list.h:37
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
OLECHAR * BSTR
Definition: compat.h:2293
#define WINE_DECLARE_DEBUG_CHANNEL(x)
Definition: compat.h:45
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HRESULT WINAPI LoadRegTypeLib(REFGUID rguid, WORD wVerMajor, WORD wVerMinor, LCID lcid, ITypeLib **ppTLib)
Definition: typelib.c:531
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: vbscript.c:1201
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
#define GUID_NULL
Definition: ks.h:106
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define WARN_ON(c)
Definition: module.h:257
const CLSID CLSID_VBScriptRegExp
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
#define STDOLE_MINORVERNUM
Definition: oleauto.h:31
#define STDOLE_LCID
Definition: oleauto.h:32
#define STDOLE_MAJORVERNUM
Definition: oleauto.h:30
const GUID IID_IDispatch
short WCHAR
Definition: pedump.c:58
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
#define list
Definition: rosglue.h:35
__WINE_SERVER_LIST_INLINE struct list * list_next(const struct list *list, const struct list *elem)
Definition: list.h:115
#define LoadStringW
Definition: utils.h:64
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
Definition: heap.c:86
Definition: mem.c:349
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
Definition: vbregexp.c:1833
void release_regexp_typelib(void)
Definition: vbregexp.c:1849
const CLSID CLSID_VBScript
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
BSTR get_vbscript_string(int id)
Definition: vbscript_main.c:39
void heap_pool_init(heap_pool_t *heap)
Definition: vbscript_main.c:54
HRESULT get_dispatch_typeinfo(ITypeInfo **out)
heap_pool_t * heap_pool_mark(heap_pool_t *heap)
void * heap_pool_alloc(heap_pool_t *heap, size_t size)
Definition: vbscript_main.c:60
static IClassFactory VBScriptFactory
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
void * heap_pool_grow(heap_pool_t *heap, void *mem, DWORD size, DWORD inc)
static HINSTANCE vbscript_hinstance
Definition: vbscript_main.c:36
#define ARENA_FREE_FILLER
Definition: vbscript_main.c:47
static ITypeInfo * dispatch_typeinfo
Definition: vbscript_main.c:37
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
static DWORD block_size(DWORD block)
Definition: vbscript_main.c:49
void heap_pool_free(heap_pool_t *heap)
void heap_pool_clear(heap_pool_t *heap)
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
#define MIN_BLOCK_SIZE
Definition: vbscript_main.c:46
static const IClassFactoryVtbl VBScriptRegExpFactoryVtbl
static const IClassFactoryVtbl VBScriptFactoryVtbl
static IClassFactory VBScriptRegExpFactory
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:3479
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:3772
static unsigned int block
Definition: xmlmemory.c:101
unsigned char BYTE
Definition: xxhash.c:193