Compare commits

..

2 Commits

Author SHA1 Message Date
coop%netscape.com
e6066de650 Tag: LIBXPT_TYPELIB_SPEC_ADHERENT is a branch of the libxpt codebase that contains
the updates outined in the typelib spec up to and including Draft 7.

See http://www.mozilla.org/scriptable/typelib_file.html

Note: these changes have only been compiled and tested on Redhat Linux 2.2.x


git-svn-id: svn://10.0.0.236/branches/LIBXPT_TYPELIB_SPEC_ADHERENT@27335 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-13 18:14:53 +00:00
(no author)
80b8266533 This commit was manufactured by cvs2svn to create branch
'LIBXPT_TYPELIB_SPEC_ADHERENT'.

git-svn-id: svn://10.0.0.236/branches/LIBXPT_TYPELIB_SPEC_ADHERENT@27080 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-11 00:31:14 +00:00
255 changed files with 19104 additions and 18467 deletions

View File

@@ -0,0 +1,32 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
DIRS += tests
DIRS += tools
DIRS += xptinfo xptcall
include $(topsrcdir)/config/rules.mk

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
@@ -16,10 +16,11 @@
* Reserved.
*/
#ifndef __NS_JSWINREG_H__
#define __NS_JSWINREG_H__
//
// libxpt.Prefix
//
// Global prefix file for the libxpt project.
//
PRInt32
InitWinRegPrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype);
#endif
#include "MacPrefix.h"
#include "libxptConfig.h"

Binary file not shown.

View File

@@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
@@ -16,9 +16,4 @@
* Reserved.
*/
#include "nsWinRegValue.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C
/* Nothing to do here. Add libxpt-specific defines here if necessary */

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
@@ -16,10 +16,11 @@
* Reserved.
*/
#ifndef __NS_JSWINPROTOTYPE_H__
#define __NS_JSWINPROTOTYPE_H__
//
// libxptDebug.Prefix
//
// Global prefix file for the libxpt project.
//
PRInt32
InitWinProfilePrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype);
#endif
#include "MacPrefix_debug.h"
#include "libxptConfig.h"

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,3 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
@@ -17,15 +16,6 @@
DEPTH=..\..
IGNORE_MANIFEST=1
DIRS=public src tests tools xptinfo xptcall
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) progress.xul $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.css $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.html $(DIST)\bin\res\xpinstall
clobber::
rm -f $(DIST)\res\xpinstall\progress.xul
rm -f $(DIST)\res\xpinstall\progress.css
rm -f $(DIST)\res\xpinstall\progress.html

View File

@@ -2,5 +2,5 @@
# This is a list of local files which get copied to the mozilla:dist directory
#
nsISoftwareUpdate.h
nsSoftwareUpdateIIDs.h
xpt_struct.h
xpt_xdr.h

View File

@@ -0,0 +1,32 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = libxpt
EXPORTS = xpt_struct.h \
xpt_xdr.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,28 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH=..\..\..
EXPORTS = xpt_struct.h \
xpt_xdr.h \
$(NULL)
MODULE = libxpt
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,482 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* Structures matching the in-memory representation of typelib structures.
* http://www.mozilla.org/scriptable/typelib_file.html
*/
#ifndef __xpt_struct_h__
#define __xpt_struct_h__
#include "prtypes.h"
/*
* The linkage of XPT API functions differs depending on whether the file is
* used within the XPT library or not. Any source file within the XPT
* library should define EXPORT_XPT_API whereas any client of the library
* should not.
*/
#ifdef EXPORT_XPT_API
#define XPT_PUBLIC_API(t) PR_IMPLEMENT(t)
#define XPT_PUBLIC_DATA(t) PR_IMPLEMENT_DATA(t)
#else
#ifdef _WIN32
# define XPT_PUBLIC_API(t) _declspec(dllimport) t
# define XPT_PUBLIC_DATA(t) _declspec(dllimport) t
#else
# define XPT_PUBLIC_API(t) PR_IMPLEMENT(t)
# define XPT_PUBLIC_DATA(t) t
#endif
#endif
#define XPT_FRIEND_API(t) XPT_PUBLIC_API(t)
#define XPT_FRIEND_DATA(t) XPT_PUBLIC_DATA(t)
PR_BEGIN_EXTERN_C
/*
* Originally, I was going to have structures that exactly matched the on-disk
* representation, but that proved difficult: different compilers can pack
* their structs differently, and that makes overlaying them atop a
* read-from-disk byte buffer troublesome. So now I just have some structures
* that are used in memory, and we're going to write a nice XDR library to
* write them to disk and stuff. It is pure joy. -- shaver
*/
/* Structures for the typelib components */
typedef struct XPTHeader XPTHeader;
typedef struct XPTInterfaceDirectoryEntry XPTInterfaceDirectoryEntry;
typedef struct XPTInterfaceDescriptor XPTInterfaceDescriptor;
typedef struct XPTConstDescriptor XPTConstDescriptor;
typedef struct XPTMethodDescriptor XPTMethodDescriptor;
typedef struct XPTParamDescriptor XPTParamDescriptor;
typedef struct XPTTypeDescriptor XPTTypeDescriptor;
typedef struct XPTTypeDescriptorPrefix XPTTypeDescriptorPrefix;
typedef struct EnumValue EnumValue;
typedef struct EnumTypeExtras EnumTypeExtras;
typedef struct TypeDef TypeDef;
typedef struct XPTString XPTString;
typedef struct XPTAnnotation XPTAnnotation;
#ifndef nsID_h__
/*
* We can't include nsID.h, because it's full of C++ goop and we're not doing
* C++ here, so we define our own minimal struct. We protect against multiple
* definitions of this struct, though, and use the same field naming.
*/
struct nsID {
PRUint32 m0;
PRUint16 m1;
PRUint16 m2;
PRUint8 m3[8];
};
typedef struct nsID nsID;
#endif
#define XPT_COPY_IID(to, from) \
(to).m0 = (from).m0; \
(to).m1 = (from).m1; \
(to).m2 = (from).m2; \
(to).m3[0] = (from).m3[0]; \
(to).m3[1] = (from).m3[1]; \
(to).m3[2] = (from).m3[2]; \
(to).m3[3] = (from).m3[3]; \
(to).m3[4] = (from).m3[4]; \
(to).m3[5] = (from).m3[5]; \
(to).m3[6] = (from).m3[6]; \
(to).m3[7] = (from).m3[7];
/*
* Every XPCOM typelib file begins with a header.
*/
struct XPTHeader {
PRUint8 magic[16];
PRUint8 major_version;
PRUint8 minor_version;
PRUint16 num_interfaces;
PRUint32 file_length;
XPTInterfaceDirectoryEntry *interface_directory;
PRUint32 data_pool;
XPTAnnotation *annotations;
};
#define XPT_MAGIC "XPCOM\nTypeLib\r\n\032"
#define XPT_MAJOR_VERSION 0x01
#define XPT_MINOR_VERSION 0x00
extern XPT_PUBLIC_API(XPTHeader *)
XPT_NewHeader(PRUint16 num_interfaces);
/* size of header and annotations */
extern XPT_PUBLIC_API(PRUint32)
XPT_SizeOfHeader(XPTHeader *header);
/* size of header and annotations and InterfaceDirectoryEntries */
extern XPT_PUBLIC_API(PRUint32)
XPT_SizeOfHeaderBlock(XPTHeader *header);
/*
* A contiguous array of fixed-size InterfaceDirectoryEntry records begins at
* the byte offset identified by the interface_directory field in the file
* header. The array is used to quickly locate an interface description
* using its IID. No interface should appear more than once in the array.
*/
struct XPTInterfaceDirectoryEntry {
nsID iid;
char *name;
char *name_space;
XPTInterfaceDescriptor *interface_descriptor;
#if 0 /* not yet */
/* not stored on disk */
PRUint32 offset; /* the offset for an ID still to be read */
#endif
};
extern XPT_PUBLIC_API(PRBool)
XPT_FillInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
nsID *iid, char *name, char *name_space,
XPTInterfaceDescriptor *descriptor);
/*
* An InterfaceDescriptor is a variable-size record used to describe a
* single XPCOM interface, including all of its methods.
*/
struct XPTInterfaceDescriptor {
PRUint16 parent_interface;
PRUint16 num_methods;
XPTMethodDescriptor *method_descriptors;
PRUint16 num_constants;
XPTConstDescriptor *const_descriptors;
PRUint8 flags;
};
#define XPT_ID_SCRIPTABLE 0x80
#define XPT_ID_FLAGMASK 0x80
#define XPT_ID_TAGMASK (~XPT_ID_FLAGMASK)
#define XPT_ID_TAG(id) ((id).flags & XPT_ID_TAGMASK)
#define XPT_ID_IS_SCRIPTABLE(flags) (flags & XPT_ID_SCRIPTABLE)
extern XPT_PUBLIC_API(PRBool)
XPT_GetInterfaceIndexByName(XPTInterfaceDirectoryEntry *ide_block,
PRUint16 num_interfaces, char *name,
PRUint16 *indexp);
extern XPT_PUBLIC_API(XPTInterfaceDescriptor *)
XPT_NewInterfaceDescriptor(PRUint16 parent_interface, PRUint16 num_methods,
PRUint16 num_constants, PRUint8 flags);
extern XPT_PUBLIC_API(PRBool)
XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, PRUint16 num);
extern XPT_PUBLIC_API(PRBool)
XPT_InterfaceDescriptorAddConsts(XPTInterfaceDescriptor *id, PRUint16 num);
/*
* This is our special string struct with a length value associated with it,
* which means that it can contains embedded NULs.
*/
struct XPTString {
PRUint16 length;
char *bytes;
};
extern XPT_PUBLIC_API(XPTString *)
XPT_NewString(PRUint16 length, char *bytes);
extern XPT_PUBLIC_API(XPTString *)
XPT_NewStringZ(char *bytes);
/*
* A TypeDescriptor is a variable-size record used to identify the type of a
* method argument or return value.
*
* There are six types of TypeDescriptors:
*
* SimpleTypeDescriptor
* InterfaceTypeDescriptor
* InterfaceIsTypeDescriptor
* OpaqueTypeDescriptor
* NamedTypeDescriptor
*
* The tag field in the prefix indicates which of the variant TypeDescriptor
* records is being used, and hence the way any remaining fields should be
* parsed.
* 0-17 = SimpleTypeDescriptors.
* 18 = InterfaceTypeDescriptor
* 19 = InterfaceIsTypeDescriptor
* 20 = OpaqueTypeDescriptor
* 21 = NamedTypeDescriptor
* 22 = EnumTypeDescriptor
*/
/* XXX why bother with a struct? */
struct XPTTypeDescriptorPrefix {
PRUint8 flags;
};
/* flag bits -- fur and jband were right, I was miserably wrong */
#define XPT_TDP_POINTER 0x80
#define XPT_TDP_UNIQUE_POINTER 0x40
#define XPT_TDP_REFERENCE 0x20
#define XPT_TDP_FLAGMASK 0xe0
#define XPT_TDP_TAGMASK (~XPT_TDP_FLAGMASK)
#define XPT_TDP_TAG(tdp) ((tdp).flags & XPT_TDP_TAGMASK)
#define XPT_TDP_IS_POINTER(flags) (flags & XPT_TDP_POINTER)
#define XPT_TDP_IS_UNIQUE_POINTER(flags) (flags & XPT_TDP_UNIQUE_POINTER)
#define XPT_TDP_IS_REFERENCE(flags) (flags & XPT_TDP_REFERENCE)
/*
* The following enum maps mnemonic names to the different numeric values
* of XPTTypeDescriptor->tag.
*/
enum XPTTypeDescriptorTags {
TD_INT8 = 0,
TD_INT16 = 1,
TD_INT32 = 2,
TD_INT64 = 3,
TD_UINT8 = 4,
TD_UINT16 = 5,
TD_UINT32 = 6,
TD_UINT64 = 7,
TD_FLOAT = 8,
TD_DOUBLE = 9,
TD_BOOL = 10,
TD_CHAR = 11,
TD_WCHAR = 12,
TD_VOID = 13,
TD_PNSIID = 14,
TD_PBSTR = 15,
TD_PSTRING = 16,
TD_PWSTRING = 17,
TD_INTERFACE_TYPE = 18,
TD_INTERFACE_IS_TYPE = 19,
TD_OPAQUE_TYPE = 20,
TD_NAMED_TYPE = 21,
TD_ENUM_TYPE = 22
};
struct XPTTypeDescriptor {
XPTTypeDescriptorPrefix prefix;
union {
PRUint16 interface;
PRUint8 argnum;
char *type_name;
TypeDef *type_def;
EnumTypeExtras *enum_extras;
} type;
};
#define XPT_TYPEDESCRIPTOR_SIZE (1 + 4)
#define XPT_COPY_TYPE(to, from) \
(to).prefix.flags = (from).prefix.flags; \
(to).type.enum_extras = (from).type.enum_extras;
/*
* An EnumTypeDescriptor is used to define an enumeration, i.e. a type
* that in C++ would be expressed using an enum declaration. The related
* EnumValue record specifies a mapping between a single human-readable
* name and a single value in the enumeration.
*/
struct EnumTypeExtras {
XPTTypeDescriptor *type;
uint16 num_values;
EnumValue *enum_values;
};
struct EnumValue {
char *name;
char *value;
};
/*
* A TypeDef record associates a human-readable name with a module-wide
* XPCOM type. TypeDef records and TypeDescriptor records are mutually
* recursive so as to allow descriptions of complex type. That is
* TypeDefs can both point to and be pointed at by TypeDescriptor records.
*/
struct TypeDef {
char *name;
char *name_space;
XPTTypeDescriptor *type;
};
/*
* A ConstDescriptor is a variable-size record that records the name and
* value of a scoped interface constant.
*
* The types of the method parameter are restricted to the following subset
* of TypeDescriptors:
*
* int8, uint8, int16, uint16, int32, uint32,
* int64, uint64, wchar_t, char, string
*
* The type (and thus the size) of the value record is determined by the
* contents of the associated TypeDescriptor record. For instance, if type
* corresponds to int16, then value is a two-byte record consisting of a
* 16-bit signed integer. For a ConstDescriptor type of string, the value
* record is of type String*, i.e. an offset within the data pool to a
* String record containing the constant string.
*/
union XPTConstValue {
PRInt8 i8;
PRUint8 ui8;
PRInt16 i16;
PRUint16 ui16;
PRInt32 i32;
PRUint32 ui32;
PRInt64 i64;
PRUint64 ui64;
float flt;
double dbl;
PRBool bul;
char ch;
PRUint16 wch;
nsID *iid;
XPTString *string;
char *str;
PRUint16 *wstr;
}; /* varies according to type */
struct XPTConstDescriptor {
char *name;
XPTTypeDescriptor type;
union XPTConstValue value;
};
/*
* A ParamDescriptor is a variable-size record used to describe either a
* single argument to a method or a method's result.
*/
struct XPTParamDescriptor {
PRUint8 flags;
XPTTypeDescriptor type;
};
/* flag bits -- jband and fur were right, and I was miserably wrong */
#define XPT_PD_IN 0x80
#define XPT_PD_OUT 0x40
#define XPT_PD_RETVAL 0x20
#define XPT_PD_SHARED 0x10
#define XPT_PD_FLAGMASK 0xf0
#define XPT_PD_IS_IN(flags) (flags & XPT_PD_IN)
#define XPT_PD_IS_OUT(flags) (flags & XPT_PD_OUT)
#define XPT_PD_IS_RETVAL(flags) (flags & XPT_PD_RETVAL)
#define XPT_PD_IS_SHARED(flags) (flags & XPT_PD_SHARED)
#define XPT_PARAMDESCRIPTOR_SIZE (XPT_TYPEDESCRIPTOR_SIZE + 1)
extern XPT_PUBLIC_API(PRBool)
XPT_FillParamDescriptor(XPTParamDescriptor *pd, PRUint8 flags,
XPTTypeDescriptor *type);
/*
* A MethodDescriptor is a variable-size record used to describe a single
* interface method.
*/
struct XPTMethodDescriptor {
PRUint8 flags;
char *name;
PRUint8 num_args;
XPTParamDescriptor *params;
XPTParamDescriptor *result;
};
/* flag bits -- jband and fur were right, and I was miserably wrong */
#define XPT_MD_GETTER 0x80
#define XPT_MD_SETTER 0x40
#define XPT_MD_VARARGS 0x20
#define XPT_MD_CTOR 0x10
#define XPT_MD_HIDDEN 0x08
#define XPT_MD_FLAGMASK 0xf8
#define XPT_MD_IS_GETTER(flags) (flags & XPT_MD_GETTER)
#define XPT_MD_IS_SETTER(flags) (flags & XPT_MD_SETTER)
#define XPT_MD_IS_VARARGS(flags) (flags & XPT_MD_VARARGS)
#define XPT_MD_IS_CTOR(flags) (flags & XPT_MD_CTOR)
#define XPT_MD_IS_HIDDEN(flags) (flags & XPT_MD_HIDDEN)
extern XPT_PUBLIC_API(PRBool)
XPT_FillMethodDescriptor(XPTMethodDescriptor *meth, PRUint8 flags, char *name,
PRUint8 num_args);
/*
* Annotation records are variable-size records used to store secondary
* information about the typelib, e.g. such as the name of the tool that
* generated the typelib file, the date it was generated, etc. The
* information is stored with very loose format requirements so as to
* allow virtually any private data to be stored in the typelib.
*
* There are two types of Annotations:
*
* EmptyAnnotation
* PrivateAnnotation
*
* The tag field of the prefix discriminates among the variant record
* types for Annotation's. If the tag is 0, this record is an
* EmptyAnnotation. EmptyAnnotation's are ignored - they're only used to
* indicate an array of Annotation's that's completely empty. If the tag
* is 1, the record is a PrivateAnnotation.
*/
struct XPTAnnotation {
XPTAnnotation *next;
PRUint8 flags;
/* remaining fields are present in typelib iff XPT_ANN_IS_PRIVATE */
XPTString *creator;
XPTString *private_data;
};
#define XPT_ANN_LAST 0x80
#define XPT_ANN_IS_LAST(flags) (flags & XPT_ANN_LAST)
#define XPT_ANN_PRIVATE 0x40
#define XPT_ANN_IS_PRIVATE(flags) (flags & XPT_ANN_PRIVATE)
extern XPT_PUBLIC_API(XPTAnnotation *)
XPT_NewAnnotation(PRUint8 flags, XPTString *creator, XPTString *private_data);
/***************************************************************************/
/*
* XXX It's not clear that these should really be exported
*/
extern XPT_PUBLIC_API(PRUint32)
XPT_SizeOfTypeDescriptor(XPTTypeDescriptor *td);
extern XPT_PUBLIC_API(PRUint32)
XPT_SizeOfMethodDescriptor(XPTMethodDescriptor *md);
extern XPT_PUBLIC_API(PRUint32)
XPT_SizeOfConstDescriptor(XPTConstDescriptor *cd);
extern XPT_PUBLIC_API(PRUint32)
XPT_SizeOfInterfaceDescriptor(XPTInterfaceDescriptor *id);
extern XPT_PUBLIC_API(PRBool)
XPT_FillConstDescriptor(XPTConstDescriptor *cd, char *name,
XPTTypeDescriptor type, union XPTConstValue value);
PR_END_EXTERN_C
#endif /* __xpt_struct_h__ */

View File

@@ -0,0 +1,214 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* Basic APIs for streaming typelib structures to/from disk.
*/
#ifndef __xpt_xdr_h__
#define __xpt_xdr_h__
#include <nspr.h>
#include <plhash.h>
#include <prmem.h>
#include "xpt_struct.h"
PR_BEGIN_EXTERN_C
typedef struct XPTState XPTState;
typedef struct XPTDatapool XPTDatapool;
typedef struct XPTCursor XPTCursor;
extern XPT_PUBLIC_API(PRBool)
XPT_DoString(XPTCursor *cursor, XPTString **strp);
extern XPT_PUBLIC_API(PRBool)
XPT_DoStringInline(XPTCursor *cursor, XPTString **strp);
extern XPT_PUBLIC_API(PRBool)
XPT_DoCString(XPTCursor *cursor, char **strp);
extern XPT_PUBLIC_API(PRBool)
XPT_DoIdentifier(XPTCursor *cursor, char **identp);
extern XPT_PUBLIC_API(PRBool)
XPT_DoIID(XPTCursor *cursor, nsID *iidp);
extern XPT_PUBLIC_API(PRBool)
XPT_Do64(XPTCursor *cursor, PRInt64 *u64p);
extern XPT_PUBLIC_API(PRBool)
XPT_Do32(XPTCursor *cursor, PRUint32 *u32p);
extern XPT_PUBLIC_API(PRBool)
XPT_Do16(XPTCursor *cursor, PRUint16 *u16p);
extern XPT_PUBLIC_API(PRBool)
XPT_Do8(XPTCursor *cursor, PRUint8 *u8p);
/*
* When working with bitfields, use the DoBits call with a uint8.
* Only the appropriate number of bits are manipulated, so when
* you're decoding you probably want to ensure that the uint8 is pre-zeroed.
* When you're done sending bits along, use
* XPT_FlushBits to make sure that you don't eat a leading bit from the
* next structure. (You should probably be writing full bytes' worth of bits
* anyway, and zeroing out the bits you don't use, but just to be sure...)
*/
extern XPT_PUBLIC_API(PRBool)
XPT_DoBits(XPTCursor *cursor, PRUint8 *u8p, int nbits);
#define XPT_DO_BITS(curs, field, width, scr) (PR_TRUE)
/* returns the number of bits skipped, which should be 0-7 */
extern XPT_PUBLIC_API(int)
XPT_FlushBits(XPTCursor *cursor);
extern XPT_PUBLIC_API(PRBool)
XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp);
typedef enum {
XPT_ENCODE,
XPT_DECODE
} XPTMode;
typedef enum {
XPT_HEADER = 0,
XPT_DATA = 1
} XPTPool;
struct XPTState {
XPTMode mode;
PRUint32 data_offset;
PRUint32 next_cursor[2];
XPTDatapool *pool;
};
struct XPTDatapool {
PLHashTable *offset_map;
char *data;
PRUint32 count;
PRUint32 allocated;
};
struct XPTCursor {
XPTState *state;
XPTPool pool;
PRUint32 offset;
PRUint8 bits;
};
extern XPT_PUBLIC_API(XPTState *)
XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len);
extern XPT_PUBLIC_API(PRBool)
XPT_MakeCursor(XPTState *state, XPTPool pool, PRUint32 len, XPTCursor *cursor);
extern XPT_PUBLIC_API(PRBool)
XPT_SeekTo(XPTCursor *cursor, PRUint32 offset);
extern XPT_PUBLIC_API(void)
XPT_DestroyXDRState(XPTState *state);
/* Set file_length based on the data used in the state. (Only ENCODE.) */
extern XPT_PUBLIC_API(PRBool)
XPT_UpdateFileLength(XPTState *state);
extern XPT_PUBLIC_API(void)
XPT_GetXDRData(XPTState *state, XPTPool pool, char **data, PRUint32 *len);
/* set or get the data offset for the state, depending on mode */
extern XPT_PUBLIC_API(void)
XPT_DataOffset(XPTState *state, PRUint32 *data_offsetp);
extern XPT_PUBLIC_API(void)
XPT_SetDataOffset(XPTState *state, PRUint32 data_offset);
extern XPT_PUBLIC_API(PRUint32)
XPT_GetOffsetForAddr(XPTCursor *cursor, void *addr);
extern XPT_PUBLIC_API(PRBool)
XPT_SetOffsetForAddr(XPTCursor *cursor, void *addr, PRUint32 offset);
extern XPT_PUBLIC_API(PRBool)
XPT_SetAddrForOffset(XPTCursor *cursor, PRUint32 offset, void *addr);
extern XPT_PUBLIC_API(void *)
XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset);
/* all data structures are big-endian */
#if defined IS_BIG_ENDIAN
# define XPT_SWAB32(x) x
# define XPT_SWAB16(x) x
#elif defined IS_LITTLE_ENDIAN
# define XPT_SWAB32(x) (((x) >> 24) | \
(((x) >> 8) & 0xff00) | \
(((x) << 8) & 0xff0000) | \
((x) << 24))
# define XPT_SWAB16(x) (((x) >> 8) | ((x) << 8))
#else
# error "unknown byte order"
#endif
/*
* If we're decoding, we want to read the offset before we check
* for already-decoded values.
*
* Then we check for repetition: CheckForRepeat will see if we've already
* encoded/decoded this value, and if so will set offset/addr correctly
* and make already be true. If not, it will set up the cursor for
* encoding (reserve space) or decoding (seek to correct location) as
* appropriate. In the encode case, it will also set the addr->offset
* mapping.
*/
#define XPT_PREAMBLE_(cursor, addrp, pool, size, new_curs, already) \
XPTMode mode = cursor->state->mode; \
if (!(mode == XPT_ENCODE || XPT_Do32(cursor, &new_curs.offset)) || \
!CheckForRepeat(cursor, (void **)addrp, pool, \
mode == XPT_ENCODE ? size : 0, &new_curs, \
&already) || \
!(mode == XPT_DECODE || XPT_Do32(cursor, &new_curs.offset))) \
return PR_FALSE; \
if (already) \
return PR_TRUE; \
#define XPT_PREAMBLE(cursor, addrp, pool, size, new_curs, already, \
XPTType, localp) \
{ \
XPT_PREAMBLE_(cursor, addrp, pool, size, new_curs, already); \
XPT_ALLOC(addrp, new_curs, XPTType, localp) \
}
#define XPT_PREAMBLE_NO_ALLOC(cursor, addrp, pool, size, new_curs, already) \
{ \
XPT_PREAMBLE_(cursor, addrp, pool, size, new_curs, already) \
}
#define XPT_ERROR_HANDLE(free_it) \
error: \
if (cursor->state->mode == XPT_DECODE) \
PR_FREEIF(free_it); \
return PR_FALSE;
PR_END_EXTERN_C
#endif /* __xpt_xdr_h__ */

View File

@@ -0,0 +1,37 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = libxpt
LIBRARY_NAME = xpt
CSRCS = xpt_struct.c \
xpt_xdr.c \
$(NULL)
REQUIRES = $(MODULE)
# build libxpt (but not xptinfo, xptcall subdirs) early so that it'll be
# available to xpidl, which also must be built early.
export:: libs
include $(topsrcdir)/config/rules.mk

View File

@@ -14,36 +14,39 @@
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
MAKE_OBJ_TYPE = EXE
PROGRAM = .\$(OBJDIR)\xpinstall.exe
IGNORE_MANIFEST=1
OBJS = \
.\$(OBJDIR)\standalone.obj \
.\$(OBJDIR)\nsSimpleConsoleProgressNotifier.obj \
MAKE_OBJ_TYPE = DLL
DEPTH=..\..\..
LIBNAME = .\$(OBJDIR)\libxpt$(MOZ_BITS)
DLL = $(LIBNAME).dll
LCFLAGS = -DEXPORT_XPT_API -DWIN32_LEAN_AND_MEAN
LINCS = \
-I$(PUBLIC)\libxpt \
$(NULL)
LLIBS = \
$(DIST)\lib\xpinstall.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\xpcom32.lib \
$(LIBNSPR) \
$(NULL)
LLIBS = $(LIBNSPR) \
$(NULL)
LINCS = \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\xpinstall \
-I$(PUBLIC)\raptor \
$(NULL)
CSRCS = \
xpt_struct.c \
xpt_xdr.c \
$(NULL)
C_OBJS = \
.\$(OBJDIR)\xpt_struct.obj \
.\$(OBJDIR)\xpt_xdr.obj \
$(NULL)
MODULE = libxpt
include <$(DEPTH)\config\rules.mak>
export:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
clobber::
rm -f $(DIST)\bin\xpinstall.exe
$(PROGRAM):: $(OBJS) $(LLIBS)
export:: $(DLL)
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib

View File

