~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to pidl/lib/Parse/Pidl/Samba4/Python.pm

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
use Parse::Pidl qw(warning fatal error);
13
13
use Parse::Pidl::Typelist qw(hasType resolveType getType mapTypeName expandAlias);
14
14
use Parse::Pidl::Util qw(has_property ParseExpr unmake_str);
15
 
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred is_charset_array);
 
15
use Parse::Pidl::NDR qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsPipe is_charset_array);
16
16
use Parse::Pidl::CUtil qw(get_value_of get_pointer_to);
17
17
use Parse::Pidl::Samba4 qw(ArrayDynamicallyAllocated);
18
18
use Parse::Pidl::Samba4::Header qw(GenerateFunctionInEnv GenerateFunctionOutEnv EnvSubstituteValue GenerateStructEnv);
24
24
        my ($class) = @_;
25
25
        my $self = { res => "", res_hdr => "", tabs => "", constants => {},
26
26
                     module_methods => [], module_objects => [], ready_types => [],
27
 
                                 module_imports => [], type_imports => {},
28
 
                                 patch_type_calls => [], readycode => [] };
 
27
                                 module_imports => {}, type_imports => {},
 
28
                                 patch_type_calls => [], prereadycode => [],
 
29
                                 postreadycode => []};
29
30
        bless($self, $class);
30
31
}
31
32
 
63
64
{
64
65
        my ($name, $basename) = @_;
65
66
 
 
67
        $basename =~ s/^.*\.([^.]+)$/\1/;
 
68
 
66
69
        $name =~ s/^$basename\_//;
67
70
 
 
71
 
68
72
        return $name;
69
73
}
70
74
 
76
80
                $_ = unmake_str($_);
77
81
                s/\.idl$//;
78
82
                $self->pidl_hdr("#include \"librpc/gen_ndr/$_\.h\"\n");
79
 
                $self->register_module_import($_);
 
83
                $self->register_module_import("samba.dcerpc.$_");
80
84
        }
81
85
}
82
86
 
126
130
                        $self->ConvertObjectToPython($mem_ctx, {}, $e, "$name->$e->{NAME}", "ret", "return NULL;");
127
131
                } else {
128
132
                        $self->pidl("ret = Py_None;");
 
133
                        $self->pidl("Py_INCREF(ret);");
129
134
                }
130
135
 
131
136
                $self->pidl("return ret;");
213
218
                        if ($l->{TYPE} eq "POINTER" and 
214
219
                                not ($nl->{TYPE} eq "ARRAY" and ($nl->{IS_FIXED} or is_charset_array($e, $nl))) and
215
220
                                not ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE}))) {
216
 
                                $self->pidl("talloc_free($varname);");
 
221
                                $self->pidl("talloc_unlink(py_talloc_get_mem_ctx(py_obj), $varname);");
217
222
                        }
218
223
                        $self->ConvertObjectFromPython($env, $mem_ctx, $e, "value", $varname, "return -1;");
219
224
                        $self->pidl("return 0;");
253
258
                $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);");
254
259
                $self->pidl("DATA_BLOB blob;");
255
260
                $self->pidl("enum ndr_err_code err;");
256
 
                $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_push_flags_fn_t)ndr_push_$name);");
 
261
                $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_push_flags_fn_t)ndr_push_$name);");
257
262
                $self->pidl("if (err != NDR_ERR_SUCCESS) {");
258
263
                $self->indent;
259
264
                $self->pidl("PyErr_SetNdrError(err);");
275
280
                $self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob.length))");
276
281
                $self->pidl("\treturn NULL;");
277
282
                $self->pidl("");
278
 
 
279
 
                # This disgusting hack works around the fact that ndr_pull_struct_blob_all will always fail on structures with relative pointers.  
280
 
                # So, map ndr_unpack to ndr_pull_struct_blob_all only if we don't have any relative pointers in this
281
 
                my $got_relative = 0;
282
 
                if ($#{$d->{ELEMENTS}} > -1) {
283
 
                        foreach my $e (@{$d->{ELEMENTS}}) {
284
 
                                my $l = $e->{LEVELS}[0];
285
 
                                if ($l->{TYPE} eq "POINTER" and ($l->{POINTER_TYPE} eq "relative")) {
286
 
                                        $got_relative = 1;
287
 
                                        last;
288
 
                                }
289
 
                        }
290
 
                }
291
 
                if ($got_relative == 0) {
292
 
                        $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
293
 
                } else {
294
 
                        $self->pidl("err = ndr_pull_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
295
 
                }
 
283
                $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
296
284
                $self->pidl("if (err != NDR_ERR_SUCCESS) {");
297
285
                $self->indent;
298
286
                $self->pidl("PyErr_SetNdrError(err);");
304
292
                $self->deindent;
305
293
                $self->pidl("}");
306
294
                $self->pidl("");
 
295
 
 
296
                $self->pidl("static PyObject *py_$name\_ndr_print(PyObject *py_obj)");
 
297
                $self->pidl("{");
 
298
                $self->indent;
 
299
                $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);");
 
300
                $self->pidl("PyObject *ret;");
 
301
                $self->pidl("char *retstr;");
 
302
                $self->pidl("");
 
303
                $self->pidl("retstr = ndr_print_struct_string(py_talloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_$name, \"$name\", object);");
 
