This file is indexed.

/usr/include/scilab/ScilabAbstractMemoryAllocator.hxx is in scilab-include 5.5.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at
 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 *
 */

#ifndef __SCILABABSTRACTMEMORYALLOCATOR_H__
#define __SCILABABSTRACTMEMORYALLOCATOR_H__

extern "C"
{
#include "api_scilab.h"
}
#include "ScilabAbstractEnvironmentWrapper.hxx"
#include "ScilabAbstractEnvironmentException.hxx"

#include <iostream>

namespace org_modules_external_objects
{

class ComplexDataPointers
{
public:

    ComplexDataPointers(double * _realPtr, double * _imagPtr) : realPtr(_realPtr), imagPtr(_imagPtr) { }
    ComplexDataPointers() : realPtr(0), imagPtr(0) { }
    ~ComplexDataPointers() { }

    double * const realPtr;
    double * const imagPtr;
};

class ScilabStackAllocator
{

public:

    ScilabStackAllocator(void * pvCtx, int _position) : position(_position), pvCtx(pvCtx) { }

    ~ScilabStackAllocator() { }

protected:

    int position;
    void * pvCtx;

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, double * ptr)
    {
        SciErr err = createMatrixOfDouble(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static double * alloc(void * pvCtx, const int position, const int rows, const int cols, double * ptr)
    {
        double * _ptr = 0;
        SciErr err = allocMatrixOfDouble(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, float * ptr)
    {
        double * _ptr = alloc(pvCtx, position, rows, cols, (double *)0);
        for (int i = 0; i < rows * cols; i++)
        {
            _ptr[i] = static_cast<double>(ptr[i]);
        }
    }

    inline static float * alloc(void * pvCtx, const int position, const int rows, const int cols, float * ptr)
    {
        return (float *)alloc(pvCtx, position, rows, cols, (double *)0);
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, double * re, double * im)
    {
        SciErr err = createComplexMatrixOfDouble(pvCtx, position, rows, cols, re, im);
        checkError(err);
    }

    inline static ComplexDataPointers alloc(void * pvCtx, const int position, const int rows, const int cols, double * re, double * im)
    {
        double * _re = 0, * _im = 0;
        SciErr err = allocComplexMatrixOfDouble(pvCtx, position, rows, cols, &_re, &_im);
        checkError(err);

        return ComplexDataPointers(_re, _im);
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, char * ptr)
    {
        SciErr err = createMatrixOfInteger8(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static char * alloc(void * pvCtx, const int position, const int rows, const int cols, char * ptr)
    {
        char * _ptr = 0;
        SciErr err = allocMatrixOfInteger8(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, unsigned char * ptr)
    {
        SciErr err = createMatrixOfUnsignedInteger8(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static unsigned char * alloc(void * pvCtx, const int position, const int rows, const int cols, unsigned char * ptr)
    {
        unsigned char * _ptr = 0;
        SciErr err = allocMatrixOfUnsignedInteger8(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, short * ptr)
    {
        SciErr err = createMatrixOfInteger16(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static short * alloc(void * pvCtx, const int position, const int rows, const int cols, short * ptr)
    {
        short * _ptr = 0;
        SciErr err = allocMatrixOfInteger16(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, unsigned short * ptr)
    {
        SciErr err = createMatrixOfUnsignedInteger16(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static unsigned short * alloc(void * pvCtx, const int position, const int rows, const int cols, unsigned short * ptr)
    {
        unsigned short * _ptr = 0;
        SciErr err = allocMatrixOfUnsignedInteger16(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, int * ptr)
    {
        SciErr err = createMatrixOfInteger32(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static int * alloc(void * pvCtx, const int position, const int rows, const int cols, int * ptr)
    {
        int * _ptr = 0;
        SciErr err = allocMatrixOfInteger32(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, unsigned int * ptr)
    {
        SciErr err = createMatrixOfUnsignedInteger32(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static unsigned int * alloc(void * pvCtx, const int position, const int rows, const int cols, unsigned int * ptr)
    {
        unsigned int * _ptr = 0;
        SciErr err = allocMatrixOfUnsignedInteger32(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

#ifdef __SCILAB_INT64__

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, long long * ptr)
    {
        SciErr err = createMatrixOfInteger64(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static long long * alloc(void * pvCtx, const int position, const int rows, const int cols, long long * ptr)
    {
        long long * _ptr = 0;
        SciErr err = allocMatrixOfInteger64(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, unsigned long long * ptr)
    {
        SciErr err = createMatrixOfUnsignedIntege64(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static unsigned long long * alloc(void * pvCtx, const int position, const int rows, const int cols, unsigned long long * ptr)
    {
        unsigned long long * _ptr = 0;
        SciErr err = allocMatrixOfUnsignedInteger64(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return_ ptr;
    }

#else

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, long long * ptr)
    {
        int * dataPtr = alloc(pvCtx, position, rows, cols, (int *)0);
        for (int i = 0; i < rows * cols; i++)
        {
            dataPtr[i] = static_cast<int>(ptr[i]);
        }
    }

    inline static long long * alloc(void * pvCtx, const int position, const int rows, const int cols, long long * ptr)
    {
        return (long long *)alloc(pvCtx, position, rows, cols, (int *)0);
    }

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, unsigned long long * ptr)
    {
        unsigned int * dataPtr = alloc(pvCtx, position, rows, cols, (unsigned int *)0);
        for (int i = 0; i < rows * cols; i++)
        {
            dataPtr[i] = static_cast<unsigned int>(ptr[i]);
        }
    }

    inline static unsigned long long * alloc(void * pvCtx, const int position, const int rows, const int cols, unsigned long long * ptr)
    {
        return (unsigned long long *)alloc(pvCtx, position, rows, cols, (unsigned int *)0);
    }

#endif

    inline static void create(void * pvCtx, const int position, const int rows, const int cols, char ** ptr)
    {
        SciErr err = createMatrixOfString(pvCtx, position, rows, cols, const_cast<const char * const *>(ptr));
        checkError(err);
    }

    inline static char ** alloc(void * pvCtx, const int position, const int rows, const int cols, char ** ptr)
    {
        throw ScilabAbstractEnvironmentException("Invalid operation: cannot allocate a matrix of String");
    }

    inline static void createBool(void * pvCtx, const int position, const int rows, const int cols, int * ptr)
    {
        SciErr err = createMatrixOfBoolean(pvCtx, position, rows, cols, ptr);
        checkError(err);
    }

    inline static int * allocBool(void * pvCtx, const int position, const int rows, const int cols, int * ptr)
    {
        int * _ptr = 0;
        SciErr err = allocMatrixOfBoolean(pvCtx, position, rows, cols, &_ptr);
        checkError(err);

        return _ptr;
    }


private:

    inline static void checkError(const SciErr & err)
    {
        if (err.iErr)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, "Cannot allocate memory");
        }
    }

};

template <typename T>
class ScilabSingleTypeStackAllocator : public ScilabStackAllocator
{

public:

    ScilabSingleTypeStackAllocator(void * _pvCtx, int _position) : ScilabStackAllocator(_pvCtx, _position) { }

    ~ScilabSingleTypeStackAllocator() { }

    virtual T * allocate(const int rows, const int cols, T * dataPtr) const
    {
        if (!rows || !cols)
        {
            createEmptyMatrix(pvCtx, position);
            return 0;
        }

        if (dataPtr)
        {
            create(pvCtx, position, rows, cols, dataPtr);
            return 0;
        }
        else
        {
            return alloc(pvCtx, position, rows, cols, dataPtr);
        }
    }
};

typedef ScilabSingleTypeStackAllocator<double> ScilabDoubleStackAllocator;
typedef ScilabSingleTypeStackAllocator<char *> ScilabStringStackAllocator;
typedef ScilabSingleTypeStackAllocator<char> ScilabCharStackAllocator;
typedef ScilabSingleTypeStackAllocator<unsigned char> ScilabUCharStackAllocator;
typedef ScilabSingleTypeStackAllocator<short> ScilabShortStackAllocator;
typedef ScilabSingleTypeStackAllocator<unsigned short> ScilabUShortStackAllocator;
typedef ScilabSingleTypeStackAllocator<int> ScilabIntStackAllocator;
typedef ScilabSingleTypeStackAllocator<unsigned int> ScilabUIntStackAllocator;
typedef ScilabSingleTypeStackAllocator<long long> ScilabLongStackAllocator;
typedef ScilabSingleTypeStackAllocator<unsigned long long> ScilabULongStackAllocator;
typedef ScilabSingleTypeStackAllocator<float> ScilabFloatStackAllocator;

class ScilabComplexStackAllocator : public ScilabStackAllocator
{

public:

    ScilabComplexStackAllocator(void * _pvCtx, int _position) : ScilabStackAllocator(_pvCtx, _position) { }

    ~ScilabComplexStackAllocator() { }

    ComplexDataPointers allocate(const int rows, const int cols, double * realPtr, double * imagPtr) const
    {
        if (!rows || !cols)
        {
            createEmptyMatrix(pvCtx, position);
            return ComplexDataPointers();
        }

        if (realPtr && imagPtr)
        {
            create(pvCtx, position, rows, cols, realPtr, imagPtr);
            return ComplexDataPointers();
        }
        else
        {
            return alloc(pvCtx, position, rows, cols, realPtr, imagPtr);
        }
    }
};

class ScilabBooleanStackAllocator : public ScilabSingleTypeStackAllocator<int>
{

public:

    ScilabBooleanStackAllocator(void * _pvCtx, int _position) : ScilabSingleTypeStackAllocator<int>(_pvCtx, _position) { }

    ~ScilabBooleanStackAllocator() { }

    int * allocate(const int rows, const int cols, int * dataPtr) const
    {
        if (!rows || !cols)
        {
            createEmptyMatrix(pvCtx, position);
            return 0;
        }

        if (dataPtr)
        {
            createBool(pvCtx, position, rows, cols, dataPtr);
            return 0;
        }
        else
        {
            return allocBool(pvCtx, position, rows, cols, dataPtr);
        }
    }

    template <typename T>
    int * allocate(const int rows, const int cols, T * dataPtr) const
    {
        if (!rows || !cols)
        {
            createEmptyMatrix(pvCtx, position);
            return 0;
        }

        if (dataPtr)
        {
            int * ptr = 0;
            allocBool(pvCtx, position, rows, cols, ptr);
            for (int i = 0; i < rows * cols; i++)
            {
                ptr[i] = static_cast<int>(dataPtr[i]);
            }

            return 0;
        }
        else
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, "Invalid operation: cannot allocate a matrix of Boolean");
        }
    }
};

}

#endif // __SCILABABSTRACTMEMORYALLOCATOR_H__