~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/wx/c_src/wxe_impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * %CopyrightBegin%
3
 
 * 
4
 
 * Copyright Ericsson AB 2008-2009. All Rights Reserved.
5
 
 * 
 
3
 *
 
4
 * Copyright Ericsson AB 2008-2011. All Rights Reserved.
 
5
 *
6
6
 * The contents of this file are subject to the Erlang Public License,
7
7
 * Version 1.1, (the "License"); you may not use this file except in
8
8
 * compliance with the License. You should have received a copy of the
9
9
 * Erlang Public License along with this software. If not, it can be
10
10
 * retrieved online at http://www.erlang.org/.
11
 
 * 
 
11
 *
12
12
 * Software distributed under the License is distributed on an "AS IS"
13
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
 * the License for the specific language governing rights and limitations
15
15
 * under the License.
16
 
 * 
 
16
 *
17
17
 * %CopyrightEnd% 
18
18
 */
19
19
 
68
68
ErlDrvTermData  init_caller = 0;
69
69
 
70
70
// extern opengl 
71
 
extern int gl_initiated;
72
71
void gl_dispatch(int op, char *bp, ErlDrvTermData caller, WXEBinRef *bins[]);
73
72
 
74
73
 
79
78
}
80
79
#endif
81
80
 
 
81
#if defined(__APPLE__) && defined(__MACH__) && !defined(__DARWIN__)
 
82
#define __DARWIN__ 1
 
83
#endif
 
84
 
 
85
#ifdef __DARWIN__
 
86
extern "C" {
 
87
  int erl_drv_stolen_main_thread_join(ErlDrvTid tid, void **respp);
 
88
  int erl_drv_steal_main_thread(char *name,
 
89
                                ErlDrvTid *dtid,
 
90
                                void* (*func)(void*),
 
91
                                void* arg,
 
92
                                ErlDrvThreadOpts *opts);
 
93
}
 
94
#endif
 
95
 
82
96
void *wxe_main_loop(void * );
83
97
 
84
98
/* ************************************************************
100
114
  wxe_batch_locker_c = erl_drv_cond_create((char *)"wxe_batch_locker_c");
101
115
  init_caller = driver_connected(sd->port); 
102
116
 
103
 
  if((res = erl_drv_thread_create((char *)"wxwidgets",
104
 
                                  &wxe_thread,wxe_main_loop,NULL,NULL)) == 0) {
 
117
#ifdef __DARWIN__
 
118
  res = erl_drv_steal_main_thread((char *)"wxwidgets",
 
119
                                  &wxe_thread,wxe_main_loop,(void *) sd->pdl,NULL);
 
120
#else
 
121
  res = erl_drv_thread_create((char *)"wxwidgets",
 
122
                              &wxe_thread,wxe_main_loop,(void *) sd->pdl,NULL);
 
123
#endif
 
124
  if(res == 0) {
105
125
    erl_drv_mutex_lock(wxe_status_m);
106
126
    for(;wxe_status == WXE_NOT_INITIATED;) {
107
127
      erl_drv_cond_wait(wxe_status_c, wxe_status_m);
118
138
 
119
139
void stop_native_gui(wxe_data *sd)
120
140
{
 
141
  if(wxe_status == WXE_INITIATED) {
 
142
    meta_command(WXE_SHUTDOWN, sd);
 
143
  }
 
144
#ifdef __DARWIN__
 
145
  erl_drv_stolen_main_thread_join(wxe_thread, NULL);
 
146
#else
121
147
  erl_drv_thread_join(wxe_thread, NULL);
 
148
#endif
122
149
  erl_drv_mutex_destroy(wxe_status_m);
123
150
  erl_drv_cond_destroy(wxe_status_c);
124
151
  erl_drv_mutex_destroy(wxe_batch_locker_m);
179
206
 *  wxWidgets Thread 
180
207
 * ************************************************************/
181
208
 
182
 
void *wxe_main_loop(void * not_used)
 
209
void *wxe_main_loop(void *vpdl)
183
210
{
184
211
  int result; 
185
212
  int  argc = 1;
186
 
  char * temp = (char *) "Erlang\0";
187
 
  char ** argv = &temp;
 
213
  char * temp = (char *) "Erlang";
 
214
  char * argv[] = {temp,NULL};
 
215
  ErlDrvPDL pdl = (ErlDrvPDL) vpdl;
 
216
  
 
217
  driver_pdl_inc_refc(pdl);
188
218
 
189
219
  // ErlDrvSysInfo einfo;
190
220
  // driver_system_info(&einfo, sizeof(ErlDrvSysInfo));
199
229
  if(result >= 0 && wxe_status == WXE_INITIATED) {
200
230
    /* We are done try to make a clean exit */
201
231
    wxe_status = WXE_EXITED;
 
232
    driver_pdl_dec_refc(pdl);
 
233
#ifndef __DARWIN__
202
234
    erl_drv_thread_exit(NULL);
 
235
#endif
203
236
    return NULL;
204
237
  } else {
205
238
    erl_drv_mutex_lock(wxe_status_m);
206
239
    wxe_status = WXE_ERROR;
207
240
    erl_drv_cond_signal(wxe_status_c);
208
241
    erl_drv_mutex_unlock(wxe_status_m);
 
242
    driver_pdl_dec_refc(pdl);
209
243
    return NULL;    
210
244
  }
211
245
}
260
294
  init_nonconsts(global_me, init_caller);
