|
@@ -270,10 +270,11 @@ with given arguments");
|
270
|
270
|
/**@brief Returns the parameters in a named tuple */
|
271
|
271
|
PyObject *rpnif_get_params(PyObject *self)
|
272
|
272
|
{
|
|
273
|
+ PyRPNIterExpr_t *expr_self = (PyRPNIterExpr_t*)self;
|
273
|
274
|
PyObject *res, *val;
|
274
|
275
|
rpn_if_default_data_t *params;
|
275
|
276
|
|
276
|
|
- params = (rpn_if_default_data_t*)(((PyRPNIterExpr_t*)self)->rif->params->data);
|
|
277
|
+ params = (rpn_if_default_data_t*)(expr_self->rif->params->data);
|
277
|
278
|
|
278
|
279
|
short expt_sizes[2];
|
279
|
280
|
if(rpn_if_sizes_from_flag(params->pos_flag, params->res_flag, expt_sizes) < 0)
|
|
@@ -287,12 +288,15 @@ PyObject *rpnif_get_params(PyObject *self)
|
287
|
288
|
{
|
288
|
289
|
return NULL;
|
289
|
290
|
}
|
290
|
|
- val = PyLong_FromLong(params->pos_flag);
|
|
291
|
+ val = PyLong_FromLong(expr_self->rif->params->rpn_argc);
|
291
|
292
|
PyStructSequence_SET_ITEM(res, 0, val);
|
292
|
293
|
|
293
|
|
- val = PyLong_FromLong(params->res_flag);
|
|
294
|
+ val = PyLong_FromLong(params->pos_flag);
|
294
|
295
|
PyStructSequence_SET_ITEM(res, 1, val);
|
295
|
296
|
|
|
297
|
+ val = PyLong_FromLong(params->res_flag);
|
|
298
|
+ PyStructSequence_SET_ITEM(res, 2, val);
|
|
299
|
+
|
296
|
300
|
if(params->pos_flag == RPN_IF_POSITION_XDIM)
|
297
|
301
|
{
|
298
|
302
|
expt_sizes[0] = params->size_lim[0] + 1;
|
|
@@ -304,7 +308,7 @@ PyObject *rpnif_get_params(PyObject *self)
|
304
|
308
|
Py_DECREF(res);
|
305
|
309
|
return NULL;
|
306
|
310
|
}
|
307
|
|
- PyStructSequence_SET_ITEM(res, 2, lim);
|
|
311
|
+ PyStructSequence_SET_ITEM(res, 3, lim);
|
308
|
312
|
|
309
|
313
|
for(Py_ssize_t i=0; i<expt_sizes[0]; i++)
|
310
|
314
|
{
|
|
@@ -315,7 +319,7 @@ PyObject *rpnif_get_params(PyObject *self)
|
315
|
319
|
if(!params->const_val)
|
316
|
320
|
{
|
317
|
321
|
Py_INCREF(Py_None);
|
318
|
|
- PyTuple_SET_ITEM(res, 3, Py_None);
|
|
322
|
+ PyTuple_SET_ITEM(res, 4, Py_None);
|
319
|
323
|
}
|
320
|
324
|
else
|
321
|
325
|
{
|
|
@@ -325,7 +329,7 @@ PyObject *rpnif_get_params(PyObject *self)
|
325
|
329
|
Py_DECREF(res);
|
326
|
330
|
return NULL;
|
327
|
331
|
}
|
328
|
|
- PyStructSequence_SET_ITEM(res, 3, values);
|
|
332
|
+ PyStructSequence_SET_ITEM(res, 4, values);
|
329
|
333
|
for(Py_ssize_t i=0; i<expt_sizes[1]; i++)
|
330
|
334
|
{
|
331
|
335
|
val = PyLong_FromRpnValue_t(params->const_val[i]);
|
|
@@ -385,7 +389,7 @@ PyObject *rpnif_keys(PyObject *self)
|
385
|
389
|
case RPN_IF_POSITION_XDIM:
|
386
|
390
|
for(size_t i=0; i<rif_data->size_lim[0];i++)
|
387
|
391
|
{
|
388
|
|
- snprintf(xdim_key, 64, "P%ld", i);
|
|
392
|
+ snprintf(xdim_key, 64, "D%ld", i);
|
389
|
393
|
_ret_append(xdim_key);
|
390
|
394
|
}
|
391
|
395
|
break;
|
|
@@ -509,7 +513,7 @@ PyObject* rpnif_expr_item(PyObject *self, Py_ssize_t idx)
|
509
|
513
|
{
|
510
|
514
|
idx = expr_self->rif->params->rpn_sz - 1 + idx;
|
511
|
515
|
}
|
512
|
|
- if(idx < 0 || idx >= expr_self->rif->params->rpn_sz)
|
|
516
|
+ if(idx < 0 || (size_t) idx >= expr_self->rif->params->rpn_sz)
|
513
|
517
|
{
|
514
|
518
|
PyErr_Format(PyExc_IndexError,
|
515
|
519
|
"No expression %ld with given options",
|
|
@@ -599,7 +603,7 @@ static Py_ssize_t _rpnif_subscript_idx(PyObject *self, PyObject *_key)
|
599
|
603
|
char possible_key[64];
|
600
|
604
|
for(size_t i=0; i<ndim; i++)
|
601
|
605
|
{
|
602
|
|
- snprintf(possible_key, 64, "P%ld", i);
|
|
606
|
+ snprintf(possible_key, 64, "D%ld", i);
|
603
|
607
|
if(!strcmp(possible_key, key))
|
604
|
608
|
{
|
605
|
609
|
idx = i;
|
|
@@ -750,23 +754,145 @@ void rpnif_releasebuffer(PyObject *self, Py_buffer *view)
|
750
|
754
|
|
751
|
755
|
PyObject* rpnif_str(PyObject *self)
|
752
|
756
|
{
|
753
|
|
- PyErr_SetString(PyExc_NotImplementedError,
|
754
|
|
- "str Not implemented");
|
755
|
|
- return NULL;
|
756
|
|
- /**@todo TODO write the function */
|
757
|
|
- Py_RETURN_NONE;
|
|
757
|
+ PyRPNIterExpr_t *expr_self = (PyRPNIterExpr_t*)self;
|
|
758
|
+ rpn_if_default_data_t *rif_data = \
|
|
759
|
+ (rpn_if_default_data_t*)expr_self->rif->params->data;
|
|
760
|
+ const size_t rpn_sz = expr_self->rif->params->rpn_sz;
|
|
761
|
+ const char pyfmt[] = "%VA%ld=%U=\"%S\";";
|
|
762
|
+
|
|
763
|
+ size_t i;
|
|
764
|
+ PyObject *buf, *tmp, *items;
|
|
765
|
+
|
|
766
|
+ buf = NULL;
|
|
767
|
+ items = rpnif_items(self);
|
|
768
|
+ if(PyErr_Occurred()) { return NULL; }
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+ for(i=0; i<rpn_sz; i++)
|
|
772
|
+ {
|
|
773
|
+ PyObject *key, *value, *elt;
|
|
774
|
+ elt = PyTuple_GET_ITEM(items, i);
|
|
775
|
+ key = PyTuple_GET_ITEM(elt, 0);
|
|
776
|
+ value = PyTuple_GET_ITEM(elt, 1);
|
|
777
|
+
|
|
778
|
+ tmp = PyUnicode_FromFormat(pyfmt,
|
|
779
|
+ buf, "",
|
|
780
|
+ i, key, value);
|
|
781
|
+ if(buf) { Py_DECREF(buf); }
|
|
782
|
+ if(PyErr_Occurred()) { return NULL; }
|
|
783
|
+ buf = tmp;
|
|
784
|
+ }
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+ switch(rif_data->res_flag)
|
|
788
|
+ {
|
|
789
|
+ case RPN_IF_RES_CONST:
|
|
790
|
+ tmp = PyUnicode_FromFormat("%U A%ld=C(*)=%lld",
|
|
791
|
+ buf, i+1, rif_data->const_val[0]);
|
|
792
|
+ Py_DECREF(buf);
|
|
793
|
+ buf=tmp;
|
|
794
|
+ break;
|
|
795
|
+ case RPN_IF_RES_CONST_RGBA:
|
|
796
|
+ tmp = PyUnicode_FromFormat("%U A%ld=R(*)=%lld A%ld=G(*)=%lld A%ld=B(*)=%lld A%ld=A(*)=%lld",
|
|
797
|
+ buf,
|
|
798
|
+ i+1, rif_data->const_val[0],
|
|
799
|
+ i+2, rif_data->const_val[1],
|
|
800
|
+ i+3, rif_data->const_val[2],
|
|
801
|
+ i+4, rif_data->const_val[3]);
|
|
802
|
+ Py_DECREF(buf);
|
|
803
|
+ buf=tmp;
|
|
804
|
+ break;
|
|
805
|
+ }
|
|
806
|
+
|
|
807
|
+ Py_INCREF(buf);
|
|
808
|
+ return buf;
|
|
809
|
+}
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+static PyObject* _rpnif_expr_repr(PyObject *self)
|
|
813
|
+{
|
|
814
|
+ PyRPNIterExpr_t *expr_self = (PyRPNIterExpr_t*)self;
|
|
815
|
+ rpn_if_default_data_t *rif_data = \
|
|
816
|
+ (rpn_if_default_data_t*)expr_self->rif->params->data;
|
|
817
|
+
|
|
818
|
+ PyObject *buf, *tmp, *items, *const_res;
|
|
819
|
+ const char pyfmt[] = "%V\"%U\":\"%S\"%V";
|
|
820
|
+
|
|
821
|
+ buf = const_res = NULL;
|
|
822
|
+
|
|
823
|
+ items = rpnif_items(self);
|
|
824
|
+ if(PyErr_Occurred()) { return NULL; }
|
|
825
|
+
|
|
826
|
+#define _const_res_key ",\"const_res\":"
|
|
827
|
+ switch(rif_data->res_flag)
|
|
828
|
+ {
|
|
829
|
+ case RPN_IF_RES_CONST:
|
|
830
|
+ const_res = PyUnicode_FromFormat(
|
|
831
|
+ _const_res_key "{\"r\":%llu}}",
|
|
832
|
+ rif_data->const_val[0]);
|
|
833
|
+ break;
|
|
834
|
+ /*
|
|
835
|
+ case RPN_IF_RES_CONST_RGB:
|
|
836
|
+ const_res = PyUnicode_FromFormat(
|
|
837
|
+ "\"const_res\": {\"r\":%llu, \"g\":%llu, \"b\":%llu}}",
|
|
838
|
+ rif_data->const_val[0],
|
|
839
|
+ rif_data->const_val[1],
|
|
840
|
+ rif_data->const_val[2])
|
|
841
|
+ break;
|
|
842
|
+ */
|
|
843
|
+ case RPN_IF_RES_CONST_RGBA:
|
|
844
|
+ const_res = PyUnicode_FromFormat(
|
|
845
|
+ _const_res_key \
|
|
846
|
+ "{\"r\":%llu,\"g\":%llu,\"b\":%llu,\"a\":%llu}}",
|
|
847
|
+ rif_data->const_val[0],
|
|
848
|
+ rif_data->const_val[1],
|
|
849
|
+ rif_data->const_val[2],
|
|
850
|
+ rif_data->const_val[3]);
|
|
851
|
+ break;
|
|
852
|
+ default:
|
|
853
|
+ const_res = PyUnicode_FromFormat("}");
|
|
854
|
+ break;
|
|
855
|
+ }
|
|
856
|
+#undef _const_res_key
|
|
857
|
+
|
|
858
|
+ const size_t rpn_sz = expr_self->rif->params->rpn_sz;
|
|
859
|
+
|
|
860
|
+ for(size_t i=0; i<rpn_sz; i++)
|
|
861
|
+ {
|
|
862
|
+ PyObject *key, *value, *elt;
|
|
863
|
+ elt = PyTuple_GET_ITEM(items, i);
|
|
864
|
+ key = PyTuple_GET_ITEM(elt, 0);
|
|
865
|
+ value = PyTuple_GET_ITEM(elt, 1);
|
|
866
|
+
|
|
867
|
+ tmp = PyUnicode_FromFormat(pyfmt,
|
|
868
|
+ buf, "{", key, value,
|
|
869
|
+ i==rpn_sz-1?const_res:NULL, ",");
|
|
870
|
+ if(buf)
|
|
871
|
+ {
|
|
872
|
+ Py_DECREF(buf);
|
|
873
|
+ }
|
|
874
|
+ if(PyErr_Occurred())
|
|
875
|
+ {
|
|
876
|
+ return NULL;
|
|
877
|
+ }
|
|
878
|
+ buf = tmp;
|
|
879
|
+ }
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+ return buf;
|
758
|
883
|
}
|
759
|
884
|
|
760
|
885
|
PyObject* rpnif_repr(PyObject *self)
|
761
|
886
|
{
|
762
|
887
|
PyRPNIterExpr_t *expr_self = (PyRPNIterExpr_t*)self;
|
763
|
|
- char *buff;
|
764
|
|
- size_t sz;
|
765
|
888
|
rpn_if_default_data_t *rif_data = (rpn_if_default_data_t*)expr_self->rif->params->data;
|
766
|
889
|
|
767
|
890
|
char *str_pos, *str_res;
|
768
|
891
|
char tmp[64];
|
769
|
892
|
|
|
893
|
+ PyObject *expr_repr = _rpnif_expr_repr(self);
|
|
894
|
+ if(PyErr_Occurred()) { return NULL; }
|
|
895
|
+
|
770
|
896
|
switch(rif_data->pos_flag)
|
771
|
897
|
{
|
772
|
898
|
case RPN_IF_POSITION_XY:
|
|
@@ -776,7 +902,7 @@ PyObject* rpnif_repr(PyObject *self)
|
776
|
902
|
str_pos = "LINEAR";
|
777
|
903
|
break;
|
778
|
904
|
case RPN_IF_POSITION_XDIM:
|
779
|
|
- snprintf(tmp, 64, "XDIM[%ld]", rif_data->size_lim[0]);
|
|
905
|
+ snprintf(tmp, 64, "XDIM%ld", rif_data->size_lim[0]);
|
780
|
906
|
str_pos = tmp;
|
781
|
907
|
break;
|
782
|
908
|
default:
|
|
@@ -785,6 +911,8 @@ PyObject* rpnif_repr(PyObject *self)
|
785
|
911
|
return NULL;
|
786
|
912
|
}
|
787
|
913
|
|
|
914
|
+ PyObject *const_res = NULL;
|
|
915
|
+
|
788
|
916
|
switch(rif_data->res_flag)
|
789
|
917
|
{
|
790
|
918
|
case RPN_IF_RES_BOOL:
|
|
@@ -792,6 +920,7 @@ PyObject* rpnif_repr(PyObject *self)
|
792
|
920
|
break;
|
793
|
921
|
case RPN_IF_RES_CONST:
|
794
|
922
|
str_res = "CONST";
|
|
923
|
+ const_res = PyTuple_New(1);
|
795
|
924
|
break;
|
796
|
925
|
case RPN_IF_RES_CONST_RGBA:
|
797
|
926
|
str_res = "CONST_RGBA";
|
|
@@ -813,24 +942,15 @@ PyObject* rpnif_repr(PyObject *self)
|
813
|
942
|
"UNKOWN RES_FLAG2");
|
814
|
943
|
return NULL;
|
815
|
944
|
}
|
816
|
|
-
|
817
|
|
- sz = snprintf(NULL, 0,
|
818
|
|
- "<RPNIterExpr pos_flag:%s res_flag:%s expr_sz:%ld>",
|
819
|
|
- str_pos, str_res, expr_self->rif->params->rpn_sz);
|
820
|
945
|
|
821
|
|
- buff = malloc(sizeof(char) * (sz + 1));
|
822
|
|
- if(!buff)
|
823
|
|
- {
|
824
|
|
- PyErr_Format(PyExc_RuntimeError, "Error allocating RPNIterExpr repr : ",
|
825
|
|
- strerror(errno));
|
826
|
|
- return NULL;
|
827
|
|
- }
|
|
946
|
+ PyObject *res;
|
|
947
|
+
|
|
948
|
+ const_res = const_res?const_res:Py_None;
|
828
|
949
|
|
829
|
|
- sz = snprintf(buff, sz+1,
|
830
|
|
- "<RPNIterExpr pos_flag:%s res_flag:%s expr_sz:%ld>",
|
831
|
|
- str_pos, str_res, expr_self->rif->params->rpn_sz);
|
832
|
|
- PyObject *res = Py_BuildValue("s", buff);
|
833
|
|
- free(buff);
|
|
950
|
+ res = PyUnicode_FromFormat(
|
|
951
|
+ "<RPNIterExpr pos_flag:%s res_flag:%s expr:'%U' const_res:%S>",
|
|
952
|
+ str_pos, str_res, expr_repr, const_res);
|
|
953
|
+ if(PyErr_Occurred()) { return NULL; }
|
834
|
954
|
return res;
|
835
|
955
|
}
|
836
|
956
|
|