Remove nested functions on broken compilers

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10848 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 2001-09-05 21:31:42 +00:00
parent a0d06a453c
commit c3c10cf464
8 changed files with 510 additions and 479 deletions

View file

@ -1,3 +1,17 @@
2001-09-05 Adam Fedor <fedor@gnu.org>
* configure.in: Define BROKEN_NESTED_FUNCTIONS if compiler sucks.
* Source/NSArray.m (-sortedArrayUsingSelector:): Remove nested
function.
([NSMutableArray -sortUsingSelector:]): Likewise.
* Source/NSConnection.m (-forwardForProxy:selector:argFrame:):
Use external encode/decode functions if BROKEN_NESTED_FUNCTIONS.
(-forwardInvocation:forProxy:): Likewise.
(-_service_forwardForProxy:): Likewise.
* Source/mframe.m (mframe_build_return_opts): Remove and
consolidate nested functions.
(mframe_handle_return): Likewise.
2001-08-31 Adam Fedor <fedor@gnu.org>
* Resources/French/Localizable.strings: Update (from

View file

@ -58,6 +58,9 @@
#undef HAVE_UINTMAX_T
#undef HANDLE_LONG_LONG_MAX
/* Define if nested functions are broken on this compiler */
#undef BROKEN_NESTED_FUNCTIONS
/* The number of bytes in a double. */
#undef SIZEOF_DOUBLE
@ -181,9 +184,6 @@
/* Define if you have the <libc.h> header file. */
#undef HAVE_LIBC_H
/* Define if you have the <libguile.h> header file. */
#undef HAVE_LIBGUILE_H
/* Define if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
@ -208,6 +208,9 @@
/* Define if you have the <openssl/ssl.h> header file. */
#undef HAVE_OPENSSL_SSL_H
/* Define if you have the <pthread.h> header file. */
#undef HAVE_PTHREAD_H
/* Define if you have the <pwd.h> header file. */
#undef HAVE_PWD_H
@ -283,6 +286,9 @@
/* Define if you have the <windows.h> header file. */
#undef HAVE_WINDOWS_H
/* Define if you have the giconv library (-lgiconv). */
#undef HAVE_LIBGICONV
/* Define if you have the iconv library (-liconv). */
#undef HAVE_LIBICONV

View file

@ -595,14 +595,14 @@ static SEL rlSel;
[self makeObjectsPerformSelector: aSelector withObject: argument];
}
static int compare(id elem1, id elem2, void* context)
{
return (int)[elem1 performSelector: (SEL)context withObject: elem2];
}
- (NSArray*) sortedArrayUsingSelector: (SEL)comparator
{
int compare(id elem1, id elem2, void* context)
{
return (int)[elem1 performSelector: comparator withObject: elem2];
}
return [self sortedArrayUsingFunction: compare context: NULL];
return [self sortedArrayUsingFunction: compare context: (void *)comparator];
}
- (NSArray*) sortedArrayUsingFunction: (int(*)(id,id,void*))comparator
@ -1293,12 +1293,7 @@ static NSString *indentStrings[] = {
- (void) sortUsingSelector: (SEL)comparator
{
int compare(id elem1, id elem2, void* context)
{
return (int)[elem1 performSelector: comparator withObject: elem2];
}
[self sortUsingFunction: compare context: NULL];
[self sortUsingFunction: compare context: (void *)comparator];
}
- (void) sortUsingFunction: (int(*)(id,id,void*))compare

View file

@ -1411,6 +1411,93 @@ static BOOL multi_threaded = NO;
RELEASE(arp);
}
#ifdef BROKEN_NESTED_FUNCTIONS
typedef struct _NSConnection_t {
@defs(NSConnection)
} NSConnection_t;
static NSConnection_t *c_self_t;
static NSPortCoder *op = nil;
static NSPortCoder *ip = nil;
static NSConnection *c_self;
static BOOL is_exception = NO;
static BOOL second_decode = NO;
static int seq_num;
void encoder (int argnum, void *datum, const char *type, int flags)
{
#define ENCODED_ARGNAME @"argument value"
switch (*type)
{
case _C_ID:
if (flags & _F_BYCOPY)
[op encodeBycopyObject: *(id*)datum];
#ifdef _F_BYREF
else if (flags & _F_BYREF)
[op encodeByrefObject: *(id*)datum];
#endif
else
[op encodeObject: *(id*)datum];
break;
default:
[op encodeValueOfObjCType: type at: datum];
}
}
void decoder(int argnum, void *datum, const char *type, int flags)
{
c_self_t = (NSConnection_t *)c_self;
if (type == 0)
{
if (ip != nil)
{
[c_self _doneInRmc: ip];
/* this must be here to avoid trashing alloca'ed retframe */
ip = (id)-1;
c_self_t->_repInCount++; /* received a reply */
}
return;
}
/* If we didn't get the reply packet yet, get it now. */
if (ip == nil)
{
if (c_self_t->_isValid == NO)
{
[NSException raise: NSGenericException
format: @"connection waiting for request was shut down"];
}
ip = [c_self _getReplyRmc: seq_num];
/*
* Find out if the server is returning an exception instead
* of the return values.
*/
[ip decodeValueOfObjCType: @encode(BOOL) at: &is_exception];
if (is_exception == YES)
{
/* Decode the exception object, and raise it. */
id exc;
[ip decodeValueOfObjCType: @encode(id) at: &exc];
[c_self _doneInRmc: ip];
ip = (id)-1;
/* xxx Is there anything else to clean up in
dissect_method_return()? */
[exc raise];
}
}
[ip decodeValueOfObjCType: type at: datum];
/* -decodeValueOfObjCType:at: malloc's new memory
for pointers. We need to make sure it gets freed eventually
so we don't have a memory leak. Request here that it be
autorelease'ed. Also autorelease created objects. */
if (second_decode == NO)
{
if ((*type == _C_CHARPTR || *type == _C_PTR) && *(void**)datum != 0)
[NSData dataWithBytesNoCopy: *(void**)datum length: 1];
}
else if (*type == _C_ID)
AUTORELEASE(*(id*)datum);
}
#endif
/*
* NSDistantObject's -forward: : method calls this to send the message
* over the wire.
@ -1419,13 +1506,16 @@ static BOOL multi_threaded = NO;
selector: (SEL)sel
argFrame: (arglist_t)argframe
{
#ifndef BROKEN_NESTED_FUNCTIONS
NSPortCoder *op;
int seq_num;
#endif
BOOL outParams;
BOOL needsResponse;
const char *type;
int seq_num;
retval_t retframe;
#ifndef BROKEN_NESTED_FUNCTIONS
/* The callback for encoding the args of the method call. */
void encoder (int argnum, void *datum, const char *type, int flags)
{
@ -1446,6 +1536,7 @@ static BOOL multi_threaded = NO;
[op encodeValueOfObjCType: type at: datum];
}
}
#endif
/* Encode the method on an RMC, and send it. */
@ -1546,6 +1637,7 @@ static BOOL multi_threaded = NO;
}
else
{
#ifndef BROKEN_NESTED_FUNCTIONS
NSPortCoder *ip = nil;
BOOL is_exception = NO;
@ -1598,6 +1690,11 @@ static BOOL multi_threaded = NO;
else if (*type == _C_ID)
AUTORELEASE(*(id*)datum);
}
#else
c_self = self;
second_decode = NO;
#endif /* not BROKEN_NESTED_FUNCTIONS */
retframe = mframe_build_return (argframe, type, outParams, decoder);
/* Make sure we processed all arguments, and dismissed the IP.
@ -1704,6 +1801,7 @@ static BOOL multi_threaded = NO;
}
else
{
#ifndef BROKEN_NESTED_FUNCTIONS
NSPortCoder *ip = nil;
BOOL is_exception = NO;
@ -1750,6 +1848,10 @@ static BOOL multi_threaded = NO;
if (*type == _C_ID)
AUTORELEASE(*(id*)datum);
}
#else
c_self = self;
second_decode = YES;
#endif /* not BROKEN_NESTED_FUNCTIONS */
#ifdef USE_FFCALL
callframe_build_return (inv, type, outParams, decoder);
@ -2002,10 +2104,77 @@ static BOOL multi_threaded = NO;
debug_connection = val;
}
#ifdef BROKEN_NESTED_FUNCTIONS
#define decoder service_decoder
#define encoder service_encoder
static id op;
static int reply_sno;
static NSConnection *c_self;
static NSConnection_t *c_self_t;
static NSPortCoder *c_aRmc;
void service_decoder (int argnum, void *datum, const char *type)
{
/* We need this "dismiss" to happen here and not later so that Coder
"-awake..." methods will get sent before the __builtin_apply! */
if (argnum == -1 && datum == 0 && type == 0)
{
[c_self _doneInRmc: c_aRmc];
return;
}
[c_aRmc decodeValueOfObjCType: type at: datum];
#ifdef USE_FFCALL
if (*type == _C_ID)
#else
/* -decodeValueOfObjCType: at: malloc's new memory
for char*'s. We need to make sure it gets freed eventually
so we don't have a memory leak. Request here that it be
autorelease'ed. Also autorelease created objects. */
if ((*type == _C_CHARPTR || *type == _C_PTR) && *(void**)datum != 0)
[NSData dataWithBytesNoCopy: *(void**)datum length: 1];
else if (*type == _C_ID)
#endif
AUTORELEASE(*(id*)datum);
}
void service_encoder (int argnum, void *datum, const char *type, int flags)
{
c_self_t = (NSConnection_t *)c_self;
if (op == nil)
{
BOOL is_exception = NO;
/* It is possible that our connection died while the method was
being called - in this case we mustn't try to send the result
back to the remote application! */
if (c_self_t->_isValid == NO)
return;
op = [c_self _makeOutRmc: reply_sno generate: 0 reply: NO];
[op encodeValueOfObjCType: @encode(BOOL) at: &is_exception];
}
switch (*type)
{
case _C_ID:
if (flags & _F_BYCOPY)
[op encodeBycopyObject: *(id*)datum];
#ifdef _F_BYREF
else if (flags & _F_BYREF)
[op encodeByrefObject: *(id*)datum];
#endif
else
[op encodeObject: *(id*)datum];
break;
default:
[op encodeValueOfObjCType: type at: datum];
}
}
#endif
/* NSConnection calls this to service the incoming method request. */
- (void) _service_forwardForProxy: (NSPortCoder*)aRmc
{
char *forward_type = 0;
#ifndef BROKEN_NESTED_FUNCTIONS
id op = nil;
int reply_sno;
@ -2063,6 +2232,10 @@ static BOOL multi_threaded = NO;
[op encodeValueOfObjCType: type at: datum];
}
}
#else
c_self = self;
c_aRmc = aRmc;
#endif /* not BROKEN_NESTED_FUNCTIONS */
/* Make sure don't let exceptions caused by servicing the client's
request cause us to crash. */