261
295
  erl_drv_mutex_lock(wxe_status_m);
262
296
  wxe_status = WXE_INITIATED;
263
 
  gl_initiated = FALSE;   
264
297
  erl_drv_cond_signal(wxe_status_c);
265
298
  erl_drv_mutex_unlock(wxe_status_m);
266
299
  return TRUE;
401
434
           node = batch->GetFirst())
402
435
        {
403
436
          wxeCommand *event = (wxeCommand *)node->GetData();
 
437
          wxeMemEnv *memenv = getMemEnv(event->port);
404
438
          batch->Erase(node);
405
439
          if(event->caller == process ||  // Callbacks from CB process only 
406
440
             event->op == WXE_CB_START || // Recursive event callback allow
407
441
             // Allow connect_cb during CB i.e. msg from wxe_server.
408
 
             event->caller == driver_connected(event->port)) 
 
442
             (memenv && event->caller == memenv->owner)) 
409
443
            {
410
444
              switch(event->op) {
411
445
              case WXE_BATCH_END:
456
490
 
457
491
void WxeApp::newMemEnv(wxeMetaCommand& Ecmd) {
458
492
  wxeMemEnv * memenv = new wxeMemEnv();
 
493
 
 
494
  driver_pdl_inc_refc(Ecmd.pdl);
 
495
 
459
496
  for(int i = 0; i < global_me->next; i++) {
460
497
    memenv->ref2ptr[i] = global_me->ref2ptr[i];    
461
498
  }
576
613
//   }
577
614
//   fflush(stderr);
578
615
  delete memenv;
 
616
  driver_pdl_dec_refc(Ecmd.pdl);
579
617
  refmap.erase((ErlDrvTermData) Ecmd.port);
580
618
}
581
619
 
615
653
  ptrMap::iterator it = ptr2ref.find(ptr);
616
654
  if(it != ptr2ref.end()) {
617
655
    wxeRefData *refd = it->second;
618
 
    return refd->ref;
619
 
  } else { // New Ptr
620
 
    int ref;
621
 
    intList free = memenv->free;
622
 
    
623
 
    if(free.IsEmpty()) {
624
 
      ref = memenv->next++;
625
 
    } else {
626
 
      ref = free.Pop();
627
 
    };
628
 
    if(ref >= memenv->max) {
629
 
      memenv->max *= 2;
630
 
      memenv->ref2ptr = 
631
 
        (void **) driver_realloc(memenv->ref2ptr,memenv->max * sizeof(void*));
632
 
    }
633
 
 
634
 
    memenv->ref2ptr[ref] = ptr;
635
 
    ptr2ref[ptr] = new wxeRefData(ref, 0, false, memenv);
636
 
    return ref;
637
 
  }
 
656
    if(refd->memenv == memenv) {
 
657
      // Found it return
 
658
      return refd->ref;
 
659
    } // else
 
660
    // Old reference to deleted object, release old and recreate in current memenv.
 
661
    clearPtr(ptr);
 
662
  }
 
663
  int ref;
 
664
  intList free = memenv->free;
 
665
 
 
666
  if(free.IsEmpty()) {
 
667
    ref = memenv->next++;
 
668
  } else {
 
669
    ref = free.Pop();
 
670
  };
 
671
  if(ref >= memenv->max) {
 
672
    memenv->max *= 2;
 
673
    memenv->ref2ptr =
 
674
      (void **) driver_realloc(memenv->ref2ptr,memenv->max * sizeof(void*));
 
675
  }
 
676
 
 
677
  memenv->ref2ptr[ref] = ptr;
 
678
  ptr2ref[ptr] = new wxeRefData(ref, 0, false, memenv);
 
679
  return ref;
638
680
}
639
681
 
 
682
 
640
683
void WxeApp::clearPtr(void * ptr) {
641
684
  ptrMap::iterator it;
642
685
  it = ptr2ref.find(ptr);
654
697
      send_msg("debug", &msg);
655
698
    }
656
699
    
657
 
    if(refd->pid != -1) {  
 
700
    if(((int) refd->pid) != -1) {
658
701
      // Send terminate pid to owner
659
702
      wxeReturn rt = wxeReturn(WXE_DRV_PORT,refd->memenv->owner, false);
660
703
      rt.addAtom("_wxe_destroy_");
697
740
 
698
741
void * WxeApp::getPtr(char * bp, wxeMemEnv *memenv) {
699
742
  int index = *(int *) bp;
700
 
  if(!memenv) 
 
743
  if(!memenv) {
701
744
    throw wxe_badarg(index);
 
745
  }
702
746
  void * temp = memenv->ref2ptr[index];
703
747
  if((index < memenv->next) && ((index == 0) || (temp > NULL)))
704
748
    return temp;
705
 
  else 
 
749
  else {
706
750
    throw wxe_badarg(index);
 
751
  }
707
752
}
708
753
 
709
754
void WxeApp::registerPid(char * bp, ErlDrvTermData pid, wxeMemEnv * memenv) {