1 /* s_object.cpp -- base of all screen drivers
2 
3    This file is part of the UPX executable compressor.
4 
5    Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer
6    Copyright (C) 1996-2020 Laszlo Molnar
7    All Rights Reserved.
8 
9    UPX and the UCL library are free software; you can redistribute them
10    and/or modify them under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2 of
12    the License, or (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; see the file COPYING.
21    If not, write to the Free Software Foundation, Inc.,
22    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24    Markus F.X.J. Oberhumer              Laszlo Molnar
25    <markus@oberhumer.com>               <ezerotven+github@gmail.com>
26  */
27 
28 #include "conf.h"
29 
30 #if (USE_SCREEN)
31 
32 #define this self
33 
34 #include "screen.h"
35 
36 /*************************************************************************
37 //
38 **************************************************************************/
39 
40 // ugly hacks
41 static screen_t *last_screen = NULL;
42 
sobject_get_screen(void)43 screen_t *sobject_get_screen(void) { return last_screen; }
44 
sobject_destroy(screen_t * this)45 void sobject_destroy(screen_t *this) {
46     last_screen = NULL;
47     if (!this)
48         return;
49     if (this->data) {
50         if (this->finalize)
51             this->finalize(this);
52         free(this->data);
53         this->data = NULL;
54     }
55     free(this);
56 }
57 
sobject_construct(const screen_t * c,size_t data_size)58 screen_t *sobject_construct(const screen_t *c, size_t data_size) {
59     screen_t *this;
60 
61     last_screen = NULL;
62 
63     /* allocate object */
64     this = (screen_t *) malloc(sizeof(*this));
65     if (!this)
66         return NULL;
67 
68     /* copy function table */
69     *this = *c;
70 
71     /* initialize instance variables */
72     this->data = (struct screen_data_t *) malloc(data_size);
73     if (!this->data) {
74         free(this);
75         return NULL;
76     }
77     memset(this->data, 0, data_size);
78 
79     last_screen = this;
80     return this;
81 }
82 
83 #endif /* (USE_SCREEN) */
84 
85 /* vim:set ts=4 sw=4 et: */
86