@@ -0,0 +1,898 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implementation of XDR routines for typelib structures. */
#include "xpt_xdr.h"
#include "xpt_struct.h"
#include <string.h>
#ifdef XP_MAC
static char *strdup(const char *c)
{
char *newStr = malloc(strlen(c) + 1);
if (newStr)
{
strcpy(newStr, c);
}
return newStr;
}
#endif
static PRBool
DoInterfaceDirectoryEntry(XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide, PRUint16 index);
static PRBool
DoInterfaceDirectoryEntryIndex(XPTCursor *cursor,
XPTInterfaceDirectoryEntry **idep);
static PRBool
DoConstDescriptor(XPTCursor *cursor, XPTConstDescriptor *cd);
static PRBool
DoMethodDescriptor(XPTCursor *cursor, XPTMethodDescriptor *md);
static PRBool
DoAnnotation(XPTCursor *cursor, XPTAnnotation **annp);
static PRBool
DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp);
static PRBool
DoTypeDescriptor(XPTCursor *cursor, XPTTypeDescriptor *td);
static PRBool
DoTypeDef(XPTCursor *cursor, TypeDef *type_def);
static PRBool
DoEnumTypeExtras(XPTCursor *cursor, EnumTypeExtras *enum_extras);
static PRBool
DoEnumValue(XPTCursor *cursor, EnumValue *enum_value);
static PRBool
DoTypeDescriptorPrefix(XPTCursor *cursor, XPTTypeDescriptorPrefix *tdp);
static PRBool
DoTypeDescriptor(XPTCursor *cursor, XPTTypeDescriptor *td);
static PRBool
DoParamDescriptor(XPTCursor *cursor, XPTParamDescriptor *pd);
#define CURS_POOL_OFFSET_RAW(cursor) \
((cursor)->pool == XPT_HEADER \
? (cursor)->offset \
: (PR_ASSERT((cursor)->state->data_offset), \
(cursor)->offset + (cursor)->state->data_offset))
#define CURS_POOL_OFFSET(cursor) \
(CURS_POOL_OFFSET_RAW(cursor) - 1)
XPT_PUBLIC_API(PRUint32)
XPT_SizeOfHeader(XPTHeader *header)
{
XPTAnnotation *ann, *last;
PRUint32 size = 16 /* magic */ +
1 /* major */ + 1 /* minor */ +
2 /* num_interfaces */ + 4 /* file_length */ +
4 /* interface_directory */ + 4 /* data_pool */;
ann = header->annotations;
do {
size += 1; /* Annotation prefix */
if (XPT_ANN_IS_PRIVATE(ann->flags))
size += 2 + ann->creator->length + 2 + ann->private_data->length;
last = ann;
ann = ann->next;
} while (!XPT_ANN_IS_LAST(last->flags));
return size;
}
XPT_PUBLIC_API(PRUint32)
XPT_SizeOfHeaderBlock(XPTHeader *header)
{
PRUint32 size = XPT_SizeOfHeader(header);
size += header->num_interfaces * sizeof (XPTInterfaceDirectoryEntry);
return size;
}
XPT_PUBLIC_API(XPTHeader *)
XPT_NewHeader(PRUint16 num_interfaces)
{
XPTHeader *header = PR_NEWZAP(XPTHeader);
if (!header)
return NULL;
memcpy(header->magic, XPT_MAGIC, 16);
header->major_version = XPT_MAJOR_VERSION;
header->minor_version = XPT_MINOR_VERSION;
header->num_interfaces = num_interfaces;
header->interface_directory = PR_CALLOC(num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
if (!header->interface_directory) {
PR_DELETE(header);
return NULL;
}
header->data_pool = 0; /* XXX do we even need this struct any more? */
return header;
}
XPT_PUBLIC_API(PRBool)
XPT_DoHeader(XPTCursor *cursor, XPTHeader **headerp)
{
XPTMode mode = cursor->state->mode;
XPTHeader *header;
PRUint32 ide_offset;
int i;
if (mode == XPT_DECODE) {
header = PR_NEWZAP(XPTHeader);
if (!header)
return PR_FALSE;
*headerp = header;
} else {
header = *headerp;
}
if (mode == XPT_ENCODE) {
/* IDEs appear after header, including annotations */
ide_offset = XPT_SizeOfHeader(*headerp) + 1; /* one-based offset */
header->data_pool = XPT_SizeOfHeaderBlock(*headerp);
XPT_SetDataOffset(cursor->state, header->data_pool);
}
for (i = 0; i < 16; i++) {
if (!XPT_Do8(cursor, &header->magic[i]))
goto error;
}
if(!XPT_Do8(cursor, &header->major_version) ||
!XPT_Do8(cursor, &header->minor_version) ||
/* XXX check major for compat! */
!XPT_Do16(cursor, &header->num_interfaces) ||
!XPT_Do32(cursor, &header->file_length) ||
!XPT_Do32(cursor, &ide_offset)) {
goto error;
}
if (mode == XPT_ENCODE)
XPT_DataOffset(cursor->state, &header->data_pool);
if (!XPT_Do32(cursor, &header->data_pool))
goto error;
if (mode == XPT_DECODE)
XPT_DataOffset(cursor->state, &header->data_pool);
if (mode == XPT_DECODE) {
header->interface_directory =
PR_CALLOC(header->num_interfaces *
sizeof(XPTInterfaceDirectoryEntry));
if (!header->interface_directory)
goto error;
}
if (!DoAnnotation(cursor, &header->annotations))
goto error;
/* shouldn't be necessary now, but maybe later */
XPT_SeekTo(cursor, ide_offset);
for (i = 0; i < header->num_interfaces; i++) {
if (!DoInterfaceDirectoryEntry(cursor,
&header->interface_directory[i],
(PRUint16)(i + 1)))
goto error;
}
return PR_TRUE;
/* XXX need to free child data sometimes! */
XPT_ERROR_HANDLE(header);
}
XPT_PUBLIC_API(PRBool)
XPT_FillInterfaceDirectoryEntry(XPTInterfaceDirectoryEntry *ide,
nsID *iid, char *name, char *name_space,
XPTInterfaceDescriptor *descriptor)
{
XPT_COPY_IID(ide->iid, *iid);
ide->name = name ? strdup(name) : NULL; /* what good is it w/o a name? */
ide->name_space = name_space ? strdup(name_space) : NULL;
ide->interface_descriptor = descriptor;
return PR_TRUE;
}
/* InterfaceDirectoryEntry records go in the header */
PRBool
DoInterfaceDirectoryEntry(XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide, PRUint16 index)
{
XPTMode mode = cursor->state->mode;
/* write the IID in our cursor space */
if (!XPT_DoIID(cursor, &(ide->iid)) ||
/* write the name string in the data pool, and the offset in our
cursor space */
!XPT_DoCString(cursor, &(ide->name)) ||
/* write the name_space string in the data pool, and the offset in our
cursor space */
!XPT_DoCString(cursor, &(ide->name_space)) ||
/* do InterfaceDescriptors -- later, only on encode (see below) */
!DoInterfaceDescriptor(cursor, &ide->interface_descriptor)) {
goto error;
}
if (mode == XPT_DECODE)
XPT_SetOffsetForAddr(cursor, ide, index);
#if 0 /* not yet -- we eagerly load for now */
/* write the InterfaceDescriptor in the data pool, and the offset
in our cursor space, but only if we're encoding. */
if (mode == XPT_ENCODE) {
if (!DoInterfaceDescriptor(cursor,
&ide->interface_descriptor)) {
goto error;
}
}
#endif
return PR_TRUE;
XPT_ERROR_HANDLE(ide);
}
/*
* Decode: Get the interface directory entry for the on-disk index.
* Encode: Write the index.
*/
PRBool
DoInterfaceDirectoryEntryIndex(XPTCursor *cursor,
XPTInterfaceDirectoryEntry **idep)
{
XPTMode mode = cursor->state->mode;
PRUint16 index;
if (mode == XPT_ENCODE) {
/* XXX index zero is legal, so how do I detect an error? */
if (*idep) {
index = (PRUint16) XPT_GetOffsetForAddr(cursor, *idep);
if (!index)
return PR_FALSE;
} else {
index = 0; /* no interface */
}
}
if (!XPT_Do16(cursor, &index))
return PR_FALSE;
if (mode == XPT_DECODE) {
if (index) {
*idep = XPT_GetAddrForOffset(cursor, index);
if (!*idep)
return PR_FALSE;
} else {
*idep = NULL;
}
}
return PR_TRUE;
}
XPT_PUBLIC_API(XPTInterfaceDescriptor *)
XPT_NewInterfaceDescriptor(PRUint16 parent_interface, PRUint16 num_methods,
PRUint16 num_constants, PRUint8 flags)
{
XPTInterfaceDescriptor *id = PR_NEWZAP(XPTInterfaceDescriptor);
if (!id)
return NULL;
if (num_methods) {
id->method_descriptors = PR_CALLOC(num_methods *
sizeof(XPTMethodDescriptor));
if (!id->method_descriptors)
goto free_id;
id->num_methods = num_methods;
}
if (num_constants) {
id->const_descriptors = PR_CALLOC(num_constants *
sizeof(XPTConstDescriptor));
if (!id->const_descriptors)
goto free_meth;
id->num_constants = num_constants;
}
if (parent_interface) {
id->parent_interface = parent_interface;
} else {
id->parent_interface = 0;
}
id->flags = flags;
return id;
free_meth:
PR_FREEIF(id->method_descriptors);
free_id:
PR_DELETE(id);
return NULL;
}
XPT_PUBLIC_API(PRBool)
XPT_InterfaceDescriptorAddMethods(XPTInterfaceDescriptor *id, PRUint16 num)
{
XPTMethodDescriptor *old = id->method_descriptors, *new;
/* XXX should grow in chunks to minimize realloc overhead */
new = PR_REALLOC(old,
(id->num_methods + num) * sizeof(XPTMethodDescriptor));
if (!new)
return PR_FALSE;
memset(new + id->num_methods, 0, sizeof(XPTMethodDescriptor) * num);
id->method_descriptors = new;
id->num_methods += num;
return PR_TRUE;
}
XPT_PUBLIC_API(PRBool)
XPT_InterfaceDescriptorAddConsts(XPTInterfaceDescriptor *id, PRUint16 num)
{
XPTConstDescriptor *old = id->const_descriptors, *new;
/* XXX should grow in chunks to minimize realloc overhead */
new = PR_REALLOC(old,
(id->num_constants + num) * sizeof(XPTConstDescriptor));
if (!new)
return PR_FALSE;
memset(new + id->num_constants, 0, sizeof(XPTConstDescriptor) * num);
id->const_descriptors = new;
id->num_constants += num;
return PR_TRUE;
}
XPT_PUBLIC_API(PRUint32)
XPT_SizeOfTypeDescriptor(XPTTypeDescriptor *td)
{
PRUint32 size = 1; /* prefix */
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE)
size += 2; /* interface_index */
else if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_IS_TYPE)
size += 1; /* arg_num */
else if (XPT_TDP_TAG(td->prefix) == TD_OPAQUE_TYPE)
size += 4; /* type_name */
else if (XPT_TDP_TAG(td->prefix) == TD_NAMED_TYPE)
size += 4; /* type */
else if (XPT_TDP_TAG(td->prefix) == TD_ENUM_TYPE)
size += 4; /* enum_extras */
return size;
}
XPT_PUBLIC_API(PRUint32)
XPT_SizeOfMethodDescriptor(XPTMethodDescriptor *md)
{
PRUint32 i, size = 1 /* flags */ + 4 /* name */ + 1 /* num_args */;
for (i = 0; i < md->num_args; i++)
size += 1 + XPT_SizeOfTypeDescriptor(&md->params[i].type);
size += 1 + XPT_SizeOfTypeDescriptor(&md->result->type);
return size;
}
XPT_PUBLIC_API(PRUint32)
XPT_SizeOfConstDescriptor(XPTConstDescriptor *cd)
{
PRUint32 size = 4 /* name */ + XPT_SizeOfTypeDescriptor(&cd->type);
switch (XPT_TDP_TAG(cd->type.prefix)) {
case TD_INT8:
case TD_UINT8:
case TD_CHAR:
size ++;
break;
case TD_INT16:
case TD_UINT16:
case TD_WCHAR:
size += 2;
break;
case TD_INT32:
case TD_UINT32:
case TD_PBSTR: /* XXX check for pointer! */
case TD_PSTRING:
size += 4;
break;
case TD_INT64:
case TD_UINT64:
size += 8;
break;
default:
fprintf(stderr, "libxpt: illegal type in ConstDescriptor: 0x%02x\n",
XPT_TDP_TAG(cd->type.prefix));
return 0;
}
return size;
}
XPT_PUBLIC_API(PRUint32)
XPT_SizeOfInterfaceDescriptor(XPTInterfaceDescriptor *id)
{
PRUint32 size = 2 /* parent interface */ + 2 /* num_methods */
+ 2 /* num_constants */ + 1 /* flags */, i;
for (i = 0; i < id->num_methods; i++)
size += XPT_SizeOfMethodDescriptor(&id->method_descriptors[i]);
for (i = 0; i < id->num_constants; i++)
size += XPT_SizeOfConstDescriptor(&id->const_descriptors[i]);
return size;
}
PRBool
DoInterfaceDescriptor(XPTCursor *outer, XPTInterfaceDescriptor **idp)
{
XPTMode mode = outer->state->mode;
XPTInterfaceDescriptor *id;
XPTCursor curs, *cursor = &curs;
PRUint32 i, id_sz = 0;
if (mode == XPT_DECODE) {
id = PR_NEWZAP(XPTInterfaceDescriptor);
if (!id)
return PR_FALSE;
*idp = id;
} else {
id = *idp;
if (!id) {
id_sz = 0;
return XPT_Do32(outer, &id_sz);
}
id_sz = XPT_SizeOfInterfaceDescriptor(id);
}
if (!XPT_MakeCursor(outer->state, XPT_DATA, id_sz, cursor))
goto error;
if (!XPT_Do32(outer, &cursor->offset))
goto error;
if (mode == XPT_DECODE && !cursor->offset) {
*idp = NULL;
return PR_TRUE;
}
if(!XPT_Do16(cursor, &id->parent_interface) ||
!XPT_Do16(cursor, &id->num_methods)) {
goto error;
}
if (mode == XPT_DECODE && id->num_methods) {
id->method_descriptors = PR_CALLOC(id->num_methods *
sizeof(XPTMethodDescriptor));
if (!id->method_descriptors)
goto error;
}
for (i = 0; i < id->num_methods; i++) {
if (!DoMethodDescriptor(cursor, &id->method_descriptors[i]))
goto error;
}
if (!XPT_Do16(cursor, &id->num_constants)) {
goto error;
}
if (mode == XPT_DECODE)
id->const_descriptors = PR_CALLOC(id->num_constants *
sizeof(XPTConstDescriptor));
for (i = 0; i < id->num_constants; i++) {
if (!DoConstDescriptor(cursor, &id->const_descriptors[i])) {
goto error;
}
}
if (!XPT_Do8(cursor, &id->flags)) {
goto error;
}
return PR_TRUE;
XPT_ERROR_HANDLE(id);
}
XPT_PUBLIC_API(PRBool)
XPT_FillConstDescriptor(XPTConstDescriptor *cd, char *name,
XPTTypeDescriptor type, union XPTConstValue value)
{
cd->name = strdup(name);
if (!cd->name)
return PR_FALSE;
XPT_COPY_TYPE(cd->type, type);
/* XXX copy value */
return PR_TRUE;
}
PRBool
DoConstDescriptor(XPTCursor *cursor, XPTConstDescriptor *cd)
{
PRBool ok = PR_FALSE;
if (!XPT_DoCString(cursor, &cd->name) ||
!DoTypeDescriptor(cursor, &cd->type)) {
return PR_FALSE;
}
switch(XPT_TDP_TAG(cd->type.prefix)) {
case TD_INT8:
ok = XPT_Do8(cursor, (PRUint8*) &cd->value.i8);
break;
case TD_INT16:
ok = XPT_Do16(cursor, (PRUint16*) &cd->value.i16);
break;
case TD_INT32:
ok = XPT_Do32(cursor, (PRUint32*) &cd->value.i32);
break;
case TD_INT64:
ok = XPT_Do64(cursor, &cd->value.i64);
break;
case TD_UINT8:
ok = XPT_Do8(cursor, &cd->value.ui8);
break;
case TD_UINT16:
ok = XPT_Do16(cursor, &cd->value.ui16);
break;
case TD_UINT32:
ok = XPT_Do32(cursor, &cd->value.ui32);
break;
case TD_UINT64:
ok = XPT_Do64(cursor, &cd->value.ui64);
break;
case TD_CHAR:
ok = XPT_Do8(cursor, (PRUint8*) &cd->value.ch);
break;
case TD_WCHAR:
ok = XPT_Do16(cursor, &cd->value.wch);
break;
case TD_PBSTR:
if (cd->type.prefix.flags & XPT_TDP_POINTER) {
ok = XPT_DoString(cursor, &cd->value.string);
break;
}
/* fall-through */
default:
fprintf(stderr, "illegal type!\n");
break;
}
return ok;
}
XPT_PUBLIC_API(PRBool)
XPT_FillMethodDescriptor(XPTMethodDescriptor *meth, PRUint8 flags, char *name,
PRUint8 num_args)
{
meth->flags = flags & XPT_MD_FLAGMASK;
meth->name = strdup(name);
if (!name)
return PR_FALSE;
meth->num_args = num_args;
if (meth->num_args) {
meth->params = PR_CALLOC(num_args * sizeof(XPTParamDescriptor));
if (!meth->params)
goto free_name;
} else {
meth->params = NULL;
}
meth->result = PR_NEWZAP(XPTParamDescriptor);
if (!meth->result)
goto free_params;
return PR_TRUE;
free_params:
PR_DELETE(meth->params);
free_name:
PR_DELETE(meth->name);
return PR_FALSE;
}
PRBool
DoMethodDescriptor(XPTCursor *cursor, XPTMethodDescriptor *md)
{
XPTMode mode = cursor->state->mode;
int i;
if (!XPT_Do8(cursor, &md->flags) ||
!XPT_DoCString(cursor, &md->name) ||
!XPT_Do8(cursor, &md->num_args))
return PR_FALSE;
if (mode == XPT_DECODE && md->num_args) {
md->params = PR_CALLOC(md->num_args * sizeof(XPTParamDescriptor));
if (!md->params)
return PR_FALSE;
}
for(i = 0; i < md->num_args; i++) {
if (!DoParamDescriptor(cursor, &md->params[i]))
goto error;
}
if (mode == XPT_DECODE) {
md->result = PR_NEWZAP(XPTParamDescriptor);
if (!md->result)
return PR_FALSE;
}
if (!md->result ||
!DoParamDescriptor(cursor, md->result))
goto error;
return PR_TRUE;
XPT_ERROR_HANDLE(md->params);
}
XPT_PUBLIC_API(PRBool)
XPT_FillParamDescriptor(XPTParamDescriptor *pd, PRUint8 flags,
XPTTypeDescriptor *type)
{
pd->flags = flags & XPT_PD_FLAGMASK;
XPT_COPY_TYPE(pd->type, *type);
return PR_TRUE;
}
PRBool
DoParamDescriptor(XPTCursor *cursor, XPTParamDescriptor *pd)
{
if (!XPT_Do8(cursor, &pd->flags) ||
!DoTypeDescriptor(cursor, &pd->type))
return PR_FALSE;
return PR_TRUE;
}
/* XXX when we lose the useless TDP wrapper struct, #define this to Do8 */
PRBool
DoTypeDescriptorPrefix(XPTCursor *cursor, XPTTypeDescriptorPrefix *tdp)
{
return XPT_Do8(cursor, &tdp->flags);
}
PRBool
DoTypeDescriptor(XPTCursor *cursor, XPTTypeDescriptor *td)
{
if (!DoTypeDescriptorPrefix(cursor, &td->prefix)) {
goto error;
}
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE) {
if (!XPT_Do16(cursor, &td->type.interface))
goto error;
} else if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_IS_TYPE) {
if (!XPT_Do8(cursor, &td->type.argnum))
goto error;
} else if (XPT_TDP_TAG(td->prefix) == TD_OPAQUE_TYPE) {
if (!XPT_DoCString(cursor, &td->type.type_name))
goto error;
} else if (XPT_TDP_TAG(td->prefix) == TD_NAMED_TYPE) {
if (!DoTypeDef(cursor, td->type.type_def))
goto error;
} else if (XPT_TDP_TAG(td->prefix) == TD_ENUM_TYPE) {
if (!DoEnumTypeExtras(cursor, td->type.enum_extras))
goto error;
}
return PR_TRUE;
XPT_ERROR_HANDLE(td);
}
PRBool
DoTypeDef(XPTCursor *cursor, TypeDef *type_def)
{
XPTMode mode = cursor->state->mode;
uint16 index;
if (!XPT_DoCString(cursor, &type_def->name))
goto error;
if (!XPT_DoCString(cursor, &type_def->name_space))
goto error;
if (mode == XPT_ENCODE) {
/* XXX index zero is legal, so how do I detect an error? */
if (&type_def->type) {
index = XPT_GetOffsetForAddr(cursor, &type_def->type);
if (!index)
return PR_FALSE;
} else {
index = 0; /* no interface */
}
}
if (!XPT_Do16(cursor, &index))
return PR_FALSE;
if (mode == XPT_DECODE) {
if (index) {
type_def->type = XPT_GetAddrForOffset(cursor, index);
if (!type_def->type)
return PR_FALSE;
} else {
type_def->type = NULL;
}
}
return PR_TRUE;
XPT_ERROR_HANDLE(type_def);
}
PRBool
DoEnumTypeExtras(XPTCursor *cursor, EnumTypeExtras *enum_extras)
{
XPTMode mode = cursor->state->mode;
uint16 index;
uint32 i;
if (mode == XPT_ENCODE) {
/* XXX index zero is legal, so how do I detect an error? */
if (&enum_extras->type) {
index = XPT_GetOffsetForAddr(cursor, &enum_extras->type);
if (!index)
return PR_FALSE;
} else {
index = 0; /* no interface */
}
}
if (!XPT_Do16(cursor, &index))
return PR_FALSE;
if (mode == XPT_DECODE) {
if (index) {
enum_extras->type = XPT_GetAddrForOffset(cursor, index);
if (!enum_extras->type)
return PR_FALSE;
} else {
enum_extras->type = NULL;
}
}
if (!XPT_Do16(cursor, &enum_extras->num_values))
goto error;
for (i = 0; i < enum_extras->num_values; i++) {
if (!DoEnumValue(cursor, &enum_extras->enum_values[i]))
goto error;
}
return PR_TRUE;
XPT_ERROR_HANDLE(enum_extras);
}
PRBool
DoEnumValue(XPTCursor *cursor, EnumValue *enum_value)
{
if (!XPT_DoCString(cursor, &enum_value->name))
goto error;
if (!XPT_DoCString(cursor, &enum_value->value))
goto error;
return PR_TRUE;
XPT_ERROR_HANDLE(enum_value);
}
XPT_PUBLIC_API(XPTAnnotation *)
XPT_NewAnnotation(PRUint8 flags, XPTString *creator, XPTString *private_data)
{
XPTAnnotation *ann = PR_NEWZAP(XPTAnnotation);
if (!ann)
return NULL;
ann->flags = flags;
if (XPT_ANN_IS_PRIVATE(flags)) {
ann->creator = creator;
ann->private_data = private_data;
}
return ann;
}
PRBool
DoAnnotation(XPTCursor *cursor, XPTAnnotation **annp)
{
XPTMode mode = cursor->state->mode;
XPTAnnotation *ann;
if (mode == XPT_DECODE) {
ann = PR_NEWZAP(XPTAnnotation);
if (!ann)
return PR_FALSE;
*annp = ann;
} else {
ann = *annp;
}
if (!XPT_Do8(cursor, &ann->flags))
goto error;
if (XPT_ANN_IS_PRIVATE(ann->flags)) {
if (!XPT_DoStringInline(cursor, &ann->creator) ||
!XPT_DoStringInline(cursor, &ann->private_data))
goto error_2;
}
/*
* If a subsequent Annotation fails, what to do?
* - free all annotations, return PR_FALSE? (current behaviour)
* - free failed annotation only, return PR_FALSE (caller can check for
* non-NULL *annp on PR_FALSE return to detect partial annotation
* decoding)?
*/
if (!XPT_ANN_IS_LAST(ann->flags) &&
!DoAnnotation(cursor, &ann->next))
goto error_2;
return PR_TRUE;
error_2:
if (ann && XPT_ANN_IS_PRIVATE(ann->flags)) {
PR_FREEIF(ann->creator);
PR_FREEIF(ann->private_data);
}
XPT_ERROR_HANDLE(ann);
}
PRBool
XPT_GetInterfaceIndexByName(XPTInterfaceDirectoryEntry *ide_block,
PRUint16 num_interfaces, char *name,
PRUint16 *indexp)
{
int i;
for (i=1; i<=num_interfaces; i++) {
fprintf(stderr, "%s == %s ?\n", ide_block[i].name, name);
if (strcmp(ide_block[i].name, name) == 0) {
*indexp = i;
return PR_TRUE;
}
}
indexp = 0;
return PR_FALSE;
}
#if 0 /* need hashtables and stuff */
XPT_PUBLIC_API(XPTInterfaceDescriptor *)
XPT_GetDescriptorByIndex(XPTCursor *cursor, XPTHeader *header, PRUint16 index)
{
XPTInterfaceDescriptor *id = header->interface_directory + index;
if (id)
return id; /* XXX refcnt? */
/* XXX lazily load and allocate later, for now we always read them all
in */
return id;
}
#endif

View File

@@ -0,0 +1,600 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implementation of XDR primitives. */
#include "xpt_xdr.h"
#include <nspr.h>
#include <string.h> /* strchr */
static PRBool
CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len,
XPTCursor *new_cursor, PRBool *already);
#define ENCODING(cursor) \
((cursor)->state->mode == XPT_ENCODE)
#define CURS_POOL_OFFSET_RAW(cursor) \
((cursor)->pool == XPT_HEADER \
? (cursor)->offset \
: (PR_ASSERT((cursor)->state->data_offset), \
(cursor)->offset + (cursor)->state->data_offset))
#define CURS_POOL_OFFSET(cursor) \
(CURS_POOL_OFFSET_RAW(cursor) - 1)
/* can be used as lvalue */
#define CURS_POINT(cursor) \
((cursor)->state->pool->data[CURS_POOL_OFFSET(cursor)])
#ifdef DEBUG_shaver
#define DBG(x) printf##x
#else
#define DBG(x) (0)
#endif
/* XXX fail if XPT_DATA and !state->data_offset */
#define CHECK_COUNT_(cursor, space) \
/* if we're in the header, then exceeding the data_offset is illegal */ \
((cursor)->pool == XPT_HEADER ? \
(ENCODING(cursor) && \
((cursor)->state->data_offset && \
((cursor)->offset - 1 + (space) > (cursor)->state->data_offset)) \
? (DBG(("no space left in HEADER %d + %d > %d\n", (cursor)->offset, \
(space), (cursor)->state->data_offset)) && PR_FALSE) \
: PR_TRUE) : \
/* if we're in the data area and we're about to exceed the allocation */ \
(CURS_POOL_OFFSET(cursor) + (space) > (cursor)->state->pool->allocated ? \
/* then grow if we're in ENCODE mode */ \
(ENCODING(cursor) ? GrowPool((cursor)->state->pool) \
/* and fail if we're in DECODE mode */ \
: (DBG(("can't extend in DECODE")) && PR_FALSE)) \
/* otherwise we're OK */ \
: PR_TRUE))
#define CHECK_COUNT(cursor, space) \
(CHECK_COUNT_(cursor, space) \
? PR_TRUE \
: (PR_ASSERT(0), \
fprintf(stderr, "FATAL: can't no room for %d in cursor\n", space), \
PR_FALSE))
/* increase the data allocation for the pool by XPT_GROW_CHUNK */
#define XPT_GROW_CHUNK 8192
static PLHashNumber
null_hash(const void *key)
{
return (PLHashNumber)key;
}
XPT_PUBLIC_API(XPTState *)
XPT_NewXDRState(XPTMode mode, char *data, PRUint32 len)
{
XPTState *state;
state = PR_NEW(XPTState);
if (!state)
return NULL;
state->mode = mode;
state->pool = PR_NEW(XPTDatapool);
state->next_cursor[0] = state->next_cursor[1] = 1;
if (!state->pool)
goto err_free_state;
state->pool->count = 0;
state->pool->offset_map = PL_NewHashTable(32, null_hash, PL_CompareValues,
PL_CompareValues, NULL, NULL);
if (!state->pool->offset_map)
goto err_free_pool;
if (mode == XPT_DECODE) {
state->pool->data = data;
state->pool->allocated = len;
} else {
state->pool->data = PR_MALLOC(XPT_GROW_CHUNK);
if (!state->pool->data)
goto err_free_hash;
state->pool->allocated = XPT_GROW_CHUNK;
}
return state;
err_free_hash:
PL_HashTableDestroy(state->pool->offset_map);
err_free_pool:
PR_DELETE(state->pool);
err_free_state:
PR_DELETE(state);
return NULL;
}
XPT_PUBLIC_API(void)
XPT_DestroyXDRState(XPTState *state)
{
if (state->mode == XPT_ENCODE)
PR_DELETE(state->pool->data);
PR_DELETE(state->pool);
PR_DELETE(state);
}
XPT_PUBLIC_API(void)
XPT_GetXDRData(XPTState *state, XPTPool pool, char **data, PRUint32 *len)
{
if (pool == XPT_HEADER) {
*data = state->pool->data;
} else {
*data = state->pool->data + state->data_offset;
}
*len = state->next_cursor[pool] - 1;
}
/* All offsets are 1-based */
XPT_PUBLIC_API(void)
XPT_DataOffset(XPTState *state, PRUint32 *data_offsetp)
{
if (state->mode == XPT_DECODE)
XPT_SetDataOffset(state, *data_offsetp);
else
*data_offsetp = state->data_offset;
}
XPT_PUBLIC_API(void)
XPT_SetDataOffset(XPTState *state, PRUint32 data_offset)
{
state->data_offset = data_offset;
}
static PRBool
GrowPool(XPTDatapool *pool)
{
char *newdata = realloc(pool->data, pool->allocated + XPT_GROW_CHUNK);
if (!newdata)
return PR_FALSE;
pool->data = newdata;
pool->allocated += XPT_GROW_CHUNK;
return PR_TRUE;
}
XPT_PUBLIC_API(PRBool)
XPT_MakeCursor(XPTState *state, XPTPool pool, PRUint32 len, XPTCursor *cursor)
{
cursor->state = state;
cursor->pool = pool;
cursor->bits = 0;
cursor->offset = state->next_cursor[pool];
if (!CHECK_COUNT(cursor, len))
return PR_FALSE;
/* this check should be in CHECK_CURSOR */
if (pool == XPT_DATA && !state->data_offset) {
fprintf(stderr, "no data offset for XPT_DATA cursor!\n");
return PR_FALSE;
}
state->next_cursor[pool] += len;
return PR_TRUE;
}
XPT_PUBLIC_API(PRBool)
XPT_SeekTo(XPTCursor *cursor, PRUint32 offset)
{
/* XXX do some real checking and update len and stuff */
cursor->offset = offset;
return PR_TRUE;
}
XPT_PUBLIC_API(XPTString *)
XPT_NewString(PRUint16 length, char *bytes)
{
XPTString *str = PR_NEW(XPTString);
if (!str)
return NULL;
str->length = length;
str->bytes = malloc(length);
if (!str->bytes) {
PR_DELETE(str);
return NULL;
}
memcpy(str->bytes, bytes, length);
return str;
}
XPT_PUBLIC_API(XPTString *)
XPT_NewStringZ(char *bytes)
{
PRUint32 length = strlen(bytes);
if (length > 0xffff)
return NULL; /* too long */
return XPT_NewString((PRUint16)length, bytes);
}
XPT_PUBLIC_API(PRBool)
XPT_DoStringInline(XPTCursor *cursor, XPTString **strp)
{
XPTString *str = *strp;
XPTMode mode = cursor->state->mode;
int i;
if (mode == XPT_DECODE) {
str = PR_NEWZAP(XPTString);
if (!str)
return PR_FALSE;
*strp = str;
}
if (!XPT_Do16(cursor, &str->length))
goto error;
if (mode == XPT_DECODE)
if (!(str->bytes = malloc(str->length + 1)))
goto error;
for (i = 0; i < str->length; i++)
if (!XPT_Do8(cursor, (PRUint8 *)&str->bytes[i]))
goto error_2;
if (mode == XPT_DECODE)
str->bytes[str->length] = 0;
return PR_TRUE;
error_2:
PR_DELETE(str->bytes);
error:
PR_DELETE(str);
return PR_FALSE;
}
XPT_PUBLIC_API(PRBool)
XPT_DoString(XPTCursor *cursor, XPTString **strp)
{
XPTCursor my_cursor;
XPTString *str = *strp;
PRBool already;
XPT_PREAMBLE_NO_ALLOC(cursor, strp, XPT_DATA, str->length + 2, my_cursor,
already);
return XPT_DoStringInline(&my_cursor, strp);
}
XPT_PUBLIC_API(PRBool)
XPT_DoCString(XPTCursor *cursor, char **identp)
{
XPTCursor my_cursor;
char *ident = *identp;
PRUint32 offset = 0;
XPTMode mode = cursor->state->mode;
if (mode == XPT_DECODE) {
char *start, *end;
int len;
if (!XPT_Do32(cursor, &offset))
return PR_FALSE;
if (!offset) {
*identp = NULL;
return PR_TRUE;
}
my_cursor.pool = XPT_DATA;
my_cursor.offset = offset;
my_cursor.state = cursor->state;
start = &CURS_POINT(&my_cursor);
end = strchr(start, 0); /* find the end of the string */
if (!end) {
fprintf(stderr, "didn't find end of string on decode!\n");
return PR_FALSE;
}
len = end - start;
ident = PR_MALLOC(len + 1);
if (!ident)
return PR_FALSE;
memcpy(ident, start, len);
ident[len] = 0;
*identp = ident;
} else {
if (!ident) {
offset = 0;
if (!XPT_Do32(cursor, &offset))
return PR_FALSE;
return PR_TRUE;
}
if (!XPT_MakeCursor(cursor->state, XPT_DATA, strlen(ident) + 1,
&my_cursor) ||
!XPT_Do32(cursor, &my_cursor.offset))
return PR_FALSE;
while(*ident)
if (!XPT_Do8(&my_cursor, (PRUint8 *)ident++))
return PR_FALSE;
if (!XPT_Do8(&my_cursor, (PRUint8 *)ident)) /* write trailing zero */
return PR_FALSE;
}
return PR_TRUE;
}
XPT_PUBLIC_API(PRUint32)
XPT_GetOffsetForAddr(XPTCursor *cursor, void *addr)
{
return (PRUint32)PL_HashTableLookup(cursor->state->pool->offset_map, addr);
}
XPT_PUBLIC_API(PRBool)
XPT_SetOffsetForAddr(XPTCursor *cursor, void *addr, PRUint32 offset)
{
return PL_HashTableAdd(cursor->state->pool->offset_map,
addr, (void *)offset) != NULL;
}
XPT_PUBLIC_API(PRBool)
XPT_SetAddrForOffset(XPTCursor *cursor, PRUint32 offset, void *addr)
{
return PL_HashTableAdd(cursor->state->pool->offset_map,
(void *)offset, addr) != NULL;
}
XPT_PUBLIC_API(void *)
XPT_GetAddrForOffset(XPTCursor *cursor, PRUint32 offset)
{
return PL_HashTableLookup(cursor->state->pool->offset_map, (void *)offset);
}
static PRBool
CheckForRepeat(XPTCursor *cursor, void **addrp, XPTPool pool, int len,
XPTCursor *new_cursor, PRBool *already)
{
void *last = *addrp;
*already = PR_FALSE;
new_cursor->state = cursor->state;
new_cursor->pool = pool;
new_cursor->bits = 0;
if (cursor->state->mode == XPT_DECODE) {
last = XPT_GetAddrForOffset(new_cursor, new_cursor->offset);
if (last) {
*already = PR_TRUE;
*addrp = last;
}
} else {
new_cursor->offset = XPT_GetOffsetForAddr(new_cursor, last);
if (new_cursor->offset) {
*already = PR_TRUE;
return PR_TRUE;
}
/* haven't already found it, so allocate room for it. */
if (!XPT_MakeCursor(cursor->state, pool, len, new_cursor) ||
!XPT_SetOffsetForAddr(new_cursor, *addrp, new_cursor->offset))
return PR_FALSE;
}
return PR_TRUE;
}
/*
* IIDs are written in struct order, in the usual big-endian way. From the
* typelib file spec:
*
* "For example, this IID:
* {00112233-4455-6677-8899-aabbccddeeff}
* is converted to the 128-bit value
* 0x00112233445566778899aabbccddeeff
* Note that the byte storage order corresponds to the layout of the nsIID
* C-struct on a big-endian architecture."
*
* (http://www.mozilla.org/scriptable/typelib_file.html#iid)
*/
XPT_PUBLIC_API(PRBool)
XPT_DoIID(XPTCursor *cursor, nsID *iidp)
{
int i;
if (!XPT_Do32(cursor, &iidp->m0) ||
!XPT_Do16(cursor, &iidp->m1) ||
!XPT_Do16(cursor, &iidp->m2))
return PR_FALSE;
for (i = 0; i < 8; i++)
if (!XPT_Do8(cursor, (PRUint8 *)&iidp->m3[i]))
return PR_FALSE;
return PR_TRUE;
}
XPT_PUBLIC_API(PRBool)
XPT_Do64(XPTCursor *cursor, PRInt64 *u64p)
{
return XPT_Do32(cursor, (PRUint32 *)u64p) &&
XPT_Do32(cursor, ((PRUint32 *)u64p) + 1);
}
/*
* When we're writing 32- or 16-bit quantities, we write a byte at a time to
* avoid alignment issues. Someone could come and optimize this to detect
* well-aligned cases and do a single store, if they cared. I might care
* later.
*/
XPT_PUBLIC_API(PRBool)
XPT_Do32(XPTCursor *cursor, PRUint32 *u32p)
{
union {
PRUint8 b8[4];
PRUint32 b32;
} u;
if (!CHECK_COUNT(cursor, 4))
return PR_FALSE;
if (ENCODING(cursor)) {
u.b32 = XPT_SWAB32(*u32p);
CURS_POINT(cursor) = u.b8[0];
cursor->offset++;
CURS_POINT(cursor) = u.b8[1];
cursor->offset++;
CURS_POINT(cursor) = u.b8[2];
cursor->offset++;
CURS_POINT(cursor) = u.b8[3];
} else {
u.b8[0] = CURS_POINT(cursor);
cursor->offset++;
u.b8[1] = CURS_POINT(cursor);
cursor->offset++;
u.b8[2] = CURS_POINT(cursor);
cursor->offset++;
u.b8[3] = CURS_POINT(cursor);
*u32p = XPT_SWAB32(u.b32);
}
cursor->offset++;
return PR_TRUE;
}
XPT_PUBLIC_API(PRBool)
XPT_Do16(XPTCursor *cursor, PRUint16 *u16p)
{
union {
PRUint8 b8[2];
PRUint16 b16;
} u;
if (!CHECK_COUNT(cursor, 2))
return PR_FALSE;
if (ENCODING(cursor)) {
u.b16 = XPT_SWAB16(*u16p);
CURS_POINT(cursor) = u.b8[0];
cursor->offset++;
CURS_POINT(cursor) = u.b8[1];
} else {
u.b8[0] = CURS_POINT(cursor);
cursor->offset++;
u.b8[1] = CURS_POINT(cursor);
*u16p = XPT_SWAB16(u.b16);
}
cursor->offset++;
return PR_TRUE;
}
XPT_PUBLIC_API(PRBool)
XPT_Do8(XPTCursor *cursor, PRUint8 *u8p)
{
if (!CHECK_COUNT(cursor, 1))
return PR_FALSE;
if (cursor->state->mode == XPT_ENCODE)
CURS_POINT(cursor) = *u8p;
else
*u8p = CURS_POINT(cursor);
cursor->offset++;
return PR_TRUE;
}
static PRBool
do_bit(XPTCursor *cursor, PRUint8 *u8p, int bitno)
{
return PR_FALSE;
#if 0
int bit_value, delta, new_value;
XPTDatapool *pool = cursor->pool;
if (cursor->state->mode == XPT_ENCODE) {
bit_value = (*u8p & 1) << (bitno); /* 7 = 0100 0000, 6 = 0010 0000 */
if (bit_value) {
delta = pool->bit + (bitno) - 7;
new_value = delta >= 0 ? bit_value >> delta : bit_value << -delta;
pool->data[pool->count] |= new_value;
}
} else {
bit_value = pool->data[pool->count] & (1 << (7 - pool->bit));
*u8p = bit_value >> (7 - pool->bit);
}
if (++pool->bit == 8) {
pool->count++;
pool->bit = 0;
}
return CHECK_COUNT(cursor);
#endif
}
XPT_PUBLIC_API(PRBool)
XPT_DoBits(XPTCursor *cursor, PRUint8 *u8p, int nbits)
{
#define DO_BIT(cursor, u8p, nbits) \
if (!do_bit(cursor, u8p, nbits)) \
return PR_FALSE;
switch(nbits) {
case 7:
DO_BIT(cursor, u8p, 7);
case 6:
DO_BIT(cursor, u8p, 6);
case 5:
DO_BIT(cursor, u8p, 5);
case 4:
DO_BIT(cursor, u8p, 4);
case 3:
DO_BIT(cursor, u8p, 3);
case 2:
DO_BIT(cursor, u8p, 2);
case 1:
DO_BIT(cursor, u8p, 1);
default:;
};
#undef DO_BIT
return PR_TRUE;
}
XPT_PUBLIC_API(int)
XPT_FlushBits(XPTCursor *cursor)
{
return 0;
#if 0
cursor->bits = 0;
cursor->offset++;
if (!CHECK_COUNT(cursor))
return -1;
return skipped == 8 ? 0 : skipped;
#endif
}

View File

@@ -0,0 +1,37 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = libxpt
SIMPLE_PROGRAMS = PrimitiveTest SimpleTypeLib
CSRCS = PrimitiveTest.c SimpleTypeLib.c
LIBS = \
-L$(DIST)/bin \
-lxpt \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,134 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Test the xdr primitives from xpt_xdr.c */
#include "xpt_xdr.h"
#include <stdio.h>
#include <string.h> /* for memcpy */
#define PASS(msg) \
fprintf(stderr, "PASSED : %s\n", msg);
#define FAIL(msg) \
fprintf(stderr, "FAILURE: %s\n", msg);
#define TRY_(msg, cond, silent) \
if ((cond) && !silent) { \
PASS(msg); \
} else { \
FAIL(msg); \
return 1; \
}
#define TRY(msg, cond) TRY_(msg, cond, 0)
#define TRY_Q(msg, cond) TRY_(msg, cond, 1);
XPTString in_str = { 4, "bazz" };
struct TestData {
uint32 bit32;
uint16 bit16;
uint8 bit8[2];
char *cstr;
XPTString *str;
} input = { 0xdeadbeef, 0xcafe, {0xba, 0xbe}, "foobar", &in_str},
output = {0, 0, {0, 0}, NULL, NULL };
void
dump_struct(char *label, struct TestData *str)
{
fprintf(stderr, "%s: {%#08x, %#04x, {%#02x, %#02x}, %s, %d/%s}\n",
label, str->bit32, str->bit16, str->bit8[0], str->bit8[1],
str->cstr, str->str->length, str->str->bytes);
}
PRBool
XDR(XPTCursor *cursor, struct TestData *str)
{
TRY("Do32", XPT_Do32(cursor, &str->bit32));
TRY("Do16", XPT_Do16(cursor, &str->bit16));
TRY("Do8", XPT_Do8 (cursor, &str->bit8[0]));
TRY("Do8", XPT_Do8 (cursor, &str->bit8[1]));
TRY("DoCString", XPT_DoCString(cursor, &str->cstr));
TRY("DoString", XPT_DoString(cursor, &str->str));
return 0;
}
int
main(int argc, char **argv)
{
XPTState *state;
XPTCursor curs, *cursor = &curs;
char *header, *data, *whole;
uint32 hlen, dlen, i;
TRY("NewState (ENCODE)", (state = XPT_NewXDRState(XPT_ENCODE, NULL, 0)));
XPT_SetDataOffset(state, sizeof input);
TRY("MakeCursor", XPT_MakeCursor(state, XPT_HEADER, sizeof input, cursor));
dump_struct("before", &input);
if (XDR(cursor, &input))
return 1;
fprintf(stderr, "ENCODE successful\n");
XPT_GetXDRData(state, XPT_HEADER, &header, &hlen);
fprintf(stderr, "XDR header %d bytes at %p:",
hlen, header);
for (i = 0; i < hlen; i++)
fprintf(stderr, "%c%02x", i ? ',' : ' ', (uint8)header[i]);
fprintf(stderr, "\n");
XPT_GetXDRData(state, XPT_DATA, &data, &dlen);
fprintf(stderr, "XDR data %d bytes at %p:",
dlen, data);
for (i = 0; i < dlen; i++)
fprintf(stderr, "%c%02x/%c", i ? ',' : ' ', (uint8)data[i],
(uint8)data[i]);
fprintf(stderr, "\n");
whole = malloc(dlen + hlen);
if (!whole) {
fprintf(stderr, "malloc %d failed!\n", dlen + hlen);
return 1;
}
/* TRY_Q("malloc", (data2 = malloc(len))); */
memcpy(whole, header, hlen);
memcpy(whole + hlen, data, dlen);
XPT_DestroyXDRState(state);
TRY("NewState (DECODE)", (state = XPT_NewXDRState(XPT_DECODE, whole,
hlen + dlen)));
TRY("MakeCursor", XPT_MakeCursor(state, XPT_HEADER, sizeof input, cursor));
XPT_SetDataOffset(state, sizeof input);
if (XDR(cursor, &output))
return 1;
dump_struct("after", &output);
XPT_DestroyXDRState(state);
free(whole);
return 0;
}