View file

@ -1249,6 +1249,57 @@ mframe_do_call (const char *encoded_types,
mframe_do_call_opts(encoded_types, decoder, encoder, NO);
}
/* For returning strucutres etc */
typedef struct { id many[8];} __big;
static __big return_block (void* data)
{
return *(__big*)data;
}
/* For returning a char (or unsigned char) */
static char return_char (char data)
{
return data;
}
/* For returning a double */
static double return_double (double data)
{
return data;
}
/* For returning a float */
static float return_float (float data)
{
return data;
}
/* For returning a short (or unsigned short) */
static short return_short (short data)
{
return data;
}
static retval_t apply_block(void* data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_block, args, sizeof(void*));
}
static retval_t apply_char(char data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_char, args, sizeof(void*));
}
static retval_t apply_float(float data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_float, args, sizeof(float));
}
static retval_t apply_double(double data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_double, args, sizeof(double));
}
static retval_t apply_short(short data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_short, args, sizeof(void*));
}
/* mframe_build_return()
@ -1287,57 +1338,6 @@ mframe_build_return_opts (arglist_t argframe,
/* A pointer into the ARGFRAME; points at individual arguments. */
void *datum;
const char *rettype;
/* For returning strucutres etc */
typedef struct { id many[8];} __big;
__big return_block (void* data)
{
return *(__big*)data;
}
/* For returning a char (or unsigned char) */
char return_char (char data)
{
return data;
}
/* For returning a double */
double return_double (double data)
{
return data;
}
/* For returning a float */
float return_float (float data)
{
return data;
}
/* For returning a short (or unsigned short) */
short return_short (short data)
{
return data;
}
retval_t apply_block(void* data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_block, args, sizeof(void*));
}
retval_t apply_char(char data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_char, args, sizeof(void*));
}
retval_t apply_float(float data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_float, args, sizeof(float));
}
retval_t apply_double(double data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_double, args, sizeof(double));
}
retval_t apply_short(short data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_short, args, sizeof(void*));
}
if (*type == _C_STRUCT_B || *type == _C_UNION_B || *type == _C_ARY_B)
{
@ -1763,56 +1763,6 @@ void*
mframe_handle_return(const char* type, void* retval, arglist_t argframe)
{
retval_t retframe;
typedef struct { id many[8];} __big;
__big return_block (void* data)
{
return *(__big*)data;
}
/* For returning a char (or unsigned char) */
char return_char (char data)
{
return data;
}
/* For returning a double */
double return_double (double data)
{
return data;
}
/* For returning a float */
float return_float (float data)
{
return data;
}
/* For returning a short (or unsigned short) */
short return_short (short data)
{
return data;
}
retval_t apply_block(void* data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_block, args, sizeof(void*));
}
retval_t apply_char(char data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_char, args, sizeof(void*));
}
retval_t apply_float(float data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_float, args, sizeof(float));
}
retval_t apply_double(double data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_double, args, sizeof(double));
}
retval_t apply_short(short data)
{
void* args = __builtin_apply_args();
return __builtin_apply((apply_t)return_short, args, sizeof(void*));
}
retframe = alloca(MFRAME_RESULT_SIZE);