304
                $self->pidl("ret = PyString_FromString(retstr);");
 
305
                $self->pidl("talloc_free(retstr);");
 
306
                $self->pidl("");
 
307
                $self->pidl("return ret;");
 
308
                $self->deindent;
 
309
                $self->pidl("}");
 
310
                $self->pidl("");
 
311
 
307
312
                $py_methods = "py_$name\_methods";
308
313
                $self->pidl("static PyMethodDef $py_methods\[] = {");
309
314
                $self->indent;
310
 
                $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },");
311
 
                $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },");
 
315
                $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.ndr_pack(object) -> blob\\nNDR pack\" },");
 
316
                $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.ndr_unpack(class, blob) -> None\\nNDR unpack\" },");
 
317
                $self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.ndr_print(object) -> None\\nNDR print\" },");
312
318
                $self->pidl("{ NULL, NULL, 0, NULL }");
313
319
                $self->deindent;
314
320
                $self->pidl("};");
323
329
        $self->indent;
324
330
        $self->pidl("PyObject_HEAD_INIT(NULL) 0,");
325
331
        $self->pidl(".tp_name = \"$modulename.$prettyname\",");
326
 
        $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),");
327
 
        $self->pidl(".tp_dealloc = py_talloc_dealloc,");
328
332
        $self->pidl(".tp_getset = $getsetters,");
329
 
        $self->pidl(".tp_repr = py_talloc_default_repr,");
330
333
        if ($docstring) {
331
334
                $self->pidl(".tp_doc = $docstring,");
332
335
        }
333
336
        $self->pidl(".tp_methods = $py_methods,");
334
337
        $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
 
338
        $self->pidl(".tp_basicsize = sizeof(py_talloc_Object),");
335
339
        $self->pidl(".tp_new = py_$name\_new,");
336
340
        $self->deindent;
337
341
        $self->pidl("};");
338
342
 
339
343
        $self->pidl("");
340
344
 
 
345
        my $talloc_typename = $self->import_type_variable("talloc", "Object");
 
346
        $self->register_module_prereadycode(["$name\_Type.tp_base = $talloc_typename;", ""]);
 
347
 
341
348
        return "&$typeobject";
342
349
}
343
350
 
388
395
        $self->pidl("static PyObject *$outfnname(struct $fn->{NAME} *r)");
389
396
        $self->pidl("{");
390
397
        $self->indent;
391
 
        $self->pidl("PyObject *result = Py_None;");
 
398
        $self->pidl("PyObject *result;");
392
399
        foreach my $e (@{$fn->{ELEMENTS}}) {
393
400
                next unless (grep(/out/,@{$e->{DIRECTION}}));
394
401
                next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or 
407
414
                $self->pidl("result = PyTuple_New($result_size);");
408
415
                $signature .= "(";
409
416
        } elsif ($result_size == 0) {
 
417
                $self->pidl("result = Py_None;");
 
418
                $self->pidl("Py_INCREF(result);");
410
419
                $signature .= "None";
411
420
        }
412
421
 
505
514
                if ($metadata_args->{in}->{$e->{NAME}}) {
506
515
                        my $py_var = "py_".$metadata_args->{in}->{$e->{NAME}};
507
516
                        $self->pidl("PY_CHECK_TYPE(&PyList_Type, $py_var, $fail);");
508
 
                        my $val = "PyList_Size($py_var)";
 
517
                        my $val = "PyList_GET_SIZE($py_var)";
509
518
                        if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") {
510
519
                                $self->pidl("r->in.$e->{NAME} = talloc_ptrtype(r, r->in.$e->{NAME});");
511
520
                                $self->pidl("*r->in.$e->{NAME} = $val;");
530
539
        my $fnname = "py_$fn->{NAME}";
531
540
        my $docstring = $self->DocString($fn, $fn->{NAME});
532
541
 
533
 
        my ($insignature, $outsignature);
534
 
        my ($infn, $outfn);
535
 
 
536
 
        if (has_property($fn, "todo")) {
537
 
                unless ($docstring) { $docstring = "NULL"; }
538
 
                $infn = "NULL";
539
 
                $outfn = "NULL";
 
542
        my ($infn, $insignature) = $self->PythonFunctionPackIn($fn, $fnname);
 
543
        my ($outfn, $outsignature) = $self->PythonFunctionUnpackOut($fn, $fnname);
 
544
        my $signature = "S.$prettyname($insignature) -> $outsignature";
 
545
        if ($docstring) {
 
546
                $docstring = "\"$signature\\n\\n\"$docstring";
540
547
        } else {
541
 
                ($infn, $insignature) = $self->PythonFunctionPackIn($fn, $fnname);
542
 
                ($outfn, $outsignature) = $self->PythonFunctionUnpackOut($fn, $fnname);
543
 
                my $signature = "S.$prettyname($insignature) -> $outsignature";
544
 
                if ($docstring) {
545
 
                        $docstring = "\"$signature\\n\\n\"$docstring";
546
 
                } else {
547
 
                        $docstring = "\"$signature\"";
548
 
                }
 
548
                $docstring = "\"$signature\"";
549
549
        }
550
550
 
551
551
        return ($infn, $outfn, $docstring);
663
663
                my @fns = ();
664
664
 
665
665
                foreach my $d (@{$interface->{FUNCTIONS}}) {
666
 
                        next if not defined($d->{OPNUM});
 
666
                        next if has_property($d, "noopnum");
667
667
                        next if has_property($d, "nopython");
 
668
                        next if has_property($d, "todo");
 
669
 
 
670
                        my $skip = 0;
 
671
                        foreach my $e (@{$d->{ELEMENTS}}) {
 
672
                                if (ContainsPipe($e, $e->{LEVELS}[0])) {
 
673
                                        $skip = 1;
 
674
                                        last;
 
675
                                }
 
676
                        }
 
677
                        next if $skip;
668
678
 
669
679
                        my $prettyname = $d->{NAME};
670
680
 
673
683
 
674
684
                        my ($infn, $outfn, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}, $prettyname);
675
685
 
676
 
                        push (@fns, [$infn, $outfn, "dcerpc_$d->{NAME}", $prettyname, $fndocstring, $d->{OPNUM}]);
 
686
                        push (@fns, [$infn, $outfn, "dcerpc_$d->{NAME}_r", $prettyname, $fndocstring, $d->{OPNUM}]);
677
687
                }
678
688
 
679
689
                $self->pidl("const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[] = {");
680
690
                $self->indent;
681
691
                foreach my $d (@fns) {
682
692
                        my ($infn, $outfn, $callfn, $prettyname, $docstring, $opnum) = @$d;
683
 
                        $self->pidl("{ \"$prettyname\", $docstring, (dcerpc_call_fn)$callfn, (py_data_pack_fn)$infn, (py_data_unpack_fn)$outfn, $opnum, &ndr_table_$interface->{NAME} },");
 
693
                        $self->pidl("{ \"$prettyname\", $docstring, (py_dcerpc_call_fn)$callfn, (py_data_pack_fn)$infn, (py_data_unpack_fn)$outfn, $opnum, &ndr_table_$interface->{NAME} },");
684
694
                }
685
695
                $self->pidl("{ NULL }");
686
696
                $self->deindent;
711
721
                        $docstring = $signature;
712
722
                }
