fix -external-runtime

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8654 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-01-31 00:02:58 +00:00
commit 0d6baa85ef
7 changed files with 226 additions and 165 deletions

56
Lib/python/pyhead.swg Normal file
View file

@ -0,0 +1,56 @@
/* Python.h has to appear first */
#include <Python.h>
/* Add PyOS_snprintf for old Pythons */
#if PY_VERSION_HEX < 0x02020000
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
# define PyOS_snprintf _snprintf
# else
# define PyOS_snprintf snprintf
# endif
#endif
/* A crude PyString_FromFormat implementation for old Pythons */
#if PY_VERSION_HEX < 0x02020000
#ifndef SWIG_PYBUFFER_SIZE
#define SWIG_PYBUFFER_SIZE 1024
#endif
static PyObject *
PyString_FromFormat(const char *fmt, ...) {
va_list ap;
char buf[SWIG_PYBUFFER_SIZE * 2];
int res;
va_start(ap, fmt);
res = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return (res < 0 || res >= sizeof(buf)) ? 0 : PyString_FromString(buf);
}
#endif
/* Add PyObject_Del for old Pythons */
#if PY_VERSION_HEX < 0x01060000
#define PyObject_Del(op) PyMem_DEL((op))
#endif
#ifndef PyObject_DEL
#define PyObject_DEL PyObject_Del
#endif
/* A crude PyExc_StopIteration exception for old Pythons */
#if PY_VERSION_HEX < 0x02020000
#define PyExc_StopIteration PyExc_RuntimeError
#define PyObject_GenericGetAttr 0
#define Py_NotImplemented PyExc_RuntimeError
#endif
/* A crude PyString_AsStringAndSize implementation for old Pythons */
#if PY_VERSION_HEX < 0x02010000
#define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;}
#endif
#if PY_VERSION_HEX < 0x02000000
#define PySequence_Size PySequence_Length
#endif

View file

@ -1,72 +1,12 @@
/* Python.h has to appear first */
%insert(runtime) %{
/* Python.h has to appear first */
#include <Python.h>
/* Add PyOS_snprintf for old Pythons */
#if PY_VERSION_HEX < 0x02020000
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
# define PyOS_snprintf _snprintf
# else
# define PyOS_snprintf snprintf
# endif
#endif
/* A crude PyString_FromFormat implementation for old Pythons */
#if PY_VERSION_HEX < 0x02020000
#ifndef SWIG_PYBUFFER_SIZE
#define SWIG_PYBUFFER_SIZE 1024
#endif
static PyObject *
PyString_FromFormat(const char *fmt, ...) {
va_list ap;
char buf[SWIG_PYBUFFER_SIZE * 2];
int res;
va_start(ap, fmt);
res = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return (res < 0 || res >= sizeof(buf)) ? 0 : PyString_FromString(buf);
}
#endif
/* Add PyObject_Del for old Pythons */
#if PY_VERSION_HEX < 0x01060000
#define PyObject_Del(op) PyMem_DEL((op))
#endif
#ifndef PyObject_DEL
#define PyObject_DEL PyObject_Del
#endif
/* A crude PyExc_StopIteration exception for old Pythons */
#if PY_VERSION_HEX < 0x02020000
#define PyExc_StopIteration PyExc_RuntimeError
#define PyObject_GenericGetAttr 0
#define Py_NotImplemented PyExc_RuntimeError
#endif
/* A crude PyString_AsStringAndSize implementation for old Pythons */
#if PY_VERSION_HEX < 0x02010000
#define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;}
#endif
#if PY_VERSION_HEX < 0x02000000
#define PySequence_Size PySequence_Length
#endif
%}
%insert(runtime) "swigrun.swg"; /* SWIG API */
%insert(runtime) "swigerrors.swg" /* SWIG errors */
%insert(runtime) "pyhead.swg"
%insert(runtime) "pythreads.swg"; /* Python thread code */
%insert(runtime) "pyapi.swg"; /* Pyton API */
%insert(runtime) "pyrun.swg"; /* Python run-time code */
/* When using -nortti, tell directors to avoid RTTI */
#ifdef SWIG_NORTTI
%insert("runtime") %{
#ifndef SWIG_DIRECTOR_NORTTI
#define SWIG_DIRECTOR_NORTTI
#endif
%}
#endif

82
Lib/ruby/rubyhead.swg Normal file
View file

