After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 119657 - Bug exporting pointers of librarys
Bug exporting pointers of librarys
Status: RESOLVED DUPLICATE of bug 71615
Product: glib
Classification: Platform
Component: general
2.0.x
Other Linux
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2003-08-11 17:57 UTC by Cesar
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Example Files (2.02 KB, text/plain)
2003-08-11 18:02 UTC, Cesar
Details

Description Cesar 2003-08-11 17:57:07 UTC
This message is for inform of a bug. (En Español mas adelante y mejor 
explicado)
Sorry, my english is very bad.

The problem is with the gmodule (glib)
I have 2 librarys (.so) and the 2 librarys have 2 functions (common_func
()) called with the same name.
If I passed a pointer out the library the common_func() always passed a 
same pointer. The pointer is a pointer to the first common_func() charged 
in memory and forget the others common_func's. 

View the exampled attached, is very easy,
main.c and program without glib => all OK!
main2.c and program2 with glib ==> failed!

NOTE: In Windows all OK, don't exist error!
Caracteristics on end of email

Español:
El error encontrado es en gmodule (perteneciente a la glib)
Si se tienen 2 librerias, y cada una de estas con una funcion que se 
llaman igual (desde ahora common_func())
Si yo paso una referencia (un puntero de la funcion) fuera de la libreria 
siempre pasa el mismo puntero. Este puntero es el de la primera common_func
() que cargo en memoria y se olvida completamente de las otras 
common_func's.

Ver el ejemplo adjunto, es muy facil
main.c y program without glib => todo OK!
main2.c y program2 with glib ==> Error!

NOTA: En Windows todo va bien, no hay error!


--------------------------------------
Caracteristics/Caracteristicas:
Pentium II 266MHz 
RAM 256 Mb
Linux System:
Distribution SuSE 8.1
kernel 2.4.19-4GB (default in SuSE 8.1)
gcc 3.2
glib 2.0.6

--------------------------------------
The exit of my programs:

# ./program

CALLING TO FUNCTION OF libDINAMIC_1 AND SAY: Hello, I'm the file 
dinamic_1.c

CALLING TO FUNCTION OF libDINAMIC_2 AND SAY: Hello, I'm the file 
dinamic_2.c


# ./program2
GLIB version 2.0.6
CALLING TO FUNCTION OF libDINAMIC_1 AND SAY: Hello, I'm the file 
dinamic_1.c

CALLING TO FUNCTION OF libDINAMIC_2 AND SAY: Hello, I'm the file 
dinamic_1.c
Hydra:~/proyecto

---------------------------------------------
For comments my e-mail: iinctg00@ucv.udc.es

Thanks to Glib, GTK, ... team's for you big work, and write me comment 
please (is opcional).



FIles:
-----------------------------------------Begin Makefile

all:main main2

main:dinamic1 dinamic2 main.c
	gcc main.c -o program -ldl

dinamic1:dinamic_1.c
	gcc -shared dinamic_1.c -o libdinamic_1.so

dinamic2:dinamic_2.c
	gcc -shared dinamic_2.c -o libdinamic_2.so

main2:dinamic1 dinamic2 main2.c
	gcc main2.c -o program2 `pkg-config --cflags --libs glib-2.0 
gmodule-2.0`
--------------------------------------------------End Makefile
--------------------------------------------------Begin dinamic_1.c
#include <stdio.h>

void
funcion (void)
{
	printf ("Hello, I'm the file %s\n", __FILE__);
}

void *
return_function (void)
{
	return funcion;
}

-----------------------------------------------End dinamic_1.c
-----------------------------------------------Begin dinamic_2.c
#include <stdio.h>

void
funcion (void)
{
	printf ("Hello, I'm the file %s\n", __FILE__);
}

void *
return_function (void)
{
	return funcion;
}

-----------------------------------------------End dinamic_2.c
-----------------------------------------------Begin main.c
#include <stdio.h>
#include <dlfcn.h>

typedef void *(*FUNC_INI)(void);
typedef void  (*FUNC_END)(void);

FUNC_INI func_ini_1, func_ini_2;
FUNC_END func_end_1, func_end_2;
void *lib1, *lib2;

int
main ()
{
    lib1 = dlopen("./libdinamic_1.so", RTLD_LAZY);
    lib2 = dlopen("./libdinamic_2.so", RTLD_LAZY);

    if (lib1 == NULL) {
		 printf ("No se cargo libdinamic_1\n");
		return -1;
	 }
    if (lib2 == NULL) {
		 printf ("No se cargo libdinamic_2\n");
		return -1;
	 }
    func_ini_1 = dlsym(lib1, "return_function");
    if (func_ini_1 == NULL) {
		puts(dlerror());
		return -1;
    }
    func_ini_2 = dlsym(lib2, "return_function");
    if (func_ini_2 == NULL) {
		puts(dlerror());
		return -1;
    }

	 func_end_1 = (func_ini_1)();
	 func_end_2 = (func_ini_2)();

	 printf ("\nCALLING TO FUNCTION OF libDINAMIC_1 AND SAY: ");
	 (func_end_1) ();
	 
	 printf ("\nCALLING TO FUNCTION OF libDINAMIC_2 AND SAY: ");
	 (func_end_2) ();
	 
    dlclose(lib1);
    dlclose(lib2);

    return 0;
}	
-----------------------------------------------End main.c
-----------------------------------------------Begin main2.c
#include <stdio.h>
#include <glib.h>

#include <gmodule.h>


typedef void *(*FUNC_INI)(void);
typedef void  (*FUNC_END)(void);

FUNC_INI func_ini_1, func_ini_2;
FUNC_END func_end_1, func_end_2;
	
int
main ()
{
	GModule *modulo1, *modulo2;
	
			g_print ("GLIB version %i.%i.%i", 
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
	
	
			modulo1 = g_module_open ("./libdinamic_1", 
G_MODULE_BIND_LAZY );
			if (!modulo1)
			{
            g_print ("NO SE CARGO libdinamic_1: %s", g_module_error ());
				return -1;
			}
			modulo2 = g_module_open ("./libdinamic_2", 
G_MODULE_BIND_LAZY );
			if (!modulo2)
			{
            g_print ("NO SE CARGO libdinamic_2: %s", g_module_error ());
				return -1;
			}
			
			
			if (!g_module_symbol (modulo1, "return_function", 
(gpointer *)&func_ini_1))
			{
				g_print ("error al cargar return_function: 
%s", g_module_error ());
			}
			if (!g_module_symbol (modulo2, "return_function", 
(gpointer *)&func_ini_2))
			{
				g_print ("error al cargar return_function: 
%s", g_module_error ());
			}

			func_end_1 = (*func_ini_1)();	
			func_end_2 = (*func_ini_2)();	
			
			printf ("\nCALLING TO FUNCTION OF libDINAMIC_1 AND 
SAY: ");
			(func_end_1) ();
			
			printf ("\nCALLING TO FUNCTION OF libDINAMIC_2 AND 
SAY: ");
			(func_end_2) ();

			g_module_close (modulo1);
			g_module_close (modulo2);
			
}
-----------------------------------------------End main2.c
EOF
Comment 1 Cesar 2003-08-11 18:02:25 UTC
Created attachment 19119 [details]
Example Files
Comment 2 Owen Taylor 2003-08-11 18:11:21 UTC

*** This bug has been marked as a duplicate of 71615 ***