View File

@@ -0,0 +1,164 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Test the structure creation and serialization APIs from xpt_struct.c */
#include "xpt_xdr.h"
#include "xpt_struct.h"
#define PASS(msg) \
fprintf(stderr, "PASSED : %s\n", msg);
#define FAIL(msg) \
fprintf(stderr, "FAILURE: %s\n", msg);
#define TRY_(msg, cond, silent) \
if ((cond) && !silent) { \
PASS(msg); \
} else { \
FAIL(msg); \
return 1; \
}
#define TRY(msg, cond) TRY_(msg, cond, 0)
#define TRY_Q(msg, cond) TRY_(msg, cond, 1);
struct nsID iid = {
0x00112233,
0x4455,
0x6677,
{0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}
};
XPTTypeDescriptor td_void = {0};
int
main(int argc, char **argv)
{
XPTHeader *header;
XPTAnnotation *ann;
XPTInterfaceDescriptor *id;
XPTMethodDescriptor *meth;
XPTState *state;
XPTCursor curs, *cursor = &curs;
char *data, *head;
FILE *out;
uint32 len, header_sz;
PRBool ok;
td_void.prefix.flags = TD_VOID;
#ifdef XP_MAC
if (argc == 0) {
static char* args[] = { "SimpleTypeLib", "simple.xpt", NULL };
argc = 2;
argv = args;
}
#endif
if (argc != 2) {
fprintf(stderr, "Usage: %s <filename.xpt>\n"
" Creates a simple typelib file.\n", argv[0]);
return 1;
}
/* construct a header */
header = XPT_NewHeader(1);
TRY("NewHeader", header);
ann = XPT_NewAnnotation(XPT_ANN_LAST | XPT_ANN_PRIVATE,
XPT_NewStringZ("SimpleTypeLib 1.0"),
XPT_NewStringZ("See You In Rome"));
TRY("NewAnnotation", ann);
header->annotations = ann;
header_sz = XPT_SizeOfHeaderBlock(header);
id = XPT_NewInterfaceDescriptor(0, 2, 2, 0);
TRY("NewInterfaceDescriptor", id);
ok = XPT_FillInterfaceDirectoryEntry(header->interface_directory, &iid,
"Interface", "NS", id);
TRY("FillInterfaceDirectoryEntry", ok);
/* void method1(void) */
meth = &id->method_descriptors[0];
ok = XPT_FillMethodDescriptor(meth, 0, "method1", 0);
TRY("FillMethodDescriptor", ok);
meth->result->flags = 0;
meth->result->type.prefix.flags = TD_VOID;
/* wstring method2(in uint32, in bool) */
meth = &id->method_descriptors[1];
ok = XPT_FillMethodDescriptor(meth, 0, "method2", 2);
TRY("FillMethodDescriptor", ok);
meth->result->flags = 0;
meth->result->type.prefix.flags = TD_PBSTR | XPT_TDP_POINTER;
meth->params[0].type.prefix.flags = TD_UINT32;
meth->params[0].flags = XPT_PD_IN;
meth->params[1].type.prefix.flags = TD_BOOL;
meth->params[1].flags = XPT_PD_IN;
/* const one = 1; */
id->const_descriptors[0].name = "one";
id->const_descriptors[0].type.prefix.flags = TD_UINT16;
id->const_descriptors[0].value.ui16 = 1;
/* const squeamish = "ossifrage"; */
id->const_descriptors[1].name = "squeamish";
id->const_descriptors[1].type.prefix.flags = TD_PBSTR | XPT_TDP_POINTER;
id->const_descriptors[1].value.string = XPT_NewStringZ("ossifrage");
/* serialize it */
state = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
TRY("NewState (ENCODE)", state);
ok = XPT_MakeCursor(state, XPT_HEADER, header_sz, cursor);
TRY("MakeCursor", ok);
ok = XPT_DoHeader(cursor, &header);
TRY("DoHeader", ok);
out = fopen(argv[1], "wb");
if (!out) {
perror("FAILED: fopen");
return 1;
}
XPT_GetXDRData(state, XPT_HEADER, &head, &len);
fwrite(head, len, 1, out);
XPT_GetXDRData(state, XPT_DATA, &data, &len);
fwrite(data, len, 1, out);
if (ferror(out) != 0 || fclose(out) != 0) {
fprintf(stderr, "\nError writing file: %s\n\n", argv[1]);
} else {
fprintf(stderr, "\nFile written: %s\n\n", argv[1]);
}
XPT_DestroyXDRState(state);
/* XXX DestroyHeader */
return 0;
}

View File

@@ -0,0 +1,67 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\PrimitiveTest.exe
PROG2 = .\$(OBJDIR)\SimpleTypeLib.exe
PROGRAMS = $(PROG1) $(PROG2)
LCFLAGS=-DUSE_NSREG
DEFINES=-DWIN32_LEAN_AND_MEAN
REQUIRES=xpcom libxpt
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAMS)
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
-for %p in ($(TESTCASES)) do $(MAKE_INSTALL) %p $(DIST)\bin
# Move this into config/obj.inc when it's allowed
.c{.\$(OBJDIR)\}.exe:
$(CC) @<<$(CFGFILE)
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
$(LLIBS)
$(OS_LIBS)
-Fd$(PDBFILE)
-Fe.\$(OBJDIR)\
-Fo.\$(OBJDIR)\
$(CURDIR)$(*B).c
<<KEEP
clobber::
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
$(PROG1): $(OBJDIR) PrimitiveTest.c
$(PROG2): $(OBJDIR) SimpleTypeLib.c

View File

@@ -0,0 +1,37 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = libxpt
SIMPLE_PROGRAMS = xpt_dump xpt_link
CSRCS = xpt_dump.c xpt_link.c
LIBS = \
-L$(DIST)/bin \
-lxpt \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,73 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\xpt_dump.exe
PROG2 = .\$(OBJDIR)\xpt_link.exe
PROGRAMS = $(PROG1) $(PROG2)
LCFLAGS=-DUSE_NSREG
DEFINES=-DWIN32_LEAN_AND_MEAN -DDEBUG
REQUIRES=xpcom libxpt
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\libxpt
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAMS)
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
-for %p in ($(TESTCASES)) do $(MAKE_INSTALL) %p $(DIST)\bin
# Move this into config/obj.inc when it's allowed
.c{.\$(OBJDIR)\}.exe:
$(CC) @<<$(CFGFILE)
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
$(LLIBS)
$(OS_LIBS)
-Fd$(PDBFILE)
-Fe.\$(OBJDIR)\
-Fo.\$(OBJDIR)\
$(CURDIR)$(*B).c
<<KEEP
clean :: clobber
clobber::
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
$(PROG1): $(OBJDIR) xpt_dump.c
$(PROG2): $(OBJDIR) xpt_link.c

View File