@ -0,0 +1,82 @@
#include <ruby.h>
/* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
#ifndef NUM2LL
#define NUM2LL(x) NUM2LONG((x))
#endif
#ifndef LL2NUM
#define LL2NUM(x) INT2NUM((long) (x))
#endif
#ifndef ULL2NUM
#define ULL2NUM(x) UINT2NUM((unsigned long) (x))
#endif
/* Ruby 1.7 doesn't (yet) define NUM2ULL() */
#ifndef NUM2ULL
#ifdef HAVE_LONG_LONG
#define NUM2ULL(x) rb_num2ull((x))
#else
#define NUM2ULL(x) NUM2ULONG(x)
#endif
#endif
/*
* Need to be very careful about how these macros are defined, especially
* when compiling C++ code or C code with an ANSI C compiler.
*
* VALUEFUNC(f) is a macro used to typecast a C function that implements
* a Ruby method so that it can be passed as an argument to API functions
* like rb_define_method() and rb_define_singleton_method().
*
* VOIDFUNC(f) is a macro used to typecast a C function that implements
* either the "mark" or "free" stuff for a Ruby Data object, so that it
* can be passed as an argument to API functions like Data_Wrap_Struct()
* and Data_Make_Struct().
*/
#ifdef __cplusplus
# ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
# define PROTECTFUNC(f) ((VALUE (*)()) f)
# define VALUEFUNC(f) ((VALUE (*)()) f)
# define VOIDFUNC(f) ((void (*)()) f)
# else
# ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
# define PROTECTFUNC(f) ((VALUE (*)()) f)
# define VALUEFUNC(f) ((VALUE (*)()) f)
# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
# else /* These definitions should work for Ruby 1.7+ */
# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
# endif
# endif
#else
# define VALUEFUNC(f) (f)
# define VOIDFUNC(f) (f)
#endif
/* Don't use for expressions have side effect */
#ifndef RB_STRING_VALUE
#define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
#endif
#ifndef StringValue
#define StringValue(s) RB_STRING_VALUE(s)
#endif
#ifndef StringValuePtr
#define StringValuePtr(s) RSTRING(RB_STRING_VALUE(s))->ptr
#endif
#ifndef StringValueLen
#define StringValueLen(s) RSTRING(RB_STRING_VALUE(s))->len
#endif
#ifndef SafeStringValue
#define SafeStringValue(v) do {\
StringValue(v);\
rb_check_safe_str(v);\
} while (0)
#endif
#ifndef HAVE_RB_DEFINE_ALLOC_FUNC
#define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1)
#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
#endif

View file

@ -1,89 +1,5 @@
%insert(runtime) %{
#include <ruby.h>
/* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
#ifndef NUM2LL
#define NUM2LL(x) NUM2LONG((x))
#endif
#ifndef LL2NUM
#define LL2NUM(x) INT2NUM((long) (x))
#endif
#ifndef ULL2NUM
#define ULL2NUM(x) UINT2NUM((unsigned long) (x))
#endif
/* Ruby 1.7 doesn't (yet) define NUM2ULL() */
#ifndef NUM2ULL
#ifdef HAVE_LONG_LONG
#define NUM2ULL(x) rb_num2ull((x))
#else
#define NUM2ULL(x) NUM2ULONG(x)
#endif
#endif
/*
* Need to be very careful about how these macros are defined, especially
* when compiling C++ code or C code with an ANSI C compiler.
*
* VALUEFUNC(f) is a macro used to typecast a C function that implements
* a Ruby method so that it can be passed as an argument to API functions
* like rb_define_method() and rb_define_singleton_method().
*
* VOIDFUNC(f) is a macro used to typecast a C function that implements
* either the "mark" or "free" stuff for a Ruby Data object, so that it
* can be passed as an argument to API functions like Data_Wrap_Struct()
* and Data_Make_Struct().
*/
#ifdef __cplusplus
# ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
# define PROTECTFUNC(f) ((VALUE (*)()) f)
# define VALUEFUNC(f) ((VALUE (*)()) f)
# define VOIDFUNC(f) ((void (*)()) f)
# else
# ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
# define PROTECTFUNC(f) ((VALUE (*)()) f)
# define VALUEFUNC(f) ((VALUE (*)()) f)
# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
# else /* These definitions should work for Ruby 1.7+ */
# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
# endif
# endif
#else
# define VALUEFUNC(f) (f)
# define VOIDFUNC(f) (f)
#endif
/* Don't use for expressions have side effect */
#ifndef RB_STRING_VALUE
#define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
#endif
#ifndef StringValue
#define StringValue(s) RB_STRING_VALUE(s)
#endif
#ifndef StringValuePtr
#define StringValuePtr(s) RSTRING(RB_STRING_VALUE(s))->ptr
#endif
#ifndef StringValueLen
#define StringValueLen(s) RSTRING(RB_STRING_VALUE(s))->len
#endif
#ifndef SafeStringValue
#define SafeStringValue(v) do {\
StringValue(v);\
rb_check_safe_str(v);\
} while (0)
#endif
#ifndef HAVE_RB_DEFINE_ALLOC_FUNC
#define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1)
#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
#endif
%}
%runtime "swigrun.swg" /* Common C API type-checking code */
%runtime "rubyhead.swg"
%runtime "rubytracking.swg" /* API for tracking C++ classes to Ruby objects */
%runtime "rubyrun.swg"
%runtime "rubyapi.swg"
%runtime "rubyrun.swg"

View file