View file

@ -15,115 +15,9 @@
/* Define if your system needs to have short/int word aligned */
#undef NEED_WORD_ALIGNMENT
/* The number of bytes in a int. */
#undef SIZEOF_INT
/* Define if you have the getcwd function. */
#undef HAVE_GETCWD
/* Define if you have the inet_aton function. */
#undef HAVE_INET_ATON
/* Define if you have the killpg function. */
#undef HAVE_KILLPG
/* Define if you have the setpgrp function. */
#undef HAVE_SETPGRP
/* Define if you have the setpgid function. */
#undef HAVE_SETPGID
/* Define if you have the mmap function. */
#undef HAVE_MMAP
/* Define if you have the register_printf_function function. */
#undef HAVE_REGISTER_PRINTF_FUNCTION
/* Define if you have the shmctl function. */
#undef HAVE_SHMCTL
/* Define if you have the mkstemp function. */
#undef HAVE_MKSTEMP
/* Define if you have the statvfs function. */
#undef HAVE_STATVFS
/* Define if you have the strerror function. */
#undef HAVE_STRERROR
/* Define if you have the times function. */
#undef HAVE_TIMES
/* Define if you have the usleep function. */
#undef HAVE_USLEEP
/* Define if you have the valloc function. */
#undef HAVE_VALLOC
/* Define if you have the vsprintf function. */
#undef HAVE_VSPRINTF
/* Define if you have the <dirent.h> header file. */
#undef HAVE_DIRENT_H
/* Define if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define if you have the <ndir.h> header file. */
#undef HAVE_NDIR_H
/* Define if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define if you have the <pwd.h> header file. */
#undef HAVE_PWD_H
/* Define if you have the <getgrent.h> header file. */
#undef HAVE_GRP_H
/* Define if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H
#undef HAVE_SYSLOG
/* Define if you have the <sys/dir.h> header file. */
#undef HAVE_SYS_DIR_H
/* Define if you have the <sys/ndir.h> header file. */
#undef HAVE_SYS_NDIR_H
/* Define if you have the <sys/resource.h> header file. */
#undef HAVE_SYS_RESOURCE_H
/* Define if you have the <sys/rusage.h> header file. */
#undef HAVE_SYS_RUSAGE_H
/* Define if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define if you have the <sys/statfs.h> header file. */
#undef HAVE_SYS_STATFS_H
/* Define if you have the <sys/statvfs.h> header file. */
#undef HAVE_SYS_STATVFS_H
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define if you have the <sys/vfs.h> header file. */
#undef HAVE_SYS_VFS_H
/* Define if you have the <ucbinclude/sys/resource.h> header file. */
#undef HAVE_UCBINCLUDE_SYS_RESOURCE_H
/* Define if you have the <values.h> header file. */
#undef HAVE_VALUES_H
/* Define if your Obj-C compiler calls +load methods before main */
#undef HAVE_LOAD_METHOD
@ -149,5 +43,6 @@
#undef HAVE_UINTMAX_T
#undef HANDLE_LONG_LONG_MAX
/* Define if wchar.h header available */
#undef HAVE_WCHAR_H
/* Define if nested functions are broken on this compiler */
#undef BROKEN_NESTED_FUNCTIONS

499
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -57,6 +57,8 @@ AC_EXEEXT
case "$target_os" in
freebsd*) CPPFLAGS="$CPPFLAGS -I/usr/local/include"
LIBS="$LIBS -L/usr/local/lib";;
darwin1.3*) CPPFLAGS="$CPPFLAGS -force_cpusubtype_ALL";;
esac
#----------------------------------------------------------------
@ -67,6 +69,7 @@ AC_TRY_RUN([#include "$srcdir/config/config.nested.c"],
gcc_nested=1, gcc_nested=0, gcc_nested=1)
if test $gcc_nested = 0; then
AC_MSG_RESULT(no)
AC_DEFINE(BROKEN_NESTED_FUNCTIONS)
echo
echo "The GCC 'nested functions' feature does not seem to be working on"
echo "this machine. "
@ -496,10 +499,6 @@ AC_CHECK_FUNCS(syslog)
# Check for pthread.h (only when building on Darwin machines)
#--------------------------------------------------------------------
AC_CHECK_HEADERS(pthread.h)
if test $ac_cv_header_pthread_h = yes ; then
HAVE_PTHREAD_H=yes
AC_DEFINE(HAVE_PTHREAD_H)
fi
#--------------------------------------------------------------------
# This function needed by StdioStream.m