@@ -0,0 +1,945 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* A utility for dumping the contents of a typelib file (.xpt) to screen
*/
#include "xpt_xdr.h"
#include <stdio.h>
#ifdef XP_MAC
#include <stat.h>
#include <StandardFile.h>
#include "FullPath.h"
#else
#include <sys/stat.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "prprf.h"
#define BASE_INDENT 3
static char *type_array[18] = {"int8", "int16", "int32", "int64",
"uint8", "uint16", "uint32", "uint64",
"float", "double", "boolean", "char",
"wchar_t", "void", "reserved", "reserved",
"reserved", "reserved"};
static char *ptype_array[23] = {"int8 *", "int16 *", "int32 *", "int64 *",
"uint8 *", "uint16 *", "uint32 *", "uint64 *",
"float *", "double *", "boolean *", "char *",
"wchar_t *", "void *", "nsIID *", "bstr",
"string", "wstring", "Interface *",
"InterfaceIs *", "Opaque *", "Named *",
"Enum *"};
static char *rtype_array[23] = {"int8 &", "int16 &", "int32 &", "int64 &",
"uint8 &", "uint16 &", "uint32 &", "uint64 &",
"float &", "double &", "boolean &", "char &",
"wchar_t &", "void &", "nsIID &", "bstr",
"string", "wstring", "Interface &",
"InterfaceIs &", "Opaque &", "Named &",
"Enum &"};
PRBool param_problems = PR_FALSE;
PRBool
XPT_DumpHeader(XPTCursor *cursor, XPTHeader *header,
const int indent, PRBool verbose_mode);
PRBool
XPT_DumpAnnotations(XPTAnnotation *ann, const int indent, PRBool verbose_mode);
PRBool
XPT_DumpInterfaceDirectoryEntry(XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide,
XPTHeader *header, const int indent,
PRBool verbose_mode);
PRBool
XPT_DumpInterfaceDescriptor(XPTCursor *cursor, XPTInterfaceDescriptor *id,
XPTHeader *header, const int indent,
PRBool verbose_mode);
PRBool
XPT_DumpMethodDescriptor(XPTHeader *header, XPTMethodDescriptor *md,
const int indent, PRBool verbose_mode);
PRBool
XPT_GetStringForType(XPTHeader *header, XPTTypeDescriptor *td,
char **type_string);
PRBool
XPT_DumpXPTString(XPTString *str);
PRBool
XPT_DumpParamDescriptor(XPTHeader *header, XPTParamDescriptor *pd,
const int indent, PRBool verbose_mode,
PRBool is_result);
PRBool
XPT_DumpTypeDescriptor(XPTHeader *header, XPTTypeDescriptor *td,
int indent, PRBool verbose_mode);
PRBool
XPT_DumpTypeDef(XPTHeader *header, TypeDef *type_def, const int indent,
PRBool verbose_mode);
PRBool
XPT_DumpEnumTypeExtras(XPTHeader *header, EnumTypeExtras *enum_extras,
const int indent, PRBool verbose_mode);
PRBool
XPT_DumpEnumValue(XPTHeader *header, EnumValue *enum_val,
const int indent, PRBool verbose_mode);
PRBool
XPT_DumpConstDescriptor(XPTHeader *header, XPTConstDescriptor *cd,
const int indent, PRBool verbose_mode);
static void
xpt_dump_usage(char *argv[]) {
fprintf(stdout, "Usage: %s [-v] <filename.xpt>\n"
" -v verbose mode\n", argv[0]);
}
#ifdef XP_MAC
static int get_args(char*** argv)
{
static char* args[] = { "xpt_dump", NULL, NULL };
static StandardFileReply reply;
*argv = args;
printf("choose an .xpt file to dump.\n");
StandardGetFile(NULL, 0, NULL, &reply);
if (reply.sfGood && !reply.sfIsFolder) {
short len = 0;
Handle fullPath = NULL;
if (FSpGetFullPath(&reply.sfFile, &len, &fullPath) == noErr && fullPath != NULL) {
char* path = args[1] = PR_Malloc(1 + len);
BlockMoveData(*fullPath, path, len);
path[len] = '\0';
DisposeHandle(fullPath);
return 2;
}
}
return 1;
}
#endif
int
main(int argc, char **argv)
{
PRBool verbose_mode = PR_FALSE;
XPTState *state;
XPTCursor curs, *cursor = &curs;
XPTHeader *header;
struct stat file_stat;
size_t flen;
char *whole;
FILE *in;
#ifdef XP_MAC
argc = get_args(&argv);
#endif
switch (argc) {
case 2:
if (argv[1][0] == '-') {
xpt_dump_usage(argv);
return 1;
}
if (stat(argv[1], &file_stat) != 0) {
perror("FAILED: fstat");
return 1;
}
flen = file_stat.st_size;
in = fopen(argv[1], "rb");
break;
case 3:
verbose_mode = PR_TRUE;
if (argv[1][0] != '-' || argv[1][1] != 'v') {
xpt_dump_usage(argv);
return 1;
}
if (stat(argv[2], &file_stat) != 0) {
perror("FAILED: fstat");
return 1;
}
flen = file_stat.st_size;
in = fopen(argv[2], "rb");
break;
default:
xpt_dump_usage(argv);
return 1;
}
if (!in) {
perror("FAILED: fopen");
return 1;
}
whole = malloc(flen);
if (!whole) {
perror("FAILED: malloc for whole");
return 1;
}
if (flen > 0) {
size_t rv = fread(whole, 1, flen, in);
if (rv < 0) {
perror("FAILED: reading typelib file");
return 1;
}
if (rv < flen) {
fprintf(stderr, "short read (%d vs %d)! ouch!\n", rv, flen);
return 1;
}
if (ferror(in) != 0 || fclose(in) != 0)
perror("FAILED: Unable to read typelib file.\n");
state = XPT_NewXDRState(XPT_DECODE, whole, flen);
if (!XPT_MakeCursor(state, XPT_HEADER, 0, cursor)) {
fprintf(stdout, "MakeCursor failed\n");
return 1;
}
if (!XPT_DoHeader(cursor, &header)) {
fprintf(stdout, "DoHeader failed\n");
return 1;
}
if (!XPT_DumpHeader(cursor, header, BASE_INDENT, verbose_mode)) {
perror("FAILED: XPT_DumpHeader");
return 1;
}
if (param_problems) {
fprintf(stdout, "\nWARNING: ParamDescriptors are present with "
"bad in/out/retval flag information.\nThese have been marked "
"with 'XXX'.\nRemember, retval params should always be marked as out!\n");
}
XPT_DestroyXDRState(state);
free(whole);
} else {
fclose(in);
perror("FAILED: file length <= 0");
return 1;
}
return 0;
}
PRBool
XPT_DumpHeader(XPTCursor *cursor, XPTHeader *header,
const int indent, PRBool verbose_mode)
{
int i;
fprintf(stdout, "Header:\n");
if (verbose_mode) {
fprintf(stdout, "%*sMagic beans: ", indent, " ");
for (i=0; i<16; i++) {
fprintf(stdout, "%02x", header->magic[i]);
}
fprintf(stdout, "\n");
if (strncmp(header->magic, XPT_MAGIC, 16) == 0)
fprintf(stdout, "%*s PASSED\n", indent, " ");
else
fprintf(stdout, "%*s FAILED\n", indent, " ");
}
fprintf(stdout, "%*sMajor version: %d\n", indent, " ",
header->major_version);
fprintf(stdout, "%*sMinor version: %d\n", indent, " ",
header->minor_version);
fprintf(stdout, "%*sNumber of interfaces: %d\n", indent, " ",
header->num_interfaces);
if (verbose_mode) {
fprintf(stdout, "%*sFile length: %d\n", indent, " ",
header->file_length);
fprintf(stdout, "%*sData pool offset: %d\n\n", indent, " ",
header->data_pool);
}
fprintf(stdout, "%*sAnnotations:\n", indent, " ");
if (!XPT_DumpAnnotations(header->annotations, indent*2, verbose_mode))
return PR_FALSE;
fprintf(stdout, "\nInterface Directory:\n");
for (i=0; i<header->num_interfaces; i++) {
if (verbose_mode) {
fprintf(stdout, "%*sInterface #%d:\n", indent, " ", i);
if (!XPT_DumpInterfaceDirectoryEntry(cursor,
&header->interface_directory[i],
header, indent*2,
verbose_mode)) {
return PR_FALSE;
}
} else {
if (!XPT_DumpInterfaceDirectoryEntry(cursor,
&header->interface_directory[i],
header, indent,
verbose_mode)) {
return PR_FALSE;
}
}
}
return PR_TRUE;
}
PRBool
XPT_DumpAnnotations(XPTAnnotation *ann, const int indent, PRBool verbose_mode)
{
int i = -1;
XPTAnnotation *last;
int new_indent = indent + BASE_INDENT;
do {
i++;
if (XPT_ANN_IS_PRIVATE(ann->flags)) {
if (verbose_mode) {
fprintf(stdout, "%*sAnnotation #%d is private.\n",
indent, " ", i);
} else {
fprintf(stdout, "%*sAnnotation #%d:\n",
indent, " ", i);
}
fprintf(stdout, "%*sCreator: ", new_indent, " ");
if (!XPT_DumpXPTString(ann->creator))
return PR_FALSE;
fprintf(stdout, "\n");
fprintf(stdout, "%*sPrivate Data: ", new_indent, " ");
if (!XPT_DumpXPTString(ann->private_data))
return PR_FALSE;
fprintf(stdout, "\n");
} else {
fprintf(stdout, "%*sAnnotation #%d is empty.\n",
indent, " ", i);
}
last = ann;
ann = ann->next;
} while (!XPT_ANN_IS_LAST(last->flags));
if (verbose_mode) {
fprintf(stdout, "%*sAnnotation #%d is the last annotation.\n",
indent, " ", i);
}
return PR_TRUE;
}
static void
print_IID(struct nsID *iid, FILE *file)
{
fprintf(file, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) iid->m0, (PRUint32) iid->m1,(PRUint32) iid->m2,
(PRUint32) iid->m3[0], (PRUint32) iid->m3[1],
(PRUint32) iid->m3[2], (PRUint32) iid->m3[3],
(PRUint32) iid->m3[4], (PRUint32) iid->m3[5],
(PRUint32) iid->m3[6], (PRUint32) iid->m3[7]);
}
PRBool
XPT_DumpInterfaceDirectoryEntry(XPTCursor *cursor,
XPTInterfaceDirectoryEntry *ide,
XPTHeader *header, const int indent,
PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
if (verbose_mode) {
fprintf(stdout, "%*sIID: ", indent, " ");
print_IID(&ide->iid, stdout);
fprintf(stdout, "\n");
fprintf(stdout, "%*sName: %s\n",
indent, " ", ide->name);
fprintf(stdout, "%*sNamespace: %s\n",
indent, " ", ide->name_space ? ide->name_space : "none");
fprintf(stdout, "%*sAddress of interface descriptor: %p\n",
indent, " ", ide->interface_descriptor);
fprintf(stdout, "%*sDescriptor:\n", indent, " ");
if (!XPT_DumpInterfaceDescriptor(cursor, ide->interface_descriptor,
header, new_indent, verbose_mode)) {
return PR_FALSE;
}
} else {
fprintf(stdout, "%*s- %s::%s (", indent, " ",
ide->name_space ? ide->name_space : "", ide->name);
print_IID(&ide->iid, stdout);
fprintf(stdout, "):\n");
if (!XPT_DumpInterfaceDescriptor(cursor, ide->interface_descriptor,
header, new_indent, verbose_mode)) {
return PR_FALSE;
}
}
return PR_TRUE;
}
PRBool
XPT_DumpInterfaceDescriptor(XPTCursor *cursor, XPTInterfaceDescriptor *id,
XPTHeader *header, const int indent,
PRBool verbose_mode)
{
XPTInterfaceDirectoryEntry *parent_ide;
int i;
int new_indent = indent + BASE_INDENT;
int more_indent = new_indent + BASE_INDENT;
if (!id) {
fprintf(stdout, "%*s[Unresolved]\n", indent, " ");
return PR_TRUE;
}
if (id->parent_interface) {
parent_ide = &header->interface_directory[id->parent_interface - 1];
fprintf(stdout, "%*sParent: %s::%s\n", indent, " ",
parent_ide->name_space ?
parent_ide->name_space : "",
parent_ide->name);
}
fprintf(stdout, "%*sFlags:\n", indent, " ");
fprintf(stdout, "%*sScriptable: %s\n", new_indent, " ",
XPT_ID_IS_SCRIPTABLE(id->flags) ? "TRUE" : "FALSE");
if (verbose_mode) {
if (id->parent_interface) {
fprintf(stdout,
"%*sIndex of parent interface (in data pool): %d\n",
indent, " ", id->parent_interface);
}
}
if (id->num_methods > 0) {
if (verbose_mode) {
fprintf(stdout,
"%*s# of Method Descriptors: %d\n",
indent, " ", id->num_methods);
} else {
fprintf(stdout, "%*sMethods:\n", indent, " ");
}
for (i=0; i<id->num_methods; i++) {
if (verbose_mode) {
fprintf(stdout, "%*sMethod #%d:\n", new_indent, " ", i);
if (!XPT_DumpMethodDescriptor(header,
&id->method_descriptors[i],
more_indent, verbose_mode)) {
return PR_FALSE;
}
} else {
if (!XPT_DumpMethodDescriptor(header,
&id->method_descriptors[i],
new_indent, verbose_mode)) {
return PR_FALSE;
}
}
}
} else {
fprintf(stdout, "%*sMethods:\n", indent, " ");
fprintf(stdout, "%*sNo Methods\n", new_indent, " ");
}
if (id->num_constants > 0) {
if (verbose_mode) {
fprintf(stdout,
"%*s# of Constant Descriptors: %d\n",
indent, " ", id->num_constants);
} else {
fprintf(stdout, "%*sConstants:\n", indent, " ");
}
for (i=0; i<id->num_constants; i++) {
if (verbose_mode) {
fprintf(stdout, "%*sConstant #%d:\n", new_indent, " ", i);
if (!XPT_DumpConstDescriptor(header,
&id->const_descriptors[i],
more_indent, verbose_mode))
return PR_FALSE;
} else {
if (!XPT_DumpConstDescriptor(header,
&id->const_descriptors[i],
new_indent, verbose_mode)) {
return PR_FALSE;
}
}
}
} else {
fprintf(stdout, "%*sConstants:\n", indent, " ");
fprintf(stdout, "%*sNo Constants\n", new_indent, " ");
}
return PR_TRUE;
}
PRBool
XPT_DumpMethodDescriptor(XPTHeader *header, XPTMethodDescriptor *md,
const int indent, PRBool verbose_mode)
{
int i;
int new_indent = indent + BASE_INDENT;
int more_indent = new_indent + BASE_INDENT;
if (verbose_mode) {
fprintf(stdout, "%*sName: %s\n", indent, " ", md->name);
fprintf(stdout, "%*sIs Getter? ", indent, " ");
if (XPT_MD_IS_GETTER(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Setter? ", indent, " ");
if (XPT_MD_IS_SETTER(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Varargs? ", indent, " ");
if (XPT_MD_IS_VARARGS(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Constructor? ", indent, " ");
if (XPT_MD_IS_CTOR(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Hidden? ", indent, " ");
if (XPT_MD_IS_HIDDEN(md->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*s# of arguments: %d\n", indent, " ", md->num_args);
fprintf(stdout, "%*sParameter Descriptors:\n", indent, " ");
for (i=0; i<md->num_args; i++) {
fprintf(stdout, "%*sParameter #%d:\n", new_indent, " ", i);
if (!XPT_DumpParamDescriptor(header, &md->params[i], more_indent,
verbose_mode, PR_FALSE))
return PR_FALSE;
}
fprintf(stdout, "%*sResult:\n", indent, " ");
if (!XPT_DumpParamDescriptor(header, md->result, new_indent,
verbose_mode, PR_TRUE)) {
return PR_FALSE;
}
} else {
char *param_type;
XPTParamDescriptor *pd;
if (!XPT_GetStringForType(header, &md->result->type, &param_type)) {
return PR_FALSE;
}
fprintf(stdout, "%*s%c%c%c%c%c %s %s(", indent - 6, " ",
XPT_MD_IS_GETTER(md->flags) ? 'G' : ' ',
XPT_MD_IS_SETTER(md->flags) ? 'S' : ' ',
XPT_MD_IS_HIDDEN(md->flags) ? 'H' : ' ',
XPT_MD_IS_VARARGS(md->flags) ? 'V' : ' ',
XPT_MD_IS_CTOR(md->flags) ? 'C' : ' ',
param_type, md->name);
for (i=0; i<md->num_args; i++) {
if (i!=0) {
fprintf(stdout, ", ");
}
pd = &md->params[i];
if (XPT_PD_IS_IN(pd->flags)) {
fprintf(stdout, "in");
if (XPT_PD_IS_OUT(pd->flags)) {
fprintf(stdout, "/out ");
if (XPT_PD_IS_RETVAL(pd->flags)) {
fprintf(stdout, "retval ");
}
if (XPT_PD_IS_SHARED(pd->flags)) {
fprintf(stdout, "shared ");
}
} else {
fprintf(stdout, " ");
}
} else {
if (XPT_PD_IS_OUT(pd->flags)) {
fprintf(stdout, "out ");
if (XPT_PD_IS_RETVAL(pd->flags)) {
fprintf(stdout, "retval ");
}
if (XPT_PD_IS_SHARED(pd->flags)) {
fprintf(stdout, "shared ");
}
} else {
param_problems = PR_TRUE;
fprintf(stdout, "XXX ");
}
}
if (!XPT_GetStringForType(header, &pd->type, &param_type)) {
return PR_FALSE;
}
fprintf(stdout, "%s", param_type);
}
fprintf(stdout, ");\n");
}
return PR_TRUE;
}
PRBool
XPT_GetStringForType(XPTHeader *header, XPTTypeDescriptor *td,
char **type_string)
{
int tag = XPT_TDP_TAG(td->prefix);
if (tag == TD_INTERFACE_TYPE) {
int index = td->type.interface;
if (!index || index > header->num_interfaces)
*type_string = "UNKNOWN_INTERFACE";
else
*type_string = header->interface_directory[index-1].name;
} else if (XPT_TDP_IS_POINTER(td->prefix.flags)) {
if (XPT_TDP_IS_REFERENCE(td->prefix.flags))
*type_string = rtype_array[tag];
else
*type_string = ptype_array[tag];
} else {
*type_string = type_array[tag];
}
return PR_TRUE;
}
PRBool
XPT_DumpXPTString(XPTString *str)
{
int i;
for (i=0; i<str->length; i++) {
fprintf(stdout, "%c", str->bytes[i]);
}
return PR_TRUE;
}
PRBool
XPT_DumpParamDescriptor(XPTHeader *header, XPTParamDescriptor *pd,
const int indent, PRBool verbose_mode,
PRBool is_result)
{
int new_indent = indent + BASE_INDENT;
if (!XPT_PD_IS_IN(pd->flags) &&
!XPT_PD_IS_OUT(pd->flags) &&
(XPT_PD_IS_RETVAL(pd->flags) ||
XPT_PD_IS_SHARED(pd->flags))) {
param_problems = PR_TRUE;
fprintf(stdout, "XXX\n");
} else {
if (!XPT_PD_IS_IN(pd->flags) && !XPT_PD_IS_OUT(pd->flags)) {
if (is_result) {
if (XPT_TDP_TAG(pd->type.prefix) != TD_UINT32 &&
XPT_TDP_TAG(pd->type.prefix) != TD_VOID) {
param_problems = PR_TRUE;
fprintf(stdout, "XXX\n");
}
} else {
param_problems = PR_TRUE;
fprintf(stdout, "XXX\n");
}
}
}
fprintf(stdout, "%*sIn Param? ", indent, " ");
if (XPT_PD_IS_IN(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sOut Param? ", indent, " ");
if (XPT_PD_IS_OUT(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sRetval? ", indent, " ");
if (XPT_PD_IS_RETVAL(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sShared? ", indent, " ");
if (XPT_PD_IS_SHARED(pd->flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sType Descriptor:\n", indent, " ");
if (!XPT_DumpTypeDescriptor(header, &pd->type, new_indent, verbose_mode))
return PR_FALSE;
return PR_TRUE;
}
PRBool
XPT_DumpTypeDescriptor(XPTHeader *header, XPTTypeDescriptor *td,
int indent, PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
fprintf(stdout, "%*sIs Pointer? ", indent, " ");
if (XPT_TDP_IS_POINTER(td->prefix.flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Unique Pointer? ", indent, " ");
if (XPT_TDP_IS_UNIQUE_POINTER(td->prefix.flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sIs Reference? ", indent, " ");
if (XPT_TDP_IS_REFERENCE(td->prefix.flags))
fprintf(stdout, "TRUE\n");
else
fprintf(stdout, "FALSE\n");
fprintf(stdout, "%*sTag: %d\n", indent, " ",
XPT_TDP_TAG(td->prefix));
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE) {
fprintf(stdout, "%*sInterfaceTypeDescriptor:\n", indent, " ");
fprintf(stdout, "%*sIndex of IDE: %d\n", new_indent, " ",
td->type.interface);
}
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_IS_TYPE) {
fprintf(stdout, "%*sInterfaceTypeDescriptor:\n", indent, " ");
fprintf(stdout, "%*sIndex of Method Argument: %d\n", new_indent, " ",
td->type.argnum);
}
if (XPT_TDP_TAG(td->prefix) == TD_OPAQUE_TYPE) {
fprintf(stdout, "%*sOpaqueTypeDescriptor:\n", indent, " ");
fprintf(stdout, "%*sType Name: %s\n", new_indent, " ",
td->type.type_name);
}
if (XPT_TDP_TAG(td->prefix) == TD_NAMED_TYPE) {
fprintf(stdout, "%*sNamedTypeDescriptor: \n", indent, " ");
if (!XPT_DumpTypeDef(header, td->type.type_def, indent,
verbose_mode)) {
return PR_FALSE;
}
}
if (XPT_TDP_TAG(td->prefix) == TD_ENUM_TYPE) {
fprintf(stdout, "%*sEnumTypeDescriptor:\n", indent, " ");
if (!XPT_DumpEnumTypeExtras(header, td->type.enum_extras, indent,
verbose_mode)) {
return PR_FALSE;
}
}
return PR_TRUE;
}
PRBool
XPT_DumpTypeDef(XPTHeader *header, TypeDef *type_def, const int indent,
PRBool verbose_mode)
{
char *type_string;
fprintf(stdout, "%*sNamespace::Name: %s::%s\n", indent, " ",
type_def->name_space ?
type_def->name_space : "",
type_def->name);
if (!XPT_GetStringForType(header, type_def->type, &type_string)) {
return PR_FALSE;
}
fprintf(stdout, "%*sType: %s\n", indent, " ",
type_string);
return PR_TRUE;
}
PRBool
XPT_DumpEnumTypeExtras(XPTHeader *header, EnumTypeExtras *enum_extras,
const int indent, PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
char *type_string;
uint32 i;
if (!XPT_GetStringForType(header, enum_extras->type, &type_string)) {
return PR_FALSE;
}
fprintf(stdout, "%*sType: %s\n", indent, " ",
type_string);
fprintf(stdout, "%*sNumber of values: %d\n", indent, " ",
enum_extras->num_values);
fprintf(stdout, "%*sEnum Values:\n", indent, " ");
for (i=0; i<enum_extras->num_values; i++) {
if (!XPT_DumpEnumValue(header, &enum_extras->enum_values[i],
new_indent, verbose_mode)) {
return PR_FALSE;
}
}
return PR_TRUE;
}
PRBool
XPT_DumpEnumValue(XPTHeader *header, EnumValue *enum_val,
const int indent, PRBool verbose_mode)
{
fprintf(stdout, "%*s%s = %s\n", indent, " ",
enum_val->name, enum_val->value);
return PR_TRUE;
}
PRBool
XPT_DumpConstDescriptor(XPTHeader *header, XPTConstDescriptor *cd,
const int indent, PRBool verbose_mode)
{
int new_indent = indent + BASE_INDENT;
char *out, *const_type;
if (verbose_mode) {
fprintf(stdout, "%*sName: %s\n", indent, " ", cd->name);
fprintf(stdout, "%*sType Descriptor: \n", indent, " ");
if (!XPT_DumpTypeDescriptor(header, &cd->type, new_indent,
verbose_mode))
return PR_FALSE;
fprintf(stdout, "%*sValue: ", indent, " ");
} else {
if (!XPT_GetStringForType(header, &cd->type, &const_type)) {
return PR_FALSE;
}
fprintf(stdout, "%*s%s %s = ", indent, " ", const_type, cd->name);
}
switch(XPT_TDP_TAG(cd->type.prefix)) {
case TD_INT8:
fprintf(stdout, "%d", cd->value.i8);
break;
case TD_INT16:
fprintf(stdout, "%d", cd->value.i16);
break;
case TD_INT32:
fprintf(stdout, "%d", cd->value.i32);
break;
case TD_INT64:
out = PR_smprintf("%lld", cd->value.i64);
fputs(out, stdout);
PR_smprintf_free(out);
break;
case TD_UINT8:
fprintf(stdout, "%d", cd->value.ui8);
break;
case TD_UINT16:
fprintf(stdout, "%d", cd->value.ui16);
break;
case TD_UINT32:
fprintf(stdout, "%d", cd->value.ui32);
break;
case TD_UINT64:
out = PR_smprintf("%lld", cd->value.ui64);
fputs(out, stdout);
PR_smprintf_free(out);
break;
case TD_FLOAT:
fprintf(stdout, "%f", cd->value.flt);
break;
case TD_DOUBLE:
fprintf(stdout, "%g", cd->value.dbl);
break;
case TD_BOOL:
if (cd->value.bul)
fprintf(stdout, "TRUE");
else
fprintf(stdout, "FALSE");
break;
case TD_CHAR:
fprintf(stdout, "%c", cd->value.ch);
break;
case TD_WCHAR:
fprintf(stdout, "%c", cd->value.wch & 0xff);
break;
case TD_VOID:
fprintf(stdout, "VOID");
break;
case TD_PNSIID:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
print_IID(cd->value.iid, stdout);
} else
return PR_FALSE;
break;
case TD_PBSTR:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
if (!XPT_DumpXPTString(cd->value.string))
return PR_FALSE;
} else
return PR_FALSE;
break;
case TD_PSTRING:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
fprintf(stdout, "%s", cd->value.str);
} else
return PR_FALSE;
break;
case TD_PWSTRING:
if (XPT_TDP_IS_POINTER(cd->type.prefix.flags)) {
PRUint16 *ch = cd->value.wstr;
while (*ch) {
fprintf(stdout, "%c", *ch & 0xff);
ch++;
}
} else
return PR_FALSE;
break;
default:
perror("Unrecognized type");
return PR_FALSE;
break;
}
if (verbose_mode) {
fprintf(stdout, "\n");
} else {
fprintf(stdout, ";\n");
}
return PR_TRUE;
}

View File

@@ -0,0 +1,665 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* A utility for linking multiple typelib files.
*/
#include "xpt_xdr.h"
#include <stdio.h>
#ifdef XP_MAC
#include <stat.h>
#else
#include <sys/stat.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "prlong.h"
#ifndef NULL
#define NULL (void *) 0
#endif
/* Forward declarations. */
typedef struct fixElement fixElement;
static int compare_IDEs_by_IID(const void *ap, const void *bp);
static int compare_IDEs_by_name(const void *ap, const void *bp);
static int compare_IDEs_by_name_space(const void *ap, const void *bp);
static int compare_strings(const void *ap, const void *bp);
static int compare_fixElements_by_IID(const void *ap, const void *bp);
static int compare_fixElements_by_name(const void *ap, const void *bp);
static int compare_IIDs(const void *ap, const void *bp);
PRBool shrink_IDE_array(XPTInterfaceDirectoryEntry *ide,
int element_to_delete, int num_interfaces);
PRBool update_fix_array(fixElement *fix, int element_to_delete,
int num_interfaces, int replacement);
static int get_new_index(const fixElement *fix, int num_elements,
int target_file, int target_interface);
PRBool copy_IDE(XPTInterfaceDirectoryEntry *from,
XPTInterfaceDirectoryEntry *to);
PRBool copy_fixElement(fixElement *from, fixElement *to);
static void print_IID(struct nsID *iid, FILE *file);
static void xpt_dump_usage(char *argv[]);
struct fixElement {
nsID iid;
char* name;
int file_num;
int interface_num;
PRBool is_deleted;
/* These next two variables will point you to the substitute interface
* if this one has been deleted.
*/
int maps_to_file_num;
int maps_to_interface_num;
};
/* Global variables. */
int trueNumberOfInterfaces = 0;
int totalNumberOfInterfaces = 0;
int
main(int argc, char **argv)
{
XPTState *state;
XPTCursor curs, *cursor = &curs;
XPTHeader *header;
XPTInterfaceDirectoryEntry *newIDE, *IDE_array;
XPTInterfaceDescriptor *id;
XPTTypeDescriptor *td;
XPTAnnotation *ann, *first_ann;
uint32 header_sz, len;
struct stat file_stat;
size_t flen = 0;
char *head, *data, *whole;
FILE *in, *out;
fixElement *newFix, *fix_array;
int i,j;
int k = 0;
if (argc < 3) {
xpt_dump_usage(argv);
return 1;
}
/* We're going to keep annotations now, so we'll start off with one
* that will let people know that the resultant type library file
* was generated by this tool (xpt_link).
*/
first_ann = XPT_NewAnnotation(XPT_ANN_LAST | XPT_ANN_PRIVATE,
XPT_NewStringZ("xpt_link"),
XPT_NewStringZ("This is a linked type library file created by xpt_link."));
for (i=2; i<argc; i++) {
if (stat(argv[i], &file_stat) != 0) {
perror("FAILED: fstat");
return 1;
}
flen = file_stat.st_size;
in = fopen(argv[i], "rb");
if (!in) {
perror("FAILED: fopen");
return 1;
}
whole = malloc(flen);
if (!whole) {
perror("FAILED: malloc for whole");
return 1;
}
if (flen > 0) {
size_t rv = fread(whole, 1, flen, in);
if (rv < 0) {
perror("FAILED: reading typelib file");
return 1;
}
if (rv < flen) {
fprintf(stderr, "short read (%d vs %d)! ouch!\n", rv, flen);
return 1;
}
if (ferror(in) != 0 || fclose(in) != 0) {
perror("FAILED: Unable to read typelib file.\n");
return 1;
}
state = XPT_NewXDRState(XPT_DECODE, whole, flen);
if (!XPT_MakeCursor(state, XPT_HEADER, 0, cursor)) {
perror("FAILED: XPT_MakeCursor");
return 1;
}
if (!XPT_DoHeader(cursor, &header)) {
perror("FAILED: XPT_DoHeader");
return 1;
}
totalNumberOfInterfaces += header->num_interfaces;
if (k == 0) {
IDE_array = PR_CALLOC(totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
fix_array = PR_CALLOC(totalNumberOfInterfaces * sizeof(fixElement));
} else {
newIDE = PR_REALLOC(IDE_array, totalNumberOfInterfaces * sizeof(XPTInterfaceDirectoryEntry));
newFix = PR_REALLOC(fix_array, totalNumberOfInterfaces * sizeof(fixElement));
if (!newIDE) {
perror("FAILED: PR_REALLOC of IDE_array");
return 1;
}
if (!newFix) {
perror("FAILED: PR_REALLOC of newFix");
return 1;
}
IDE_array = newIDE;
fix_array = newFix;
}
for (j=0; j<header->num_interfaces; j++) {
if (!copy_IDE(&header->interface_directory[j],
&IDE_array[k])) {
perror("FAILED: 1st copying of IDE");
return 1;
}
fix_array[k].iid = IDE_array[k].iid;
fix_array[k].name = IDE_array[k].name;
fix_array[k].file_num = i-2;
fix_array[k].interface_num = j+1;
fix_array[k].is_deleted = PR_FALSE;
fix_array[k].maps_to_file_num = i-2;
fix_array[k].maps_to_interface_num = j+1;
k++;
}
/* Copy the annotations.
*/
ann = first_ann;
while (ann->next != NULL) {
ann = ann->next;
}
if (header->annotations != NULL) {
ann->next = header->annotations;
}
PR_FREEIF(header)
if (state)
XPT_DestroyXDRState(state);
free(whole);
flen = 0;
} else {
fclose(in);
perror("FAILED: file length <= 0");
return 1;
}
}
/* Make sure the last annotation is the only one marked as XP_ANN_LAST.
*/
ann = first_ann;
while (ann->next != NULL) {
ann->flags &= ~XPT_ANN_LAST;
ann = ann->next;
}
ann->flags |= XPT_ANN_LAST;
/* Sort both IDE_array and fix_array by name so we can check for
* name_space::name collisions.
*/
qsort(IDE_array,
totalNumberOfInterfaces,
sizeof(XPTInterfaceDirectoryEntry),
compare_IDEs_by_name);
qsort(fix_array,
totalNumberOfInterfaces,
sizeof(fixElement),
compare_fixElements_by_name);
/* trueNumberOfInterfaces == number of interfaces left after deletions
* are made. Initialize it here to be the same as the total number of
* interfaces we'ce encountered thus far.
*/
trueNumberOfInterfaces = totalNumberOfInterfaces;
/* Iterate through the sorted interfaces. Start at one so we don't
* accidentally walk off the end of the array.
*/
i = 1;
while (i != trueNumberOfInterfaces) {
/* Check for name_space::name collision.
*/
if (compare_IDEs_by_name(&IDE_array[i-1], &IDE_array[i]) == 0 &&
compare_IDEs_by_name_space(&IDE_array[i-1], &IDE_array[i]) == 0) {
/* If one of the interfaces is unresolved, delete that one
* preferentailly.
*/
if (!IDE_array[i-1].interface_descriptor) {
/* Shrink the IDE_array to delete the duplicate interface.
*/
if (!shrink_IDE_array(IDE_array,
i-1,
trueNumberOfInterfaces)) {
perror("FAILED: shrink_IDE_array");
return 1;
}
/* Update the fix array. This involves moving the deleted
* entry to the end of the array (rather than deleting it)
* and mapping it to the "replacement" element so we can
* update interface indices appropriately later.
*/
update_fix_array(fix_array, i-1, totalNumberOfInterfaces, i);
/* Decrement the true number of interfaces since we just
* deleted one. There's more than one way to get out of
* this loop.
*/
trueNumberOfInterfaces--;
} else {
if (!IDE_array[i].interface_descriptor ||
(compare_IIDs(&IDE_array[i-1].iid, &IDE_array[i].iid) == 0)) {
/* Shrink the IDE_array to delete the duplicate interface.
*/
if (!shrink_IDE_array(IDE_array,
i,
trueNumberOfInterfaces)) {
perror("FAILED: shrink_IDE_array");
return 1;
}
/* Update the fix array. This involves moving the deleted
* entry to the end of the array (rather than deleting it)
* and mapping it to the "replacement" element so we can
* update interface indices appropriately later.
*/
update_fix_array(fix_array, i,
totalNumberOfInterfaces, i-1);
/* Decrement the true number of interfaces since we just
* deleted one. There's more than one way to get out of
* this loop.
*/
trueNumberOfInterfaces--;
}
}
} else {
/* Only increment if there was no name_space::name collision.
*/
i++;
}
}
/* Sort the IDE_array (put them in their final order) so that updating
* of indices will be meaningful.
*/
qsort(IDE_array,
trueNumberOfInterfaces,
sizeof(XPTInterfaceDirectoryEntry),
compare_IDEs_by_IID);
/* Sort the fix_array to match the IDE_array.
*/
qsort(fix_array,
trueNumberOfInterfaces,
sizeof(fixElement),
compare_fixElements_by_IID);
/* Iterate through the remaining interfaces (those not deleted)
* looking for references to interfaces (such as id->parent_interface)
* which need an updated index number.
*/
for (i=0; i<trueNumberOfInterfaces; i++) {
/* Define id to save some keystrokes.
*/
id = IDE_array[i].interface_descriptor;
/* Check for unresolved interface.
*/
if (id) {
/* Fix parent_interface first.
*/
if (id->parent_interface && id->parent_interface != 0) {
id->parent_interface =
get_new_index(fix_array, totalNumberOfInterfaces,
fix_array[i].file_num, id->parent_interface);
}
/* Iterate through the method descriptors looking for params of
* type TD_INTERFACE_TYPE.
*/
for (j=0; j<id->num_methods; j++) {
/* Cycle through the params first.
*/
for (k=0; k<id->method_descriptors[j].num_args; k++) {
/* Define td to save some keystrokes.
*/
td = &id->method_descriptors[j].params[k].type;
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE) {
td->type.interface =
get_new_index(fix_array,
totalNumberOfInterfaces,
fix_array[i].file_num,
td->type.interface);
}
}
/* Check the result param too. Define td again to save
* some keystrokes.
*/
td = &id->method_descriptors[j].result->type;
if (XPT_TDP_TAG(td->prefix) == TD_INTERFACE_TYPE) {
td->type.interface =
get_new_index(fix_array, totalNumberOfInterfaces,
fix_array[i].file_num,
td->type.interface);
}
}
}
}
/* Iterate through the array quickly looking for duplicate IIDS.
* This shouldn't happen, i.e. is a failure condition, so bail
* if we find a duplicate. If we have more than one entry, start
* at one so we don't accidentally grep the ether.
*/
if (trueNumberOfInterfaces>1) {
for (i=1; i<trueNumberOfInterfaces; i++) {
if (compare_IDEs_by_IID(&IDE_array[i-1], &IDE_array[i]) == 0) {
fprintf(stderr, "FATAL ERROR:\n"
"Duplicate IID detected (");
print_IID(&IDE_array[i-1].iid, stderr);
fprintf(stderr, ") in\n"
"interface %s::%s from %s\n"
"and\n"
"interface %s::%s from %s\n",
IDE_array[i-1].name_space ?
IDE_array[i-1].name_space : "",
IDE_array[i-1].name,
argv[fix_array[i-1].file_num+2],
IDE_array[i].name_space ?
IDE_array[i].name_space : "",
IDE_array[i].name,
argv[fix_array[i].file_num+2]);
return 1;
}
}
}
header = XPT_NewHeader(trueNumberOfInterfaces);
header->annotations = first_ann;
for (i=0; i<trueNumberOfInterfaces; i++) {
if (!copy_IDE(&IDE_array[i], &header->interface_directory[i])) {
perror("FAILED: 2nd copying of IDE");
return 1;
}
}
header_sz = XPT_SizeOfHeaderBlock(header);
state = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
if (!state) {
perror("FAILED: error creating XDRState");
return 1;
}
if (!XPT_MakeCursor(state, XPT_HEADER, header_sz, cursor)) {
perror("FAILED: error making cursor");
return 1;
}
if (!XPT_DoHeader(cursor, &header)) {
perror("FAILED: error doing Header");
return 1;
}
out = fopen(argv[1], "wb");
if (!out) {
perror("FAILED: fopen");
return 1;
}
XPT_GetXDRData(state, XPT_HEADER, &head, &len);
fwrite(head, len, 1, out);
XPT_GetXDRData(state, XPT_DATA, &data, &len);
fwrite(data, len, 1, out);
if (ferror(out) != 0 || fclose(out) != 0) {
fprintf(stderr, "Error writing file: %s\n", argv[1]);
} else {
fprintf(stderr, "File written: %s\n", argv[1]);
}
if (state)
XPT_DestroyXDRState(state);
return 0;
}
static int
compare_IDEs_by_IID(const void *ap,
const void *bp)
{
const XPTInterfaceDirectoryEntry *ide1 = ap, *ide2 = bp;
return compare_IIDs(&ide1->iid, &ide2->iid);
}
static int
compare_fixElements_by_IID(const void *ap,
const void *bp)
{
const fixElement *fix1 = ap, *fix2 = bp;
return compare_IIDs(&fix1->iid, &fix2->iid);
}
static int
compare_IDEs_by_name(const void *ap,
const void *bp)
{
const XPTInterfaceDirectoryEntry *ide1 = ap, *ide2 = bp;
return compare_strings(ide1->name, ide2->name);
}
static int
compare_IDEs_by_name_space(const void *ap,
const void *bp)
{
const XPTInterfaceDirectoryEntry *ide1 = ap, *ide2 = bp;
return compare_strings(ide1->name_space, ide2->name_space);
}
static int
compare_strings(const void *ap, const void *bp)
{
const char *string1 = ap, *string2 = bp;
if (!string1 && !string2)
return 0;
if (!string1)
return -1;
if (!string2)
return 1;
return strcmp(string1, string2);
}
static int
compare_fixElements_by_name(const void *ap,
const void *bp)
{
const fixElement *fix1 = ap, *fix2 = bp;
return compare_strings(fix1->name, fix2->name);
}
static int
compare_IIDs(const void *ap, const void *bp)
{
const nsID *a = ap, *b = bp;
int i;
#define COMPARE(field) if (a->field > b->field) return 1; \
if (b->field > a->field) return -1;
COMPARE(m0);
COMPARE(m1);
COMPARE(m2);
for (i = 0; i < 8; i++) {
COMPARE(m3[i]);
}
return 0;
#undef COMPARE
}
PRBool
shrink_IDE_array(XPTInterfaceDirectoryEntry *ide, int element_to_delete,
int num_interfaces)
{
int i;
if (element_to_delete >= num_interfaces) {
return PR_FALSE;
}
for (i=element_to_delete+1; i<num_interfaces; i++) {
if (!copy_IDE(&ide[i], &ide[i-1])) {
return PR_FALSE;
}
}
return PR_TRUE;
}
/* update_fix_array marks a fixElement as deleted, updates its mapping
* to point to the "replacement" element, and moves it to the end of
* the array.
*/
PRBool
update_fix_array(fixElement *fix, int element_to_delete,
int num_interfaces, int replacement)
{
fixElement *deleted;
int i;
if (element_to_delete >= num_interfaces) {
return PR_FALSE;
}
deleted = PR_CALLOC(sizeof(fixElement));
if (!copy_fixElement(&fix[element_to_delete], deleted)) {
return PR_FALSE;
}
deleted->is_deleted = PR_TRUE;
deleted->maps_to_file_num = fix[replacement].file_num;
deleted->maps_to_interface_num = fix[replacement].interface_num;
for (i=element_to_delete+1; i<num_interfaces; i++) {
if (!copy_fixElement(&fix[i], &fix[i-1])) {
return PR_FALSE;
}
}
if (!copy_fixElement(deleted, &fix[num_interfaces-1])) {
return PR_FALSE;
}
return PR_TRUE;
}
/* get_new_index returns the new interface index by walking the fix_array
* until the file_num and interface_num match the target values. If a match
* is found, it checks to see if that element has been deleted. If it has
* been deleted, it follows that elements mapping until it gets to the
* proper interface (recursion). FYI, Indices are one-based; zero
* represents the special case (no parent interface).
*/
static int
get_new_index(const fixElement *fix, int num_elements,
int target_file, int target_interface)
{
int i;
for (i=0; i<num_elements; i++) {
if (fix[i].file_num == target_file &&
fix[i].interface_num == target_interface) {
if (fix[i].is_deleted) {
return get_new_index(fix, num_elements,
fix[i].maps_to_file_num,
fix[i].maps_to_interface_num);
}
return i+1;
}
}
return 0;
}
PRBool
copy_IDE(XPTInterfaceDirectoryEntry *from, XPTInterfaceDirectoryEntry *to)
{
if (!from || !to) {
return PR_FALSE;
}
to->iid = from->iid;
to->name = from->name;
to->name_space = from->name_space;
to->interface_descriptor = from->interface_descriptor;
return PR_TRUE;
}
PRBool
copy_fixElement(fixElement *from, fixElement *to)
{
if (!from || !to) {
return PR_FALSE;
}
to->iid = from->iid;
to->name = from->name;
to->file_num = from->file_num;
to->interface_num = from->interface_num;
to->is_deleted = from->is_deleted;
to->maps_to_file_num = from->maps_to_file_num;
to->maps_to_interface_num = from->maps_to_interface_num;
return PR_TRUE;
}
static void
print_IID(struct nsID *iid, FILE *file)
{
fprintf(file, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
(PRUint32) iid->m0, (PRUint32) iid->m1,(PRUint32) iid->m2,
(PRUint32) iid->m3[0], (PRUint32) iid->m3[1],
(PRUint32) iid->m3[2], (PRUint32) iid->m3[3],
(PRUint32) iid->m3[4], (PRUint32) iid->m3[5],
(PRUint32) iid->m3[6], (PRUint32) iid->m3[7]);
}
static void
xpt_dump_usage(char *argv[])
{
fprintf(stdout, "Usage: %s outfile file1.xpt file2.xpt ...\n"
" Links multiple typelib files into one outfile\n", argv[0]);
}

View File

@@ -0,0 +1,33 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = public src
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,6 @@
see:
http://www.mozilla.org/scriptable/xptcall-faq.html
and
http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/porting.html

View File

@@ -0,0 +1,21 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
DIRS=public src tests
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,205 @@
<html>
<head>
<title>xptcall Porting Guide</title>
</head>
<body bgcolor = "white">
<h2><center>xptcall Porting Guide</center></h2>
<h3>Overview</h3>
<blockquote>
<a href="http://www.mozilla.org/scriptable/xptcall-faq.html"> xptcall</a> is a
library that supports both invoking methods on arbitrary xpcom objects and
implementing classes whose objects can impersonate any xpcom interface. It does
this using platform specific assembly language code. This code needs to be
ported to all platforms that want to support xptcall (and thus mozilla).
</blockquote>
<h3>The tree</h3>
<blockquote>
<pre>
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall">mozilla/xpcom/libxpt/xptcall</a>
+--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public">public</a> // exported headers
+--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src">src</a> // core source
| \--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md">md</a> // platform specific parts
| +--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/mac">mac</a> // mac ppc
| +--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/unix">unix</a> // all unix
| \--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/win32">win32</a> // win32
| +--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/test">test</a> // simple tests to get started
\--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/tests">tests</a> // full tests via api
</pre>
Porters are free to create subdirectories under the base <code>md</code>
directory for their given platforms and to integrate into the build system as
appropriate for their platform.
</blockquote>
<h3>Theory of operation</h3>
<blockquote>
There are really two pieces of functionality: <i>invoke</i> and <i>stubs</i>...
<p>
The <b><i>invoke</i></b> functionality requires the implementation of the
following on each platform (from <a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcall.h#131">xptcall/public/xptcall.h</a>):
<pre>
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params);
</pre>
Calling code is expected to supply an array of <code>nsXPTCVariant</code>
structs. These are discriminated unions describing the type and value of each
parameter of the target function. The platform specific code then builds a call
frame and invokes the method indicated by the index <code>methodIndex</code> on
the xpcom interface <code>that</code>.
<p>
Here are examples of this implementation for
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/win32/xptcinvoke.cpp">Win32</a>
and
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/unix/xptcinvoke_linux_x86.cpp">Linux x86</a>.
Both of these implementations use the basic strategy of: figure out how much
stack space is needed for the params, make the space in a new frame, copy the
params to that space, invoke the method, cleanup and return. C++ is used where
appropriate, Assembly language is used where necessary. Inline assembly language is used here,
but it is equally valid to use separate assembly language source files. Porters
can decide how best to do this for their platforms.
<p>
The <b><i>stubs</i></b> functionality is more complex. The goal here is a class
whose vtbl can look like the vtbl of any arbitrary xpcom interface. Objects of
this class can then be built to impersonate any xpcom object. The base interface
for this is (from <a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcall.h#109">xptcall/public/xptcall.h</a>):
<pre>
class nsXPTCStubBase : public nsISupports
{
public:
// Include generated vtbl stub declarations.
// These are virtual and *also* implemented by this class..
#include "xptcstubsdecl.inc"
// The following methods must be provided by inheritor of this class.
// return a refcounted pointer to the InterfaceInfo for this object
// NOTE: on some platforms this MUST not fail or we crash!
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
// call this method and return result
NS_IMETHOD CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params) = 0;
};
</pre>
Code that wishes to make use of this <i>stubs</i> functionality (such as
<a href="http://www.mozilla.org/scriptable/">XPConnect</a>) implement a class
which inherits from <code>nsXPTCStubBase</code> and implements the
<code>GetInterfaceInfo</code> and <code>CallMethod</code> to let the
platform specific code know how to get interface information and how to dispatch methods
once their parameters have been pulled out of the platform specific calling
frame.
<p>
Porters of this functionality implement the platform specific code for the
<i>stub</i> methods that fill the vtbl for this class. The idea here is that the
class has a vtbl full of a large number of generic stubs. All instances of this
class share that vtbl and the same stubs. The stubs forward calls to a platform
specific method that uses the interface information supplied by
the overridden <code>GetInterfaceInfo</code> to extract the parameters and build
an array of platform independent <code>nsXPTCMiniVariant</code> structs which
are in turn passed on to the overridden <code>CallMethod</code>. The
platform dependent code is responsible for doing any cleanup and returning.
<p>
The stub methods are declared in <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcstubsdecl.inc">xptcall/public/xptcstubsdecl.inc</a>.
These are '#included' into the declaration of <code>nsXPTCStubBase</code>. A
similar include file (<a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcstubsdef.inc">xptcall/public/xptcstubsdef.inc</a>)
is expanded using platform specific macros to define the stub functions. These
'.inc' files are checked into cvs. However, they can be regenerated as necessary
(i.e. to change the number of stubs or to change their specific declaration)
using the Perl script <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/genstubs.pl">xptcall/public/genstubs.pl</a>.
<p>
Here are examples of this implementation for <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/win32/xptcstubs.cpp">Win32</a>
and <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/unix/xptcstubs_linux_x86.cpp">Linux
x86</a>. Both of these examples use inline assembly language. That is just how I
decided to do it. You can do it as you choose.
<p>
The Win32 version is somewhat tighter because the __declspec(naked) feature
allows for very small stubs. However, the __stdcall requires the callee to clean
up the stack, so it is imperative that the interface information scheme allow
the code to determine the correct stack pointer fixup for return without fail,
else the process will crash.
<p>
I opted to use inline assembler for the gcc Linux x86 port. I ended up with
larger stubs than I would have preferred rather than battle the compiler over
what would happen to the stack before my asm code began running.
<p>
I believe that the non-assembly parts of these files can be copied and reused
with minimal (but not zero) platform specific tweaks. Feel free to copy and
paste as necessary. Please remember that safety and reliability are more
important than speed optimizations. This code is primarily used to connect XPCOM
components with JavaScript; function call overhead is a <b>tiny</b> part of the
time involved.
<p>
I put together
<a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/test">xptcall/src/md/test
</a> as a place to evolve the basic functionality as a port is coming together.
Not all of the functionality is exercised, but it is a place to get started.
<a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/tests">xptcall/tests
</a> has an api level test for <code>XPTC_InvokeByIndex</code>, but no tests for
the <i>stubs</i> functionality. Such a test ought to be written, but this has not
yet been done.
<p>
A full 'test' at this point requires building the client and running the
XPConnect test called <i>TestXPC</i> in
<a
href="http://lxr.mozilla.org/mozilla/source/js/src/xpconnect/tests">mozilla/js/src/xpconnect/tests
</a>.
<p>
Getting these ports done is very important. Please let <a
href="mailto:jband@netscape.com">me</a> know if you are interested in doing one.
I'll answer any questions as I get them.
</blockquote>
<hr>
<b>Author:</b> <a href="mailto:jband@netscape.com">John Bandhauer &lt;jband@netscape.com&gt;</a><br>
<b>Last modified:</b> 1 April 1999
</body>
</html>

View File

@@ -0,0 +1,7 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
xptcall.h
xptcstubsdecl.inc
xptcstubsdef.inc

View File

@@ -0,0 +1,33 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptcall
EXPORTS = xptcall.h \
xptcstubsdecl.inc \
xptcstubsdef.inc \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,55 @@
#!/usr/local/bin/perl
# This is used to generate stub entry points. We generate a file to
# be included in the declaraion and a file to be used for expanding macros
# to represent the implementation of the stubs.
$entry_count = 256;
$sentinel_count = 10;
$decl_name = "xptcstubsdecl.inc";
$def_name = "xptcstubsdef.inc";
##
## Write the declarations include file
##
die "Can't open $decl_name" if !open(OUTFILE, ">$decl_name");
print OUTFILE "// generated file - DO NOT EDIT \n\n";
print OUTFILE "// includes ",$entry_count," stub entries, and ",
$sentinel_count," sentinel entries\n\n";
print OUTFILE "// declarations of normal stubs...\n";
print OUTFILE "// 0 is QueryInterface\n";
print OUTFILE "// 1 is AddRef\n";
print OUTFILE "// 2 is Release\n";
for($i = 0; $i < $entry_count; $i++) {
print OUTFILE "XPTC_EXPORT NS_IMETHOD Stub",$i+3,"();\n";
}
print OUTFILE "\n// declarations of sentinel stubs\n";
for($i = 0; $i < $sentinel_count; $i++) {
print OUTFILE "XPTC_EXPORT NS_IMETHOD Sentinel",$i,"();\n";
}
close(OUTFILE);
##
## Write the definitions include file. This assumes a macro will be used to
## expand the entries written...
##
die "Can't open $def_name" if !open(OUTFILE, ">$def_name");
print OUTFILE "// generated file - DO NOT EDIT \n\n";
print OUTFILE "// includes ",$entry_count," stub entries, and ",
$sentinel_count," sentinel entries\n\n";
for($i = 0; $i < $entry_count; $i++) {
print OUTFILE "STUB_ENTRY(",$i+3,")\n";
}
for($i = 0; $i < $sentinel_count; $i++) {
print OUTFILE "SENTINEL_ENTRY(",$i,")\n";
}

View File

@@ -0,0 +1,29 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH=..\..\..\..
EXPORTS = xptcall.h \
xptcstubsdecl.inc \
xptcstubsdef.inc \
$(NULL)
MODULE = xptcall
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,137 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Public declarations for xptcall. */
#ifndef xptcall_h___
#define xptcall_h___
#include "prtypes.h"
#include "nscore.h"
#include "nsISupports.h"
#include "xpt_struct.h"
#include "xptinfo.h"
#include "nsIInterfaceInfo.h"
/***************************************************************************/
/*
* The linkage of XPTC API functions differs depending on whether the file is
* used within the XPTC library or not. Any source file within the XPTC
* library should define EXPORT_XPTC_API whereas any client of the library
* should not.
*/
#ifdef EXPORT_XPTC_API
#define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
#define XPTC_PUBLIC_DATA(t) PR_IMPLEMENT_DATA(t)
#ifdef _WIN32
# define XPTC_EXPORT _declspec(dllexport)
#else
# define XPTC_EXPORT
#endif
#else
#ifdef _WIN32
# define XPTC_PUBLIC_API(t) _declspec(dllimport) t
# define XPTC_PUBLIC_DATA(t) _declspec(dllimport) t
# define XPTC_EXPORT _declspec(dllimport)
#else
# define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
# define XPTC_PUBLIC_DATA(t) t
# define XPTC_EXPORT
#endif
#endif
#define XPTC_FRIEND_API(t) XPTC_PUBLIC_API(t)
#define XPTC_FRIEND_DATA(t) XPTC_PUBLIC_DATA(t)
/***************************************************************************/
struct nsXPTCMiniVariant
{
// No ctors or dtors so that we can use arrays of these on the stack
// with no penalty.
union
{
PRInt8 i8;
PRInt16 i16;
PRInt32 i32;
PRInt64 i64;
PRUint8 u8;
PRUint16 u16;
PRUint32 u32;
PRUint64 u64;
float f;
double d;
PRBool b;
char c;
wchar_t wc;
void* p;
} val;
};
struct nsXPTCVariant : public nsXPTCMiniVariant
{
// No ctors or dtors so that we can use arrays of these on the stack
// with no penalty.
// inherits 'val' here
void* ptr;
nsXPTType type;
PRUint8 flags;
enum
{
// these are bitflags!
PTR_IS_DATA = 0x1, // ptr points to 'real' data in val
VAL_IS_OWNED = 0x2, // val.p holds alloc'd ptr that must be freed
VAL_IS_IFACE = 0x4 // val.p holds interface ptr that must be released
};
PRBool IsPtrData() const {return (PRBool) (flags & PTR_IS_DATA);}
PRBool IsValOwned() const {return (PRBool) (flags & VAL_IS_OWNED);}
PRBool IsValInterface() const {return (PRBool) (flags & VAL_IS_IFACE);}
};
/***************************************************************************/
class nsXPTCStubBase : public nsISupports
{
public:
// Include generated vtbl stub declarations.
// These are virtual and *also* implemented by this class..
#include "xptcstubsdecl.inc"
// The following methods must be provided by inheritor of this class.
// return a refcounted pointer to the InterfaceInfo for this object
// NOTE: on some platforms this MUST not fail or we crash!
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
// call this method and return result
NS_IMETHOD CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params) = 0;
};
PR_BEGIN_EXTERN_C
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params);
PR_END_EXTERN_C
#endif /* xptcall_h___ */

View File

@@ -0,0 +1,276 @@
// generated file - DO NOT EDIT
// includes 256 stub entries, and 10 sentinel entries
// declarations of normal stubs...
// 0 is QueryInterface
// 1 is AddRef
// 2 is Release
XPTC_EXPORT NS_IMETHOD Stub3();
XPTC_EXPORT NS_IMETHOD Stub4();
XPTC_EXPORT NS_IMETHOD Stub5();
XPTC_EXPORT NS_IMETHOD Stub6();
XPTC_EXPORT NS_IMETHOD Stub7();
XPTC_EXPORT NS_IMETHOD Stub8();
XPTC_EXPORT NS_IMETHOD Stub9();
XPTC_EXPORT NS_IMETHOD Stub10();
XPTC_EXPORT NS_IMETHOD Stub11();
XPTC_EXPORT NS_IMETHOD Stub12();
XPTC_EXPORT NS_IMETHOD Stub13();
XPTC_EXPORT NS_IMETHOD Stub14();
XPTC_EXPORT NS_IMETHOD Stub15();
XPTC_EXPORT NS_IMETHOD Stub16();
XPTC_EXPORT NS_IMETHOD Stub17();
XPTC_EXPORT NS_IMETHOD Stub18();
XPTC_EXPORT NS_IMETHOD Stub19();
XPTC_EXPORT NS_IMETHOD Stub20();
XPTC_EXPORT NS_IMETHOD Stub21();
XPTC_EXPORT NS_IMETHOD Stub22();
XPTC_EXPORT NS_IMETHOD Stub23();
XPTC_EXPORT NS_IMETHOD Stub24();
XPTC_EXPORT NS_IMETHOD Stub25();
XPTC_EXPORT NS_IMETHOD Stub26();
XPTC_EXPORT NS_IMETHOD Stub27();
XPTC_EXPORT NS_IMETHOD Stub28();
XPTC_EXPORT NS_IMETHOD Stub29();
XPTC_EXPORT NS_IMETHOD Stub30();
XPTC_EXPORT NS_IMETHOD Stub31();
XPTC_EXPORT NS_IMETHOD Stub32();
XPTC_EXPORT NS_IMETHOD Stub33();
XPTC_EXPORT NS_IMETHOD Stub34();
XPTC_EXPORT NS_IMETHOD Stub35();
XPTC_EXPORT NS_IMETHOD Stub36();
XPTC_EXPORT NS_IMETHOD Stub37();
XPTC_EXPORT NS_IMETHOD Stub38();
XPTC_EXPORT NS_IMETHOD Stub39();
XPTC_EXPORT NS_IMETHOD Stub40();
XPTC_EXPORT NS_IMETHOD Stub41();
XPTC_EXPORT NS_IMETHOD Stub42();
XPTC_EXPORT NS_IMETHOD Stub43();
XPTC_EXPORT NS_IMETHOD Stub44();
XPTC_EXPORT NS_IMETHOD Stub45();
XPTC_EXPORT NS_IMETHOD Stub46();
XPTC_EXPORT NS_IMETHOD Stub47();
XPTC_EXPORT NS_IMETHOD Stub48();
XPTC_EXPORT NS_IMETHOD Stub49();
XPTC_EXPORT NS_IMETHOD Stub50();
XPTC_EXPORT NS_IMETHOD Stub51();
XPTC_EXPORT NS_IMETHOD Stub52();
XPTC_EXPORT NS_IMETHOD Stub53();
XPTC_EXPORT NS_IMETHOD Stub54();
XPTC_EXPORT NS_IMETHOD Stub55();
XPTC_EXPORT NS_IMETHOD Stub56();
XPTC_EXPORT NS_IMETHOD Stub57();
XPTC_EXPORT NS_IMETHOD Stub58();
XPTC_EXPORT NS_IMETHOD Stub59();
XPTC_EXPORT NS_IMETHOD Stub60();
XPTC_EXPORT NS_IMETHOD Stub61();
XPTC_EXPORT NS_IMETHOD Stub62();
XPTC_EXPORT NS_IMETHOD Stub63();
XPTC_EXPORT NS_IMETHOD Stub64();
XPTC_EXPORT NS_IMETHOD Stub65();
XPTC_EXPORT NS_IMETHOD Stub66();
XPTC_EXPORT NS_IMETHOD Stub67();
XPTC_EXPORT NS_IMETHOD Stub68();
XPTC_EXPORT NS_IMETHOD Stub69();
XPTC_EXPORT NS_IMETHOD Stub70();
XPTC_EXPORT NS_IMETHOD Stub71();
XPTC_EXPORT NS_IMETHOD Stub72();
XPTC_EXPORT NS_IMETHOD Stub73();
XPTC_EXPORT NS_IMETHOD Stub74();
XPTC_EXPORT NS_IMETHOD Stub75();
XPTC_EXPORT NS_IMETHOD Stub76();
XPTC_EXPORT NS_IMETHOD Stub77();
XPTC_EXPORT NS_IMETHOD Stub78();
XPTC_EXPORT NS_IMETHOD Stub79();
XPTC_EXPORT NS_IMETHOD Stub80();
XPTC_EXPORT NS_IMETHOD Stub81();
XPTC_EXPORT NS_IMETHOD Stub82();
XPTC_EXPORT NS_IMETHOD Stub83();
XPTC_EXPORT NS_IMETHOD Stub84();
XPTC_EXPORT NS_IMETHOD Stub85();
XPTC_EXPORT NS_IMETHOD Stub86();
XPTC_EXPORT NS_IMETHOD Stub87();
XPTC_EXPORT NS_IMETHOD Stub88();
XPTC_EXPORT NS_IMETHOD Stub89();
XPTC_EXPORT NS_IMETHOD Stub90();
XPTC_EXPORT NS_IMETHOD Stub91();
XPTC_EXPORT NS_IMETHOD Stub92();
XPTC_EXPORT NS_IMETHOD Stub93();
XPTC_EXPORT NS_IMETHOD Stub94();
XPTC_EXPORT NS_IMETHOD Stub95();
XPTC_EXPORT NS_IMETHOD Stub96();
XPTC_EXPORT NS_IMETHOD Stub97();
XPTC_EXPORT NS_IMETHOD Stub98();
XPTC_EXPORT NS_IMETHOD Stub99();
XPTC_EXPORT NS_IMETHOD Stub100();
XPTC_EXPORT NS_IMETHOD Stub101();
XPTC_EXPORT NS_IMETHOD Stub102();
XPTC_EXPORT NS_IMETHOD Stub103();
XPTC_EXPORT NS_IMETHOD Stub104();
XPTC_EXPORT NS_IMETHOD Stub105();
XPTC_EXPORT NS_IMETHOD Stub106();
XPTC_EXPORT NS_IMETHOD Stub107();
XPTC_EXPORT NS_IMETHOD Stub108();
XPTC_EXPORT NS_IMETHOD Stub109();
XPTC_EXPORT NS_IMETHOD Stub110();
XPTC_EXPORT NS_IMETHOD Stub111();
XPTC_EXPORT NS_IMETHOD Stub112();
XPTC_EXPORT NS_IMETHOD Stub113();
XPTC_EXPORT NS_IMETHOD Stub114();
XPTC_EXPORT NS_IMETHOD Stub115();
XPTC_EXPORT NS_IMETHOD Stub116();
XPTC_EXPORT NS_IMETHOD Stub117();
XPTC_EXPORT NS_IMETHOD Stub118();
XPTC_EXPORT NS_IMETHOD Stub119();
XPTC_EXPORT NS_IMETHOD Stub120();
XPTC_EXPORT NS_IMETHOD Stub121();
XPTC_EXPORT NS_IMETHOD Stub122();
XPTC_EXPORT NS_IMETHOD Stub123();
XPTC_EXPORT NS_IMETHOD Stub124();
XPTC_EXPORT NS_IMETHOD Stub125();
XPTC_EXPORT NS_IMETHOD Stub126();
XPTC_EXPORT NS_IMETHOD Stub127();
XPTC_EXPORT NS_IMETHOD Stub128();
XPTC_EXPORT NS_IMETHOD Stub129();
XPTC_EXPORT NS_IMETHOD Stub130();
XPTC_EXPORT NS_IMETHOD Stub131();
XPTC_EXPORT NS_IMETHOD Stub132();
XPTC_EXPORT NS_IMETHOD Stub133();
XPTC_EXPORT NS_IMETHOD Stub134();
XPTC_EXPORT NS_IMETHOD Stub135();
XPTC_EXPORT NS_IMETHOD Stub136();
XPTC_EXPORT NS_IMETHOD Stub137();
XPTC_EXPORT NS_IMETHOD Stub138();
XPTC_EXPORT NS_IMETHOD Stub139();
XPTC_EXPORT NS_IMETHOD Stub140();
XPTC_EXPORT NS_IMETHOD Stub141();
XPTC_EXPORT NS_IMETHOD Stub142();
XPTC_EXPORT NS_IMETHOD Stub143();
XPTC_EXPORT NS_IMETHOD Stub144();
XPTC_EXPORT NS_IMETHOD Stub145();
XPTC_EXPORT NS_IMETHOD Stub146();
XPTC_EXPORT NS_IMETHOD Stub147();
XPTC_EXPORT NS_IMETHOD Stub148();
XPTC_EXPORT NS_IMETHOD Stub149();
XPTC_EXPORT NS_IMETHOD Stub150();
XPTC_EXPORT NS_IMETHOD Stub151();
XPTC_EXPORT NS_IMETHOD Stub152();
XPTC_EXPORT NS_IMETHOD Stub153();
XPTC_EXPORT NS_IMETHOD Stub154();
XPTC_EXPORT NS_IMETHOD Stub155();
XPTC_EXPORT NS_IMETHOD Stub156();
XPTC_EXPORT NS_IMETHOD Stub157();
XPTC_EXPORT NS_IMETHOD Stub158();
XPTC_EXPORT NS_IMETHOD Stub159();
XPTC_EXPORT NS_IMETHOD Stub160();
XPTC_EXPORT NS_IMETHOD Stub161();
XPTC_EXPORT NS_IMETHOD Stub162();
XPTC_EXPORT NS_IMETHOD Stub163();
XPTC_EXPORT NS_IMETHOD Stub164();
XPTC_EXPORT NS_IMETHOD Stub165();
XPTC_EXPORT NS_IMETHOD Stub166();
XPTC_EXPORT NS_IMETHOD Stub167();
XPTC_EXPORT NS_IMETHOD Stub168();
XPTC_EXPORT NS_IMETHOD Stub169();
XPTC_EXPORT NS_IMETHOD Stub170();
XPTC_EXPORT NS_IMETHOD Stub171();
XPTC_EXPORT NS_IMETHOD Stub172();
XPTC_EXPORT NS_IMETHOD Stub173();
XPTC_EXPORT NS_IMETHOD Stub174();
XPTC_EXPORT NS_IMETHOD Stub175();
XPTC_EXPORT NS_IMETHOD Stub176();
XPTC_EXPORT NS_IMETHOD Stub177();
XPTC_EXPORT NS_IMETHOD Stub178();
XPTC_EXPORT NS_IMETHOD Stub179();
XPTC_EXPORT NS_IMETHOD Stub180();
XPTC_EXPORT NS_IMETHOD Stub181();
XPTC_EXPORT NS_IMETHOD Stub182();
XPTC_EXPORT NS_IMETHOD Stub183();
XPTC_EXPORT NS_IMETHOD Stub184();
XPTC_EXPORT NS_IMETHOD Stub185();
XPTC_EXPORT NS_IMETHOD Stub186();
XPTC_EXPORT NS_IMETHOD Stub187();
XPTC_EXPORT NS_IMETHOD Stub188();
XPTC_EXPORT NS_IMETHOD Stub189();
XPTC_EXPORT NS_IMETHOD Stub190();
XPTC_EXPORT NS_IMETHOD Stub191();
XPTC_EXPORT NS_IMETHOD Stub192();
XPTC_EXPORT NS_IMETHOD Stub193();
XPTC_EXPORT NS_IMETHOD Stub194();
XPTC_EXPORT NS_IMETHOD Stub195();
XPTC_EXPORT NS_IMETHOD Stub196();
XPTC_EXPORT NS_IMETHOD Stub197();
XPTC_EXPORT NS_IMETHOD Stub198();
XPTC_EXPORT NS_IMETHOD Stub199();
XPTC_EXPORT NS_IMETHOD Stub200();
XPTC_EXPORT NS_IMETHOD Stub201();
XPTC_EXPORT NS_IMETHOD Stub202();
XPTC_EXPORT NS_IMETHOD Stub203();
XPTC_EXPORT NS_IMETHOD Stub204();
XPTC_EXPORT NS_IMETHOD Stub205();
XPTC_EXPORT NS_IMETHOD Stub206();
XPTC_EXPORT NS_IMETHOD Stub207();
XPTC_EXPORT NS_IMETHOD Stub208();
XPTC_EXPORT NS_IMETHOD Stub209();
XPTC_EXPORT NS_IMETHOD Stub210();
XPTC_EXPORT NS_IMETHOD Stub211();
XPTC_EXPORT NS_IMETHOD Stub212();
XPTC_EXPORT NS_IMETHOD Stub213();
XPTC_EXPORT NS_IMETHOD Stub214();
XPTC_EXPORT NS_IMETHOD Stub215();
XPTC_EXPORT NS_IMETHOD Stub216();
XPTC_EXPORT NS_IMETHOD Stub217();
XPTC_EXPORT NS_IMETHOD Stub218();
XPTC_EXPORT NS_IMETHOD Stub219();
XPTC_EXPORT NS_IMETHOD Stub220();
XPTC_EXPORT NS_IMETHOD Stub221();
XPTC_EXPORT NS_IMETHOD Stub222();
XPTC_EXPORT NS_IMETHOD Stub223();
XPTC_EXPORT NS_IMETHOD Stub224();
XPTC_EXPORT NS_IMETHOD Stub225();
XPTC_EXPORT NS_IMETHOD Stub226();
XPTC_EXPORT NS_IMETHOD Stub227();
XPTC_EXPORT NS_IMETHOD Stub228();
XPTC_EXPORT NS_IMETHOD Stub229();
XPTC_EXPORT NS_IMETHOD Stub230();
XPTC_EXPORT NS_IMETHOD Stub231();
XPTC_EXPORT NS_IMETHOD Stub232();
XPTC_EXPORT NS_IMETHOD Stub233();
XPTC_EXPORT NS_IMETHOD Stub234();
XPTC_EXPORT NS_IMETHOD Stub235();
XPTC_EXPORT NS_IMETHOD Stub236();
XPTC_EXPORT NS_IMETHOD Stub237();
XPTC_EXPORT NS_IMETHOD Stub238();
XPTC_EXPORT NS_IMETHOD Stub239();
XPTC_EXPORT NS_IMETHOD Stub240();
XPTC_EXPORT NS_IMETHOD Stub241();
XPTC_EXPORT NS_IMETHOD Stub242();
XPTC_EXPORT NS_IMETHOD Stub243();
XPTC_EXPORT NS_IMETHOD Stub244();
XPTC_EXPORT NS_IMETHOD Stub245();
XPTC_EXPORT NS_IMETHOD Stub246();
XPTC_EXPORT NS_IMETHOD Stub247();
XPTC_EXPORT NS_IMETHOD Stub248();
XPTC_EXPORT NS_IMETHOD Stub249();
XPTC_EXPORT NS_IMETHOD Stub250();
XPTC_EXPORT NS_IMETHOD Stub251();
XPTC_EXPORT NS_IMETHOD Stub252();
XPTC_EXPORT NS_IMETHOD Stub253();
XPTC_EXPORT NS_IMETHOD Stub254();
XPTC_EXPORT NS_IMETHOD Stub255();
XPTC_EXPORT NS_IMETHOD Stub256();
XPTC_EXPORT NS_IMETHOD Stub257();
XPTC_EXPORT NS_IMETHOD Stub258();
// declarations of sentinel stubs
XPTC_EXPORT NS_IMETHOD Sentinel0();
XPTC_EXPORT NS_IMETHOD Sentinel1();
XPTC_EXPORT NS_IMETHOD Sentinel2();
XPTC_EXPORT NS_IMETHOD Sentinel3();
XPTC_EXPORT NS_IMETHOD Sentinel4();
XPTC_EXPORT NS_IMETHOD Sentinel5();
XPTC_EXPORT NS_IMETHOD Sentinel6();
XPTC_EXPORT NS_IMETHOD Sentinel7();
XPTC_EXPORT NS_IMETHOD Sentinel8();
XPTC_EXPORT NS_IMETHOD Sentinel9();

View File

@@ -0,0 +1,270 @@
// generated file - DO NOT EDIT
// includes 256 stub entries, and 10 sentinel entries
STUB_ENTRY(3)
STUB_ENTRY(4)
STUB_ENTRY(5)
STUB_ENTRY(6)
STUB_ENTRY(7)
STUB_ENTRY(8)
STUB_ENTRY(9)
STUB_ENTRY(10)
STUB_ENTRY(11)
STUB_ENTRY(12)
STUB_ENTRY(13)
STUB_ENTRY(14)
STUB_ENTRY(15)
STUB_ENTRY(16)
STUB_ENTRY(17)
STUB_ENTRY(18)
STUB_ENTRY(19)
STUB_ENTRY(20)
STUB_ENTRY(21)
STUB_ENTRY(22)
STUB_ENTRY(23)
STUB_ENTRY(24)
STUB_ENTRY(25)
STUB_ENTRY(26)
STUB_ENTRY(27)
STUB_ENTRY(28)
STUB_ENTRY(29)
STUB_ENTRY(30)
STUB_ENTRY(31)
STUB_ENTRY(32)
STUB_ENTRY(33)
STUB_ENTRY(34)
STUB_ENTRY(35)
STUB_ENTRY(36)
STUB_ENTRY(37)
STUB_ENTRY(38)
STUB_ENTRY(39)
STUB_ENTRY(40)
STUB_ENTRY(41)
STUB_ENTRY(42)
STUB_ENTRY(43)
STUB_ENTRY(44)
STUB_ENTRY(45)
STUB_ENTRY(46)
STUB_ENTRY(47)
STUB_ENTRY(48)
STUB_ENTRY(49)
STUB_ENTRY(50)
STUB_ENTRY(51)
STUB_ENTRY(52)
STUB_ENTRY(53)
STUB_ENTRY(54)
STUB_ENTRY(55)
STUB_ENTRY(56)
STUB_ENTRY(57)
STUB_ENTRY(58)
STUB_ENTRY(59)
STUB_ENTRY(60)
STUB_ENTRY(61)
STUB_ENTRY(62)
STUB_ENTRY(63)
STUB_ENTRY(64)
STUB_ENTRY(65)
STUB_ENTRY(66)
STUB_ENTRY(67)
STUB_ENTRY(68)
STUB_ENTRY(69)
STUB_ENTRY(70)
STUB_ENTRY(71)
STUB_ENTRY(72)
STUB_ENTRY(73)
STUB_ENTRY(74)
STUB_ENTRY(75)
STUB_ENTRY(76)
STUB_ENTRY(77)
STUB_ENTRY(78)
STUB_ENTRY(79)
STUB_ENTRY(80)
STUB_ENTRY(81)
STUB_ENTRY(82)
STUB_ENTRY(83)
STUB_ENTRY(84)
STUB_ENTRY(85)
STUB_ENTRY(86)
STUB_ENTRY(87)
STUB_ENTRY(88)
STUB_ENTRY(89)
STUB_ENTRY(90)
STUB_ENTRY(91)
STUB_ENTRY(92)
STUB_ENTRY(93)
STUB_ENTRY(94)
STUB_ENTRY(95)
STUB_ENTRY(96)
STUB_ENTRY(97)
STUB_ENTRY(98)
STUB_ENTRY(99)
STUB_ENTRY(100)
STUB_ENTRY(101)
STUB_ENTRY(102)
STUB_ENTRY(103)
STUB_ENTRY(104)
STUB_ENTRY(105)
STUB_ENTRY(106)
STUB_ENTRY(107)
STUB_ENTRY(108)
STUB_ENTRY(109)
STUB_ENTRY(110)
STUB_ENTRY(111)
STUB_ENTRY(112)
STUB_ENTRY(113)
STUB_ENTRY(114)
STUB_ENTRY(115)
STUB_ENTRY(116)
STUB_ENTRY(117)
STUB_ENTRY(118)
STUB_ENTRY(119)
STUB_ENTRY(120)
STUB_ENTRY(121)
STUB_ENTRY(122)
STUB_ENTRY(123)
STUB_ENTRY(124)
STUB_ENTRY(125)
STUB_ENTRY(126)
STUB_ENTRY(127)
STUB_ENTRY(128)
STUB_ENTRY(129)
STUB_ENTRY(130)
STUB_ENTRY(131)
STUB_ENTRY(132)
STUB_ENTRY(133)
STUB_ENTRY(134)
STUB_ENTRY(135)
STUB_ENTRY(136)
STUB_ENTRY(137)
STUB_ENTRY(138)
STUB_ENTRY(139)
STUB_ENTRY(140)
STUB_ENTRY(141)
STUB_ENTRY(142)
STUB_ENTRY(143)
STUB_ENTRY(144)
STUB_ENTRY(145)
STUB_ENTRY(146)
STUB_ENTRY(147)
STUB_ENTRY(148)
STUB_ENTRY(149)
STUB_ENTRY(150)
STUB_ENTRY(151)
STUB_ENTRY(152)
STUB_ENTRY(153)
STUB_ENTRY(154)
STUB_ENTRY(155)
STUB_ENTRY(156)
STUB_ENTRY(157)
STUB_ENTRY(158)
STUB_ENTRY(159)
STUB_ENTRY(160)
STUB_ENTRY(161)
STUB_ENTRY(162)
STUB_ENTRY(163)
STUB_ENTRY(164)
STUB_ENTRY(165)
STUB_ENTRY(166)
STUB_ENTRY(167)
STUB_ENTRY(168)
STUB_ENTRY(169)
STUB_ENTRY(170)
STUB_ENTRY(171)
STUB_ENTRY(172)
STUB_ENTRY(173)
STUB_ENTRY(174)
STUB_ENTRY(175)
STUB_ENTRY(176)
STUB_ENTRY(177)
STUB_ENTRY(178)
STUB_ENTRY(179)
STUB_ENTRY(180)
STUB_ENTRY(181)
STUB_ENTRY(182)
STUB_ENTRY(183)
STUB_ENTRY(184)
STUB_ENTRY(185)
STUB_ENTRY(186)
STUB_ENTRY(187)
STUB_ENTRY(188)
STUB_ENTRY(189)
STUB_ENTRY(190)
STUB_ENTRY(191)
STUB_ENTRY(192)
STUB_ENTRY(193)
STUB_ENTRY(194)
STUB_ENTRY(195)
STUB_ENTRY(196)
STUB_ENTRY(197)
STUB_ENTRY(198)
STUB_ENTRY(199)
STUB_ENTRY(200)
STUB_ENTRY(201)
STUB_ENTRY(202)
STUB_ENTRY(203)
STUB_ENTRY(204)
STUB_ENTRY(205)
STUB_ENTRY(206)
STUB_ENTRY(207)
STUB_ENTRY(208)
STUB_ENTRY(209)
STUB_ENTRY(210)
STUB_ENTRY(211)
STUB_ENTRY(212)
STUB_ENTRY(213)
STUB_ENTRY(214)
STUB_ENTRY(215)
STUB_ENTRY(216)
STUB_ENTRY(217)
STUB_ENTRY(218)
STUB_ENTRY(219)
STUB_ENTRY(220)
STUB_ENTRY(221)
STUB_ENTRY(222)
STUB_ENTRY(223)
STUB_ENTRY(224)
STUB_ENTRY(225)
STUB_ENTRY(226)
STUB_ENTRY(227)
STUB_ENTRY(228)
STUB_ENTRY(229)
STUB_ENTRY(230)
STUB_ENTRY(231)
STUB_ENTRY(232)
STUB_ENTRY(233)
STUB_ENTRY(234)
STUB_ENTRY(235)
STUB_ENTRY(236)
STUB_ENTRY(237)
STUB_ENTRY(238)
STUB_ENTRY(239)
STUB_ENTRY(240)
STUB_ENTRY(241)
STUB_ENTRY(242)
STUB_ENTRY(243)
STUB_ENTRY(244)
STUB_ENTRY(245)
STUB_ENTRY(246)
STUB_ENTRY(247)
STUB_ENTRY(248)
STUB_ENTRY(249)
STUB_ENTRY(250)
STUB_ENTRY(251)
STUB_ENTRY(252)
STUB_ENTRY(253)
STUB_ENTRY(254)
STUB_ENTRY(255)
STUB_ENTRY(256)
STUB_ENTRY(257)
STUB_ENTRY(258)
SENTINEL_ENTRY(0)
SENTINEL_ENTRY(1)
SENTINEL_ENTRY(2)
SENTINEL_ENTRY(3)
SENTINEL_ENTRY(4)
SENTINEL_ENTRY(5)
SENTINEL_ENTRY(6)
SENTINEL_ENTRY(7)
SENTINEL_ENTRY(8)
SENTINEL_ENTRY(9)

View File

@@ -0,0 +1,38 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptcall
LIBRARY_NAME = xptcall
DIRS = md
CFLAGS += -DEXPORT_XPTC_API
CSRCS = xptcall.c \
$(NULL)
REQUIRES = $(MODULE)
# export:: libs
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,65 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
DIRS=md
MAKE_OBJ_TYPE = DLL
DLLNAME = xptcall$(MOZ_BITS)
#PDBFILE = $(DLLNAME).pdb
#MAPFILE = $(DLLNAME).map
DLL =.\$(OBJDIR)\$(DLLNAME).dll
MODULE=xptcall
REQUIRES=xpcom libxpt xptinfo
DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPTC_API
OBJS= \
.\$(OBJDIR)\xptcall.obj \
.\md\win32\$(OBJDIR)\xptcinvoke.obj \
.\md\win32\$(OBJDIR)\xptcstubs.obj \
$(NULL)
EXPORTS = \
$(NULL)
LINCS=-I$(PUBLIC)\xptcall -I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LLIBS= $(LIBNSPR) \
$(DIST)\lib\xpcom$(MOZ_BITS).lib \
$(DIST)\lib\xptinfo$(MOZ_BITS).lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(DLLNAME).lib
rm -f $(DIST)\bin\$(DLLNAME).dll

View File

@@ -14,21 +14,18 @@
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH=../../../../..
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = unix
include $(topsrcdir)/config/rules.mk
EXPORT_RESOURCE_XPINSTALL = \
$(srcdir)/progress.xul \
$(srcdir)/progress.html \
$(srcdir)/progress.css \
$(NULL)
install::
$(INSTALL) $(EXPORT_RESOURCE_XPINSTALL) $(DIST)/bin/res/xpinstall

View File

@@ -0,0 +1,129 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
#include "xptcprivate.h"
#ifndef XP_MAC
#error "This code is for Macintosh only"
#endif
extern "C" uint32
invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
{
PRUint32 result = 0;
for(PRUint32 i = 0; i < paramCount; i++, s++)
{
if(s->IsPtrData())
{
result++;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
result++;
break;
case nsXPTType::T_I64 :
result+=2;
break;
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
result++;
break;
case nsXPTType::T_U64 :
result+=2;
break;
case nsXPTType::T_FLOAT :
result++;
break;
case nsXPTType::T_DOUBLE :
result+=2;
break;
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
result++;
break;
default:
// all the others are plain pointer types
result++;
break;
}
}
return result;
}
extern "C" void
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s, double *fprData)
{
PRUint32 fpCount = 0;
for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
{
if(s->IsPtrData())
{
*((void**)d) = s->ptr;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 : *((PRInt8*) d) = s->val.i8; break;
case nsXPTType::T_I16 : *((PRInt16*) d) = s->val.i16; break;
case nsXPTType::T_I32 : *((PRInt32*) d) = s->val.i32; break;
case nsXPTType::T_I64 : *((PRInt64*) d) = s->val.i64; d++; break;
case nsXPTType::T_U8 : *((PRUint8*) d) = s->val.u8; break;
case nsXPTType::T_U16 : *((PRUint16*)d) = s->val.u16; break;
case nsXPTType::T_U32 : *((PRUint32*)d) = s->val.u32; break;
case nsXPTType::T_U64 : *((PRUint64*)d) = s->val.u64; d++; break;
case nsXPTType::T_FLOAT : *((float*) d) = s->val.f;
if (fpCount < 13)
fprData[fpCount++] = s->val.f;
break;
case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++;
if (fpCount < 13)
fprData[fpCount++] = s->val.d;
break;
case nsXPTType::T_BOOL : *((PRBool*) d) = s->val.b; break;
case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break;
case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break;
default:
// all the others are plain pointer types
*((void**)d) = s->val.p;
break;
}
}
}
#pragma export on
extern "C" nsresult _XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params);
extern "C"
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params)
{
return _XPTC_InvokeByIndex(that, methodIndex, paramCount, params);
}
#pragma export off

View File

@@ -0,0 +1,90 @@
csect CODE{PR}
#
# XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
# PRUint32 paramCount, nsXPTCVariant* params)
#
import .invoke_count_words
import .invoke_copy_to_stack
import .__ptr_glue
._XPTC_InvokeByIndex:
mflr r0
stw r31,-4(sp)
#
# save off the incoming values in the caller's parameter area
#
stw r3,24(sp) # that
stw r4,28(sp) # methodIndex
stw r5,32(sp) # paramCount
stw r6,36(sp) # params
stw r0,8(sp)
stwu sp,-136(sp) # = 24 for linkage area, 8 * 13 for fprData area, 8 for saved registers
# set up for and call 'invoke_count_words' to get new stack size
#
mr r3,r5
bl .invoke_count_words
nop
# prepare args for 'invoke_copy_to_stack' call
#
lwz r4,168(sp) # paramCount
lwz r5,172(sp) # params
addi r6,sp,128 # fprData
slwi r3,r3,2 # number of bytes of stack required
mr r31,sp # save original stack top
sub sp,sp,r3 # bump the stack
addi r3,sp,28 # parameter pointer excludes linkage area size + 'this'
bl .invoke_copy_to_stack
nop
lfd f1,128(r31)
lfd f2,120(r31)
lfd f3,112(r31)
lfd f4,104(r31)
lfd f5,96(r31)
lfd f6,88(r31)
lfd f7,80(r31)
lfd f8,72(r31)
lfd f9,64(r31)
lfd f10,56(r31)
lfd f11,48(r31)
lfd f12,40(r31)
lfd f13,32(r31)
lwz r3,160(r31) # that
lwz r4,0(r3) # get vTable from 'that'
lwz r5,164(r31) # methodIndex
slwi r5,r5,2 # methodIndex * 4
addi r5,r5,8 # step over junk at start of vTable !
lwzx r12,r5,r4 # get function pointer
lwz r4,28(sp)
lwz r5,32(sp)
lwz r6,36(sp)
lwz r7,40(sp)
lwz r8,44(sp)
lwz r9,48(sp)
lwz r10,52(sp)
bl .__ptr_glue
nop
mr sp,r31
lwz r0,144(sp)
addi sp,sp,136
mtlr r0
lwz r31,-4(sp)
blr
csect DATA
import TOC
export ._XPTC_InvokeByIndex
dc.l ._XPTC_InvokeByIndex
dc.l TOC

View File

@@ -0,0 +1,41 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implement shared vtbl methods. */
#pragma export on
#include "xptcprivate.h"
#define STUB_ENTRY(n) \
nsresult nsXPTCStubBase::Stub##n() \
{ \
NS_ASSERTION(0,"nsXPTCStubBase::Stub called on unsupported platform"); \
return NS_ERROR_NOT_IMPLEMENTED; \
}
#define SENTINEL_ENTRY(n) \
nsresult nsXPTCStubBase::Sentinel##n() \
{ \
NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
return NS_ERROR_NOT_IMPLEMENTED; \
}
#include "xptcstubsdef.inc"
#pragma export off

View File

@@ -0,0 +1,21 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..\..
IGNORE_MANIFEST=1
DIRS=win32
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,6 @@
These are just simple test programs in which stripped down versions of the
XPConnect invoke and stubs code can be built and tested as the code is brought
up on various platforms. These probrams do not test the param sizing and copying
functionality of the routines. However, they do supply a place where the lowest
level assembly language code can be developed and debugged in the simplest of
contexts before it is moved into the real routines.

View File

@@ -0,0 +1,5 @@
@echo off
echo deleting intermediate files
if exist *.obj del *.obj > NUL
if exist *.ilk del *.ilk > NUL
if exist *.pdb del *.pdb > NUL

View File

@@ -0,0 +1,203 @@
#include <stdio.h>
typedef unsigned nsresult;
typedef unsigned PRUint32;
typedef unsigned nsXPCVariant;
#if defined(WIN32)
#define NS_IMETHOD virtual nsresult __stdcall
#define NS_IMETHODIMP nsresult __stdcall
#else
#define NS_IMETHOD virtual nsresult
#define NS_IMETHODIMP nsresult
#endif
class base{
public:
NS_IMETHOD ignored() = 0;
};
class foo : public base {
public:
NS_IMETHOD callme1(int i, int j) = 0;
NS_IMETHOD callme2(int i, int j) = 0;
NS_IMETHOD callme3(int i, int j) = 0;
};
class bar : public foo{
public:
NS_IMETHOD ignored();
NS_IMETHOD callme1(int i, int j);
NS_IMETHOD callme2(int i, int j);
NS_IMETHOD callme3(int i, int j);
};
/*
class baz : public base {
public:
NS_IMETHOD ignored();
NS_IMETHOD callme1();
NS_IMETHOD callme2();
NS_IMETHOD callme3();
void setfoo(foo* f) {other = f;}
foo* other;
};
NS_IMETHODIMP baz::ignored(){return 0;}
*/
NS_IMETHODIMP bar::ignored(){return 0;}
NS_IMETHODIMP bar::callme1(int i, int j)
{
printf("called bar::callme1 with: %d %d\n", i, j);
return 5;
}
NS_IMETHODIMP bar::callme2(int i, int j)
{
printf("called bar::callme2 with: %d %d\n", i, j);
return 5;
}
NS_IMETHODIMP bar::callme3(int i, int j)
{
printf("called bar::callme3 with: %d %d\n", i, j);
return 5;
}
void docall(foo* f, int i, int j){
f->callme1(i, j);
}
/***************************************************************************/
#if defined(WIN32)
static PRUint32 __stdcall
invoke_count_words(PRUint32 paramCount, nsXPCVariant* s)
{
return paramCount;
}
static void __stdcall
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPCVariant* s)
{
for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
{
*((PRUint32*)d) = *((PRUint32*)s);
}
}
static nsresult __stdcall
DoInvoke(void* that, PRUint32 index,
PRUint32 paramCount, nsXPCVariant* params)
{
__asm {
push params
push paramCount
call invoke_count_words // stdcall, result in eax
shl eax,2 // *= 4
sub esp,eax // make space for params
mov edx,esp
push params
push paramCount
push edx
call invoke_copy_to_stack // stdcall
mov ecx,that // instance in ecx
push ecx // push this
mov edx,[ecx] // vtable in edx
mov eax,index
shl eax,2 // *= 4
add edx,eax
call [edx] // stdcall, i.e. callee cleans up stack.
}
}
#else
/***************************************************************************/
// just Linux_x86 now. Add other later...
static PRUint32
invoke_count_words(PRUint32 paramCount, nsXPCVariant* s)
{
return paramCount;
}
static void
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPCVariant* s)
{
for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
{
*((PRUint32*)d) = *((PRUint32*)s);
}
}
static nsresult
DoInvoke(void* that, PRUint32 index,
PRUint32 paramCount, nsXPCVariant* params)
{
PRUint32 result;
void* fn_count = invoke_count_words;
void* fn_copy = invoke_copy_to_stack;
__asm__ __volatile__(
"pushl %4\n\t"
"pushl %3\n\t"
"movl %5, %%eax\n\t"
"call *%%eax\n\t" /* count words */
"addl $0x8, %%esp\n\t"
"shl $2, %%eax\n\t" /* *= 4 */
"subl %%eax, %%esp\n\t" /* make room for params */
"movl %%esp, %%edx\n\t"
"pushl %4\n\t"
"pushl %3\n\t"
"pushl %%edx\n\t"
"movl %6, %%eax\n\t"
"call *%%eax\n\t" /* copy params */
"addl $0xc, %%esp\n\t"
"movl %1, %%ecx\n\t"
"pushl %%ecx\n\t"
"movl (%%ecx), %%edx\n\t"
"movl %2, %%eax\n\t" /* function index */
"shl $2, %%eax\n\t" /* *= 4 */
"addl $8, %%eax\n\t" /* += 8 */
"addl %%eax, %%edx\n\t"
"call *(%%edx)\n\t" /* safe to not cleanup esp */
"movl %%eax, %0"
: "=g" (result) /* %0 */
: "g" (that), /* %1 */
"g" (index), /* %2 */
"g" (paramCount), /* %3 */
"g" (params), /* %4 */
"g" (fn_count), /* %5 */
"g" (fn_copy) /* %6 */
: "ax", "cx", "dx", "memory"
);
return result;
}
#endif
/***************************************************************************/
int main()
{
nsXPCVariant params1[2] = {1,2};
nsXPCVariant params2[2] = {2,4};
nsXPCVariant params3[2] = {3,6};
foo* a = new bar();
// printf("calling via C++...\n");
// docall(a, 12, 24);
printf("calling via ASM...\n");
DoInvoke(a, 1, 2, params1);
DoInvoke(a, 2, 2, params2);
DoInvoke(a, 3, 2, params3);
return 0;
}

View File

@@ -0,0 +1,9 @@
@echo off
@echo deleing old output
if exist invoke_test.obj del invoke_test.obj > NUL
if exist invoke_test.ilk del invoke_test.ilk > NUL
if exist *.pdb del *.pdb > NUL
if exist invoke_test.exe del invoke_test.exe > NUL
@echo building...
cl /nologo -Zi -DWIN32 invoke_test.cpp

View File

@@ -0,0 +1,9 @@
@echo off
@echo deleing old output
if exist stub_test.obj del stub_test.obj > NUL
if exist stub_test.ilk del stub_test.ilk > NUL
if exist *.pdb del *.pdb > NUL
if exist stub_test.exe del stub_test.exe > NUL
@echo building...
cl /nologo -Zi -DWIN32 stub_test.cpp

View File

@@ -0,0 +1,184 @@
#include <stdio.h>
typedef unsigned nsresult;
typedef unsigned PRUint32;
typedef unsigned nsXPCVariant;
#if defined(WIN32)
#define NS_IMETHOD virtual nsresult __stdcall
#define NS_IMETHODIMP nsresult __stdcall
#else
#define NS_IMETHOD virtual nsresult
#define NS_IMETHODIMP nsresult
#endif
class base{
public:
NS_IMETHOD ignored() = 0;
};
class foo : public base {
public:
NS_IMETHOD callme1(int i, int j) = 0;
NS_IMETHOD callme2(int i, int j) = 0;
NS_IMETHOD callme3(int i, int j) = 0;
};
class bar : public foo{
public:
NS_IMETHOD ignored();
NS_IMETHOD callme1(int i, int j);
NS_IMETHOD callme2(int i, int j);
NS_IMETHOD callme3(int i, int j);
};
class baz : public base {
public:
NS_IMETHOD ignored();
NS_IMETHOD callme1();
NS_IMETHOD callme2();
NS_IMETHOD callme3();
void setfoo(foo* f) {other = f;}
foo* other;
};
NS_IMETHODIMP baz::ignored(){return 0;}
NS_IMETHODIMP bar::ignored(){return 0;}
NS_IMETHODIMP bar::callme1(int i, int j)
{
printf("called bar::callme1 with: %d %d\n", i, j);
return 5;
}
NS_IMETHODIMP bar::callme2(int i, int j)
{
printf("called bar::callme2 with: %d %d\n", i, j);
return 5;
}
NS_IMETHODIMP bar::callme3(int i, int j)
{
printf("called bar::callme3 with: %d %d\n", i, j);
return 5;
}
void docall(foo* f, int i, int j){
f->callme1(i, j);
}
/***************************************************************************/
#if defined(WIN32)
static int __stdcall
PrepareAndDispatch(baz* self, PRUint32 methodIndex,
PRUint32* args, PRUint32* stackBytesToPop)
{
foo* a = self->other;
int p1 = (int) *args;
int p2 = (int) *(args+1);
switch(methodIndex)
{
case 1: a->callme1(p1, p2); break;
case 2: a->callme2(p1, p2); break;
case 3: a->callme3(p1, p2); break;
}
*stackBytesToPop = 2*4;
return 1;
}
static __declspec(naked) void SharedStub(void)
{
__asm {
push ebp // set up simple stack frame
mov ebp, esp // stack has: ebp/vtbl_index/retaddr/this/args
push ecx // make room for a ptr
lea eax, [ebp-4] // pointer to stackBytesToPop
push eax
lea ecx, [ebp+16] // pointer to args
push ecx
mov edx, [ebp+4] // vtbl_index
push edx
mov eax, [ebp+12] // this
push eax
call PrepareAndDispatch
mov edx, [ebp+8] // return address
mov ecx, [ebp-4] // stackBytesToPop
add ecx, 12 // for this, the index, and ret address
mov esp, ebp
pop ebp
add esp, ecx // fix up stack pointer
jmp edx // simulate __stdcall return
}
}
// these macros get expanded (many times) in the file #included below
#define STUB_ENTRY(n) \
__declspec(naked) nsresult __stdcall baz::callme##n() \
{ __asm push n __asm jmp SharedStub }
#else
/***************************************************************************/
// just Linux_x86 now. Add other later...
static int
PrepareAndDispatch(baz* self, PRUint32 methodIndex, PRUint32* args)
{
foo* a = self->other;
int p1 = (int) *args;
int p2 = (int) *(args+1);
switch(methodIndex)
{
case 1: a->callme1(p1, p2); break;
case 2: a->callme2(p1, p2); break;
case 3: a->callme3(p1, p2); break;
}
return 1;
}
//nsresult nsXPCWrappedJS::Stub##n() \
#define STUB_ENTRY(n) \
nsresult baz::callme##n() \
{ \
register void* method = PrepareAndDispatch; \
register nsresult result; \
__asm__ __volatile__( \
"leal 0x0c(%%ebp), %%ecx\n\t" /* args */ \
"pushl %%ecx\n\t" \
"pushl $"#n"\n\t" /* method index */ \
"movl 0x08(%%ebp), %%ecx\n\t" /* this */ \
"pushl %%ecx\n\t" \
"call *%%edx" /* PrepareAndDispatch */ \
: "=a" (result) /* %0 */ \
: "d" (method) /* %1 */ \
: "ax", "dx", "cx", "memory" ); \
return result; \
}
#endif
/***************************************************************************/
STUB_ENTRY(1)
STUB_ENTRY(2)
STUB_ENTRY(3)
int main()
{
foo* a = new bar();
baz* b = new baz();
foo* c = (foo*)b;
b->setfoo(a);
c->callme1(1,2);
c->callme2(2,4);
c->callme3(3,6);
return 0;
}

View File

@@ -0,0 +1,49 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../../../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
CFLAGS += -DEXPORT_XPTC_API
LIBRARY_NAME = xptcmd
MODULE = xptcall
CPPSRCS = \
xptcinvoke_unsupported.cpp \
xptcstubs_unsupported.cpp \
$(NULL)
ifeq ($(OS_ARCH),Linux)
ifeq (86,$(findstring 86,$(OS_TEST)))
CPPSRCS = \
xptcinvoke_linux_x86.cpp \
xptcstubs_linux_x86.cpp \
$(NULL)
endif
endif
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../..

View File

@@ -0,0 +1,154 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
#include "xptcprivate.h"
// Remember that these 'words' are 32bit DWORDS
#if defined(LINUX)
static PRUint32
invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
{
PRUint32 result = 0;
for(PRUint32 i = 0; i < paramCount; i++, s++)
{
if(s->IsPtrData())
{
result++;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
result++;
break;
case nsXPTType::T_I64 :
result+=2;
break;
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
result++;
break;
case nsXPTType::T_U64 :
result+=2;
break;
case nsXPTType::T_FLOAT :
result++;
break;
case nsXPTType::T_DOUBLE :
result+=2;
break;
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
result++;
break;
default:
// all the others are plain pointer types
result++;
break;
}
}
return result;
}
static void
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
{
for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
{
if(s->IsPtrData())
{
*((void**)d) = s->ptr;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 : *((PRInt8*) d) = s->val.i8; break;
case nsXPTType::T_I16 : *((PRInt16*) d) = s->val.i16; break;
case nsXPTType::T_I32 : *((PRInt32*) d) = s->val.i32; break;
case nsXPTType::T_I64 : *((PRInt64*) d) = s->val.i64; d++; break;
case nsXPTType::T_U8 : *((PRUint8*) d) = s->val.u8; break;
case nsXPTType::T_U16 : *((PRUint16*)d) = s->val.u16; break;
case nsXPTType::T_U32 : *((PRUint32*)d) = s->val.u32; break;
case nsXPTType::T_U64 : *((PRUint64*)d) = s->val.u64; d++; break;
case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break;
case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break;
case nsXPTType::T_BOOL : *((PRBool*) d) = s->val.b; break;
case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break;
case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break;
default:
// all the others are plain pointer types
*((void**)d) = s->val.p;
break;
}
}
}
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params)
{
PRUint32 result;
void* fn_count = invoke_count_words;
void* fn_copy = invoke_copy_to_stack;
__asm__ __volatile__(
"pushl %4\n\t"
"pushl %3\n\t"
"movl %5, %%eax\n\t"
"call *%%eax\n\t" /* count words */
"addl $0x8, %%esp\n\t"
"shl $2, %%eax\n\t" /* *= 4 */
"subl %%eax, %%esp\n\t" /* make room for params */
"movl %%esp, %%edx\n\t"
"pushl %4\n\t"
"pushl %3\n\t"
"pushl %%edx\n\t"
"movl %6, %%eax\n\t"
"call *%%eax\n\t" /* copy params */
"addl $0xc, %%esp\n\t"
"movl %1, %%ecx\n\t"
"pushl %%ecx\n\t"
"movl (%%ecx), %%edx\n\t"
"movl %2, %%eax\n\t" /* function index */
"shl $2, %%eax\n\t" /* *= 4 */
"addl $8, %%eax\n\t" /* += 8 */
"addl %%eax, %%edx\n\t"
"call *(%%edx)\n\t" /* safe to not cleanup esp */
"movl %%eax, %0"
: "=g" (result) /* %0 */
: "g" (that), /* %1 */
"g" (methodIndex), /* %2 */
"g" (paramCount), /* %3 */
"g" (params), /* %4 */
"g" (fn_count), /* %5 */
"g" (fn_copy) /* %6 */
: "ax", "cx", "dx", "memory"
);
return result;
}
#endif

View File

@@ -0,0 +1,118 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
#include "xptcprivate.h"
#ifndef sparc
#error "This code is for Sparc only"
#endif
PRUint32
invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
{
PRUint32 result = 0;
for(PRUint32 i = 0; i < paramCount; i++, s++)
{
if(s->IsPtrData())
{
result++;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
result++;
break;
case nsXPTType::T_I64 :
result+=2;
break;
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
result++;
break;
case nsXPTType::T_U64 :
result+=2;
break;
case nsXPTType::T_FLOAT :
result++;
break;
case nsXPTType::T_DOUBLE :
result+=2;
break;
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
result++;
break;
default:
// all the others are plain pointer types
result++;
break;
}
}
return result;
}
void
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
{
/*
We need to copy the parameters for this function to locals and use them
from there since the parameters occupy the same stack space as the stack
we're trying to populate.
*/
uint32 *l_d;
nsXPCVariant *l_s = s;
uint32 l_paramCount = paramCount;
for(uint32 i = 0; i < l_paramCount; i++, l_d++, l_s++)
{
if(l_s->IsPtrData())
{
*((void**)l_d) = l_s->ptr;
continue;
}
switch(l_s->type)
{
case nsXPTType::T_I8 : *((int8*) l_d) = l_s->val.i8; break;
case nsXPTType::T_I16 : *((int16*) l_d) = l_s->val.i16; break;
case nsXPTType::T_I32 : *((int32*) l_d) = l_s->val.i32; break;
case nsXPTType::T_I64 : *((int64*) l_d) = l_s->val.i64; l_d++; break;
case nsXPTType::T_U8 : *((uint8*) l_d) = l_s->val.u8; break;
case nsXPTType::T_U16 : *((uint16*) l_d) = l_s->val.u16; break;
case nsXPTType::T_U32 : *((uint32*) l_d) = l_s->val.u32; break;
case nsXPTType::T_U64 : *((uint64*) l_d) = l_s->val.u64; l_d++; break;
case nsXPTType::T_FLOAT : *((float*) l_d) = l_s->val.f; break;
case nsXPTType::T_DOUBLE : *((double*) l_d) = l_s->val.d; l_d++; break;
case nsXPTType::T_BOOL : *((PRBool*) l_d) = l_s->val.b; break;
case nsXPTType::T_CHAR : *((char*) l_d) = l_s->val.c; break;
case nsXPTType::T_WCHAR : *((wchar_t*)l_d) = l_s->val.wc; break;
default:
// all the others are plain pointer types
*((void**)l_d) = l_s->val.p;
break;
}
}
}

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
.global XPTC_InvokeByIndex
/*
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params);
*/
XPTC_InvokeByIndex:
save %sp,-(64 + 8),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 8
mov %i2,%o0 ! paramCount
mov %i3,%o1 ! params
call invoke_count_words ! returns the required stack size in %o0
nop
sll %o0,2,%l0 ! number of bytes
sub %sp,%l0,%sp ! create the additional stack space
mov %sp,%o0 ! pointer for copied args
add %o0,72,%o0 ! step past the register window, the
! struct result pointer and the 'this' slot
mov %i2,%o1 ! paramCount
mov %i3,%o2 ! params
call invoke_copy_to_stack
nop
!
! calculate the target address from the vtable
!
sll %i1,2,%l0 ! index *= 4
ld [%i0],%l1 ! *that --> address of vtable
ld [%l0 + %l1],%l0 ! that->vtable[index * 4] --> target address
!
! set 'that' as the 'this' pointer and then load the next arguments
! into the outgoing registers
!
mov %i0,%o0
ld [%sp + 72],%o1
ld [%sp + 76],%o2
ld [%sp + 80],%o3
ld [%sp + 84],%o4
ld [%sp + 88],%o5
jmpl %l0,%o7 ! call the routine
nop
mov %o0,%i0 ! propogate return value
b .LL1
nop
.LL1:
ret
restore

View File

@@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
@@ -16,15 +16,14 @@
* Reserved.
*/
#include "nsISupports.idl"
/* Platform specific code to invoke XPCOM methods on native objects */
[uuid(eea90d40-b059-11d2-915e-c12b696c9333)]
interface nsIXPInstallProgress : nsISupports
#include "xptcprivate.h"
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params)
{
void BeforeJavascriptEvaluation();
void AfterJavascriptEvaluation();
void InstallStarted([const] in string UIPackageName);
void ItemScheduled([const] in string message );
void InstallFinalization([const] in string message, in long itemNum, in long totNum );
void InstallAborted();
};
NS_ASSERTION(0,"XPTC_InvokeByIndex called on unsupported platform");
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@@ -0,0 +1,126 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implement shared vtbl methods. */
#include "xptcprivate.h"
#if defined(LINUX)
static nsresult
PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, uint32* args)
{
#define PARAM_BUFFER_COUNT 16
nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
nsXPTCMiniVariant* dispatchParams = NULL;
nsIInterfaceInfo* iface_info = NULL;
const nsXPTMethodInfo* info;
PRUint8 paramCount;
PRUint8 i;
nsresult result = NS_ERROR_FAILURE;
NS_ASSERTION(self,"no self");
self->GetInterfaceInfo(&iface_info);
NS_ASSERTION(iface_info,"no interface info");
iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
NS_ASSERTION(info,"no interface info");
paramCount = info->GetParamCount();
// setup variant array pointer
if(paramCount > PARAM_BUFFER_COUNT)
dispatchParams = new nsXPTCMiniVariant[paramCount];
else
dispatchParams = paramBuffer;
NS_ASSERTION(dispatchParams,"no place for params");
PRUint32* ap = args;
for(i = 0; i < paramCount; i++, ap++)
{
const nsXPTParamInfo& param = info->GetParam(i);
const nsXPTType& type = param.GetType();
nsXPTCMiniVariant* dp = &dispatchParams[i];
if(param.IsOut() || !type.IsArithmetic())
{
dp->val.p = (void*) *ap;
continue;
}
// else
switch(type)
{
case nsXPTType::T_I8 : dp->val.i8 = *((PRInt8*) ap); break;
case nsXPTType::T_I16 : dp->val.i16 = *((PRInt16*) ap); break;
case nsXPTType::T_I32 : dp->val.i32 = *((PRInt32*) ap); break;
case nsXPTType::T_I64 : dp->val.i64 = *((PRInt64*) ap); ap++; break;
case nsXPTType::T_U8 : dp->val.u8 = *((PRUint8*) ap); break;
case nsXPTType::T_U16 : dp->val.u16 = *((PRUint16*)ap); break;
case nsXPTType::T_U32 : dp->val.u32 = *((PRUint32*)ap); break;
case nsXPTType::T_U64 : dp->val.u64 = *((PRUint64*)ap); ap++; break;
case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
case nsXPTType::T_BOOL : dp->val.b = *((PRBool*) ap); break;
case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break;
case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break;
default:
NS_ASSERTION(0, "bad type");
break;
}
}
result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
NS_RELEASE(iface_info);
if(dispatchParams != paramBuffer)
delete [] dispatchParams;
return result;
}
#define STUB_ENTRY(n) \
nsresult nsXPTCStubBase::Stub##n() \
{ \
register void* method = PrepareAndDispatch; \
register nsresult result; \
__asm__ __volatile__( \
"leal 0x0c(%%ebp), %%ecx\n\t" /* args */ \
"pushl %%ecx\n\t" \
"pushl $"#n"\n\t" /* method index */ \
"movl 0x08(%%ebp), %%ecx\n\t" /* this */ \
"pushl %%ecx\n\t" \
"call *%%edx" /* PrepareAndDispatch */ \
: "=a" (result) /* %0 */ \
: "d" (method) /* %1 */ \
: "ax", "dx", "cx", "memory" ); \
return result; \
}
#define SENTINEL_ENTRY(n) \
nsresult nsXPTCStubBase::Sentinel##n() \
{ \
NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
return NS_ERROR_NOT_IMPLEMENTED; \
}
#include "xptcstubsdef.inc"
#endif

View File

@@ -0,0 +1,37 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implement shared vtbl methods. */
#include "xptcprivate.h"
#define STUB_ENTRY(n) \
nsresult nsXPTCStubBase::Stub##n() \
{ \
NS_ASSERTION(0,"nsXPTCStubBase::Stub called on unsupported platform"); \
return NS_ERROR_NOT_IMPLEMENTED; \
}
#define SENTINEL_ENTRY(n) \
nsresult nsXPTCStubBase::Sentinel##n() \
{ \
NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
return NS_ERROR_NOT_IMPLEMENTED; \
}
#include "xptcstubsdef.inc"

View File

@@ -0,0 +1,41 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..\..\..
IGNORE_MANIFEST=1
include <$(DEPTH)\config\config.mak>
DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPTC_API
LINCS=-I..\.. -I$(PUBLIC)\xptcall -I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LIBRARY_NAME = xptcmd
OBJS= \
.\$(OBJDIR)\xptcinvoke.obj \
.\$(OBJDIR)\xptcstubs.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)

View File

@@ -0,0 +1,136 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
#include "xptcprivate.h"
#ifndef WIN32
#error "This code is for Win32 only"
#endif
// Remember that on Win32 these 'words' are 32bit DWORDS
static uint32 __stdcall
invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
{
PRUint32 result = 0;
for(PRUint32 i = 0; i < paramCount; i++, s++)
{
if(s->IsPtrData())
{
result++;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
result++;
break;
case nsXPTType::T_I64 :
result+=2;
break;
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
result++;
break;
case nsXPTType::T_U64 :
result+=2;
break;
case nsXPTType::T_FLOAT :
result++;
break;
case nsXPTType::T_DOUBLE :
result+=2;
break;
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
result++;
break;
default:
// all the others are plain pointer types
result++;
break;
}
}
return result;
}
static void __stdcall
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
{
for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
{
if(s->IsPtrData())
{
*((void**)d) = s->ptr;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 : *((PRInt8*) d) = s->val.i8; break;
case nsXPTType::T_I16 : *((PRInt16*) d) = s->val.i16; break;
case nsXPTType::T_I32 : *((PRInt32*) d) = s->val.i32; break;
case nsXPTType::T_I64 : *((PRInt64*) d) = s->val.i64; d++; break;
case nsXPTType::T_U8 : *((PRUint8*) d) = s->val.u8; break;
case nsXPTType::T_U16 : *((PRUint16*)d) = s->val.u16; break;
case nsXPTType::T_U32 : *((PRUint32*)d) = s->val.u32; break;
case nsXPTType::T_U64 : *((PRUint64*)d) = s->val.u64; d++; break;
case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break;
case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break;
case nsXPTType::T_BOOL : *((PRBool*) d) = s->val.b; break;
case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break;
case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break;
default:
// all the others are plain pointer types
*((void**)d) = s->val.p;
break;
}
}
}
#pragma warning(disable : 4035) // OK to have no return value
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params)
{
__asm {
push params
push paramCount
call invoke_count_words // stdcall, result in eax
shl eax,2 // *= 4
sub esp,eax // make space for params
mov edx,esp
push params
push paramCount
push edx
call invoke_copy_to_stack // stdcall
mov ecx,that // instance in ecx
push ecx // push this
mov edx,[ecx] // vtable in edx
mov eax,methodIndex
shl eax,2 // *= 4
add edx,eax
call [edx] // stdcall, i.e. callee cleans up stack.
}
}
#pragma warning(default : 4035) // restore default

View File

@@ -0,0 +1,146 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implement shared vtbl methods. */
#include "xptcprivate.h"
#ifndef WIN32
#error "This code is for Win32 only"
#endif
static nsresult __stdcall
PrepareAndDispatch(nsXPTCStubBase* self, PRUint32 methodIndex,
PRUint32* args, PRUint32* stackBytesToPop)
{
#define PARAM_BUFFER_COUNT 16
nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
nsXPTCMiniVariant* dispatchParams = NULL;
nsIInterfaceInfo* iface_info = NULL;
const nsXPTMethodInfo* info;
PRUint8 paramCount;
PRUint8 i;
nsresult result = NS_ERROR_FAILURE;
// If anything fails before stackBytesToPop can be set then
// the failure is completely catastrophic!
NS_ASSERTION(self,"no self");
self->GetInterfaceInfo(&iface_info);
NS_ASSERTION(iface_info,"no interface info");
iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
NS_ASSERTION(info,"no interface info");
paramCount = info->GetParamCount();
// setup variant array pointer
if(paramCount > PARAM_BUFFER_COUNT)
dispatchParams = new nsXPTCMiniVariant[paramCount];
else
dispatchParams = paramBuffer;
NS_ASSERTION(dispatchParams,"no place for params");
PRUint32* ap = args;
for(i = 0; i < paramCount; i++, ap++)
{
const nsXPTParamInfo& param = info->GetParam(i);
const nsXPTType& type = param.GetType();
nsXPTCMiniVariant* dp = &dispatchParams[i];
if(param.IsOut() || !type.IsArithmetic())
{
dp->val.p = (void*) *ap;
continue;
}
// else
switch(type)
{
case nsXPTType::T_I8 : dp->val.i8 = *((PRInt8*) ap); break;
case nsXPTType::T_I16 : dp->val.i16 = *((PRInt16*) ap); break;
case nsXPTType::T_I32 : dp->val.i32 = *((PRInt32*) ap); break;
case nsXPTType::T_I64 : dp->val.i64 = *((PRInt64*) ap); ap++; break;
case nsXPTType::T_U8 : dp->val.u8 = *((PRUint8*) ap); break;
case nsXPTType::T_U16 : dp->val.u16 = *((PRUint16*)ap); break;
case nsXPTType::T_U32 : dp->val.u32 = *((PRUint32*)ap); break;
case nsXPTType::T_U64 : dp->val.u64 = *((PRUint64*)ap); ap++; break;
case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
case nsXPTType::T_BOOL : dp->val.b = *((PRBool*) ap); break;
case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break;
case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break;
default:
NS_ASSERTION(0, "bad type");
break;
}
}
*stackBytesToPop = ((PRUint32)ap) - ((PRUint32)args);
result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
NS_RELEASE(iface_info);
if(dispatchParams != paramBuffer)
delete [] dispatchParams;
return result;
}
static __declspec(naked) void SharedStub(void)
{
__asm {
push ebp // set up simple stack frame
mov ebp, esp // stack has: ebp/vtbl_index/retaddr/this/args
push ecx // make room for a ptr
lea eax, [ebp-4] // pointer to stackBytesToPop
push eax
lea ecx, [ebp+16] // pointer to args
push ecx
mov edx, [ebp+4] // vtbl_index
push edx
mov eax, [ebp+12] // this
push eax
call PrepareAndDispatch
mov edx, [ebp+8] // return address
mov ecx, [ebp-4] // stackBytesToPop
add ecx, 12 // for this, the index, and ret address
mov esp, ebp
pop ebp
add esp, ecx // fix up stack pointer
jmp edx // simulate __stdcall return
}
}
// these macros get expanded (many times) in the file #included below
#define STUB_ENTRY(n) \
__declspec(naked) nsresult __stdcall nsXPTCStubBase::Stub##n() \
{ __asm push n __asm jmp SharedStub }
#define SENTINEL_ENTRY(n) \
nsresult __stdcall nsXPTCStubBase::Sentinel##n() \
{ \
NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
return NS_ERROR_NOT_IMPLEMENTED; \
}
#pragma warning(disable : 4035) // OK to have no return value
#include "xptcstubsdef.inc"
#pragma warning(default : 4035) // restore default

View File

@@ -0,0 +1,21 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* entry point wrappers. */
#include "xptcprivate.h"

View File

@@ -0,0 +1,26 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* All the xptcall private declarations - only include locally. */
#ifndef xptcprivate_h___
#define xptcprivate_h___
#include "xptcall.h"
#endif /* xptcprivate_h___ */

View File

@@ -0,0 +1,67 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = TestXPTC
SIMPLE_PROGRAMS = TestXPTCInvoke
CPPSRCS = \
TestXPTCInvoke.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk
CFLAGS += -DJS_THREADSAFE
LIBS = \
-L$(DIST)/bin \
-lxpcom \
-lxpt \
-lxptcmd \
-lxptinfo \
-lreg \
-l$(MOZ_LIB_UTIL_PREFIX)util \
$(NSPR_LIBS) \
$(NULL)
# PROGS = $(OBJDIR)/TestXPTCInvoke
# TARGETS= $(PROGS)
include $(topsrcdir)/config/rules.mk
# INCLUDES += -I$(PUBLIC)/xpcom -I$(PUBLIC)/js -I$(PUBLIC)/xptcall \
# -I$(PUBLIC)/xptinfo -I$(PUBLIC)/libxpt -I$(PUBLIC)/raptor
#$(PROGS): $(OBJS)
# @$(MAKE_OBJDIR)
# $(CC) -o $@ $(OBJS) $(LD_FLAGS) -L$(DIST)/lib $(LIBS) $(OS_LIBS)
# export:: $(TARGETS)
# $(INSTALL) $(PROGS) $(DIST)/bin
# clobber::
# rm -f $(DIST)/bin/TestXPTCInvoke
# rm -f $(PROGS) $(OBJS)

View File

@@ -0,0 +1,127 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Invoke tests xptcall. */
#include <stdio.h>
#include "xptcall.h"
// {AAC1FB90-E099-11d2-984E-006008962422}
#define INVOKETESTTARGET_IID \
{ 0xaac1fb90, 0xe099, 0x11d2, \
{ 0x98, 0x4e, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
class InvokeTestTargetInterface : public nsISupports
{
public:
NS_IMETHOD AddTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval) = 0;
NS_IMETHOD MultTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval) = 0;
};
class InvokeTestTarget : public InvokeTestTargetInterface
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD AddTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval);
NS_IMETHOD MultTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval);
InvokeTestTarget();
};
static NS_DEFINE_IID(kInvokeTestTargetIID, INVOKETESTTARGET_IID);
NS_IMPL_ISUPPORTS(InvokeTestTarget, kInvokeTestTargetIID);
InvokeTestTarget::InvokeTestTarget()
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
}
NS_IMETHODIMP
InvokeTestTarget::AddTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval)
{
*retval = p1 + p2;
return NS_OK;
}
NS_IMETHODIMP
InvokeTestTarget::MultTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval)
{
*retval = p1 * p2;
return NS_OK;
}
int main()
{
InvokeTestTarget *test = new InvokeTestTarget();
PRInt32 out;
printf("calling direct:\n");
if(NS_SUCCEEDED(test->AddTwoInts(1,1,&out)))
printf("\t1 + 1 = %d\n", out);
else
printf("\tFAILED");
if(NS_SUCCEEDED(test->MultTwoInts(2,2,&out)))
printf("\t2 * 2 = %d\n", out);
else
printf("\tFAILED");
nsXPTCVariant var[3];
printf("calling via invoke:\n");
var[0].val.i32 = 1;
var[0].type = nsXPTType::T_I32;
var[0].flags = 0;
var[1].val.i32 = 1;
var[1].type = nsXPTType::T_I32;
var[1].flags = 0;
var[2].val.i32 = 0;
var[2].type = nsXPTType::T_I32;
var[2].flags = nsXPTCVariant::PTR_IS_DATA;
var[2].ptr = &var[2].val.i32;
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 3, 3, var)))
printf("\t1 + 1 = %d\n", var[2].val.i32);
else
printf("\tFAILED");
var[0].val.i32 = 2;
var[0].type = nsXPTType::T_I32;
var[0].flags = 0;
var[1].val.i32 = 2;
var[1].type = nsXPTType::T_I32;
var[1].flags = 0;
var[2].val.i32 = 0;
var[2].type = nsXPTType::T_I32;
var[2].flags = nsXPTCVariant::PTR_IS_DATA;
var[2].ptr = &var[2].val.i32;
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 4, 3, var)))
printf("\t2 * 2 = %d\n", var[2].val.i32);
else
printf("\tFAILED");
return 0;
}

