Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d53a4f3

Browse files
New built-in module "cl" (Compression Library). Only for Irix 4.0.5
and higher. Made a few improvements to previous version.
1 parent 2b65c03 commit d53a4f3

2 files changed

Lines changed: 129 additions & 42 deletions

File tree

Modules/clmodule.c

Lines changed: 122 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2525

2626
/* Cl objects */
2727

28+
#include <stdarg.h>
2829
#include <cl.h>
2930
#include "allobjects.h"
3031
#include "modsupport.h" /* For getargs() etc. */
@@ -44,13 +45,30 @@ extern typeobject Cltype; /* Really static, forward */
4445

4546
#define is_clobject(v) ((v)->ob_type == &Cltype)
4647

48+
static object *ClError; /* exception cl.error */
49+
50+
static int error_handler_called = 0;
51+
52+
static void
53+
cl_ErrorHandler(long errnum, const char *fmt, ...)
54+
{
55+
va_list ap;
56+
char errbuf[BUFSIZ]; /* hopefully big enough */
57+
58+
error_handler_called = 1;
59+
va_start(ap, fmt);
60+
vsprintf(errbuf, fmt, ap);
61+
va_end(ap);
62+
err_setstr(ClError, errbuf);
63+
}
64+
4765
static object *
4866
cl_Compress(self, args)
4967
clobject *self;
5068
object *args;
5169
{
52-
object *data, *res;
53-
long frameIndex, numberOfFrames, dataSize, result;
70+
object *data;
71+
long frameIndex, numberOfFrames, dataSize;
5472

5573
if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames))
5674
return NULL;
@@ -62,25 +80,29 @@ cl_Compress(self, args)
6280

6381
dataSize = numberOfFrames * self->ob_dataMaxSize;
6482

65-
result = clCompress(self->ob_compressorHdl, frameIndex, numberOfFrames,
66-
&dataSize, (void *) getstringvalue(data));
83+
error_handler_called = 0;
84+
if (clCompress(self->ob_compressorHdl, frameIndex, numberOfFrames,
85+
&dataSize, (void *) getstringvalue(data)) == FAILURE) {
86+
DECREF(data);
87+
if (!error_handler_called)
88+
err_setstr(ClError, "compress failed");
89+
return NULL;
90+
}
6791

6892
if (dataSize < numberOfFrames * self->ob_dataMaxSize)
6993
if (resizestring(&data, dataSize))
7094
return NULL;
7195

72-
res = mkvalue("(iO)", result, data);
73-
DECREF(data);
74-
return res;
96+
return data;
7597
}
7698

7799
static object *
78100
cl_Decompress(self, args)
79101
clobject *self;
80102
object *args;
81103
{
82-
object *data, *res;
83-
long frameIndex, numberOfFrames, result;
104+
object *data;
105+
long frameIndex, numberOfFrames;
84106

85107
if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames))
86108
return NULL;
@@ -90,12 +112,16 @@ cl_Decompress(self, args)
90112
if (data == NULL)
91113
return NULL;
92114

93-
result = clDecompress(self->ob_compressorHdl, frameIndex,
94-
numberOfFrames, (void *) getstringvalue(data));
115+
error_handler_called = 0;
116+
if (clDecompress(self->ob_compressorHdl, frameIndex, numberOfFrames,
117+
(void *) getstringvalue(data)) == FAILURE) {
118+
DECREF(data);
119+
if (!error_handler_called)
120+
err_setstr(ClError, "decompress failed");
121+
return NULL;
122+
}
95123

96-
res = mkvalue("(iO)", result, data);
97-
DECREF(data);
98-
return res;
124+
return data;
99125
}
100126

101127
static object *
@@ -110,13 +136,14 @@ cl_GetCompressorInfo(self, args)
110136
if (!getnoarg(args))
111137
return NULL;
112138

113-
result = clGetCompressorInfo(self->ob_compressorHdl, &infoSize, &info);
114-
115-
infoObject = newsizedstringobject((char *) info, infoSize);
139+
error_handler_called = 0;
140+
if (clGetCompressorInfo(self->ob_compressorHdl, &infoSize, &info) == FAILURE) {
141+
if (!error_handler_called)
142+
err_setstr(ClError, "getcompressorinfo failed");
143+
return NULL;
144+
}
116145

117-
res = mkvalue("(iO)", result, infoObject);
118-
DECREF(infoObject);
119-
return res;
146+
return newsizedstringobject((char *) info, infoSize);
120147
}
121148