713
723
 
714
 
                $self->pidl("static PyTypeObject $interface->{NAME}_InterfaceType = {");
 
724
                my $if_typename = "$interface->{NAME}_InterfaceType";
 
725
 
 
726
                $self->pidl("static PyTypeObject $if_typename = {");
715
727
                $self->indent;
716
728
                $self->pidl("PyObject_HEAD_INIT(NULL) 0,");
717
729
                $self->pidl(".tp_name = \"$basename.$interface->{NAME}\",");
718
730
                $self->pidl(".tp_basicsize = sizeof(dcerpc_InterfaceObject),");
719
 
                $self->pidl(".tp_base = &dcerpc_InterfaceType,");
720
731
                $self->pidl(".tp_doc = $docstring,");
721
732
                $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
722
733
                $self->pidl(".tp_new = interface_$interface->{NAME}_new,");
725
736
 
726
737
                $self->pidl("");
727
738
 
728
 
                $self->register_module_typeobject($interface->{NAME}, "&$interface->{NAME}_InterfaceType");
729
 
                $self->register_module_readycode(["if (!PyInterface_AddNdrRpcMethods(&$interface->{NAME}_InterfaceType, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]);
 
739
                $self->register_module_typeobject($interface->{NAME}, "&$if_typename");
 
740
                my $dcerpc_typename = $self->import_type_variable("samba.dcerpc.base", "ClientConnection");
 
741
                $self->register_module_prereadycode(["$if_typename.tp_base = $dcerpc_typename;", ""]);
 
742
                $self->register_module_postreadycode(["if (!PyInterface_AddNdrRpcMethods(&$if_typename, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]);
730
743
        }
731
744
 
732
745
        $self->pidl_hdr("\n");
743
756
{
744
757
        my ($self, $name, $py_name) = @_;
745
758
 
746
 
        $self->register_module_object($name, "(PyObject *)$py_name");
 
759
        $self->register_module_object($name, "(PyObject *)(void *)$py_name");
747
760
 
748
761
        $self->check_ready_type($py_name);
749
762
 
758
771
 
759
772
sub register_module_import($$)
760
773
{
761
 
        my ($self, $basename) = @_;
762
 
 
763
 
        push (@{$self->{module_imports}}, $basename) unless (grep(/^$basename$/,@{$self->{module_imports}}));
 
774
        my ($self, $module_path) = @_;
 
775
 
 
776
        my $var_name = $module_path;
 
777
        $var_name =~ s/\./_/g;
 
778
        $var_name = "dep_$var_name";
 
779
 
 
780
        $self->{module_imports}->{$var_name} = $module_path;
 
781
 
 
782
        return $var_name;
 
783
}
 
784
 
 
785
sub import_type_variable($$$)
 
786
{
 
787
        my ($self, $module, $name) = @_;
 
788
 
 
789
        $self->register_module_import($module);
 
790
        unless (defined($self->{type_imports}->{$name})) {
 
791
                $self->{type_imports}->{$name} = $module;
 
792
        }
 
793
        return "$name\_Type";
764
794
}
765
795
 
766
796
sub use_type_variable($$)
768
798
        my ($self, $orig_ctype) = @_;
769
799
        # FIXME: Have a global lookup table for types that look different on the 
770
800
        # wire than they are named in C?
771
 
        if ($orig_ctype->{NAME} eq "dom_sid2") {
 
801
        if ($orig_ctype->{NAME} eq "dom_sid2" or $orig_ctype->{NAME} eq "dom_sid28") {
772
802
                $orig_ctype->{NAME} = "dom_sid";
773
803
        }
774
804
        my $ctype = resolveType($orig_ctype);
777
807
        }
778
808
        # If this is an external type, make sure we do the right imports.
779
809
        if (($ctype->{BASEFILE} ne $self->{BASENAME})) {
780
 
                $self->register_module_import($ctype->{BASEFILE});
781
 
                unless (defined($self->{type_imports}->{$ctype->{NAME}})) {
782
 
                        $self->{type_imports}->{$ctype->{NAME}} = $ctype->{BASEFILE};
783
 
                }
784
 
                return "$ctype->{NAME}_Type";
 
810
                return $self->import_type_variable("samba.dcerpc.$ctype->{BASEFILE}", $ctype->{NAME});
785
811
        }
786
812
        return "&$ctype->{NAME}_Type";
787
813
}
794
820
 
795
821
}
796
822
 
797
 
sub register_module_readycode($$)
798
 
{
799
 
        my ($self, $code) = @_;
800
 
 
801
 
        push (@{$self->{readycode}}, @$code);
 
823
sub register_module_prereadycode($$)
 
824
{
 
825
        my ($self, $code) = @_;
 
826
 
 
827
        push (@{$self->{prereadycode}}, @$code);
 
828
}
 
829
 
 
830
sub register_module_postreadycode($$)
 
831
{
 
832
        my ($self, $code) = @_;
 
833
 
 
834
        push (@{$self->{postreadycode}}, @$code);
802
835
}
803
836
 
804
837
sub register_module_object($$$)
814
847
        if ($dest =~ /^\&/ and $src eq "NULL") {
815
848
                $self->pidl("memset($dest, 0, sizeof(" . get_value_of($dest) . "));");
816
849
        } elsif ($dest =~ /^\&/) {
817
 
                $self->pidl("memcpy($dest, $src, sizeof(" . get_value_of($dest) . "));");
 
850
                my $destvar = get_value_of($dest);
 
851
                $self->pidl("$destvar = *$src;");
818
852
        } else {
819
853
                $self->pidl("$dest = $src;");
820
854
        }
833
867
                $actual_ctype = $actual_ctype->{DATA};
834
868
        }
835
869
 
836
 
        if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP" or 
837
 
                $actual_ctype->{TYPE} eq "SCALAR" and (
838
 
                expandAlias($actual_ctype->{NAME}) =~ /^(u?int[0-9]*|hyper|NTTIME|time_t|NTTIME_hyper|NTTIME_1sec|dlong|udlong|udlongr)$/)) {
839
 
                $self->pidl("PY_CHECK_TYPE(&PyInt_Type, $cvar, $fail);");
 
870
        if ($actual_ctype->{TYPE} eq "ENUM" or $actual_ctype->{TYPE} eq "BITMAP") {
 
871
                $self->pidl("if (PyLong_Check($cvar)) {");
 
872
                $self->indent;
 
873
                $self->pidl("$target = PyLong_AsLongLong($cvar);");
 
874
                $self->deindent;
 
875
                $self->pidl("} else if (PyInt_Check($cvar)) {");
 
876
                $self->indent;
840
877
                $self->pidl("$target = PyInt_AsLong($cvar);");
 
878
                $self->deindent;
 
879
                $self->pidl("} else {");
 
880
                $self->indent;
 
881
                $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type %s or %s\",\\");
 
882
                $self->pidl("  PyInt_Type.tp_name, PyLong_Type.tp_name);");
 
883
                $self->pidl($fail);
 
884
                $self->deindent;
 
885
                $self->pidl("}");
841
886
                return;
842
887
        }
 
888
        if ($actual_ctype->{TYPE} eq "SCALAR" ) {
 
889
                if (expandAlias($actual_ctype->{NAME}) =~ /^(u?int64|hyper|dlong|udlong|udlongr|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) {
 
890
                        $self->pidl("if (PyLong_Check($cvar)) {");
 
891
                        $self->indent;
 
892
                        $self->pidl("$target = PyLong_AsLongLong($cvar);");
 
893
                        $self->deindent;
 
894
                        $self->pidl("} else if (PyInt_Check($cvar)) {");
 
895
                        $self->indent;
 
896
                        $self->pidl("$target = PyInt_AsLong($cvar);");
 
897
                        $self->deindent;
 
898
                        $self->pidl("} else {");
 
899
                        $self->indent;
 
900
                        $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected type %s or %s\",\\");
 
901
                        $self->pidl("  PyInt_Type.tp_name, PyLong_Type.tp_name);");
 
902
                        $self->pidl($fail);
 
903
                        $self->deindent;
 
904
                        $self->pidl("}");
 
905
                        return;
 
906
                }
 
907
                if (expandAlias($actual_ctype->{NAME}) =~ /^(char|u?int[0-9]*|time_t|uid_t|gid_t)$/) {
 
908
                        $self->pidl("PY_CHECK_TYPE(&PyInt_Type, $cvar, $fail);");
 
909
                        $self->pidl("$target = PyInt_AsLong($cvar);");
 
910
                        return;
 
911
                }
 
912
        }
843
913
 
844
914
        if ($actual_ctype->{TYPE} eq "STRUCT" or $actual_ctype->{TYPE} eq "INTERFACE") {
845
915
                my $ctype_name = $self->use_type_variable($ctype);
846
916
                unless (defined ($ctype_name)) {
847
917
                        error($location, "Unable to determine origin of type `" . mapTypeName($ctype) . "'");
848
 
                        $self->pidl("PyErr_SetString(PyExc_TypeError, \"Can not convert C Type " . mapTypeName($ctype) . " to Python\");");
 
918
                        $self->pidl("PyErr_SetString(PyExc_TypeError, \"Can not convert C Type " . mapTypeName($ctype) . " from Python\");");
849
919
                        return;
850
920
                }
851
921
                $self->pidl("PY_CHECK_TYPE($ctype_name, $cvar, $fail);");
852
 
                $self->assign($target, "py_talloc_get_ptr($cvar)");
 
922
                $self->pidl("if (talloc_reference($mem_ctx, py_talloc_get_mem_ctx($cvar)) == NULL) {");
 
923
                $self->indent;
 
924
                $self->pidl("PyErr_NoMemory();");
 
925
                $self->pidl("$fail");
 
926
                $self->deindent;
 
927
                $self->pidl("}");
 
928
                $self->assign($target, "(".mapTypeName($ctype)." *)py_talloc_get_ptr($cvar)");
853
929
                return;
854
930
        }
855
931
 
856
932
        if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "DATA_BLOB") {
857
 
                $self->pidl("$target = data_blob_talloc($mem_ctx, PyString_AsString($cvar), PyString_Size($cvar));");
 
933
                $self->pidl("$target = data_blob_talloc($mem_ctx, PyString_AS_STRING($cvar), PyString_GET_SIZE($cvar));");
858
934
                return;
859
935
        }