View File

@@ -0,0 +1,66 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\TestXPTCInvoke.exe
PROGRAMS = $(PROG1)
LCFLAGS=-DUSE_NSREG
DEFINES=-DWIN32_LEAN_AND_MEAN
REQUIRES=xpcom xptcall
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\xptcall \
-I$(PUBLIC)\raptor -I$(PUBLIC)\xptinfo -I$(PUBLIC)\libxpt
LLIBS= \
$(DIST)\lib\xptcall32.lib \
$(DIST)\lib\xpcom32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAMS)
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
-for %p in ($(TESTCASES)) do $(MAKE_INSTALL) %p $(DIST)\bin
clobber::
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
# Move this into config/obj.inc when it's allowed
.cpp{.\$(OBJDIR)\}.exe:
$(CC) @<<$(CFGFILE)
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
$(LLIBS)
$(OS_LIBS)
-Fd$(PDBFILE)
-Fe.\$(OBJDIR)\
-Fo.\$(OBJDIR)\
$(CURDIR)$(*B).cpp
<<KEEP
$(PROG1): $(OBJDIR) TestXPTCInvoke.cpp

View File

@@ -0,0 +1,29 @@
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,22 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
DIRS=public src tests
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,7 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
xptinfo.h
nsIInterfaceInfoManager.h
nsIInterfaceInfo.h