122149
static object *
@@ -129,7 +156,10 @@ cl_GetDefault(self, args)
129156
if (!getargs(args, "i", &initial))
130157
return NULL;
131158

159+
error_handler_called = 0;
132160
result = clGetDefault(self->ob_compressorHdl, initial);
161+
if (error_handler_called)
162+
return NULL;
133163

134164
return newintobject(result);
135165
}
@@ -144,7 +174,10 @@ cl_GetMinMax(self, args)
144174
if (!getargs(args, "i", &param))
145175
return NULL;
146176

177+
error_handler_called = 0;
147178
clGetMinMax(self->ob_compressorHdl, param, &min, &max);
179+
if (error_handler_called)
180+
return NULL;
148181

149182
return mkvalue("(ii)", min, max);
150183
}
@@ -160,7 +193,14 @@ cl_GetName(self, args)
160193
if (!getargs(args, "i", &descriptor))
161194
return NULL;
162195

196+
error_handler_called = 0;
163197
name = clGetName(self->ob_compressorHdl, descriptor);
198+
if (error_handler_called)
199+
return NULL;
200+
if (name == NULL) {
201+
err_setstr(ClError, "getname failed");
202+
return NULL;
203+
}
164204

165205
return newstringobject(name);
166206
}
@@ -197,7 +237,10 @@ doParams(self, args, func, modified)
197237
PVbuffer[i] = getintvalue(v);
198238
}
199239

240+
error_handler_called = 0;
200241
(*func)(self->ob_compressorHdl, PVbuffer, length);
242+
if (error_handler_called)
243+
return NULL;
201244