860
936
 
861
937
        if ($actual_ctype->{TYPE} eq "SCALAR" and 
862
938
                ($actual_ctype->{NAME} eq "string" or $actual_ctype->{NAME} eq "nbt_string" or $actual_ctype->{NAME} eq "nbt_name" or $actual_ctype->{NAME} eq "wrepl_nbt_name")) {
863
 
                $self->pidl("$target = talloc_strdup($mem_ctx, PyString_AsString($cvar));");
 
939
                $self->pidl("$target = talloc_strdup($mem_ctx, PyString_AS_STRING($cvar));");
 
940
                return;
 
941
        }
 
942
 
 
943
        if ($actual_ctype->{TYPE} eq "SCALAR" and ($actual_ctype->{NAME} eq "dns_string" or $actual_ctype->{NAME} eq "dns_name")) {
 
944
                $self->pidl("$target = talloc_strdup($mem_ctx, PyString_AS_STRING($cvar));");
864
945
                return;
865
946
        }
866
947
 
867
948
        if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv4address") {
 
949
                $self->pidl("$target = PyString_AS_STRING($cvar);");
 
950
                return;
 
951
        }
 
952
 
 
953
        if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "ipv6address") {
868
954
                $self->pidl("$target = PyString_AsString($cvar);");
869
955
                return;
870
 
                }