@ -73,6 +73,7 @@ static int modernargs = 0;
static int aliasobj0 = 0;
static int castmode = 0;
static int outputtuple = 0;
static int nortti = 0;
/* flags for the make_autodoc function */
enum autodoc_t {
@ -285,8 +286,7 @@ public:
outputtuple = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nortti") == 0) {
/* Turn on no-RTTI mode */
Preprocessor_define((DOH *) "SWIG_NORTTI", 0);
nortti = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-threads") == 0) {
threads = 1;
@ -524,6 +524,13 @@ public:
Printf(f_runtime,"#define SWIG_PYTHON_OUTPUT_TUPLE\n");
}
if (nortti) {
Printf(f_runtime,"#ifndef SWIG_DIRECTOR_NORTTI\n");
Printf(f_runtime,"#define SWIG_DIRECTOR_NORTTI\n");
Printf(f_runtime,"#endif\n");
}
if (castmode) {
Printf(f_runtime,"#define SWIG_CASTRANK_MODE\n");
Printf(f_runtime,"#define SWIG_PYTHON_CAST_MODE\n");
@ -573,7 +580,7 @@ public:
Swig_register_filebyname("shadow",f_shadow);
Swig_register_filebyname("python",f_shadow);
Printv(f_shadow_py,
Printv(f_shadow,
"# This file was created automatically by SWIG ", PACKAGE_VERSION, ".\n",
"# Don't modify this file, modify the SWIG interface instead.\n",
NIL);
@ -589,6 +596,8 @@ public:
Delete(mod_docstring); mod_docstring = NULL;
}
Printf(f_shadow,"\nimport %s\n", module);
Printv(f_shadow,"import new\n",NULL);
Printv(f_shadow,"new_instancemethod = new.instancemethod\n",NULL);
/* if (!modern) */
@ -710,7 +719,6 @@ public:
Printf(f_shadow_imports,"\nimport %s\n", module);
Printv(f_shadow_py, f_shadow_imports, "\n",NIL);
*/
Printf(f_shadow_py,"\nimport %s\n", module);
Printv(f_shadow_py, f_shadow, "\n",NIL);
Printv(f_shadow_py, f_shadow_stubs, "\n",NIL);
@ -3156,10 +3164,34 @@ public:
}
virtual String *runtimeCode() {
String *s = Swig_include_sys("pyrun.swg");
if (!s) {
Append(stderr, "*** Unable to open 'pyrun.swg'\n");
s = NewString("");
String *s = NewString("");
String *shead = Swig_include_sys("pyhead.swg");
if (!shead) {
Printf(stderr, "*** Unable to open 'pyhead.swg'\n");
} else {
Append(s, shead);
Delete(shead);
}
String *sthread = Swig_include_sys("pythreads.swg");
if (!sthread) {
Printf(stderr, "*** Unable to open 'pythreads.swg'\n");
} else {
Append(s, sthread);
Delete(sthread);
}
String *sapi = Swig_include_sys("pyapi.swg");
if (!sapi) {
Printf(stderr, "*** Unable to open 'pyapi.swg'\n");
} else {
Append(s, sapi);
Delete(sapi);
}
String *srun = Swig_include_sys("pyrun.swg");
if (!srun) {
Printf(stderr, "*** Unable to open 'pyrun.swg'\n");
} else {
Append(s, srun);
Delete(srun);
}
return s;
}

View file

@ -2636,10 +2636,34 @@ public:
}
String *runtimeCode() {
String *s = Swig_include_sys("rubyrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'rubyruntime.swg'\n");
s = NewString("");
String *s = NewString("");
String *shead = Swig_include_sys("rubyhead.swg");
if (!shead) {
Printf(stderr, "*** Unable to open 'rubyhead.swg'\n");
} else {
Append(s, shead);
Delete(shead);
}
String *strack = Swig_include_sys("rubytracking.swg");
if (!strack) {
Printf(stderr, "*** Unable to open 'rubytracking.swg'\n");
} else {
Append(s, strack);
Delete(strack);
}
String *sapi = Swig_include_sys("rubyapi.swg");
if (!sapi) {
Printf(stderr, "*** Unable to open 'rubyapi.swg'\n");
} else {
Append(s, sapi);
Delete(sapi);
}
String *srun = Swig_include_sys("rubyrun.swg");
if (!srun) {
Printf(stderr, "*** Unable to open 'rubyrun.swg'\n");
} else {
Append(s, srun);
Delete(srun);
}
return s;
}

View file

@ -1273,11 +1273,22 @@ public:
}
String *runtimeCode() {
String *s = Swig_include_sys("swigtcl8.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swigtcl8.swg'\n");
s = NewString("");
String *s = NewString("");
String *sapi = Swig_include_sys("tclapi.swg");
if (!sapi) {
Printf(stderr, "*** Unable to open 'tclapi.swg'\n");
} else {
Append(s, sapi);
Delete(sapi);
}
String *srun = Swig_include_sys("tclrun.swg");
if (!srun) {
Printf(stderr, "*** Unable to open 'tclrun.swg'\n");
} else {
Append(s, srun);
Delete(srun);
}
return s;
}