Hi folks:

The bug described in the attached C++ file (matlabifc_test.cc) makes the
MATLAB 5.x interface unusable if fclose() will be used in the same
program. Actually, nearly every program uses fclose(). Thus, the MATLAB
interface becomes unusable for nearly every program.

Is there any known work around for that problem (I urgently need a
short-term solution)?

Will Mathworks release new MATLAB interface libraries built and linked
against glibc2.1 (which would be a clean long-term solution to the
problem)?

Any hints will be greatly appreciated. Please send replies to my e-mail
address because I did not subscribe to the mailing lists.

Best regards,

Wolfgang.
PS: A binary of matlabifc_test.cc can be easily built using the attached
makefile.
-- 
Wolfgang Reimer (Dr.-Ing.)
 
T U I  --  Technical University of Ilmenau,  GERMANY, Thuringia
Address: TU Ilmenau, FEI/IKM, PF 100565, 98684 Ilmenau, GERMANY
http://ikmcip1.e-technik.tu-ilmenau.de  Phone: +49-3677-69-2619
mailto:[EMAIL PROTECTED]   Fax  : +49-3677-69-1195

V I R T U A L     P H O T O N I C S     I N C O R P O R A T E D
mailto:[EMAIL PROTECTED]                http://www.vp-bned.com
// Program name: matlabifc_test.cc
// Written by  : Olaf Lenzmann (with minor changes by Wolfgang Reimer)
//
// This program demonstrates a bug which shows up under glibc2.1.1 based
// ix86 Linux (e.g. RedHat Linux 6.0) in conjunction with the MATLAB 5.1,
// 5.2 and 5.3 interface libraries which were built and linked against
// obsolete Linux libc5, unfortunately.
//
// If fclose() is used somewhere in the program then inside engClose()
// the function _IO_new_fclose() will be called which will cause a SIGSEGV.
// If fclose() is not used in the program then inside engClose() the function
// _IO_old_fclose() will be called and the program runs fine.
//
// IMHO, this problem is an compatibility problem which could be solved
// cleanly if Mathworks would release also interface libaries built and
// linked against glibc2.1.
// 
// Wolfgang Reimer mailto:[EMAIL PROTECTED]

#include <dlfcn.h>
#include <stdio.h>
#include <iostream.h>

int main (void) {
    char buf[1024];

    fclose(fopen("/etc/passwd", "r")); // fclose() is only used to show the bug

    void * hnd = dlopen( "libeng.so", RTLD_LAZY );

    if( !hnd ) {
        cerr << "Could not load library" << endl;
        exit(-1);
    }

    void *(*engOpen) (const char *) = (typeof(engOpen))dlsym( hnd, "engOpen" );
    int (*engClose) (void *) = (typeof(engClose))dlsym( hnd, "engClose" );
    int (*engEvalString) (void *, const char *) = 
        (typeof(engEvalString))dlsym( hnd, "engEvalString" );
    int (*engOutputBuffer) (void *, char *, int) =
        (typeof(engOutputBuffer))dlsym( hnd, "engOutputBuffer" );

    void * eng = engOpen(NULL);

    if( !eng ) {
        cerr << "Could not open engine" << endl;
        exit(-1);
    }

    engOutputBuffer( eng, buf, 1024 );
    engEvalString( eng, "plot(1:10); pause(3);" );
    engClose(eng);
    cerr << "Done" << endl;
}
# Minimum makefile for matlabifc_test
# written by Wolfgang Reimer mailto:[EMAIL PROTECTED]

TARGET   = matlabifc_test

CXXFLAGS = -ggdb3
ifndef MATLAB
  # adjust MATLAB to point to your Matlab home directory
  MATLAB = /usr/local/matlab
endif
LDFLAGS  = -Wl,-R$(MATLAB)/extern/lib/lnx86:$(MATLAB)/sys/os/lnx86:$(MATLAB)/sys/lnx86 
-ldl

all: $(TARGET)

clean:
        rm -f $(TARGET) core

Reply via email to