871
 
 
 
956
        }
 
957
 
 
958
        if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "dnsp_name") {
 
959
                $self->pidl("$target = PyString_AS_STRING($cvar);");
 
960
                return;
 
961
        }
 
962
 
 
963
        if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "dnsp_string") {
 
964
                $self->pidl("$target = PyString_AS_STRING($cvar);");
 
965
                return;
 
966
        }
872
967
 
873
968
        if ($actual_ctype->{TYPE} eq "SCALAR" and $actual_ctype->{NAME} eq "NTSTATUS") {
874
969
                $self->pidl("$target = NT_STATUS(PyInt_AsLong($cvar));");
898
993
{
899
994
        my ($self, $env, $mem_ctx, $py_var, $e, $l, $var_name, $fail) = @_;
900
995
        my $nl = GetNextLevel($e, $l);
 
996
        if ($nl and $nl->{TYPE} eq "SUBCONTEXT") {
 
997
                $nl = GetNextLevel($e, $nl);
 
998
        }
 
999
        my $pl = GetPrevLevel($e, $l);
 
1000
        if ($pl and $pl->{TYPE} eq "SUBCONTEXT") {
 
1001
                $pl = GetPrevLevel($e, $pl);
 
1002
        }
901
1003
 
902
1004
        if ($l->{TYPE} eq "POINTER") {
903
 
                if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) {
904
 
                        $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, $var_name, $fail);
905
 
                        return;
906
 
                }
907
1005
                if ($l->{POINTER_TYPE} ne "ref") {
908
1006
                        $self->pidl("if ($py_var == Py_None) {");
909
1007
                        $self->indent;
912
1010
                        $self->pidl("} else {");
913
1011
                        $self->indent;
914
1012
                }
915
 
                $self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);");
916
 
                $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, get_value_of($var_name), $fail);
 
1013
                # if we want to handle more than one level of pointer in python interfaces
 
1014
                # then this is where we would need to allocate it
 
1015
                if ($l->{POINTER_TYPE} eq "ref") {
 
1016
                        $self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);");
 
1017
                } elsif ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::is_scalar($nl->{DATA_TYPE})
 
1018
                         and not Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) {
 
1019
                        $self->pidl("$var_name = talloc_ptrtype($mem_ctx, $var_name);");
 
1020
                } else {
 
1021
                        $self->pidl("$var_name = NULL;");
 
1022
                }
 