View File

@@ -0,0 +1,36 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptinfo
CFLAGS += -DEXPORT_XPCI_API
EXPORTS = \
xptinfo.h \
nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,30 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH=..\..\..\..
EXPORTS = \
xptinfo.h \
nsIInterfaceInfoManager.h \
nsIInterfaceInfo.h \
$(NULL)
MODULE = xptinfo
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* The nsIInterfaceInfo xpcom public declaration. */
#ifndef nsIInterfaceInfo_h___
#define nsIInterfaceInfo_h___
#include "nsISupports.h"
// forward declaration of non-XPCOM types
class nsXPTMethodInfo;
class nsXPTConstant;
class nsXPTParamInfo;
// {215DBE04-94A7-11d2-BA58-00805F8A5DD7}
#define NS_IINTERFACEINFO_IID \
{ 0x215dbe04, 0x94a7, 0x11d2, \
{ 0xba, 0x58, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }
class nsIInterfaceInfo : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_IID)
NS_IMETHOD GetName(char** name) = 0; // returns IAllocatator alloc'd copy
NS_IMETHOD GetIID(nsIID** iid) = 0; // returns IAllocatator alloc'd copy
NS_IMETHOD IsScriptable(PRBool* result) = 0;
NS_IMETHOD GetParent(nsIInterfaceInfo** parent) = 0;
// these include counts of parents
NS_IMETHOD GetMethodCount(uint16* count) = 0;
NS_IMETHOD GetConstantCount(uint16* count) = 0;
// These include methods and constants of parents.
// There do *not* make copies ***explicit bending of XPCOM rules***
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info) = 0;
NS_IMETHOD GetMethodInfoForName(const char* methodName, uint16 *index,
const nsXPTMethodInfo** info) = 0;
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant) = 0;
// Get the interface information or iid associated with a param of some
// method in this interface.
NS_IMETHOD GetInfoForParam(const nsXPTParamInfo* param,
nsIInterfaceInfo** info) = 0;
// returns IAllocatator alloc'd copy
NS_IMETHOD GetIIDForParam(const nsXPTParamInfo* param, nsIID** iid) = 0;
};
#endif /* nsIInterfaceInfo_h___ */

View File

@@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* The nsIInterfaceInfoManager xpcom public declaration. */
#ifndef nsIInterfaceInfoManager_h___
#define nsIInterfaceInfoManager_h___
#include "nsIInterfaceInfo.h"
// This should be implemented as a Service
// {8B161900-BE2B-11d2-9831-006008962422}
#define NS_IINTERFACEINFO_MANAGER_IID \
{ 0x8b161900, 0xbe2b, 0x11d2, \
{ 0x98, 0x31, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
class nsIInterfaceInfoManager : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IINTERFACEINFO_MANAGER_IID)
// nsIInformationInfo management services
NS_IMETHOD GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info) = 0;
NS_IMETHOD GetInfoForName(const char* name, nsIInterfaceInfo** info) = 0;
// name <-> IID mapping services
// NOTE: these return IAllocatator alloc'd copies of the data
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid) = 0;
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name) = 0;
// XXX other methods?
};
#endif /* nsIInterfaceInfoManager_h___ */

View File

@@ -0,0 +1,212 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
#ifndef xptiinfo_h___
#define xptiinfo_h___
#include "prtypes.h"
#include "xpt_struct.h"
/*
* The linkage of XPTI API functions differs depending on whether the file is
* used within the XPTI library or not. Any source file within the XPTI
* library should define EXPORT_XPTI_API whereas any client of the library
* should not.
*/
#ifdef EXPORT_XPTI_API
#define XPTI_PUBLIC_API(t) PR_IMPLEMENT(t)
#define XPTI_PUBLIC_DATA(t) PR_IMPLEMENT_DATA(t)
#ifdef _WIN32
# define XPTI_EXPORT _declspec(dllexport)
#else
# define XPTI_EXPORT
#endif
#else
#ifdef _WIN32
# define XPTI_PUBLIC_API(t) _declspec(dllimport) t
# define XPTI_PUBLIC_DATA(t) _declspec(dllimport) t
# define XPTI_EXPORT _declspec(dllimport)
#else
# define XPTI_PUBLIC_API(t) PR_IMPLEMENT(t)
# define XPTI_PUBLIC_DATA(t) t
# define XPTI_EXPORT
#endif
#endif
#define XPTI_FRIEND_API(t) XPTI_PUBLIC_API(t)
#define XPTI_FRIEND_DATA(t) XPTI_PUBLIC_DATA(t)
class nsIInterfaceInfoManager;
PR_BEGIN_EXTERN_C
// Even if this is a service, it is cool to provide a direct accessor
XPTI_PUBLIC_API(nsIInterfaceInfoManager*)
XPTI_GetInterfaceInfoManager();
PR_END_EXTERN_C
// Flyweight wrapper classes for xpt_struct.h structs.
// Everything here is dependent upon - and sensitive to changes in -
// xpcom/libxpt/xpt_struct.h!
class nsXPTType : public XPTTypeDescriptorPrefix
{
// NO DATA - this a flyweight wrapper
public:
nsXPTType()
{} // random contents
nsXPTType(const XPTTypeDescriptorPrefix& prefix)
{*(XPTTypeDescriptorPrefix*)this = prefix;}
nsXPTType(const uint8& prefix)
{*(uint8*)this = prefix;}
nsXPTType& operator=(uint8 val)
{flags = val; return *this;}
nsXPTType& operator=(const nsXPTType& other)
{flags = other.flags; return *this;}
operator uint8() const
{return flags;}
PRBool IsPointer() const
{return (PRBool) (XPT_TDP_IS_POINTER(flags));}
PRBool IsUniquePointer() const
{return (PRBool) (XPT_TDP_IS_UNIQUE_POINTER(flags));}
PRBool IsReference() const
{return (PRBool) (XPT_TDP_IS_REFERENCE(flags));}
PRBool IsArithmetic() const // terminology from Harbison/Steele
{return flags <= T_WCHAR;}
PRBool IsInterfacePointer() const
{return (PRBool) (TagPart() == T_INTERFACE ||
TagPart() == T_INTERFACE_IS);}
uint8 TagPart() const
{return (uint8) (flags & XPT_TDP_TAGMASK);}
enum
{
T_I8 = TD_INT8 ,
T_I16 = TD_INT16 ,
T_I32 = TD_INT32 ,
T_I64 = TD_INT64 ,
T_U8 = TD_UINT8 ,
T_U16 = TD_UINT16 ,
T_U32 = TD_UINT32 ,
T_U64 = TD_UINT64 ,
T_FLOAT = TD_FLOAT ,
T_DOUBLE = TD_DOUBLE ,
T_BOOL = TD_BOOL ,
T_CHAR = TD_CHAR ,
T_WCHAR = TD_WCHAR ,
T_VOID = TD_VOID ,
T_IID = TD_PNSIID ,
T_BSTR = TD_PBSTR ,
T_CHAR_STR = TD_PSTRING ,
T_WCHAR_STR = TD_PWSTRING ,
T_INTERFACE = TD_INTERFACE_TYPE ,
T_INTERFACE_IS = TD_INTERFACE_IS_TYPE
};
// NO DATA - this a flyweight wrapper
};
class nsXPTParamInfo : public XPTParamDescriptor
{
// NO DATA - this a flyweight wrapper
public:
nsXPTParamInfo(const XPTParamDescriptor& desc)
{*(XPTParamDescriptor*)this = desc;}
PRBool IsIn() const {return (PRBool) (XPT_PD_IS_IN(flags));}
PRBool IsOut() const {return (PRBool) (XPT_PD_IS_OUT(flags));}
PRBool IsRetval() const {return (PRBool) (XPT_PD_IS_RETVAL(flags));}
PRBool IsShared() const {return (PRBool) (XPT_PD_IS_SHARED(flags));}
const nsXPTType GetType() const {return type.prefix;}
uint8 GetInterfaceIsArgNumber() const
{
NS_PRECONDITION(GetType().TagPart() == nsXPTType::T_INTERFACE_IS,"not an interface_is");
return type.type.argnum;
}
// NOTE: gettting the interface or interface iid is done via methods on
// nsIInterfaceInfo
private:
nsXPTParamInfo(); // no implementation
// NO DATA - this a flyweight wrapper
};
class nsXPTMethodInfo : public XPTMethodDescriptor
{
// NO DATA - this a flyweight wrapper
public:
nsXPTMethodInfo(const XPTMethodDescriptor& desc)
{*(XPTMethodDescriptor*)this = desc;}
PRBool IsGetter() const {return (PRBool) (XPT_MD_IS_GETTER(flags) );}
PRBool IsSetter() const {return (PRBool) (XPT_MD_IS_SETTER(flags) );}
PRBool IsVarArgs() const {return (PRBool) (XPT_MD_IS_VARARGS(flags));}
PRBool IsConstructor() const {return (PRBool) (XPT_MD_IS_CTOR(flags) );}
PRBool IsHidden() const {return (PRBool) (XPT_MD_IS_HIDDEN(flags) );}
const char* GetName() const {return name;}
uint8 GetParamCount() const {return num_args;}
const nsXPTParamInfo GetParam(uint8 index) const
{
NS_PRECONDITION(index < GetParamCount(),"bad arg");
return params[index];
}
const nsXPTParamInfo GetResult() const
{return *result;}
private:
nsXPTMethodInfo(); // no implementation
// NO DATA - this a flyweight wrapper
};
// forward declaration
struct nsXPTCMiniVariant;
class nsXPTConstant : public XPTConstDescriptor
{
// NO DATA - this a flyweight wrapper
public:
nsXPTConstant(const XPTConstDescriptor& desc)
{*(XPTConstDescriptor*)this = desc;}
const char* GetName() const
{return name;}
const nsXPTType GetType() const
{return type.prefix;}
// XXX this is ugly
const nsXPTCMiniVariant* GetValue() const
{return (nsXPTCMiniVariant*) &value;}
private:
nsXPTConstant(); // no implementation
// NO DATA - this a flyweight wrapper
};
#endif /* xptiinfo_h___ */

View File

@@ -0,0 +1,39 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptinfo
LIBRARY_NAME = xptinfo
CSRCS = $(NULL)
CPPSRCS = nsInterfaceInfo.cpp \
nsInterfaceInfoManager.cpp \
nsTypelibRecord.cpp \
nsInterfaceRecord.cpp \
$(NULL)
REQUIRES = $(MODULE)
# export:: libs
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,70 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
DEPTH=..\..\..\..
DLLNAME = xptinfo$(MOZ_BITS)
DLL =.\$(OBJDIR)\$(DLLNAME).dll
LCFLAGS = -DEXPORT_XPTI_API -DWIN32_LEAN_AND_MEAN
LINCS = \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\libxpt \
-I$(PUBLIC)\xptinfo \
$(NULL)
LLIBS = \
$(DIST)\lib\libxpt$(MOZ_BITS).lib \
$(DIST)\lib\xpcom$(MOZ_BITS).lib \
$(LIBNSPR) \
$(DIST)\lib\plc3.lib \
$(NULL)
CSRCS = \
$(NULL)
C_OBJS = \
$(NULL)
CPPSRCS = \
nsInterfaceInfoManager.cpp \
nsInterfaceInfo.cpp \
nsInterfaceRecord.cpp \
nsTypelibRecord.cpp \
$(NULL)
CPP_OBJS = \
.\$(OBJDIR)\nsInterfaceInfoManager.obj \
.\$(OBJDIR)\nsInterfaceInfo.obj \
.\$(OBJDIR)\nsInterfaceRecord.obj \
.\$(OBJDIR)\nsTypelibRecord.obj \
$(NULL)
MODULE = xptinfo
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib

View File