202245
if (modified) {
203246
for (i = 0; i < length; i++)
@@ -237,23 +280,34 @@ cl_QueryParams(self, args)
237280
if (!getnoarg(args))
238281
return NULL;
239282

283+
error_handler_called = 0;
240284
bufferlength = clQueryParams(self->ob_compressorHdl, 0, 0);
285+
if (error_handler_called)
286+
return NULL;
241287

242288
PVbuffer = NEW(long, bufferlength);
243289
if (PVbuffer == NULL)
244290
return err_nomem();
245291

246292
bufferlength = clQueryParams(self->ob_compressorHdl, PVbuffer,
247293
bufferlength);
294+
if (error_handler_called) {
295+
DEL(PVbuffer);
296+
return NULL;
297+
}
248298

249299
list = newlistobject(bufferlength);
250300
if (list == NULL) {
251301
DEL(PVbuffer);
252302
return NULL;
253303
}
254304

255-
for (i = 0; i < bufferlength; i++)
256-
setlistitem(list, i, newintobject(PVbuffer[i]));
305+
for (i = 0; i < bufferlength; i++) {
306+
if (i & 1)
307+
setlistitem(list, i, newintobject(PVbuffer[i]));
308+
else
309+
setlistitem(list, i, newstringobject((char *) PVbuffer[i]));
310+
}
257311

258312
DEL(PVbuffer);
259313

@@ -424,8 +478,6 @@ cl_OpenCompressor(self, args)
424478
object *GetFrameCBPtr;
425479
object *callbackID;
426480
clobject *new;
427-
long result;
428-
object *res;
429481

430482
if (!getargs(args, "((iiiiiiiiii)iOO)",
431483
&compressionFormat.width,
@@ -445,8 +497,19 @@ cl_OpenCompressor(self, args)
445497
if (new == 0)
446498
return NULL;
447499

448-
result = clOpenCompressor(&compressionFormat, qualityFactor, GetFrame,
449-
(void *) new, &new->ob_compressorHdl);
500+
new->ob_compressorHdl = NULL;
501+
new->ob_callbackFunc = NULL;
502+
new->ob_callbackID = NULL;
503+
new->ob_data = NULL;
504+
505+
error_handler_called = 0;
506+
if (clOpenCompressor(&compressionFormat, qualityFactor, GetFrame,
507+
(void *) new, &new->ob_compressorHdl) == FAILURE) {
508+
DECREF(new);
509+
if (!error_handler_called)
510+
err_setstr(ClError, "opencompressor failed");
511+
return NULL;
512+
}
450513

451514
new->ob_isCompressor = 1;
452515
new->ob_callbackFunc = GetFrameCBPtr;
@@ -458,9 +521,7 @@ cl_OpenCompressor(self, args)
458521
new->ob_data = NULL;
459522
new->ob_dataMaxSize = compressionFormat.dataMaxSize;
460523

461-
res = mkvalue("(iO)", result, new);
462-
DECREF(new);
463-
return res;
524+
return new;
464525
}
465526

466527
static object *
@@ -473,7 +534,6 @@ cl_OpenDecompressor(self, args)
473534
object *GetDataCBPtr;
474535
object *callbackID;
475536
clobject *new;
476-
long result;
477537
object *res;
478538

479539
if (!getargs(args, "(s#OO)", &info, &infoSize, &GetDataCBPtr,
@@ -484,9 +544,19 @@ cl_OpenDecompressor(self, args)
484544
if (new == 0)
485545
return NULL;
486546

487-
result = clOpenDecompressor(&compressionFormat, infoSize, info,
488-
GetData, (void *) new,
489-
&new->ob_compressorHdl);
547+
new->ob_compressorHdl = NULL;
548+
new->ob_callbackFunc = NULL;
549+
new->ob_callbackID = NULL;
550+
new->ob_data = NULL;
551+
552+
error_handler_called = 0;
553+
if (clOpenDecompressor(&compressionFormat, infoSize, info, GetData,
554+
(void *) new, &new->ob_compressorHdl) == FAILURE) {
555+
DECREF(new);
556+
if (!error_handler_called)
557+
err_setstr(ClError, "opendecompressor failed");
558+
return NULL;
559+
}
490560

491561
new->ob_isCompressor = 0;
492562
new->ob_callbackFunc = GetDataCBPtr;
@@ -497,7 +567,7 @@ cl_OpenDecompressor(self, args)
497567
XINCREF(new->ob_callbackID);
498568
new->ob_data = NULL;
499569

500-
res = mkvalue("(iO(iiiiiiiiii))", result, new,
570+
res = mkvalue("(O(iiiiiiiiii))", new,
501571
compressionFormat.width,
502572
compressionFormat.height,
503573
compressionFormat.frameSize,
@@ -508,10 +578,6 @@ cl_OpenDecompressor(self, args)
508578
compressionFormat.frameRate,
509579
compressionFormat.numberOfFrames,
510580
compressionFormat.compressionScheme);
511-
if (res == NULL) {
512-
XDECREF(new->ob_callbackFunc);
513-
XDECREF(new->ob_callbackID);
514-
}
515581

516582
DECREF(new);
517583
return res;
@@ -522,14 +588,19 @@ cl_AddParam(self, args)
522588
object *self, *args;
523589
{
524590
char *name;
525-
long type, min, max, initial, paramID, result;
591+
long type, min, max, initial, paramID;
526592

527593
if (!getargs(args, "(siiii)", &name, &type, &min, &max, &initial))
528594
return NULL;
529595

530-
result = clAddParam(name, type, min, max, initial, &paramID);
596+
error_handler_called = 0;
597+
if (clAddParam(name, type, min, max, initial, &paramID) == FAILURE) {
598+
if (!error_handler_called)
599+
err_setstr(ClError, "addparam failed");
600+
return NULL;
601+
}
531602

532-
return mkvalue("(ii)", result, paramID);
603+
return newintobject(paramID);
533604
}
534605

535606
static struct methodlist cl_methods[] = {
@@ -542,5 +613,14 @@ static struct methodlist cl_methods[] = {
542613
void
543614
initcl()
544615
{
545-
(void) initmodule("cl", cl_methods);
616+
object *m, *d;
617+
618+
m = initmodule("cl", cl_methods);
619+
d = getmoduledict(m);
620+
621+
ClError = newstringobject("cl.error");
622+
if (ClError == NULL || dictinsert(d, "error", ClError) != 0)
623+
fatal("can't define cl.error");
624+
625+
(void) clSetErrorHandler(cl_ErrorHandler);
546626
}

Modules/config.c.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ extern void initthread();
214214
#ifdef USE_SV
215215
extern void initsv();
216216
#endif
217+
#ifdef USE_CL
218+
extern void initcl();
219+
#endif
217220
#ifdef USE_TIME
218221
extern void inittime();
219222
#endif
@@ -335,6 +338,10 @@ struct {
335338
{"sv", initsv},
336339
#endif
337340

341+
#ifdef USE_CL
342+
{"cl", initcl},
343+
#endif
344+
338345
#ifdef USE_THREAD
339346
{"thread", initthread},
340347
#endif

0 commit comments

Comments
 (0)