1023
                unless ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) {
 
1024
                        $var_name = get_value_of($var_name);
 
1025
                }
 
1026
                $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, $var_name, $fail);
917
1027
                if ($l->{POINTER_TYPE} ne "ref") {
918
1028
                        $self->deindent;
919
1029
                        $self->pidl("}");
920
1030
                }
921
1031
        } elsif ($l->{TYPE} eq "ARRAY") {
922
 
                my $pl = GetPrevLevel($e, $l);
923
1032
                if ($pl && $pl->{TYPE} eq "POINTER") {
924
1033
                        $var_name = get_pointer_to($var_name);
925
1034
                }
926
1035
 
927
1036
                if (is_charset_array($e, $l)) {
928
 
                        $self->pidl("PY_CHECK_TYPE(&PyUnicode_Type, $py_var, $fail);");
 
1037
                        $self->pidl("if (PyUnicode_Check($py_var)) {");
 
1038
                        $self->indent;
929
1039
                        # FIXME: Use Unix charset setting rather than utf-8
930
 
                        $self->pidl($var_name . " = PyString_AsString(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));");
 
1040
                        $self->pidl($var_name . " = PyString_AS_STRING(PyUnicode_AsEncodedString($py_var, \"utf-8\", \"ignore\"));");
 
1041
                        $self->deindent;
 
1042
                        $self->pidl("} else if (PyString_Check($py_var)) {");
 
1043
                        $self->indent;
 
1044
                        $self->pidl($var_name . " = PyString_AS_STRING($py_var);");
 
1045
                        $self->deindent;
 
1046
                        $self->pidl("} else {");
 
1047
                        $self->indent;
 
1048
                        $self->pidl("PyErr_Format(PyExc_TypeError, \"Expected string or unicode object, got %s\", Py_TYPE($py_var)->tp_name);");
 
1049
                        $self->pidl("$fail");
 
1050
                        $self->deindent;
 
1051
                        $self->pidl("}");
931
1052
                } else {
932
1053
                        my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}";
933
1054
                        $self->pidl("PY_CHECK_TYPE(&PyList_Type, $py_var, $fail);");
935
1056
                        $self->indent;
936
1057
                        $self->pidl("int $counter;");
937
1058
                        if (ArrayDynamicallyAllocated($e, $l)) {
938
 
                                $self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_Size($py_var));");
 
1059
                                $self->pidl("$var_name = talloc_array_ptrtype($mem_ctx, $var_name, PyList_GET_SIZE($py_var));");
 
1060
                                $self->pidl("if (!$var_name) { $fail; }");
 
1061
                                $self->pidl("talloc_set_name_const($var_name, \"ARRAY: $var_name\");");
939
1062
                        }
940
 
                        $self->pidl("for ($counter = 0; $counter < PyList_Size($py_var); $counter++) {");
 
1063
                        $self->pidl("for ($counter = 0; $counter < PyList_GET_SIZE($py_var); $counter++) {");
941
1064
                        $self->indent;
942
 
                        $self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GetItem($py_var, $counter)", $e, GetNextLevel($e, $l), $var_name."[$counter]", $fail);
 
1065
                        $self->ConvertObjectFromPythonLevel($env, $var_name, "PyList_GET_ITEM($py_var, $counter)", $e, $nl, $var_name."[$counter]", $fail);
943
1066
                        $self->deindent;
944
1067
                        $self->pidl("}");
945
1068
                        $self->deindent;
946
1069
                        $self->pidl("}");
947
1070
                }
948
1071
        } elsif ($l->{TYPE} eq "DATA") {
949
 
 
950
1072
                if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) {
951
1073
                        $var_name = get_pointer_to($var_name);
952
1074
                }
954
1076
        } elsif ($l->{TYPE} eq "SWITCH") {
955
1077
                $var_name = get_pointer_to($var_name);
956
1078
                my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e);
957
 
                $self->assign($var_name, "py_export_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $py_var)");
 
1079
                my $switch_ptr = "$e->{NAME}_switch_$l->{LEVEL_INDEX}";
 
1080
                $self->pidl("{");
 
1081
                $self->indent;
 
1082
                my $union_type = mapTypeName($nl->{DATA_TYPE});
 
1083
                $self->pidl("$union_type *$switch_ptr;");
 
1084
                $self->pidl("$switch_ptr = py_export_" . $nl->{DATA_TYPE} . "($mem_ctx, $switch, $py_var);");
 
1085
                $self->fail_on_null($switch_ptr, $fail);
 
1086
                $self->assign($var_name, "$switch_ptr");
 
1087
                $self->deindent;
 
1088
                $self->pidl("}");
958
1089
        } elsif ($l->{TYPE} eq "SUBCONTEXT") {
959
 
                $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail);
 
1090
                $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, $nl, $var_name, $fail);
960
1091
        } else {
961
1092
                fatal($e->{ORIGINAL}, "unknown level type $l->{TYPE}");
962
1093
        }
977
1108
 
978
1109
        $ctypename = expandAlias($ctypename);
979
1110
 