@@ -0,0 +1,233 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implementation of nsIInterfaceInfoManager. */
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIAllocator.h"
#include "nsInterfaceInfo.h"
#include "nsInterfaceInfoManager.h"
#include "xptinfo.h"
static NS_DEFINE_IID(kIInterfaceInfoIID, NS_IINTERFACEINFO_IID);
NS_IMPL_ISUPPORTS(nsInterfaceInfo, kIInterfaceInfoIID);
nsInterfaceInfo::nsInterfaceInfo(nsInterfaceRecord *record,
nsInterfaceInfo *parent)
: mInterfaceRecord(record),
mParent(parent)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
if(mParent != NULL) {
NS_ADDREF(mParent);
mMethodBaseIndex =
mParent->mMethodBaseIndex + mParent->mMethodCount;
mConstantBaseIndex =
mParent->mConstantBaseIndex + mParent->mConstantCount;
} else {
mMethodBaseIndex = mConstantBaseIndex = 0;
}
mMethodCount =
mInterfaceRecord->interfaceDescriptor->num_methods;
mConstantCount =
mInterfaceRecord->interfaceDescriptor->num_constants;
}
nsInterfaceInfo::~nsInterfaceInfo()
{
if (this->mParent != NULL)
NS_RELEASE(mParent);
// remove interface record's notion of my existence
mInterfaceRecord->info = NULL;
}
NS_IMETHODIMP
nsInterfaceInfo::GetName(char **name)
{
return this->mInterfaceRecord->GetName(name);
}
NS_IMETHODIMP
nsInterfaceInfo::GetIID(nsIID **iid)
{
return this->mInterfaceRecord->GetIID(iid);
}
NS_IMETHODIMP
nsInterfaceInfo::IsScriptable(PRBool* result)
{
if(!result)
return NS_ERROR_NULL_POINTER;
*result = XPT_ID_IS_SCRIPTABLE(this->mInterfaceRecord->
interfaceDescriptor->flags);
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetParent(nsIInterfaceInfo** parent)
{
NS_PRECONDITION(parent, "bad param");
if(mParent) {
NS_ADDREF(mParent);
*parent = mParent;
return NS_OK;
}
*parent = NULL;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsInterfaceInfo::GetMethodCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mMethodBaseIndex + mMethodCount;
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetConstantCount(uint16* count)
{
NS_PRECONDITION(count, "bad param");
*count = mConstantBaseIndex + mConstantCount;
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetMethodInfo(uint16 index, const nsXPTMethodInfo** info)
{
NS_PRECONDITION(info, "bad param");
if (index < mMethodBaseIndex)
return mParent->GetMethodInfo(index, info);
if (index >= mMethodBaseIndex + mMethodCount) {
NS_PRECONDITION(0, "bad param");
*info = NULL;
return NS_ERROR_INVALID_ARG;
}
// else...
*info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
&mInterfaceRecord->interfaceDescriptor->
method_descriptors[index - mMethodBaseIndex]);
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetMethodInfoForName(const char* methodName, uint16 *index,
const nsXPTMethodInfo** result)
{
// XXX probably want to speed this up with a hashtable, or by at least interning
// the names to avoid the strcmp
nsresult rv;
for (uint16 i = mMethodBaseIndex; i < mMethodCount; i++) {
const nsXPTMethodInfo* info;
info = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
&mInterfaceRecord->interfaceDescriptor->
method_descriptors[i - mMethodBaseIndex]);
if (PL_strcmp(methodName, info->name) == 0) {
#ifdef NS_DEBUG
// make sure there aren't duplicate names
for (; i < mMethodCount; i++) {
const nsXPTMethodInfo* info2;
info2 = NS_REINTERPRET_CAST(nsXPTMethodInfo*,
&mInterfaceRecord->interfaceDescriptor->
method_descriptors[i - mMethodBaseIndex]);
NS_ASSERTION(PL_strcmp(methodName, info2->name)!= 0, "duplicate names");
}
#endif
*result = info;
return NS_OK;
}
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
nsInterfaceInfo::GetConstant(uint16 index, const nsXPTConstant** constant)
{
NS_PRECONDITION(constant, "bad param");
if (index < mConstantBaseIndex)
return mParent->GetConstant(index, constant);
if (index >= mConstantBaseIndex + mConstantCount) {
NS_PRECONDITION(0, "bad param");
*constant = NULL;
return NS_ERROR_INVALID_ARG;
}
// else...
*constant =
NS_REINTERPRET_CAST(nsXPTConstant*,
&mInterfaceRecord->interfaceDescriptor->
const_descriptors[index-mConstantBaseIndex]);
return NS_OK;
}
NS_IMETHODIMP
nsInterfaceInfo::GetInfoForParam(const nsXPTParamInfo *param,
nsIInterfaceInfo** info)
{
// XXX should be a soft failure?
NS_PRECONDITION(param->GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsInterfaceRecord *paramRecord =
*(this->mInterfaceRecord->typelibRecord->
interfaceRecords + (param->type.type.interface - 1));
return paramRecord->GetInfo((nsInterfaceInfo **)info);
}
NS_IMETHODIMP
nsInterfaceInfo::GetIIDForParam(const nsXPTParamInfo* param, nsIID** iid)
{
NS_PRECONDITION(param->GetType().TagPart() == nsXPTType::T_INTERFACE,
"not an interface");
nsInterfaceRecord *paramRecord =
*(this->mInterfaceRecord->typelibRecord->
interfaceRecords + (param->type.type.interface - 1));
return paramRecord->GetIID(iid);
}
#ifdef DEBUG
#include <stdio.h>
void
nsInterfaceInfo::print(FILE *fd)
{
fprintf(fd, "iid: %s name: %s name_space: %s\n",
this->mInterfaceRecord->iid.ToString(),
this->mInterfaceRecord->name,
this->mInterfaceRecord->name_space);
if (mParent != NULL) {
fprintf(fd, "parent:\n\t");
this->mParent->print(fd);
}
}
#endif

View File

@@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Library-private header for nsInterfaceInfo implementation. */
#ifndef nsInterfaceInfo_h___
#define nsInterfaceInfo_h___
#include "nsIInterfaceInfo.h"
#include "xpt_struct.h"
#include "nsInterfaceRecord.h"
#include "nsInterfaceInfoManager.h"
#ifdef DEBUG
#include <stdio.h>
#endif
class nsInterfaceInfo : public nsIInterfaceInfo
{
NS_DECL_ISUPPORTS
NS_IMETHOD GetName(char** name); // returns IAllocatator alloc'd copy
NS_IMETHOD GetIID(nsIID** iid); // returns IAllocatator alloc'd copy
NS_IMETHOD IsScriptable(PRBool* result);
NS_IMETHOD GetParent(nsIInterfaceInfo** parent);
// these include counts of parents
NS_IMETHOD GetMethodCount(uint16* count);
NS_IMETHOD GetConstantCount(uint16* count);
// These include methods and constants of parents.
// There do *not* make copies ***explicit bending of XPCOM rules***
NS_IMETHOD GetMethodInfo(uint16 index, const nsXPTMethodInfo** info);
NS_IMETHOD GetMethodInfoForName(const char* methodName, uint16 *index,
const nsXPTMethodInfo** info);
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant);
// Get the interface information or iid associated with a param of some
// method in this interface.
NS_IMETHOD GetInfoForParam(const nsXPTParamInfo* param,
nsIInterfaceInfo** info);
// returns IAllocatator alloc'd copy
NS_IMETHOD GetIIDForParam(const nsXPTParamInfo* param, nsIID** iid);
public:
virtual ~nsInterfaceInfo();
#ifdef DEBUG
void NS_EXPORT print(FILE *fd);
#endif
private:
friend class nsInterfaceRecord;
nsInterfaceInfo(nsInterfaceRecord *record, nsInterfaceInfo *parent);
nsInterfaceRecord *mInterfaceRecord;
nsInterfaceInfo* mParent;
uint16 mMethodBaseIndex;
uint16 mMethodCount;
uint16 mConstantBaseIndex;
uint16 mConstantCount;
};
#endif /* nsInterfaceInfo_h___ */

View File

@@ -0,0 +1,456 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implementation of nsIInterfaceInfo. */
#ifdef XP_MAC
#include <stat.h>
#else
#include <sys/stat.h>
#endif
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIInterfaceInfo.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
#include "nsInterfaceInfoManager.h"
#include "nsInterfaceInfo.h"
#include "xptinfo.h"
#include "prio.h"
#include "plstr.h"
#include "prenv.h"
// this after nsISupports, to pick up IID
// so that xpt stuff doesn't try to define it itself...
#include "xpt_xdr.h"
#ifdef DEBUG_mccabe
#define TRACE(x) fprintf x
#else
#define TRACE(x)
#endif
static NS_DEFINE_IID(kIIIManagerIID, NS_IINTERFACEINFO_MANAGER_IID);
NS_IMPL_ISUPPORTS(nsInterfaceInfoManager, kIIIManagerIID);
// static
nsInterfaceInfoManager*
nsInterfaceInfoManager::GetInterfaceInfoManager()
{
static nsInterfaceInfoManager* impl = NULL;
if(!impl)
{
impl = new nsInterfaceInfoManager();
}
if(impl)
NS_ADDREF(impl);
return impl;
}
// static
nsIAllocator*
nsInterfaceInfoManager::GetAllocator(nsInterfaceInfoManager* iim /*= NULL*/)
{
nsIAllocator* al;
nsInterfaceInfoManager* iiml = iim;
if(!iiml && !(iiml = GetInterfaceInfoManager()))
return NULL;
if(NULL != (al = iiml->allocator))
NS_ADDREF(al);
if(!iim)
NS_RELEASE(iiml);
return al;
}
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
nsInterfaceInfoManager::nsInterfaceInfoManager()
: allocator(NULL)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
nsServiceManager::GetService(kAllocatorCID,
kIAllocatorIID,
(nsISupports **)&this->allocator);
PR_ASSERT(this->allocator != NULL);
this->initInterfaceTables();
}
static
XPTHeader *getHeader(const char *filename, nsIAllocator *al) {
XPTState *state = NULL;
XPTCursor curs, *cursor = &curs;
XPTHeader *header = NULL;
PRFileInfo fileinfo;
PRUint32 flen;
char *whole = NULL;
PRFileDesc *in = NULL;
if (PR_GetFileInfo(filename, &fileinfo) != PR_SUCCESS) {
NS_ERROR("PR_GetFileInfo failed");
return NULL;
}
flen = fileinfo.size;
whole = (char *)al->Alloc(flen);
if (!whole) {
NS_ERROR("FAILED: allocation for whole");
return NULL;
}
in = PR_Open(filename, PR_RDONLY, 0);
if (!in) {
NS_ERROR("FAILED: fopen");
goto out;
}
if (flen > 0) {
PRInt32 howmany = PR_Read(in, whole, flen);
if (howmany < 0) {
NS_ERROR("FAILED: reading typelib file");
goto out;
}
// XXX lengths are PRUInt32, reads are PRInt32?
if (howmany < flen) {
NS_ERROR("short read of typelib file");
goto out;
}
state = XPT_NewXDRState(XPT_DECODE, whole, flen);
if (!XPT_MakeCursor(state, XPT_HEADER, 0, cursor)) {
NS_ERROR("MakeCursor failed\n");
goto out;
}
if (!XPT_DoHeader(cursor, &header)) {
NS_ERROR("DoHeader failed\n");
goto out;
}
}
out:
if (state != NULL)
XPT_DestroyXDRState(state);
if (whole != NULL)
al->Free(whole);
if (in != NULL)
PR_Close(in);
return header;
}
nsresult
nsInterfaceInfoManager::indexify_file(const char *filename)
{
XPTHeader *header = getHeader(filename, this->allocator);
if (header == NULL) {
// XXX glean something more meaningful from getHeader?
return NS_ERROR_FAILURE;
}
int limit = header->num_interfaces;
nsTypelibRecord *tlrecord = new nsTypelibRecord(limit, this->typelibRecords,
header, this->allocator);
this->typelibRecords = tlrecord; // add it to the list of typelibs
for (int i = 0; i < limit; i++) {
XPTInterfaceDirectoryEntry *current = header->interface_directory + i;
// find or create an interface record, and set the appropriate
// slot in the nsTypelibRecord array.
nsID zero =
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
nsInterfaceRecord *record = NULL;
PRBool iidIsZero = current->iid.Equals(zero);
// XXX fix bogus repetitive logic.
PRBool foundInIIDTable = PR_FALSE;
if (iidIsZero == PR_FALSE) {
// prefer the iid.
nsIDKey idKey(current->iid);
record = (nsInterfaceRecord *)this->IIDTable->Get(&idKey);
} else {
foundInIIDTable = PR_TRUE;
// resort to using the name. Warn?
record = (nsInterfaceRecord *)PL_HashTableLookup(this->nameTable,
current->name);
}
// if none was found, create one and tuck it into the appropriate places.
if (record == NULL) {
record = new nsInterfaceRecord();
record->typelibRecord = tlrecord;
record->interfaceDescriptor = NULL;
record->info = NULL;
// XXX copy these values?
record->name = current->name;
record->name_space = current->name_space;
// add it to the name->interfaceRecord table
// XXX check that result (PLHashEntry *) isn't NULL
PL_HashTableAdd(this->nameTable, current->name, record);
if (iidIsZero == PR_FALSE) {
// Add it to the iid table too, if we have an iid.
// don't check against old value, b/c we shouldn't have one.
foundInIIDTable = PR_TRUE;
nsIDKey idKey(current->iid);
this->IIDTable->Put(&idKey, record);
}
}
// Is the entry we're looking at resolved?
if (current->interface_descriptor != NULL) {
if (record->interfaceDescriptor != NULL) {
char *warnstr = PR_smprintf
("interface %s in typelib %s overrides previous definition",
current->name, filename);
NS_WARNING(warnstr);
PR_smprintf_free(warnstr);
}
record->interfaceDescriptor = current->interface_descriptor;
record->iid = current->iid;
if (foundInIIDTable == PR_FALSE) {
nsIDKey idKey(current->iid);
this->IIDTable->Put(&idKey, record);
}
}
// all fixed up? Put a pointer to the interfaceRecord we
// found/made into the appropriate place.
*(tlrecord->interfaceRecords + i) = record;
}
return NS_OK;
}
// as many InterfaceDirectoryEntries as we expect to see.
#define XPT_HASHSIZE 64
#ifdef DEBUG
PRIntn check_nametable_enumerator(PLHashEntry *he, PRIntn index, void *arg) {
char *key = (char *)he->key;
nsInterfaceRecord *value = (nsInterfaceRecord *)he->value;
nsHashtable *iidtable = (nsHashtable *)arg;
TRACE((stderr, "name table has %s\n", key));
if (value->interfaceDescriptor == NULL) {
TRACE((stderr, "unresolved interface %s\n", key));
} else {
nsIDKey idKey(value->iid);
char *name_from_iid = (char *)iidtable->Get(&idKey);
NS_ASSERTION(name_from_iid != NULL,
"no name assoc'd with iid for entry for name?");
// XXX note that below is only ncc'ly the case if xdr doesn't give us
// duplicated strings.
// NS_ASSERTION(name_from_iid == key,
// "key and iid name xpected to be same");
}
return HT_ENUMERATE_NEXT;
}
PRBool check_iidtable_enumerator(nsHashKey *aKey, void *aData, void *closure) {
// PLHashTable *nameTable = (PLHashTable *)closure;
nsInterfaceRecord *record = (nsInterfaceRecord *)aData;
// can I do anything with the key?
TRACE((stderr, "record has name %s, iid %s\n",
record->name, record->iid.ToString()));
return PR_TRUE;
}
#endif
nsresult
nsInterfaceInfoManager::initInterfaceTables()
{
// make a hashtable to map names to interface records.
this->nameTable = PL_NewHashTable(XPT_HASHSIZE,
PL_HashString, // hash keys
PL_CompareStrings, // compare keys
PL_CompareValues, // comp values
NULL, NULL);
if (this->nameTable == NULL)
return NS_ERROR_FAILURE;
// make a hashtable to map iids to interface records.
this->IIDTable = new nsHashtable(XPT_HASHSIZE);
if (this->IIDTable == NULL) {
PL_HashTableDestroy(this->nameTable);
return NS_ERROR_FAILURE;
}
// First, find the xpt directory from the env. XXX Temporary hack.
char *xptdirname = PR_GetEnv("XPTDIR");
PRDir *xptdir;
if (xptdirname == NULL || (xptdir = PR_OpenDir(xptdirname)) == NULL)
return NS_ERROR_FAILURE;
// Create a buffer that has dir/ in it so we can append the
// filename each time in the loop
char fullname[1024]; // NS_MAX_FILENAME_LEN
PL_strncpyz(fullname, xptdirname, sizeof(fullname));
unsigned int n = strlen(fullname);
if (n+1 < sizeof(fullname)) {
fullname[n] = '/';
n++;
}
char *filepart = fullname + n;
PRDirEntry *dirent = NULL;
#ifdef DEBUG
int which = 0;
#endif
while ((dirent = PR_ReadDir(xptdir, PR_SKIP_BOTH)) != NULL) {
PL_strncpyz(filepart, dirent->name, sizeof(fullname)-n);
PRFileInfo statbuf;
// stattable?
if (PR_GetFileInfo(fullname,&statbuf) != PR_SUCCESS)
continue;
// plain file?
else if (statbuf.type != PR_FILE_FILE)
continue;
// .xpt suffix?
int flen = PL_strlen(fullname);
if (flen < 4 || PL_strcasecmp(&(fullname[flen - 4]), ".xpt"))
continue;
// it's a valid file, read it in.
#ifdef DEBUG
which++;
TRACE((stderr, "%d %s\n", which, fullname));
#endif
nsresult nsr = this->indexify_file(fullname);
if (NS_IS_ERROR(nsr)) {
char *warnstr = PR_smprintf("failed to process typelib file %s",
fullname);
NS_WARNING(warnstr);
PR_smprintf_free(warnstr);
}
}
PR_CloseDir(xptdir);
#ifdef DEBUG
TRACE((stderr, "\nchecking name table for unresolved entries...\n"));
// scan here to confirm that all interfaces are resolved.
PL_HashTableEnumerateEntries(this->nameTable,
check_nametable_enumerator,
this->IIDTable);
TRACE((stderr, "\nchecking iid table for unresolved entries...\n"));
IIDTable->Enumerate(check_iidtable_enumerator, this->nameTable);
#endif
return NS_OK;
}
nsInterfaceInfoManager::~nsInterfaceInfoManager()
{
// let the singleton leak
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetInfoForIID(const nsIID* iid,
nsIInterfaceInfo **info)
{
nsIDKey idKey(*iid);
nsInterfaceRecord *record =
(nsInterfaceRecord *)this->IIDTable->Get(&idKey);
if (record == NULL) {
*info = NULL;
return NS_ERROR_FAILURE;
}
return record->GetInfo((nsInterfaceInfo **)info);
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetInfoForName(const char* name,
nsIInterfaceInfo **info)
{
nsInterfaceRecord *record =
(nsInterfaceRecord *)PL_HashTableLookup(this->nameTable, name);
if (record == NULL) {
*info = NULL;
return NS_ERROR_FAILURE;
}
return record->GetInfo((nsInterfaceInfo **)info);
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid)
{
nsInterfaceRecord *record =
(nsInterfaceRecord *)PL_HashTableLookup(this->nameTable, name);
if (record == NULL) {
*iid = NULL;
return NS_ERROR_FAILURE;
}
return record->GetIID(iid);
}
NS_IMETHODIMP
nsInterfaceInfoManager::GetNameForIID(const nsIID* iid, char** name)
{
nsIDKey idKey(*iid);
nsInterfaceRecord *record =
(nsInterfaceRecord *)this->IIDTable->Get(&idKey);
if (record == NULL) {
*name = NULL;
return NS_ERROR_FAILURE;
}
#ifdef DEBUG
// Note that this might fail for same-name, different-iid interfaces!
nsIID *newid;
nsresult isok = GetIIDForName(record->name, &newid);
PR_ASSERT(!(NS_IS_ERROR(isok)));
PR_ASSERT(newid->Equals(*newid));
#endif
PR_ASSERT(record->name != NULL);
char *p;
int len = strlen(record->name) + 1;
if((p = (char *)this->allocator->Alloc(len)) == NULL) {
*name = NULL;
return NS_ERROR_FAILURE;
}
memcpy(p, record->name, len);
*name = p;
return NS_OK;
}
XPTI_PUBLIC_API(nsIInterfaceInfoManager*)
XPTI_GetInterfaceInfoManager()
{
return nsInterfaceInfoManager::GetInterfaceInfoManager();
}

View File

@@ -0,0 +1,76 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Library-private header for nsInterfaceInfoManager implementation. */
#ifndef nsInterfaceInfoManager_h___
#define nsInterfaceInfoManager_h___
#include "plhash.h"
#include "nsIAllocator.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsHashtable.h"
#include "xpt_struct.h"
#include "nsInterfaceInfo.h"
#include "nsInterfaceRecord.h"
#include "nsTypelibRecord.h"
class nsInterfaceInfoManager : public nsIInterfaceInfoManager
{
NS_DECL_ISUPPORTS
// nsIInformationInfo management services
NS_IMETHOD GetInfoForIID(const nsIID* iid, nsIInterfaceInfo** info);
NS_IMETHOD GetInfoForName(const char* name, nsIInterfaceInfo** info);
// name <-> IID mapping services
NS_IMETHOD GetIIDForName(const char* name, nsIID** iid);
NS_IMETHOD GetNameForIID(const nsIID* iid, char** name);
public:
virtual ~nsInterfaceInfoManager();
static nsInterfaceInfoManager* GetInterfaceInfoManager();
static nsIAllocator* GetAllocator(nsInterfaceInfoManager* iim = NULL);
private:
nsInterfaceInfoManager();
nsresult initInterfaceTables();
// Should this be public?
nsresult indexify_file(const char *filename);
// list of typelib records for enumeration. (freeing?)
nsTypelibRecord *typelibRecords;
// mapping between names and records
PLHashTable *nameTable;
// mapping between IIDs and records.
nsHashtable *IIDTable;
nsIAllocator *allocator;
};
#endif /* nsInterfaceInfoManager_h___ */

View File

@@ -0,0 +1,108 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Persistent interface records, shared between typelib records. */
#include "nsInterfaceRecord.h"
#include "nsInterfaceInfo.h"
// Follow XPCOM pattern for these functions to allow forwarding
// through xpcom interfaces.
nsresult
nsInterfaceRecord::GetInfo(nsInterfaceInfo **result)
{
if (this->info != NULL) {
// XXX should add ref here? (not xposed in public api...)
NS_ADDREF(this->info);
*result = this->info;
return NS_OK;
}
if (this->interfaceDescriptor == NULL) {
*result = NULL;
return NS_ERROR_FAILURE;
}
// time to make one. First, find a parent.
nsIInterfaceInfo *parent;
uint16 parent_index = this->interfaceDescriptor->parent_interface;
if (parent_index == 0) { // is it nsISupports?
parent = NULL;
} else {
nsInterfaceRecord *parent_record =
this->typelibRecord->interfaceRecords[parent_index - 1];
nsresult nsr = parent_record->GetInfo((nsInterfaceInfo **)&parent);
if (NS_IS_ERROR(nsr)) {
*result = NULL;
return nsr; // ? ... or NS_ERROR_FAILURE
}
}
// got a parent for it, now build the object itself
*result = new nsInterfaceInfo(this, (nsInterfaceInfo *)parent);
if (*result == NULL) {
NS_RELEASE(parent);
} else {
NS_ADDREF(*result);
this->info = *result;
}
return NS_OK;
}
nsresult
nsInterfaceRecord::GetIID(nsIID **iid) {
NS_PRECONDITION(iid, "bad param");
nsIAllocator* allocator;
if(this->interfaceDescriptor != NULL &&
NULL != (allocator = nsInterfaceInfoManager::GetAllocator()))
{
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
NS_RELEASE(allocator);
if(p) {
memcpy(p, &(this->iid), sizeof(nsIID));
*iid = p;
return NS_OK;
}
}
*iid = NULL;
return NS_ERROR_FAILURE;
}
nsresult
nsInterfaceRecord::GetName(char **name)
{
NS_PRECONDITION(name, "bad param");
nsIAllocator* allocator;
if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) {
int len = strlen(this->name)+1;
char* p = (char*)allocator->Alloc(len);
NS_RELEASE(allocator);
if(p) {
memcpy(p, this->name, len);
*name = p;
return NS_OK;
}
}
*name = NULL;
return NS_ERROR_FAILURE;
}

View File

@@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* For keeping track of interface directory entries. */
#ifndef nsInterfaceRecord_h___
#define nsInterfaceRecord_h___
#include "nsInterfaceInfo.h"
#include "xpt_struct.h"
// resolve circular ref...
class nsInterfaceInfo;
class nsTypelibRecord;
// For references in the IIDTable, nameTable hashtables in the
// nsInterfaceInfoManager.
class nsInterfaceRecord {
public:
// Accessors for these?
nsID iid;
char *name;
char *name_space;
nsTypelibRecord *typelibRecord;
XPTInterfaceDescriptor *interfaceDescriptor;
// adds ref
nsresult GetInfo(nsInterfaceInfo **result);
// makes allocator alloc'd copy.
nsresult GetIID(nsIID **iid);
nsresult GetName(char **name);
// so that nsInterfaceInfo destructor can null it out.
nsInterfaceInfo *info;
};
#endif /* nsInterfaceRecord_h___ */

View File

@@ -0,0 +1,37 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
// XXX fold this (and the .h file) into nsInterfaceInfoManager.cpp?
#include "nsTypelibRecord.h"
#include "nsInterfaceRecord.h"
#include "xpt_struct.h"
nsTypelibRecord::nsTypelibRecord(int size, nsTypelibRecord *next,
XPTHeader *header, nsIAllocator *allocator)
: next(next),
header(header)
{
this->interfaceRecords = (nsInterfaceRecord **)
allocator->Alloc(size * (sizeof (nsInterfaceRecord *)) + 1);
// XXX how to account for failure in a constructor? Can we return null?
// NULL-terminate it. The rest will get filled in.
this->interfaceRecords[size] = NULL;
}

View File

@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* For keeping track of typelibs and their interface directory tables. */
#ifndef nsTypelibRecord_h___
#define nsTypelibRecord_h___
/* class nsInterfaceInfoManager; */
struct XPTHeader;
class nsIAllocator;
class nsInterfaceInfoManager;
class nsInterfaceRecord;
class nsTypelibRecord {
// XXX accessors? Could conceal 1-based offset here.
public:
friend class nsInterfaceInfoManager;
nsTypelibRecord(int size, nsTypelibRecord *next, XPTHeader *header,
nsIAllocator *allocator);
// array of pointers to (potentially shared) interface records,
// NULL terminated.
nsInterfaceRecord **interfaceRecords;
nsTypelibRecord *next;
XPTHeader *header;
};
#endif /* nsTypelibRecord_h___ */

View File

@@ -0,0 +1,44 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = libxpt
SIMPLE_PROGRAMS = TestInterfaceInfo
CSRCS =
CPPSRCS = \
TestInterfaceInfo.cpp \
$(NULL)
LIBS = \
-L$(DIST)/bin \
-lxptinfo \
-lxpt \
-lxpcom \
-lreg \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,151 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Some simple smoke tests of the typelib loader. */
#include "nscore.h"
#include "nsISupports.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "xptinfo.h"
#include <stdio.h>
#include "../src/nsInterfaceInfo.h"
static void RegAllocator();
// This file expects the nsInterfaceInfoManager to be able to discover
// .xpt files corresponding to those in xpcom/idl. Currently this
// means setting XPTDIR in the environment to some directory
// containing these files.
int main (int argc, char **argv) {
int i;
nsIID *iid1, *iid2, *iid3, *iid4, *iid5, *iid6;
char *name1, *name2, *name3, *name4, *name5, *name6;
nsIInterfaceInfo *info1, *info2, *info3, *info4, *info5, *info6;;
RegAllocator();
nsIInterfaceInfoManager *iim = XPTI_GetInterfaceInfoManager();
fprintf(stderr, "\ngetting iid for 'nsISupports'\n");
iim->GetIIDForName("nsISupports", &iid1);
iim->GetNameForIID(iid1, &name1);
fprintf(stderr, "%s iid %s\n", name1, iid1->ToString());
fprintf(stderr, "\ngetting iid for 'nsIBaseStream'\n");
iim->GetIIDForName("nsIBaseStream", &iid2);
iim->GetNameForIID(iid2, &name2);
fprintf(stderr, "%s iid %s\n", name2, iid2->ToString());
fprintf(stderr, "iid: %s, name: %s\n", iid1->ToString(), name1);
fprintf(stderr, "iid: %s, name: %s\n", iid2->ToString(), name2);
fprintf(stderr, "\ngetting info for iid2 from above\n");
iim->GetInfoForIID(iid2, &info2);
#ifdef DEBUG
((nsInterfaceInfo *)info2)->print(stderr);
#endif
fprintf(stderr, "\ngetting iid for 'nsIInputStream'\n");
iim->GetIIDForName("nsIInputStream", &iid3);
iim->GetNameForIID(iid3, &name3);
fprintf(stderr, "%s iid %s\n", name3, iid2->ToString());
iim->GetInfoForIID(iid3, &info3);
#ifdef DEBUG
((nsInterfaceInfo *)info3)->print(stderr);
#endif
fprintf(stderr, "\ngetting info for name 'nsIBidirectionalEnumerator'\n");
iim->GetInfoForName("nsIBidirectionalEnumerator", &info4);
#ifdef DEBUG
((nsInterfaceInfo *)info4)->print(stderr);
#endif
fprintf(stderr, "\nparams work?\n");
fprintf(stderr, "\ngetting info for name 'nsIServiceManager'\n");
iim->GetInfoForName("nsIServiceManager", &info5);
#ifdef DEBUG
((nsInterfaceInfo *)info5)->print(stderr);
#endif
uint16 methodcount;
info5->GetMethodCount(&methodcount);
const nsXPTMethodInfo *mi;
for (i = 0; i < methodcount; i++) {
info5->GetMethodInfo(i, &mi);
char *methodname;
fprintf(stderr, "method %d, name %s\n", i, mi->GetName());
}
// 7 is GetServiceWithListener, which has juicy params.
info5->GetMethodInfo(7, &mi);
uint8 paramcount = mi->GetParamCount();
nsXPTParamInfo param2 = mi->GetParam(2);
// should be IID for nsIShutdownListener
nsIID *nsISL;
info5->GetIIDForParam(&param2, &nsISL);
// const nsIID *nsISL = param2.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 2 of method 7 of GetServiceWithListener - %s\n", nsISL->ToString());
// if we look up the name?
char *nsISLname;
iim->GetNameForIID(nsISL, &nsISLname);
fprintf(stderr, "which is called %s\n", nsISLname);
fprintf(stderr, "\nhow about one defined in a different typelib\n");
nsXPTParamInfo param3 = mi->GetParam(3);
// should be IID for nsIShutdownListener
nsIID *nsISS;
info5->GetIIDForParam(&param3, &nsISS);
// const nsIID *nsISS = param3.GetInterfaceIID(info5);
fprintf(stderr, "iid assoc'd with param 3 of method 7 of GetServiceWithListener - %s\n", nsISS->ToString());
// if we look up the name?
char *nsISSname;
iim->GetNameForIID(nsISS, &nsISSname);
fprintf(stderr, "which is called %s\n", nsISSname);
return 0;
}
// XXX remove following code when allocator autoregisters.
#include "nsRepository.h"
#include "nsIAllocator.h"
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
#ifdef XP_PC
#define XPCOM_DLL "xpcom32.dll"
#else
#ifdef XP_MAC
#define XPCOM_DLL "XPCOM_DLL"
#else
#define XPCOM_DLL "libxpcom.so"
#endif
#endif
static void RegAllocator()
{
nsRepository::RegisterComponent(kAllocatorCID, NULL, NULL, XPCOM_DLL,
PR_FALSE, PR_FALSE);
}

View File

@@ -0,0 +1,68 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\TestInterfaceInfo.exe
PROGRAMS = $(PROG1)
LCFLAGS=-DUSE_NSREG
DEFINES=-DWIN32_LEAN_AND_MEAN
REQUIRES=xpcom libxpt xptinfo
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\libxpt32.lib \
$(DIST)\lib\xptinfo32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAMS)
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
-for %p in ($(TESTCASES)) do $(MAKE_INSTALL) %p $(DIST)\bin
# Move this into config/obj.inc when it's allowed
.cpp{.\$(OBJDIR)\}.exe:
$(CC) @<<$(CFGFILE)
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
$(LLIBS)
$(OS_LIBS)
-Fd$(PDBFILE)
-Fe.\$(OBJDIR)\
-Fo.\$(OBJDIR)\
$(CURDIR)$(*B).cpp
<<KEEP
clobber::
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
$(PROG1): $(OBJDIR) TestInterfaceInfo.cpp

View File

@@ -0,0 +1,33 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = public src
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,6 @@
see:
http://www.mozilla.org/scriptable/xptcall-faq.html
and
http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/porting.html

View File

@@ -0,0 +1,21 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
DIRS=public src tests
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,205 @@
<html>
<head>
<title>xptcall Porting Guide</title>
</head>
<body bgcolor = "white">
<h2><center>xptcall Porting Guide</center></h2>
<h3>Overview</h3>
<blockquote>
<a href="http://www.mozilla.org/scriptable/xptcall-faq.html"> xptcall</a> is a
library that supports both invoking methods on arbitrary xpcom objects and
implementing classes whose objects can impersonate any xpcom interface. It does
this using platform specific assembly language code. This code needs to be
ported to all platforms that want to support xptcall (and thus mozilla).
</blockquote>
<h3>The tree</h3>
<blockquote>
<pre>
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall">mozilla/xpcom/libxpt/xptcall</a>
+--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public">public</a> // exported headers
+--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src">src</a> // core source
| \--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md">md</a> // platform specific parts
| +--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/mac">mac</a> // mac ppc
| +--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/unix">unix</a> // all unix
| \--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/win32">win32</a> // win32
| +--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/test">test</a> // simple tests to get started
\--<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/tests">tests</a> // full tests via api
</pre>
Porters are free to create subdirectories under the base <code>md</code>
directory for their given platforms and to integrate into the build system as
appropriate for their platform.
</blockquote>
<h3>Theory of operation</h3>
<blockquote>
There are really two pieces of functionality: <i>invoke</i> and <i>stubs</i>...
<p>
The <b><i>invoke</i></b> functionality requires the implementation of the
following on each platform (from <a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcall.h#131">xptcall/public/xptcall.h</a>):
<pre>
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params);
</pre>
Calling code is expected to supply an array of <code>nsXPTCVariant</code>
structs. These are discriminated unions describing the type and value of each
parameter of the target function. The platform specific code then builds a call
frame and invokes the method indicated by the index <code>methodIndex</code> on
the xpcom interface <code>that</code>.
<p>
Here are examples of this implementation for
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/win32/xptcinvoke.cpp">Win32</a>
and
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/unix/xptcinvoke_linux_x86.cpp">Linux x86</a>.
Both of these implementations use the basic strategy of: figure out how much
stack space is needed for the params, make the space in a new frame, copy the
params to that space, invoke the method, cleanup and return. C++ is used where
appropriate, Assembly language is used where necessary. Inline assembly language is used here,
but it is equally valid to use separate assembly language source files. Porters
can decide how best to do this for their platforms.
<p>
The <b><i>stubs</i></b> functionality is more complex. The goal here is a class
whose vtbl can look like the vtbl of any arbitrary xpcom interface. Objects of
this class can then be built to impersonate any xpcom object. The base interface
for this is (from <a href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcall.h#109">xptcall/public/xptcall.h</a>):
<pre>
class nsXPTCStubBase : public nsISupports
{
public:
// Include generated vtbl stub declarations.
// These are virtual and *also* implemented by this class..
#include "xptcstubsdecl.inc"
// The following methods must be provided by inheritor of this class.
// return a refcounted pointer to the InterfaceInfo for this object
// NOTE: on some platforms this MUST not fail or we crash!
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
// call this method and return result
NS_IMETHOD CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params) = 0;
};
</pre>
Code that wishes to make use of this <i>stubs</i> functionality (such as
<a href="http://www.mozilla.org/scriptable/">XPConnect</a>) implement a class
which inherits from <code>nsXPTCStubBase</code> and implements the
<code>GetInterfaceInfo</code> and <code>CallMethod</code> to let the
platform specific code know how to get interface information and how to dispatch methods
once their parameters have been pulled out of the platform specific calling
frame.
<p>
Porters of this functionality implement the platform specific code for the
<i>stub</i> methods that fill the vtbl for this class. The idea here is that the
class has a vtbl full of a large number of generic stubs. All instances of this
class share that vtbl and the same stubs. The stubs forward calls to a platform
specific method that uses the interface information supplied by
the overridden <code>GetInterfaceInfo</code> to extract the parameters and build
an array of platform independent <code>nsXPTCMiniVariant</code> structs which
are in turn passed on to the overridden <code>CallMethod</code>. The
platform dependent code is responsible for doing any cleanup and returning.
<p>
The stub methods are declared in <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcstubsdecl.inc">xptcall/public/xptcstubsdecl.inc</a>.
These are '#included' into the declaration of <code>nsXPTCStubBase</code>. A
similar include file (<a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/xptcstubsdef.inc">xptcall/public/xptcstubsdef.inc</a>)
is expanded using platform specific macros to define the stub functions. These
'.inc' files are checked into cvs. However, they can be regenerated as necessary
(i.e. to change the number of stubs or to change their specific declaration)
using the Perl script <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/public/genstubs.pl">xptcall/public/genstubs.pl</a>.
<p>
Here are examples of this implementation for <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/win32/xptcstubs.cpp">Win32</a>
and <a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/unix/xptcstubs_linux_x86.cpp">Linux
x86</a>. Both of these examples use inline assembly language. That is just how I
decided to do it. You can do it as you choose.
<p>
The Win32 version is somewhat tighter because the __declspec(naked) feature
allows for very small stubs. However, the __stdcall requires the callee to clean
up the stack, so it is imperative that the interface information scheme allow
the code to determine the correct stack pointer fixup for return without fail,
else the process will crash.
<p>
I opted to use inline assembler for the gcc Linux x86 port. I ended up with
larger stubs than I would have preferred rather than battle the compiler over
what would happen to the stack before my asm code began running.
<p>
I believe that the non-assembly parts of these files can be copied and reused
with minimal (but not zero) platform specific tweaks. Feel free to copy and
paste as necessary. Please remember that safety and reliability are more
important than speed optimizations. This code is primarily used to connect XPCOM
components with JavaScript; function call overhead is a <b>tiny</b> part of the
time involved.
<p>
I put together
<a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/src/md/test">xptcall/src/md/test
</a> as a place to evolve the basic functionality as a port is coming together.
Not all of the functionality is exercised, but it is a place to get started.
<a
href="http://lxr.mozilla.org/mozilla/source/xpcom/libxpt/xptcall/tests">xptcall/tests
</a> has an api level test for <code>XPTC_InvokeByIndex</code>, but no tests for
the <i>stubs</i> functionality. Such a test ought to be written, but this has not
yet been done.
<p>
A full 'test' at this point requires building the client and running the
XPConnect test called <i>TestXPC</i> in
<a
href="http://lxr.mozilla.org/mozilla/source/js/src/xpconnect/tests">mozilla/js/src/xpconnect/tests
</a>.
<p>
Getting these ports done is very important. Please let <a
href="mailto:jband@netscape.com">me</a> know if you are interested in doing one.
I'll answer any questions as I get them.
</blockquote>
<hr>
<b>Author:</b> <a href="mailto:jband@netscape.com">John Bandhauer &lt;jband@netscape.com&gt;</a><br>
<b>Last modified:</b> 1 April 1999
</body>
</html>

View File

@@ -0,0 +1,7 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
xptcall.h
xptcstubsdecl.inc
xptcstubsdef.inc

View File

@@ -0,0 +1,33 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptcall
EXPORTS = xptcall.h \
xptcstubsdecl.inc \
xptcstubsdef.inc \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,55 @@
#!/usr/local/bin/perl
# This is used to generate stub entry points. We generate a file to
# be included in the declaraion and a file to be used for expanding macros
# to represent the implementation of the stubs.
$entry_count = 256;
$sentinel_count = 10;
$decl_name = "xptcstubsdecl.inc";
$def_name = "xptcstubsdef.inc";
##
## Write the declarations include file
##
die "Can't open $decl_name" if !open(OUTFILE, ">$decl_name");
print OUTFILE "// generated file - DO NOT EDIT \n\n";
print OUTFILE "// includes ",$entry_count," stub entries, and ",
$sentinel_count," sentinel entries\n\n";
print OUTFILE "// declarations of normal stubs...\n";
print OUTFILE "// 0 is QueryInterface\n";
print OUTFILE "// 1 is AddRef\n";
print OUTFILE "// 2 is Release\n";
for($i = 0; $i < $entry_count; $i++) {
print OUTFILE "XPTC_EXPORT NS_IMETHOD Stub",$i+3,"();\n";
}
print OUTFILE "\n// declarations of sentinel stubs\n";
for($i = 0; $i < $sentinel_count; $i++) {
print OUTFILE "XPTC_EXPORT NS_IMETHOD Sentinel",$i,"();\n";
}
close(OUTFILE);
##
## Write the definitions include file. This assumes a macro will be used to
## expand the entries written...
##
die "Can't open $def_name" if !open(OUTFILE, ">$def_name");
print OUTFILE "// generated file - DO NOT EDIT \n\n";
print OUTFILE "// includes ",$entry_count," stub entries, and ",
$sentinel_count," sentinel entries\n\n";
for($i = 0; $i < $entry_count; $i++) {
print OUTFILE "STUB_ENTRY(",$i+3,")\n";
}
for($i = 0; $i < $sentinel_count; $i++) {
print OUTFILE "SENTINEL_ENTRY(",$i,")\n";
}

View File

@@ -0,0 +1,29 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
DEPTH=..\..\..\..
EXPORTS = xptcall.h \
xptcstubsdecl.inc \
xptcstubsdef.inc \
$(NULL)
MODULE = xptcall
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,137 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Public declarations for xptcall. */
#ifndef xptcall_h___
#define xptcall_h___
#include "prtypes.h"
#include "nscore.h"
#include "nsISupports.h"
#include "xpt_struct.h"
#include "xptinfo.h"
#include "nsIInterfaceInfo.h"
/***************************************************************************/
/*
* The linkage of XPTC API functions differs depending on whether the file is
* used within the XPTC library or not. Any source file within the XPTC
* library should define EXPORT_XPTC_API whereas any client of the library
* should not.
*/
#ifdef EXPORT_XPTC_API
#define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
#define XPTC_PUBLIC_DATA(t) PR_IMPLEMENT_DATA(t)
#ifdef _WIN32
# define XPTC_EXPORT _declspec(dllexport)
#else
# define XPTC_EXPORT
#endif
#else
#ifdef _WIN32
# define XPTC_PUBLIC_API(t) _declspec(dllimport) t
# define XPTC_PUBLIC_DATA(t) _declspec(dllimport) t
# define XPTC_EXPORT _declspec(dllimport)
#else
# define XPTC_PUBLIC_API(t) PR_IMPLEMENT(t)
# define XPTC_PUBLIC_DATA(t) t
# define XPTC_EXPORT
#endif
#endif
#define XPTC_FRIEND_API(t) XPTC_PUBLIC_API(t)
#define XPTC_FRIEND_DATA(t) XPTC_PUBLIC_DATA(t)
/***************************************************************************/
struct nsXPTCMiniVariant
{
// No ctors or dtors so that we can use arrays of these on the stack
// with no penalty.
union
{
PRInt8 i8;
PRInt16 i16;
PRInt32 i32;
PRInt64 i64;
PRUint8 u8;
PRUint16 u16;
PRUint32 u32;
PRUint64 u64;
float f;
double d;
PRBool b;
char c;
wchar_t wc;
void* p;
} val;
};
struct nsXPTCVariant : public nsXPTCMiniVariant
{
// No ctors or dtors so that we can use arrays of these on the stack
// with no penalty.
// inherits 'val' here
void* ptr;
nsXPTType type;
PRUint8 flags;
enum
{
// these are bitflags!
PTR_IS_DATA = 0x1, // ptr points to 'real' data in val
VAL_IS_OWNED = 0x2, // val.p holds alloc'd ptr that must be freed
VAL_IS_IFACE = 0x4 // val.p holds interface ptr that must be released
};
PRBool IsPtrData() const {return (PRBool) (flags & PTR_IS_DATA);}
PRBool IsValOwned() const {return (PRBool) (flags & VAL_IS_OWNED);}
PRBool IsValInterface() const {return (PRBool) (flags & VAL_IS_IFACE);}
};
/***************************************************************************/
class nsXPTCStubBase : public nsISupports
{
public:
// Include generated vtbl stub declarations.
// These are virtual and *also* implemented by this class..
#include "xptcstubsdecl.inc"
// The following methods must be provided by inheritor of this class.
// return a refcounted pointer to the InterfaceInfo for this object
// NOTE: on some platforms this MUST not fail or we crash!
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
// call this method and return result
NS_IMETHOD CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo* info,
nsXPTCMiniVariant* params) = 0;
};
PR_BEGIN_EXTERN_C
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params);
PR_END_EXTERN_C
#endif /* xptcall_h___ */

View File

@@ -0,0 +1,276 @@
// generated file - DO NOT EDIT
// includes 256 stub entries, and 10 sentinel entries
// declarations of normal stubs...
// 0 is QueryInterface
// 1 is AddRef
// 2 is Release
XPTC_EXPORT NS_IMETHOD Stub3();
XPTC_EXPORT NS_IMETHOD Stub4();
XPTC_EXPORT NS_IMETHOD Stub5();
XPTC_EXPORT NS_IMETHOD Stub6();
XPTC_EXPORT NS_IMETHOD Stub7();
XPTC_EXPORT NS_IMETHOD Stub8();
XPTC_EXPORT NS_IMETHOD Stub9();
XPTC_EXPORT NS_IMETHOD Stub10();
XPTC_EXPORT NS_IMETHOD Stub11();
XPTC_EXPORT NS_IMETHOD Stub12();
XPTC_EXPORT NS_IMETHOD Stub13();
XPTC_EXPORT NS_IMETHOD Stub14();
XPTC_EXPORT NS_IMETHOD Stub15();
XPTC_EXPORT NS_IMETHOD Stub16();
XPTC_EXPORT NS_IMETHOD Stub17();
XPTC_EXPORT NS_IMETHOD Stub18();
XPTC_EXPORT NS_IMETHOD Stub19();
XPTC_EXPORT NS_IMETHOD Stub20();
XPTC_EXPORT NS_IMETHOD Stub21();
XPTC_EXPORT NS_IMETHOD Stub22();
XPTC_EXPORT NS_IMETHOD Stub23();
XPTC_EXPORT NS_IMETHOD Stub24();
XPTC_EXPORT NS_IMETHOD Stub25();
XPTC_EXPORT NS_IMETHOD Stub26();
XPTC_EXPORT NS_IMETHOD Stub27();
XPTC_EXPORT NS_IMETHOD Stub28();
XPTC_EXPORT NS_IMETHOD Stub29();
XPTC_EXPORT NS_IMETHOD Stub30();
XPTC_EXPORT NS_IMETHOD Stub31();
XPTC_EXPORT NS_IMETHOD Stub32();
XPTC_EXPORT NS_IMETHOD Stub33();
XPTC_EXPORT NS_IMETHOD Stub34();
XPTC_EXPORT NS_IMETHOD Stub35();
XPTC_EXPORT NS_IMETHOD Stub36();
XPTC_EXPORT NS_IMETHOD Stub37();
XPTC_EXPORT NS_IMETHOD Stub38();
XPTC_EXPORT NS_IMETHOD Stub39();
XPTC_EXPORT NS_IMETHOD Stub40();
XPTC_EXPORT NS_IMETHOD Stub41();
XPTC_EXPORT NS_IMETHOD Stub42();
XPTC_EXPORT NS_IMETHOD Stub43();
XPTC_EXPORT NS_IMETHOD Stub44();
XPTC_EXPORT NS_IMETHOD Stub45();
XPTC_EXPORT NS_IMETHOD Stub46();
XPTC_EXPORT NS_IMETHOD Stub47();
XPTC_EXPORT NS_IMETHOD Stub48();
XPTC_EXPORT NS_IMETHOD Stub49();
XPTC_EXPORT NS_IMETHOD Stub50();
XPTC_EXPORT NS_IMETHOD Stub51();
XPTC_EXPORT NS_IMETHOD Stub52();
XPTC_EXPORT NS_IMETHOD Stub53();
XPTC_EXPORT NS_IMETHOD Stub54();
XPTC_EXPORT NS_IMETHOD Stub55();
XPTC_EXPORT NS_IMETHOD Stub56();
XPTC_EXPORT NS_IMETHOD Stub57();
XPTC_EXPORT NS_IMETHOD Stub58();
XPTC_EXPORT NS_IMETHOD Stub59();
XPTC_EXPORT NS_IMETHOD Stub60();
XPTC_EXPORT NS_IMETHOD Stub61();
XPTC_EXPORT NS_IMETHOD Stub62();
XPTC_EXPORT NS_IMETHOD Stub63();
XPTC_EXPORT NS_IMETHOD Stub64();
XPTC_EXPORT NS_IMETHOD Stub65();
XPTC_EXPORT NS_IMETHOD Stub66();
XPTC_EXPORT NS_IMETHOD Stub67();
XPTC_EXPORT NS_IMETHOD Stub68();
XPTC_EXPORT NS_IMETHOD Stub69();
XPTC_EXPORT NS_IMETHOD Stub70();
XPTC_EXPORT NS_IMETHOD Stub71();
XPTC_EXPORT NS_IMETHOD Stub72();
XPTC_EXPORT NS_IMETHOD Stub73();
XPTC_EXPORT NS_IMETHOD Stub74();
XPTC_EXPORT NS_IMETHOD Stub75();
XPTC_EXPORT NS_IMETHOD Stub76();
XPTC_EXPORT NS_IMETHOD Stub77();
XPTC_EXPORT NS_IMETHOD Stub78();
XPTC_EXPORT NS_IMETHOD Stub79();
XPTC_EXPORT NS_IMETHOD Stub80();
XPTC_EXPORT NS_IMETHOD Stub81();
XPTC_EXPORT NS_IMETHOD Stub82();
XPTC_EXPORT NS_IMETHOD Stub83();
XPTC_EXPORT NS_IMETHOD Stub84();
XPTC_EXPORT NS_IMETHOD Stub85();
XPTC_EXPORT NS_IMETHOD Stub86();
XPTC_EXPORT NS_IMETHOD Stub87();
XPTC_EXPORT NS_IMETHOD Stub88();
XPTC_EXPORT NS_IMETHOD Stub89();
XPTC_EXPORT NS_IMETHOD Stub90();
XPTC_EXPORT NS_IMETHOD Stub91();
XPTC_EXPORT NS_IMETHOD Stub92();
XPTC_EXPORT NS_IMETHOD Stub93();
XPTC_EXPORT NS_IMETHOD Stub94();
XPTC_EXPORT NS_IMETHOD Stub95();
XPTC_EXPORT NS_IMETHOD Stub96();
XPTC_EXPORT NS_IMETHOD Stub97();
XPTC_EXPORT NS_IMETHOD Stub98();
XPTC_EXPORT NS_IMETHOD Stub99();
XPTC_EXPORT NS_IMETHOD Stub100();
XPTC_EXPORT NS_IMETHOD Stub101();
XPTC_EXPORT NS_IMETHOD Stub102();
XPTC_EXPORT NS_IMETHOD Stub103();
XPTC_EXPORT NS_IMETHOD Stub104();
XPTC_EXPORT NS_IMETHOD Stub105();
XPTC_EXPORT NS_IMETHOD Stub106();
XPTC_EXPORT NS_IMETHOD Stub107();
XPTC_EXPORT NS_IMETHOD Stub108();
XPTC_EXPORT NS_IMETHOD Stub109();
XPTC_EXPORT NS_IMETHOD Stub110();
XPTC_EXPORT NS_IMETHOD Stub111();
XPTC_EXPORT NS_IMETHOD Stub112();
XPTC_EXPORT NS_IMETHOD Stub113();
XPTC_EXPORT NS_IMETHOD Stub114();
XPTC_EXPORT NS_IMETHOD Stub115();
XPTC_EXPORT NS_IMETHOD Stub116();
XPTC_EXPORT NS_IMETHOD Stub117();
XPTC_EXPORT NS_IMETHOD Stub118();
XPTC_EXPORT NS_IMETHOD Stub119();
XPTC_EXPORT NS_IMETHOD Stub120();
XPTC_EXPORT NS_IMETHOD Stub121();
XPTC_EXPORT NS_IMETHOD Stub122();
XPTC_EXPORT NS_IMETHOD Stub123();
XPTC_EXPORT NS_IMETHOD Stub124();
XPTC_EXPORT NS_IMETHOD Stub125();
XPTC_EXPORT NS_IMETHOD Stub126();
XPTC_EXPORT NS_IMETHOD Stub127();
XPTC_EXPORT NS_IMETHOD Stub128();
XPTC_EXPORT NS_IMETHOD Stub129();
XPTC_EXPORT NS_IMETHOD Stub130();
XPTC_EXPORT NS_IMETHOD Stub131();
XPTC_EXPORT NS_IMETHOD Stub132();
XPTC_EXPORT NS_IMETHOD Stub133();
XPTC_EXPORT NS_IMETHOD Stub134();
XPTC_EXPORT NS_IMETHOD Stub135();
XPTC_EXPORT NS_IMETHOD Stub136();
XPTC_EXPORT NS_IMETHOD Stub137();
XPTC_EXPORT NS_IMETHOD Stub138();
XPTC_EXPORT NS_IMETHOD Stub139();
XPTC_EXPORT NS_IMETHOD Stub140();
XPTC_EXPORT NS_IMETHOD Stub141();
XPTC_EXPORT NS_IMETHOD Stub142();
XPTC_EXPORT NS_IMETHOD Stub143();
XPTC_EXPORT NS_IMETHOD Stub144();
XPTC_EXPORT NS_IMETHOD Stub145();
XPTC_EXPORT NS_IMETHOD Stub146();
XPTC_EXPORT NS_IMETHOD Stub147();
XPTC_EXPORT NS_IMETHOD Stub148();
XPTC_EXPORT NS_IMETHOD Stub149();
XPTC_EXPORT NS_IMETHOD Stub150();
XPTC_EXPORT NS_IMETHOD Stub151();
XPTC_EXPORT NS_IMETHOD Stub152();
XPTC_EXPORT NS_IMETHOD Stub153();
XPTC_EXPORT NS_IMETHOD Stub154();
XPTC_EXPORT NS_IMETHOD Stub155();
XPTC_EXPORT NS_IMETHOD Stub156();
XPTC_EXPORT NS_IMETHOD Stub157();
XPTC_EXPORT NS_IMETHOD Stub158();
XPTC_EXPORT NS_IMETHOD Stub159();
XPTC_EXPORT NS_IMETHOD Stub160();
XPTC_EXPORT NS_IMETHOD Stub161();
XPTC_EXPORT NS_IMETHOD Stub162();
XPTC_EXPORT NS_IMETHOD Stub163();
XPTC_EXPORT NS_IMETHOD Stub164();
XPTC_EXPORT NS_IMETHOD Stub165();
XPTC_EXPORT NS_IMETHOD Stub166();
XPTC_EXPORT NS_IMETHOD Stub167();
XPTC_EXPORT NS_IMETHOD Stub168();
XPTC_EXPORT NS_IMETHOD Stub169();
XPTC_EXPORT NS_IMETHOD Stub170();
XPTC_EXPORT NS_IMETHOD Stub171();
XPTC_EXPORT NS_IMETHOD Stub172();
XPTC_EXPORT NS_IMETHOD Stub173();
XPTC_EXPORT NS_IMETHOD Stub174();
XPTC_EXPORT NS_IMETHOD Stub175();
XPTC_EXPORT NS_IMETHOD Stub176();
XPTC_EXPORT NS_IMETHOD Stub177();
XPTC_EXPORT NS_IMETHOD Stub178();
XPTC_EXPORT NS_IMETHOD Stub179();
XPTC_EXPORT NS_IMETHOD Stub180();
XPTC_EXPORT NS_IMETHOD Stub181();
XPTC_EXPORT NS_IMETHOD Stub182();
XPTC_EXPORT NS_IMETHOD Stub183();
XPTC_EXPORT NS_IMETHOD Stub184();
XPTC_EXPORT NS_IMETHOD Stub185();
XPTC_EXPORT NS_IMETHOD Stub186();
XPTC_EXPORT NS_IMETHOD Stub187();
XPTC_EXPORT NS_IMETHOD Stub188();
XPTC_EXPORT NS_IMETHOD Stub189();
XPTC_EXPORT NS_IMETHOD Stub190();
XPTC_EXPORT NS_IMETHOD Stub191();
XPTC_EXPORT NS_IMETHOD Stub192();
XPTC_EXPORT NS_IMETHOD Stub193();
XPTC_EXPORT NS_IMETHOD Stub194();
XPTC_EXPORT NS_IMETHOD Stub195();
XPTC_EXPORT NS_IMETHOD Stub196();
XPTC_EXPORT NS_IMETHOD Stub197();
XPTC_EXPORT NS_IMETHOD Stub198();
XPTC_EXPORT NS_IMETHOD Stub199();
XPTC_EXPORT NS_IMETHOD Stub200();
XPTC_EXPORT NS_IMETHOD Stub201();
XPTC_EXPORT NS_IMETHOD Stub202();
XPTC_EXPORT NS_IMETHOD Stub203();
XPTC_EXPORT NS_IMETHOD Stub204();
XPTC_EXPORT NS_IMETHOD Stub205();
XPTC_EXPORT NS_IMETHOD Stub206();
XPTC_EXPORT NS_IMETHOD Stub207();
XPTC_EXPORT NS_IMETHOD Stub208();
XPTC_EXPORT NS_IMETHOD Stub209();
XPTC_EXPORT NS_IMETHOD Stub210();
XPTC_EXPORT NS_IMETHOD Stub211();
XPTC_EXPORT NS_IMETHOD Stub212();
XPTC_EXPORT NS_IMETHOD Stub213();
XPTC_EXPORT NS_IMETHOD Stub214();
XPTC_EXPORT NS_IMETHOD Stub215();
XPTC_EXPORT NS_IMETHOD Stub216();
XPTC_EXPORT NS_IMETHOD Stub217();
XPTC_EXPORT NS_IMETHOD Stub218();
XPTC_EXPORT NS_IMETHOD Stub219();
XPTC_EXPORT NS_IMETHOD Stub220();
XPTC_EXPORT NS_IMETHOD Stub221();
XPTC_EXPORT NS_IMETHOD Stub222();
XPTC_EXPORT NS_IMETHOD Stub223();
XPTC_EXPORT NS_IMETHOD Stub224();
XPTC_EXPORT NS_IMETHOD Stub225();
XPTC_EXPORT NS_IMETHOD Stub226();
XPTC_EXPORT NS_IMETHOD Stub227();
XPTC_EXPORT NS_IMETHOD Stub228();
XPTC_EXPORT NS_IMETHOD Stub229();
XPTC_EXPORT NS_IMETHOD Stub230();
XPTC_EXPORT NS_IMETHOD Stub231();
XPTC_EXPORT NS_IMETHOD Stub232();
XPTC_EXPORT NS_IMETHOD Stub233();
XPTC_EXPORT NS_IMETHOD Stub234();
XPTC_EXPORT NS_IMETHOD Stub235();
XPTC_EXPORT NS_IMETHOD Stub236();
XPTC_EXPORT NS_IMETHOD Stub237();
XPTC_EXPORT NS_IMETHOD Stub238();
XPTC_EXPORT NS_IMETHOD Stub239();
XPTC_EXPORT NS_IMETHOD Stub240();
XPTC_EXPORT NS_IMETHOD Stub241();
XPTC_EXPORT NS_IMETHOD Stub242();
XPTC_EXPORT NS_IMETHOD Stub243();
XPTC_EXPORT NS_IMETHOD Stub244();
XPTC_EXPORT NS_IMETHOD Stub245();
XPTC_EXPORT NS_IMETHOD Stub246();
XPTC_EXPORT NS_IMETHOD Stub247();
XPTC_EXPORT NS_IMETHOD Stub248();
XPTC_EXPORT NS_IMETHOD Stub249();
XPTC_EXPORT NS_IMETHOD Stub250();
XPTC_EXPORT NS_IMETHOD Stub251();
XPTC_EXPORT NS_IMETHOD Stub252();
XPTC_EXPORT NS_IMETHOD Stub253();
XPTC_EXPORT NS_IMETHOD Stub254();
XPTC_EXPORT NS_IMETHOD Stub255();
XPTC_EXPORT NS_IMETHOD Stub256();
XPTC_EXPORT NS_IMETHOD Stub257();
XPTC_EXPORT NS_IMETHOD Stub258();
// declarations of sentinel stubs
XPTC_EXPORT NS_IMETHOD Sentinel0();
XPTC_EXPORT NS_IMETHOD Sentinel1();
XPTC_EXPORT NS_IMETHOD Sentinel2();
XPTC_EXPORT NS_IMETHOD Sentinel3();
XPTC_EXPORT NS_IMETHOD Sentinel4();
XPTC_EXPORT NS_IMETHOD Sentinel5();
XPTC_EXPORT NS_IMETHOD Sentinel6();
XPTC_EXPORT NS_IMETHOD Sentinel7();
XPTC_EXPORT NS_IMETHOD Sentinel8();
XPTC_EXPORT NS_IMETHOD Sentinel9();

View File

@@ -0,0 +1,270 @@
// generated file - DO NOT EDIT
// includes 256 stub entries, and 10 sentinel entries
STUB_ENTRY(3)
STUB_ENTRY(4)
STUB_ENTRY(5)
STUB_ENTRY(6)
STUB_ENTRY(7)
STUB_ENTRY(8)
STUB_ENTRY(9)
STUB_ENTRY(10)
STUB_ENTRY(11)
STUB_ENTRY(12)
STUB_ENTRY(13)
STUB_ENTRY(14)
STUB_ENTRY(15)
STUB_ENTRY(16)
STUB_ENTRY(17)
STUB_ENTRY(18)
STUB_ENTRY(19)
STUB_ENTRY(20)
STUB_ENTRY(21)
STUB_ENTRY(22)
STUB_ENTRY(23)
STUB_ENTRY(24)
STUB_ENTRY(25)
STUB_ENTRY(26)
STUB_ENTRY(27)
STUB_ENTRY(28)
STUB_ENTRY(29)
STUB_ENTRY(30)
STUB_ENTRY(31)
STUB_ENTRY(32)
STUB_ENTRY(33)
STUB_ENTRY(34)
STUB_ENTRY(35)
STUB_ENTRY(36)
STUB_ENTRY(37)
STUB_ENTRY(38)
STUB_ENTRY(39)
STUB_ENTRY(40)
STUB_ENTRY(41)
STUB_ENTRY(42)
STUB_ENTRY(43)
STUB_ENTRY(44)
STUB_ENTRY(45)
STUB_ENTRY(46)
STUB_ENTRY(47)
STUB_ENTRY(48)
STUB_ENTRY(49)
STUB_ENTRY(50)
STUB_ENTRY(51)
STUB_ENTRY(52)
STUB_ENTRY(53)
STUB_ENTRY(54)
STUB_ENTRY(55)
STUB_ENTRY(56)
STUB_ENTRY(57)
STUB_ENTRY(58)
STUB_ENTRY(59)
STUB_ENTRY(60)
STUB_ENTRY(61)
STUB_ENTRY(62)
STUB_ENTRY(63)
STUB_ENTRY(64)
STUB_ENTRY(65)
STUB_ENTRY(66)
STUB_ENTRY(67)
STUB_ENTRY(68)
STUB_ENTRY(69)
STUB_ENTRY(70)
STUB_ENTRY(71)
STUB_ENTRY(72)
STUB_ENTRY(73)
STUB_ENTRY(74)
STUB_ENTRY(75)
STUB_ENTRY(76)
STUB_ENTRY(77)
STUB_ENTRY(78)
STUB_ENTRY(79)
STUB_ENTRY(80)
STUB_ENTRY(81)
STUB_ENTRY(82)
STUB_ENTRY(83)
STUB_ENTRY(84)
STUB_ENTRY(85)
STUB_ENTRY(86)
STUB_ENTRY(87)
STUB_ENTRY(88)
STUB_ENTRY(89)
STUB_ENTRY(90)
STUB_ENTRY(91)
STUB_ENTRY(92)
STUB_ENTRY(93)
STUB_ENTRY(94)
STUB_ENTRY(95)
STUB_ENTRY(96)
STUB_ENTRY(97)
STUB_ENTRY(98)
STUB_ENTRY(99)
STUB_ENTRY(100)
STUB_ENTRY(101)
STUB_ENTRY(102)
STUB_ENTRY(103)
STUB_ENTRY(104)
STUB_ENTRY(105)
STUB_ENTRY(106)
STUB_ENTRY(107)
STUB_ENTRY(108)
STUB_ENTRY(109)
STUB_ENTRY(110)
STUB_ENTRY(111)
STUB_ENTRY(112)
STUB_ENTRY(113)
STUB_ENTRY(114)
STUB_ENTRY(115)
STUB_ENTRY(116)
STUB_ENTRY(117)
STUB_ENTRY(118)
STUB_ENTRY(119)
STUB_ENTRY(120)
STUB_ENTRY(121)
STUB_ENTRY(122)
STUB_ENTRY(123)
STUB_ENTRY(124)
STUB_ENTRY(125)
STUB_ENTRY(126)
STUB_ENTRY(127)
STUB_ENTRY(128)
STUB_ENTRY(129)
STUB_ENTRY(130)
STUB_ENTRY(131)
STUB_ENTRY(132)
STUB_ENTRY(133)
STUB_ENTRY(134)
STUB_ENTRY(135)
STUB_ENTRY(136)
STUB_ENTRY(137)
STUB_ENTRY(138)
STUB_ENTRY(139)
STUB_ENTRY(140)
STUB_ENTRY(141)
STUB_ENTRY(142)
STUB_ENTRY(143)
STUB_ENTRY(144)
STUB_ENTRY(145)
STUB_ENTRY(146)
STUB_ENTRY(147)
STUB_ENTRY(148)
STUB_ENTRY(149)
STUB_ENTRY(150)
STUB_ENTRY(151)
STUB_ENTRY(152)
STUB_ENTRY(153)
STUB_ENTRY(154)
STUB_ENTRY(155)
STUB_ENTRY(156)
STUB_ENTRY(157)
STUB_ENTRY(158)
STUB_ENTRY(159)
STUB_ENTRY(160)
STUB_ENTRY(161)
STUB_ENTRY(162)
STUB_ENTRY(163)
STUB_ENTRY(164)
STUB_ENTRY(165)
STUB_ENTRY(166)
STUB_ENTRY(167)
STUB_ENTRY(168)
STUB_ENTRY(169)
STUB_ENTRY(170)
STUB_ENTRY(171)
STUB_ENTRY(172)
STUB_ENTRY(173)
STUB_ENTRY(174)
STUB_ENTRY(175)
STUB_ENTRY(176)
STUB_ENTRY(177)
STUB_ENTRY(178)
STUB_ENTRY(179)
STUB_ENTRY(180)
STUB_ENTRY(181)
STUB_ENTRY(182)
STUB_ENTRY(183)
STUB_ENTRY(184)
STUB_ENTRY(185)
STUB_ENTRY(186)
STUB_ENTRY(187)
STUB_ENTRY(188)
STUB_ENTRY(189)
STUB_ENTRY(190)
STUB_ENTRY(191)
STUB_ENTRY(192)
STUB_ENTRY(193)
STUB_ENTRY(194)
STUB_ENTRY(195)
STUB_ENTRY(196)
STUB_ENTRY(197)
STUB_ENTRY(198)
STUB_ENTRY(199)
STUB_ENTRY(200)
STUB_ENTRY(201)
STUB_ENTRY(202)
STUB_ENTRY(203)
STUB_ENTRY(204)
STUB_ENTRY(205)
STUB_ENTRY(206)
STUB_ENTRY(207)
STUB_ENTRY(208)
STUB_ENTRY(209)
STUB_ENTRY(210)
STUB_ENTRY(211)
STUB_ENTRY(212)
STUB_ENTRY(213)
STUB_ENTRY(214)
STUB_ENTRY(215)
STUB_ENTRY(216)
STUB_ENTRY(217)
STUB_ENTRY(218)
STUB_ENTRY(219)
STUB_ENTRY(220)
STUB_ENTRY(221)
STUB_ENTRY(222)
STUB_ENTRY(223)
STUB_ENTRY(224)
STUB_ENTRY(225)
STUB_ENTRY(226)
STUB_ENTRY(227)
STUB_ENTRY(228)
STUB_ENTRY(229)
STUB_ENTRY(230)
STUB_ENTRY(231)
STUB_ENTRY(232)
STUB_ENTRY(233)
STUB_ENTRY(234)
STUB_ENTRY(235)
STUB_ENTRY(236)
STUB_ENTRY(237)
STUB_ENTRY(238)
STUB_ENTRY(239)
STUB_ENTRY(240)
STUB_ENTRY(241)
STUB_ENTRY(242)
STUB_ENTRY(243)
STUB_ENTRY(244)
STUB_ENTRY(245)
STUB_ENTRY(246)
STUB_ENTRY(247)
STUB_ENTRY(248)
STUB_ENTRY(249)
STUB_ENTRY(250)
STUB_ENTRY(251)
STUB_ENTRY(252)
STUB_ENTRY(253)
STUB_ENTRY(254)
STUB_ENTRY(255)
STUB_ENTRY(256)
STUB_ENTRY(257)
STUB_ENTRY(258)
SENTINEL_ENTRY(0)
SENTINEL_ENTRY(1)
SENTINEL_ENTRY(2)
SENTINEL_ENTRY(3)
SENTINEL_ENTRY(4)
SENTINEL_ENTRY(5)
SENTINEL_ENTRY(6)
SENTINEL_ENTRY(7)
SENTINEL_ENTRY(8)
SENTINEL_ENTRY(9)

View File

@@ -0,0 +1,38 @@
#!gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xptcall
LIBRARY_NAME = xptcall
DIRS = md
CFLAGS += -DEXPORT_XPTC_API
CSRCS = xptcall.c \
$(NULL)
REQUIRES = $(MODULE)
# export:: libs
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,65 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
DIRS=md
MAKE_OBJ_TYPE = DLL
DLLNAME = xptcall$(MOZ_BITS)
#PDBFILE = $(DLLNAME).pdb
#MAPFILE = $(DLLNAME).map
DLL =.\$(OBJDIR)\$(DLLNAME).dll
MODULE=xptcall
REQUIRES=xpcom libxpt xptinfo
DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPTC_API
OBJS= \
.\$(OBJDIR)\xptcall.obj \
.\md\win32\$(OBJDIR)\xptcinvoke.obj \
.\md\win32\$(OBJDIR)\xptcstubs.obj \
$(NULL)
EXPORTS = \
$(NULL)
LINCS=-I$(PUBLIC)\xptcall -I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\libxpt -I$(PUBLIC)\xptinfo
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LLIBS= $(LIBNSPR) \
$(DIST)\lib\xpcom$(MOZ_BITS).lib \
$(DIST)\lib\xptinfo$(MOZ_BITS).lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(DLLNAME).lib
rm -f $(DIST)\bin\$(DLLNAME).dll

View File

@@ -0,0 +1,31 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH=../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = unix
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,129 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
#include "xptcprivate.h"
#ifndef XP_MAC
#error "This code is for Macintosh only"
#endif
extern "C" uint32
invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
{
PRUint32 result = 0;
for(PRUint32 i = 0; i < paramCount; i++, s++)
{
if(s->IsPtrData())
{
result++;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
result++;
break;
case nsXPTType::T_I64 :
result+=2;
break;
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
result++;
break;
case nsXPTType::T_U64 :
result+=2;
break;
case nsXPTType::T_FLOAT :
result++;
break;
case nsXPTType::T_DOUBLE :
result+=2;
break;
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
result++;
break;
default:
// all the others are plain pointer types
result++;
break;
}
}
return result;
}
extern "C" void
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s, double *fprData)
{
PRUint32 fpCount = 0;
for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
{
if(s->IsPtrData())
{
*((void**)d) = s->ptr;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 : *((PRInt8*) d) = s->val.i8; break;
case nsXPTType::T_I16 : *((PRInt16*) d) = s->val.i16; break;
case nsXPTType::T_I32 : *((PRInt32*) d) = s->val.i32; break;
case nsXPTType::T_I64 : *((PRInt64*) d) = s->val.i64; d++; break;
case nsXPTType::T_U8 : *((PRUint8*) d) = s->val.u8; break;
case nsXPTType::T_U16 : *((PRUint16*)d) = s->val.u16; break;
case nsXPTType::T_U32 : *((PRUint32*)d) = s->val.u32; break;
case nsXPTType::T_U64 : *((PRUint64*)d) = s->val.u64; d++; break;
case nsXPTType::T_FLOAT : *((float*) d) = s->val.f;
if (fpCount < 13)
fprData[fpCount++] = s->val.f;
break;
case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++;
if (fpCount < 13)
fprData[fpCount++] = s->val.d;
break;
case nsXPTType::T_BOOL : *((PRBool*) d) = s->val.b; break;
case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break;
case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break;
default:
// all the others are plain pointer types
*((void**)d) = s->val.p;
break;
}
}
}
#pragma export on
extern "C" nsresult _XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params);
extern "C"
XPTC_PUBLIC_API(nsresult)
XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
PRUint32 paramCount, nsXPTCVariant* params)
{
return _XPTC_InvokeByIndex(that, methodIndex, paramCount, params);
}
#pragma export off

Some files were not shown because too many files have changed in this diff Show More