summaryrefslogtreecommitdiffabout
path: root/microkde/kdecore/klibloader.cpp
Unidiff
Diffstat (limited to 'microkde/kdecore/klibloader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/klibloader.cpp14
1 files changed, 3 insertions, 11 deletions
diff --git a/microkde/kdecore/klibloader.cpp b/microkde/kdecore/klibloader.cpp
index 1394154..6d0475a 100644
--- a/microkde/kdecore/klibloader.cpp
+++ b/microkde/kdecore/klibloader.cpp
@@ -403,203 +403,195 @@ QString KLibLoader::findLibrary( const char * name/*US , const KInstance * insta
403 403
404 404
405//US libfile = instance->dirs()->findResource( "module", libname ); 405//US libfile = instance->dirs()->findResource( "module", libname );
406 //qDebug("libname = %s ",libname.data() ); 406 //qDebug("libname = %s ",libname.data() );
407 libfile = KGlobal::dirs()->findResource( "module", libname ); 407 libfile = KGlobal::dirs()->findResource( "module", libname );
408 //qDebug("libfile = %s ",libfile.latin1() ); 408 //qDebug("libfile = %s ",libfile.latin1() );
409 409
410 if ( libfile.isEmpty() ) 410 if ( libfile.isEmpty() )
411 { 411 {
412//US libfile = instance->dirs()->findResource( "lib", libname ); 412//US libfile = instance->dirs()->findResource( "lib", libname );
413 libfile = KGlobal::dirs()->findResource( "lib", libname ); 413 libfile = KGlobal::dirs()->findResource( "lib", libname );
414 //qDebug("libfile2 = %s ",libfile.latin1() ); 414 //qDebug("libfile2 = %s ",libfile.latin1() );
415#ifndef NDEBUG 415#ifndef NDEBUG
416 if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules 416 if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules
417 kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; 417 kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl;
418#endif 418#endif
419 } 419 }
420 if ( libfile.isEmpty() ) 420 if ( libfile.isEmpty() )
421 { 421 {
422#ifndef NDEBUG 422#ifndef NDEBUG
423 kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; 423 kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl;
424 self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname); 424 self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname);
425 425
426 qDebug("KLibLoader::library could not find library: %s", libname.data()); 426 qDebug("KLibLoader::library could not find library: %s", libname.data());
427#endif 427#endif
428 428
429 } 429 }
430 else 430 else
431 self()->d->errorMessage = QString::null; 431 self()->d->errorMessage = QString::null;
432 } 432 }
433 433
434 //qDebug("return libfile = %s ",libfile.latin1() ); 434 //qDebug("return libfile = %s ",libfile.latin1() );
435 return libfile; 435 return libfile;
436} 436}
437 437
438 438
439KLibrary* KLibLoader::globalLibrary( const char *name ) 439KLibrary* KLibLoader::globalLibrary( const char *name )
440{ 440{
441KLibrary *tmp; 441KLibrary *tmp;
442/*US 442/*US
443int olt_dlopen_flag = lt_dlopen_flag; 443int olt_dlopen_flag = lt_dlopen_flag;
444 444
445 lt_dlopen_flag |= LT_GLOBAL; 445 lt_dlopen_flag |= LT_GLOBAL;
446 kdDebug(150) << "Loading the next library global with flag " 446 kdDebug(150) << "Loading the next library global with flag "
447 << lt_dlopen_flag 447 << lt_dlopen_flag
448 << "." << endl; 448 << "." << endl;
449*/ 449*/
450 tmp = library(name); 450 tmp = library(name);
451/*US 451/*US
452 lt_dlopen_flag = olt_dlopen_flag; 452 lt_dlopen_flag = olt_dlopen_flag;
453*/ 453*/
454return tmp; 454return tmp;
455} 455}
456 456
457 457
458KLibrary* KLibLoader::library( const char *name ) 458KLibrary* KLibLoader::library( const char *name )
459{ 459{
460 if (!name) 460 if (!name)
461 return 0; 461 return 0;
462 462
463 KLibWrapPrivate* wrap = m_libs[name]; 463 KLibWrapPrivate* wrap = m_libs[name];
464 if (wrap) { 464 if (wrap) {
465 /* Nothing to do to load the library. */ 465 /* Nothing to do to load the library. */
466 wrap->ref_count++; 466 wrap->ref_count++;
467 return wrap->lib; 467 return wrap->lib;
468 } 468 }
469 469
470 /* Test if this library was loaded at some time, but got 470 /* Test if this library was loaded at some time, but got
471 unloaded meanwhile, whithout being dlclose()'ed. */ 471 unloaded meanwhile, whithout being dlclose()'ed. */
472 QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); 472 QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack);
473 for (; it.current(); ++it) { 473 for (; it.current(); ++it) {
474 if (it.current()->name == name) 474 if (it.current()->name == name)
475 wrap = it.current(); 475 wrap = it.current();
476 } 476 }
477 477
478 if (wrap) { 478 if (wrap) {
479 d->pending_close.removeRef(wrap); 479 d->pending_close.removeRef(wrap);
480 if (!wrap->lib) { 480 if (!wrap->lib) {
481 /* This lib only was in loaded_stack, but not in m_libs. */ 481 /* This lib only was in loaded_stack, but not in m_libs. */
482 wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); 482 wrap->lib = new KLibrary( name, wrap->filename, wrap->handle );
483 } 483 }
484 wrap->ref_count++; 484 wrap->ref_count++;
485 } else { 485 } else {
486 QString libfile = findLibrary( name ); 486 QString libfile = findLibrary( name );
487 if ( libfile.isEmpty() ) 487 if ( libfile.isEmpty() )
488 return 0; 488 return 0;
489#ifdef DESKTOP_VERSION 489#ifdef DESKTOP_VERSION
490 QLibrary *qlib = new QLibrary( libfile.latin1() ); 490 QLibrary *qlib = new QLibrary( libfile.latin1() );
491#else 491#else
492 QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately ); 492 QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately );
493#endif 493#endif
494 494
495//US lt_dlhandle handle = lt_dlopen( libfile.latin1() ); 495//US lt_dlhandle handle = lt_dlopen( libfile.latin1() );
496//US if ( !handle ) 496//US if ( !handle )
497 if ( !qlib ) 497 if ( !qlib )
498 { 498 {
499//US const char* errmsg = lt_dlerror(); 499 qDebug( "KLibLoader::library could not load library: %s", libfile.latin1());
500 char* errmsg; 500 d->errorMessage = QString::null;
501 sprintf(errmsg, "KLibLoader::library could not load library: %s", libfile.latin1()); 501 return 0;
502 qDebug(errmsg);
503
504 if(errmsg)
505 d->errorMessage = QString::fromLatin1(errmsg);
506 else
507 d->errorMessage = QString::null;
508 kdWarning(150) << "library=" << name << ": file=" << libfile << ": " << d->errorMessage << endl;
509 return 0;
510 } 502 }
511 else 503 else
512 d->errorMessage = QString::null; 504 d->errorMessage = QString::null;
513 505
514 KLibrary *lib = new KLibrary( name, libfile, qlib ); 506 KLibrary *lib = new KLibrary( name, libfile, qlib );
515 wrap = new KLibWrapPrivate(lib, qlib); 507 wrap = new KLibWrapPrivate(lib, qlib);
516 d->loaded_stack.prepend(wrap); 508 d->loaded_stack.prepend(wrap);
517 } 509 }
518 m_libs.insert( name, wrap ); 510 m_libs.insert( name, wrap );
519 511
520 connect( wrap->lib, SIGNAL( destroyed() ), 512 connect( wrap->lib, SIGNAL( destroyed() ),
521 this, SLOT( slotLibraryDestroyed() ) ); 513 this, SLOT( slotLibraryDestroyed() ) );
522 514
523 return wrap->lib; 515 return wrap->lib;
524} 516}
525 517
526QString KLibLoader::lastErrorMessage() const 518QString KLibLoader::lastErrorMessage() const
527{ 519{
528 return d->errorMessage; 520 return d->errorMessage;
529} 521}
530 522
531void KLibLoader::unloadLibrary( const char *libname ) 523void KLibLoader::unloadLibrary( const char *libname )
532{ 524{
533 KLibWrapPrivate *wrap = m_libs[ libname ]; 525 KLibWrapPrivate *wrap = m_libs[ libname ];
534 if (!wrap) 526 if (!wrap)
535 return; 527 return;
536 if (--wrap->ref_count) 528 if (--wrap->ref_count)
537 return; 529 return;
538 530
539// kdDebug(150) << "closing library " << libname << endl; 531// kdDebug(150) << "closing library " << libname << endl;
540 532
541 m_libs.remove( libname ); 533 m_libs.remove( libname );
542 534
543 disconnect( wrap->lib, SIGNAL( destroyed() ), 535 disconnect( wrap->lib, SIGNAL( destroyed() ),
544 this, SLOT( slotLibraryDestroyed() ) ); 536 this, SLOT( slotLibraryDestroyed() ) );
545 close_pending( wrap ); 537 close_pending( wrap );
546} 538}
547 539
548KLibFactory* KLibLoader::factory( const char* name ) 540KLibFactory* KLibLoader::factory( const char* name )
549{ 541{
550 KLibrary* lib = library( name ); 542 KLibrary* lib = library( name );
551 if ( !lib ) 543 if ( !lib )
552 return 0; 544 return 0;
553 545
554 return lib->factory(); 546 return lib->factory();
555} 547}
556 548
557void KLibLoader::slotLibraryDestroyed() 549void KLibLoader::slotLibraryDestroyed()
558{ 550{
559 const KLibrary *lib = static_cast<const KLibrary *>( sender() ); 551 const KLibrary *lib = static_cast<const KLibrary *>( sender() );
560 552
561 QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); 553 QAsciiDictIterator<KLibWrapPrivate> it( m_libs );
562 for (; it.current(); ++it ) 554 for (; it.current(); ++it )
563 if ( it.current()->lib == lib ) 555 if ( it.current()->lib == lib )
564 { 556 {
565 KLibWrapPrivate *wrap = it.current(); 557 KLibWrapPrivate *wrap = it.current();
566 wrap->lib = 0; /* the KLibrary object is already away */ 558 wrap->lib = 0; /* the KLibrary object is already away */
567 m_libs.remove( it.currentKey() ); 559 m_libs.remove( it.currentKey() );
568 close_pending( wrap ); 560 close_pending( wrap );
569 return; 561 return;
570 } 562 }
571} 563}
572 564
573void KLibLoader::close_pending(KLibWrapPrivate *wrap) 565void KLibLoader::close_pending(KLibWrapPrivate *wrap)
574{ 566{
575 if (wrap && !d->pending_close.containsRef( wrap )) 567 if (wrap && !d->pending_close.containsRef( wrap ))
576 d->pending_close.append( wrap ); 568 d->pending_close.append( wrap );
577 569
578 /* First delete all KLibrary objects in pending_close, but _don't_ unload 570 /* First delete all KLibrary objects in pending_close, but _don't_ unload
579 the DSO behind it. */ 571 the DSO behind it. */
580 QPtrListIterator<KLibWrapPrivate> it(d->pending_close); 572 QPtrListIterator<KLibWrapPrivate> it(d->pending_close);
581 for (; it.current(); ++it) { 573 for (; it.current(); ++it) {
582 wrap = it.current(); 574 wrap = it.current();
583 if (wrap->lib) { 575 if (wrap->lib) {
584 disconnect( wrap->lib, SIGNAL( destroyed() ), 576 disconnect( wrap->lib, SIGNAL( destroyed() ),
585 this, SLOT( slotLibraryDestroyed() ) ); 577 this, SLOT( slotLibraryDestroyed() ) );
586 delete wrap->lib; 578 delete wrap->lib;
587 wrap->lib = 0; 579 wrap->lib = 0;
588 } 580 }
589 } 581 }
590 582
591 if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return; 583 if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return;
592 584
593 bool deleted_one = false; 585 bool deleted_one = false;
594 while ((wrap = d->loaded_stack.first())) { 586 while ((wrap = d->loaded_stack.first())) {
595 /* Let's first see, if we want to try to unload this lib. 587 /* Let's first see, if we want to try to unload this lib.
596 If the env. var KDE_DOUNLOAD is set, we try to unload every lib. 588 If the env. var KDE_DOUNLOAD is set, we try to unload every lib.
597 If not, we look at the lib itself, and unload it only, if it exports 589 If not, we look at the lib itself, and unload it only, if it exports
598 the symbol __kde_do_unload. */ 590 the symbol __kde_do_unload. */
599 if (d->unload_mode != KLibLoaderPrivate::UNLOAD 591 if (d->unload_mode != KLibLoaderPrivate::UNLOAD
600 && wrap->unload_mode != KLibWrapPrivate::UNLOAD) 592 && wrap->unload_mode != KLibWrapPrivate::UNLOAD)
601 break; 593 break;
602 594
603 /* Now ensure, that the libs are only unloaded in the reverse direction 595 /* Now ensure, that the libs are only unloaded in the reverse direction
604 they were loaded. */ 596 they were loaded. */
605 if (!d->pending_close.containsRef( wrap )) { 597 if (!d->pending_close.containsRef( wrap )) {