980
 
        if ($ctypename =~ /^(char|u?int[0-9]*|hyper|dlong|udlong|udlongr|time_t|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) {
 
1111
        if ($ctypename =~ /^(u?int64|hyper|dlong|udlong|udlongr|NTTIME_hyper|NTTIME|NTTIME_1sec)$/) {
 
1112
                return "PyLong_FromLongLong($cvar)";
 
1113
        }
 
1114
 
 
1115
        if ($ctypename =~ /^(char|u?int[0-9]*|time_t|uid_t|gid_t)$/) {
981
1116
                return "PyInt_FromLong($cvar)";
982
1117
        }
983
1118
 
994
1129
        }
995
1130
 
996
1131
        if (($ctypename eq "string" or $ctypename eq "nbt_string" or $ctypename eq "nbt_name" or $ctypename eq "wrepl_nbt_name")) {
997
 
                return "PyString_FromString($cvar)";
 
1132
                return "PyString_FromStringOrNULL($cvar)";
 
1133
        }
 
1134
 
 
1135
        if (($ctypename eq "dns_string" or $ctypename eq "dns_name")) {
 
1136
                return "PyString_FromStringOrNULL($cvar)";
998
1137
        }
999
1138
 
1000
1139
        # Not yet supported
1001
1140
        if ($ctypename eq "string_array") { return "PyCObject_FromTallocPtr($cvar)"; }
1002
 
        if ($ctypename eq "ipv4address") { return "PyString_FromString($cvar)"; }
 
1141
        if ($ctypename eq "ipv4address") { return "PyString_FromStringOrNULL($cvar)"; }
 
1142
        if ($ctypename eq "ipv6address") { return "PyString_FromStringOrNULL($cvar)"; }
 
1143
        if ($ctypename eq "dnsp_name") { return "PyString_FromStringOrNULL($cvar)"; }
 
1144
        if ($ctypename eq "dnsp_string") { return "PyString_FromStringOrNULL($cvar)"; }
1003
1145
        if ($ctypename eq "pointer") {
1004
1146
                return "PyCObject_FromTallocPtr($cvar)";
1005
1147
        }
1054
1196
{
1055
1197
        my ($self, $mem_ctx, $env, $e, $l, $var_name, $py_var, $fail) = @_;
1056
1198
        my $nl = GetNextLevel($e, $l);
 
1199
        if ($nl and $nl->{TYPE} eq "SUBCONTEXT") {
 
1200
                $nl = GetNextLevel($e, $nl);
 
1201
        }
 
1202
        my $pl = GetPrevLevel($e, $l);
 
1203
        if ($pl and $pl->{TYPE} eq "SUBCONTEXT") {
 
1204
                $pl = GetPrevLevel($e, $pl);
 
1205
        }
1057
1206
 
1058
1207
        if ($l->{TYPE} eq "POINTER") {
1059
 
                if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) {
1060
 
                        $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, $var_name, $py_var, $fail);
1061
 
                        return;
1062
 
                }
1063
1208
                if ($l->{POINTER_TYPE} ne "ref") {
1064
1209
                        $self->pidl("if ($var_name == NULL) {");
1065
1210
                        $self->indent;
1066
1211
                        $self->pidl("$py_var = Py_None;");
 
1212
                        $self->pidl("Py_INCREF($py_var);");
1067
1213
                        $self->deindent;
1068
1214
                        $self->pidl("} else {");
1069
1215
                        $self->indent;
1070
1216
                }
1071
 
                $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, get_value_of($var_name), $py_var, $fail);
 
1217
                my $var_name2 = $var_name;
 
1218
                unless ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) {
 
1219
                        $var_name2 = get_value_of($var_name);
 
1220
                }
 
1221
                $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, $var_name2, $py_var, $fail);
1072
1222
                if ($l->{POINTER_TYPE} ne "ref") {
1073
1223
                        $self->deindent;
1074
1224
                        $self->pidl("}");
1075
1225
                }
1076
1226
        } elsif ($l->{TYPE} eq "ARRAY") {
1077
 
                my $pl = GetPrevLevel($e, $l);
1078
1227
                if ($pl && $pl->{TYPE} eq "POINTER") {
1079
1228
                        $var_name = get_pointer_to($var_name);
1080
1229
                }
1081
1230
 
1082
1231
                if (is_charset_array($e, $l)) {
1083
1232
                        # FIXME: Use Unix charset setting rather than utf-8
 
1233
                        $self->pidl("if ($var_name == NULL) {");
 
1234
                        $self->indent;
 
1235
                        $self->pidl("$py_var = Py_None;");
 
1236
                        $self->pidl("Py_INCREF($py_var);");
 
1237
                        $self->deindent;
 
1238
                        $self->pidl("} else {");
 
1239
                        $self->indent;
1084
1240
                        $self->pidl("$py_var = PyUnicode_Decode($var_name, strlen($var_name), \"utf-8\", \"ignore\");");
 
1241
                        $self->deindent;
 
1242
                        $self->pidl("}");
1085
1243
                } else {
1086
1244
                        die("No SIZE_IS for array $var_name") unless (defined($l->{SIZE_IS}));
1087
1245
                        my $length = $l->{SIZE_IS};
1100
1258
                        $self->indent;
1101
1259
                        my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}";
1102
1260
                        $self->pidl("PyObject *$member_var;");
1103
 
                        $self->ConvertObjectToPythonLevel($var_name, $env, $e, GetNextLevel($e, $l), $var_name."[$counter]", $member_var, $fail);
 
1261
                        $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, $var_name."[$counter]", $member_var, $fail);
1104
1262
                        $self->pidl("PyList_SetItem($py_var, $counter, $member_var);");
1105
1263
                        $self->deindent;
1106
1264
                        $self->pidl("}");
1110
1268
        } elsif ($l->{TYPE} eq "SWITCH") {
1111
1269
                $var_name = get_pointer_to($var_name);
1112
1270
                my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e);
1113
 
                $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);");
 
1271
                $self->pidl("$py_var = py_import_" . $nl->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);");
1114
1272
                $self->fail_on_null($py_var, $fail);
1115
1273
 
1116
1274
        } elsif ($l->{TYPE} eq "DATA") {
1120
1278
                my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name, $e->{ORIGINAL});
1121
1279
                $self->pidl("$py_var = $conv;");
1122
1280
        } elsif ($l->{TYPE} eq "SUBCONTEXT") {
1123
 
                $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var, $fail);
 
1281
                $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, $nl, $var_name, $py_var, $fail);
1124
1282
        } else {
1125
1283
                fatal($e->{ORIGINAL}, "Unknown level type $l->{TYPE} $var_name");
1126
1284
        }
1141
1299
 
1142
1300
    $self->pidl_hdr("
1143
1301
/* Python wrapper functions auto-generated by pidl */
 
1302
#include <Python.h>
1144
1303
#include \"includes.h\"
1145
 
#include <Python.h>
1146
 
#include \"librpc/rpc/dcerpc.h\"
1147
 
#include \"lib/talloc/pytalloc.h\"
 
1304
#include <pytalloc.h>
1148
1305
#include \"librpc/rpc/pyrpc.h\"
 
1306
#include \"librpc/rpc/pyrpc_util.h\"
1149
1307
#include \"$hdr\"
1150
1308
#include \"$ndr_hdr\"
1151
1309
 
1152
 
#ifndef Py_RETURN_NONE
1153
 
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
1154
 
#endif
1155
 
 
1156
1310
");
1157
1311
 
1158
1312
        foreach my $x (@$ndr) {
1173
1327
 
1174
1328
        $self->pidl("");
1175
1329
 
 
1330
        $self->pidl_hdr("void init$basename(void);");
1176
1331
        $self->pidl("void init$basename(void)");
1177
1332
        $self->pidl("{");
1178
1333
        $self->indent;
1179
1334
        $self->pidl("PyObject *m;");
1180
 
        foreach (@{$self->{module_imports}}) {
1181
 
                $self->pidl("PyObject *dep_$_;");
 
1335
        foreach (keys %{$self->{module_imports}}) {
 
1336
                $self->pidl("PyObject *$_;");
1182
1337
        }
1183
1338
        $self->pidl("");
1184
1339
 
1185
 
        foreach (@{$self->{module_imports}}) {
1186
 
                $self->pidl("dep_$_ = PyImport_ImportModule(\"samba.dcerpc.$_\");");
1187
 
                $self->pidl("if (dep_$_ == NULL)");
 
1340
        foreach (keys %{$self->{module_imports}}) {
 
1341
                my $var_name = $_;
 
1342
                my $module_path = $self->{module_imports}->{$var_name};
 
1343
                $self->pidl("$var_name = PyImport_ImportModule(\"$module_path\");");
 
1344
                $self->pidl("if ($var_name == NULL)");
1188
1345
                $self->pidl("\treturn;");
1189
1346
                $self->pidl("");
1190
1347
        }
1191
1348
 
1192
1349
        foreach (keys %{$self->{type_imports}}) {
1193
 
                my $basefile = $self->{type_imports}->{$_};
1194
 
                $self->pidl_hdr("static PyTypeObject *$_\_Type;\n");
1195
 
                my $pretty_name = PrettifyTypeName($_, $basefile);
1196
 
                $self->pidl("$_\_Type = (PyTypeObject *)PyObject_GetAttrString(dep_$basefile, \"$pretty_name\");");
1197
 
                $self->pidl("if ($_\_Type == NULL)");
 
1350
                my $type_var = "$_\_Type";
 
1351
                my $module_path = $self->{type_imports}->{$_};
 
1352
                $self->pidl_hdr("static PyTypeObject *$type_var;\n");
 
1353
                my $pretty_name = PrettifyTypeName($_, $module_path);
 
1354
                my $module_var = "dep_$module_path";
 
1355
                $module_var =~ s/\./_/g;
 
1356
                $self->pidl("$type_var = (PyTypeObject *)PyObject_GetAttrString($module_var, \"$pretty_name\");");
 
1357
                $self->pidl("if ($type_var == NULL)");
1198
1358
                $self->pidl("\treturn;");
1199
1359
                $self->pidl("");
1200
1360
        }
1201
1361
 
 
1362
        $self->pidl($_) foreach (@{$self->{prereadycode}});
 
1363
 
1202
1364
        foreach (@{$self->{ready_types}}) {
1203
1365
                $self->pidl("if (PyType_Ready($_) < 0)");
1204
1366
                $self->pidl("\treturn;");
1205
1367
        }
1206
1368
 
1207
 
        $self->pidl($_) foreach (@{$self->{readycode}});
 
1369
        $self->pidl($_) foreach (@{$self->{postreadycode}});
1208
1370
 
1209
1371
        foreach (@{$self->{patch_type_calls}}) {
1210
1372
                my ($typename, $cvar) = @$_;